// Tiled 导出 JSON 的读取辅助（CONTRACT §3）。

export interface TiledObj {
  name: string;
  x: number;
  y: number;
  properties?: { name: string; type: string; value: unknown }[];
}

export type Props = Record<string, string | number | boolean>;

export function propsOf(obj: { properties?: { name: string; value: unknown }[] }): Props {
  const out: Props = {};
  if (Array.isArray(obj.properties)) {
    for (const p of obj.properties) out[p.name] = p.value as string | number | boolean;
  }
  return out;
}

export function strProp(p: Props, key: string, fallback = ''): string {
  const v = p[key];
  return v === undefined ? fallback : String(v);
}
