@flare-engine/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,235 @@
1
+ // src/pack-atlas.ts
2
+ import { mkdir, readFile, readdir, writeFile } from "fs/promises";
3
+ import { basename, extname, isAbsolute, join, resolve } from "path";
4
+ import { MaxRectsPacker } from "maxrects-packer";
5
+ import sharp from "sharp";
6
+ function absPath(p) {
7
+ return isAbsolute(p) ? p : resolve(process.cwd(), p);
8
+ }
9
+ async function listPngs(dir) {
10
+ const entries = await readdir(dir, { withFileTypes: true });
11
+ const result = [];
12
+ for (const e of entries) {
13
+ if (!e.isFile()) continue;
14
+ if (extname(e.name).toLowerCase() === ".png") result.push(join(dir, e.name));
15
+ }
16
+ result.sort();
17
+ return result;
18
+ }
19
+ async function readSprite(path) {
20
+ const meta = await sharp(path).metadata();
21
+ if (!meta.width || !meta.height) {
22
+ throw new Error(`[pack-atlas] unable to read dimensions for ${path}`);
23
+ }
24
+ return {
25
+ name: basename(path, extname(path)),
26
+ path,
27
+ width: meta.width,
28
+ height: meta.height
29
+ };
30
+ }
31
+ async function packAtlas(opts) {
32
+ const inputDir = absPath(opts.input);
33
+ const outDir = absPath(opts.out ?? opts.input);
34
+ const name = opts.name ?? "atlas";
35
+ const padding = opts.padding ?? 2;
36
+ const maxSize = opts.maxSize ?? 2048;
37
+ const format = opts.format ?? "png";
38
+ await mkdir(outDir, { recursive: true });
39
+ const files = await listPngs(inputDir);
40
+ if (files.length === 0) {
41
+ throw new Error(`[pack-atlas] no .png files found in ${inputDir}`);
42
+ }
43
+ const sprites = [];
44
+ for (const f of files) sprites.push(await readSprite(f));
45
+ const packer = new MaxRectsPacker(maxSize, maxSize, padding, {
46
+ smart: true,
47
+ pot: false,
48
+ square: false,
49
+ allowRotation: false,
50
+ tag: false,
51
+ border: 0
52
+ });
53
+ for (const s of sprites) packer.add(s.width, s.height, s);
54
+ if (packer.bins.length !== 1) {
55
+ throw new Error(
56
+ `[pack-atlas] sprites do not fit in a single ${maxSize}x${maxSize} atlas (got ${packer.bins.length} bins)`
57
+ );
58
+ }
59
+ const bin = packer.bins[0];
60
+ if (!bin) throw new Error("[pack-atlas] packing produced no bin");
61
+ const atlasWidth = bin.width;
62
+ const atlasHeight = bin.height;
63
+ const frames = [];
64
+ const composites = [];
65
+ for (const rect of bin.rects) {
66
+ const sprite = rect.data;
67
+ const buf = await readFile(sprite.path);
68
+ composites.push({ input: buf, left: rect.x, top: rect.y });
69
+ frames.push({
70
+ name: sprite.name,
71
+ x: rect.x,
72
+ y: rect.y,
73
+ w: sprite.width,
74
+ h: sprite.height
75
+ });
76
+ }
77
+ frames.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
78
+ const imageName = `${name}.${format}`;
79
+ const jsonName = `${name}.json`;
80
+ const imagePath = join(outDir, imageName);
81
+ const jsonPath = join(outDir, jsonName);
82
+ let pipeline = sharp({
83
+ create: {
84
+ width: atlasWidth,
85
+ height: atlasHeight,
86
+ channels: 4,
87
+ background: { r: 0, g: 0, b: 0, alpha: 0 }
88
+ }
89
+ }).composite(composites);
90
+ pipeline = format === "webp" ? pipeline.webp() : pipeline.png();
91
+ await pipeline.toFile(imagePath);
92
+ const jsonFrames = {};
93
+ for (const f of frames) {
94
+ jsonFrames[f.name] = { frame: { x: f.x, y: f.y, w: f.w, h: f.h } };
95
+ }
96
+ const jsonDoc = {
97
+ frames: jsonFrames,
98
+ meta: {
99
+ app: "@flare-engine/cli",
100
+ version: "1.0",
101
+ image: imageName,
102
+ format: "RGBA8888",
103
+ size: { w: atlasWidth, h: atlasHeight },
104
+ scale: "1"
105
+ }
106
+ };
107
+ await writeFile(jsonPath, `${JSON.stringify(jsonDoc, null, 2)}
108
+ `, "utf8");
109
+ return {
110
+ jsonPath,
111
+ imagePath,
112
+ frames,
113
+ width: atlasWidth,
114
+ height: atlasHeight
115
+ };
116
+ }
117
+
118
+ // src/tiled-to-flare.ts
119
+ import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
120
+ import { dirname, isAbsolute as isAbsolute2, join as join2, resolve as resolve2 } from "path";
121
+ function absPath2(p, base) {
122
+ return isAbsolute2(p) ? p : resolve2(base, p);
123
+ }
124
+ function propsToRecord(props) {
125
+ const out = {};
126
+ if (!props) return out;
127
+ for (const p of props) out[p.name] = p.value;
128
+ return out;
129
+ }
130
+ async function resolveTileset(ref, mapDir, embed) {
131
+ let data = ref;
132
+ if (ref.source && embed) {
133
+ const srcPath = absPath2(ref.source, mapDir);
134
+ const raw = await readFile2(srcPath, "utf8");
135
+ const external = JSON.parse(raw);
136
+ data = { ...external, firstgid: ref.firstgid };
137
+ }
138
+ return {
139
+ name: data.name ?? "tileset",
140
+ firstgid: data.firstgid,
141
+ tilewidth: data.tilewidth ?? 0,
142
+ tileheight: data.tileheight ?? 0,
143
+ columns: data.columns ?? 0,
144
+ tilecount: data.tilecount ?? 0,
145
+ image: data.image ?? "",
146
+ imagewidth: data.imagewidth ?? 0,
147
+ imageheight: data.imageheight ?? 0
148
+ };
149
+ }
150
+ function flattenLayers(layers) {
151
+ const out = [];
152
+ const walk = (ls) => {
153
+ for (const l of ls) {
154
+ if (l.type === "group") {
155
+ const inner = l.layers;
156
+ if (inner) walk(inner);
157
+ } else {
158
+ out.push(l);
159
+ }
160
+ }
161
+ };
162
+ walk(layers);
163
+ return out;
164
+ }
165
+ function convertLayer(layer) {
166
+ const visible = layer.visible !== false;
167
+ const opacity = typeof layer.opacity === "number" ? layer.opacity : 1;
168
+ if (layer.type === "tilelayer") {
169
+ const tile = {
170
+ kind: "tile",
171
+ name: layer.name,
172
+ width: layer.width ?? 0,
173
+ height: layer.height ?? 0,
174
+ data: layer.data ?? [],
175
+ visible,
176
+ opacity
177
+ };
178
+ return tile;
179
+ }
180
+ if (layer.type === "objectgroup") {
181
+ const objects = (layer.objects ?? []).map((o) => ({
182
+ id: o.id,
183
+ name: o.name ?? "",
184
+ type: o.type ?? o.class ?? "",
185
+ x: o.x,
186
+ y: o.y,
187
+ width: o.width,
188
+ height: o.height,
189
+ properties: propsToRecord(o.properties)
190
+ }));
191
+ const obj = {
192
+ kind: "object",
193
+ name: layer.name,
194
+ objects,
195
+ visible,
196
+ opacity
197
+ };
198
+ return obj;
199
+ }
200
+ return null;
201
+ }
202
+ async function convertTiled(opts) {
203
+ const inputPath = absPath2(opts.input, process.cwd());
204
+ const outPath = opts.out ? absPath2(opts.out, process.cwd()) : join2(dirname(inputPath), `${inputPath.replace(/\.tmj$|\.json$/i, "")}.flare.json`);
205
+ const embed = opts.embedTilesets !== false;
206
+ const raw = await readFile2(inputPath, "utf8");
207
+ const parsed = JSON.parse(raw);
208
+ const mapDir = dirname(inputPath);
209
+ const tilesets = [];
210
+ for (const ref of parsed.tilesets ?? []) {
211
+ tilesets.push(await resolveTileset(ref, mapDir, embed));
212
+ }
213
+ const layers = [];
214
+ for (const l of flattenLayers(parsed.layers ?? [])) {
215
+ const converted = convertLayer(l);
216
+ if (converted) layers.push(converted);
217
+ }
218
+ const map = {
219
+ width: parsed.width,
220
+ height: parsed.height,
221
+ tilewidth: parsed.tilewidth,
222
+ tileheight: parsed.tileheight,
223
+ tilesets,
224
+ layers
225
+ };
226
+ await writeFile2(outPath, `${JSON.stringify(map, null, 2)}
227
+ `, "utf8");
228
+ return { outPath, layers, tilesets, map };
229
+ }
230
+
231
+ export {
232
+ packAtlas,
233
+ convertTiled
234
+ };
235
+ //# sourceMappingURL=chunk-SUMZ7TVL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/pack-atlas.ts","../src/tiled-to-flare.ts"],"sourcesContent":["import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises';\nimport { basename, extname, isAbsolute, join, resolve } from 'node:path';\nimport { MaxRectsPacker } from 'maxrects-packer';\nimport sharp from 'sharp';\nimport type { AtlasFrame, AtlasPackerOptions, AtlasResult } from './types.js';\n\ninterface SpriteInput {\n name: string;\n path: string;\n width: number;\n height: number;\n}\n\nfunction absPath(p: string): string {\n return isAbsolute(p) ? p : resolve(process.cwd(), p);\n}\n\nasync function listPngs(dir: string): Promise<string[]> {\n const entries = await readdir(dir, { withFileTypes: true });\n const result: string[] = [];\n for (const e of entries) {\n if (!e.isFile()) continue;\n if (extname(e.name).toLowerCase() === '.png') result.push(join(dir, e.name));\n }\n result.sort();\n return result;\n}\n\nasync function readSprite(path: string): Promise<SpriteInput> {\n const meta = await sharp(path).metadata();\n if (!meta.width || !meta.height) {\n throw new Error(`[pack-atlas] unable to read dimensions for ${path}`);\n }\n return {\n name: basename(path, extname(path)),\n path,\n width: meta.width,\n height: meta.height,\n };\n}\n\n/**\n * Pack a directory of PNG sprites into a single TexturePacker-compatible\n * atlas (JSON + image) consumable by `@flare-engine/assets`.\n */\nexport async function packAtlas(opts: AtlasPackerOptions): Promise<AtlasResult> {\n const inputDir = absPath(opts.input);\n const outDir = absPath(opts.out ?? opts.input);\n const name = opts.name ?? 'atlas';\n const padding = opts.padding ?? 2;\n const maxSize = opts.maxSize ?? 2048;\n const format = opts.format ?? 'png';\n\n await mkdir(outDir, { recursive: true });\n\n const files = await listPngs(inputDir);\n if (files.length === 0) {\n throw new Error(`[pack-atlas] no .png files found in ${inputDir}`);\n }\n\n const sprites: SpriteInput[] = [];\n for (const f of files) sprites.push(await readSprite(f));\n\n const packer = new MaxRectsPacker(maxSize, maxSize, padding, {\n smart: true,\n pot: false,\n square: false,\n allowRotation: false,\n tag: false,\n border: 0,\n });\n for (const s of sprites) packer.add(s.width, s.height, s);\n\n if (packer.bins.length !== 1) {\n throw new Error(\n `[pack-atlas] sprites do not fit in a single ${maxSize}x${maxSize} atlas (got ${packer.bins.length} bins)`,\n );\n }\n const bin = packer.bins[0];\n if (!bin) throw new Error('[pack-atlas] packing produced no bin');\n\n const atlasWidth = bin.width;\n const atlasHeight = bin.height;\n\n const frames: AtlasFrame[] = [];\n const composites: { input: Buffer; left: number; top: number }[] = [];\n\n for (const rect of bin.rects) {\n const sprite = rect.data as SpriteInput;\n const buf = await readFile(sprite.path);\n composites.push({ input: buf, left: rect.x, top: rect.y });\n frames.push({\n name: sprite.name,\n x: rect.x,\n y: rect.y,\n w: sprite.width,\n h: sprite.height,\n });\n }\n frames.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n\n const imageName = `${name}.${format}`;\n const jsonName = `${name}.json`;\n const imagePath = join(outDir, imageName);\n const jsonPath = join(outDir, jsonName);\n\n let pipeline = sharp({\n create: {\n width: atlasWidth,\n height: atlasHeight,\n channels: 4,\n background: { r: 0, g: 0, b: 0, alpha: 0 },\n },\n }).composite(composites);\n pipeline = format === 'webp' ? pipeline.webp() : pipeline.png();\n await pipeline.toFile(imagePath);\n\n // TexturePacker-compatible JSON (hash format).\n const jsonFrames: Record<string, { frame: { x: number; y: number; w: number; h: number } }> = {};\n for (const f of frames) {\n jsonFrames[f.name] = { frame: { x: f.x, y: f.y, w: f.w, h: f.h } };\n }\n const jsonDoc = {\n frames: jsonFrames,\n meta: {\n app: '@flare-engine/cli',\n version: '1.0',\n image: imageName,\n format: 'RGBA8888',\n size: { w: atlasWidth, h: atlasHeight },\n scale: '1',\n },\n };\n await writeFile(jsonPath, `${JSON.stringify(jsonDoc, null, 2)}\\n`, 'utf8');\n\n return {\n jsonPath,\n imagePath,\n frames,\n width: atlasWidth,\n height: atlasHeight,\n };\n}\n","import { readFile, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\nimport type {\n FlareLayer,\n FlareMap,\n FlareObject,\n FlareObjectLayer,\n FlareTileLayer,\n FlareTileset,\n TiledConvertOptions,\n TiledResult,\n} from './types.js';\n\ninterface TiledProperty {\n name: string;\n type?: string;\n value: string | number | boolean;\n}\n\ninterface TiledObject {\n id: number;\n name?: string;\n type?: string;\n class?: string;\n x: number;\n y: number;\n width: number;\n height: number;\n visible?: boolean;\n properties?: TiledProperty[];\n}\n\ninterface TiledLayer {\n type: 'tilelayer' | 'objectgroup' | 'imagelayer' | 'group';\n name: string;\n visible?: boolean;\n opacity?: number;\n width?: number;\n height?: number;\n data?: number[];\n objects?: TiledObject[];\n}\n\ninterface TiledTilesetRef {\n firstgid: number;\n source?: string;\n name?: string;\n tilewidth?: number;\n tileheight?: number;\n columns?: number;\n tilecount?: number;\n image?: string;\n imagewidth?: number;\n imageheight?: number;\n}\n\ninterface TiledMap {\n width: number;\n height: number;\n tilewidth: number;\n tileheight: number;\n layers: TiledLayer[];\n tilesets: TiledTilesetRef[];\n}\n\nfunction absPath(p: string, base: string): string {\n return isAbsolute(p) ? p : resolve(base, p);\n}\n\nfunction propsToRecord(\n props: TiledProperty[] | undefined,\n): Record<string, string | number | boolean> {\n const out: Record<string, string | number | boolean> = {};\n if (!props) return out;\n for (const p of props) out[p.name] = p.value;\n return out;\n}\n\nasync function resolveTileset(\n ref: TiledTilesetRef,\n mapDir: string,\n embed: boolean,\n): Promise<FlareTileset> {\n let data: TiledTilesetRef = ref;\n if (ref.source && embed) {\n const srcPath = absPath(ref.source, mapDir);\n const raw = await readFile(srcPath, 'utf8');\n const external = JSON.parse(raw) as TiledTilesetRef;\n data = { ...external, firstgid: ref.firstgid };\n }\n return {\n name: data.name ?? 'tileset',\n firstgid: data.firstgid,\n tilewidth: data.tilewidth ?? 0,\n tileheight: data.tileheight ?? 0,\n columns: data.columns ?? 0,\n tilecount: data.tilecount ?? 0,\n image: data.image ?? '',\n imagewidth: data.imagewidth ?? 0,\n imageheight: data.imageheight ?? 0,\n };\n}\n\nfunction flattenLayers(layers: TiledLayer[]): TiledLayer[] {\n const out: TiledLayer[] = [];\n const walk = (ls: TiledLayer[]): void => {\n for (const l of ls) {\n if (l.type === 'group') {\n const inner = (l as unknown as { layers?: TiledLayer[] }).layers;\n if (inner) walk(inner);\n } else {\n out.push(l);\n }\n }\n };\n walk(layers);\n return out;\n}\n\nfunction convertLayer(layer: TiledLayer): FlareLayer | null {\n const visible = layer.visible !== false;\n const opacity = typeof layer.opacity === 'number' ? layer.opacity : 1;\n if (layer.type === 'tilelayer') {\n const tile: FlareTileLayer = {\n kind: 'tile',\n name: layer.name,\n width: layer.width ?? 0,\n height: layer.height ?? 0,\n data: layer.data ?? [],\n visible,\n opacity,\n };\n return tile;\n }\n if (layer.type === 'objectgroup') {\n const objects: FlareObject[] = (layer.objects ?? []).map((o) => ({\n id: o.id,\n name: o.name ?? '',\n type: o.type ?? o.class ?? '',\n x: o.x,\n y: o.y,\n width: o.width,\n height: o.height,\n properties: propsToRecord(o.properties),\n }));\n const obj: FlareObjectLayer = {\n kind: 'object',\n name: layer.name,\n objects,\n visible,\n opacity,\n };\n return obj;\n }\n return null;\n}\n\n/**\n * Convert a Tiled `.tmj` JSON map into Flare's normalized runtime format.\n * Flattens group layers, resolves external tilesets (when `embedTilesets`),\n * and drops image/editor-only layers.\n */\nexport async function convertTiled(opts: TiledConvertOptions): Promise<TiledResult> {\n const inputPath = absPath(opts.input, process.cwd());\n const outPath = opts.out\n ? absPath(opts.out, process.cwd())\n : join(dirname(inputPath), `${inputPath.replace(/\\.tmj$|\\.json$/i, '')}.flare.json`);\n const embed = opts.embedTilesets !== false;\n\n const raw = await readFile(inputPath, 'utf8');\n const parsed = JSON.parse(raw) as TiledMap;\n const mapDir = dirname(inputPath);\n\n const tilesets: FlareTileset[] = [];\n for (const ref of parsed.tilesets ?? []) {\n tilesets.push(await resolveTileset(ref, mapDir, embed));\n }\n\n const layers: FlareLayer[] = [];\n for (const l of flattenLayers(parsed.layers ?? [])) {\n const converted = convertLayer(l);\n if (converted) layers.push(converted);\n }\n\n const map: FlareMap = {\n width: parsed.width,\n height: parsed.height,\n tilewidth: parsed.tilewidth,\n tileheight: parsed.tileheight,\n tilesets,\n layers,\n };\n\n await writeFile(outPath, `${JSON.stringify(map, null, 2)}\\n`, 'utf8');\n return { outPath, layers, tilesets, map };\n}\n"],"mappings":";AAAA,SAAS,OAAO,UAAU,SAAS,iBAAiB;AACpD,SAAS,UAAU,SAAS,YAAY,MAAM,eAAe;A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AO;AAAA,IACnB;AAAA,IACA;AAAA,EACF;AAEA,QAAMC,WAAU,SAAS,GAAG,KAAK,UAAU,KAAK,MAAM,CAAC,CAAC;AAAA,GAAM,MAAM;AACpE,SAAO,EAAE,SAAS,QAAQ,UAAU,IAAI;AAC1C;","names":["readFile","writeFile","isAbsolute","join","resolve","absPath"]}
@@ -0,0 +1,123 @@
1
+ /** Options for `packAtlas` / `flare pack-atlas`. */
2
+ interface AtlasPackerOptions {
3
+ /** Directory containing source `.png` sprites (non-recursive). */
4
+ input: string;
5
+ /** Output directory for atlas JSON + image (default: `input`). */
6
+ out?: string;
7
+ /** Base filename (no extension) for the atlas pair (default: `atlas`). */
8
+ name?: string;
9
+ /** Pixel padding between sprites in the packed atlas (default: 2). */
10
+ padding?: number;
11
+ /** Maximum atlas side length in pixels (default: 2048). */
12
+ maxSize?: number;
13
+ /** Output image format (default: `png`). */
14
+ format?: 'png' | 'webp';
15
+ }
16
+ /** One packed frame in the resulting atlas. */
17
+ interface AtlasFrame {
18
+ /** Frame name — sprite filename without extension. */
19
+ name: string;
20
+ /** X position in atlas (px). */
21
+ x: number;
22
+ /** Y position in atlas (px). */
23
+ y: number;
24
+ /** Source sprite width (px). */
25
+ w: number;
26
+ /** Source sprite height (px). */
27
+ h: number;
28
+ }
29
+ /** Result returned by `packAtlas`. */
30
+ interface AtlasResult {
31
+ /** Absolute path to the written JSON descriptor. */
32
+ jsonPath: string;
33
+ /** Absolute path to the written atlas image. */
34
+ imagePath: string;
35
+ /** Packed frames. */
36
+ frames: readonly AtlasFrame[];
37
+ /** Final atlas width (px). */
38
+ width: number;
39
+ /** Final atlas height (px). */
40
+ height: number;
41
+ }
42
+ /** Options for `convertTiled` / `flare tiled-to-flare`. */
43
+ interface TiledConvertOptions {
44
+ /** Path to a Tiled `.tmj` (JSON) map file. */
45
+ input: string;
46
+ /** Output `.json` path (default: `<input>.flare.json`). */
47
+ out?: string;
48
+ /** Embed external tilesets inline rather than leaving references (default: true). */
49
+ embedTilesets?: boolean;
50
+ }
51
+ /** Normalized Flare tileset descriptor. */
52
+ interface FlareTileset {
53
+ name: string;
54
+ firstgid: number;
55
+ tilewidth: number;
56
+ tileheight: number;
57
+ columns: number;
58
+ tilecount: number;
59
+ image: string;
60
+ imagewidth: number;
61
+ imageheight: number;
62
+ }
63
+ /** Normalized Flare tile layer. */
64
+ interface FlareTileLayer {
65
+ kind: 'tile';
66
+ name: string;
67
+ width: number;
68
+ height: number;
69
+ data: number[];
70
+ visible: boolean;
71
+ opacity: number;
72
+ }
73
+ /** Normalized Flare object. */
74
+ interface FlareObject {
75
+ id: number;
76
+ name: string;
77
+ type: string;
78
+ x: number;
79
+ y: number;
80
+ width: number;
81
+ height: number;
82
+ properties: Record<string, string | number | boolean>;
83
+ }
84
+ /** Normalized Flare object layer. */
85
+ interface FlareObjectLayer {
86
+ kind: 'object';
87
+ name: string;
88
+ objects: FlareObject[];
89
+ visible: boolean;
90
+ opacity: number;
91
+ }
92
+ type FlareLayer = FlareTileLayer | FlareObjectLayer;
93
+ /** Normalized runtime JSON produced by `convertTiled`. */
94
+ interface FlareMap {
95
+ width: number;
96
+ height: number;
97
+ tilewidth: number;
98
+ tileheight: number;
99
+ tilesets: FlareTileset[];
100
+ layers: FlareLayer[];
101
+ }
102
+ /** Result returned by `convertTiled`. */
103
+ interface TiledResult {
104
+ outPath: string;
105
+ layers: FlareLayer[];
106
+ tilesets: FlareTileset[];
107
+ map: FlareMap;
108
+ }
109
+
110
+ /**
111
+ * Pack a directory of PNG sprites into a single TexturePacker-compatible
112
+ * atlas (JSON + image) consumable by `@flare-engine/assets`.
113
+ */
114
+ declare function packAtlas(opts: AtlasPackerOptions): Promise<AtlasResult>;
115
+
116
+ /**
117
+ * Convert a Tiled `.tmj` JSON map into Flare's normalized runtime format.
118
+ * Flattens group layers, resolves external tilesets (when `embedTilesets`),
119
+ * and drops image/editor-only layers.
120
+ */
121
+ declare function convertTiled(opts: TiledConvertOptions): Promise<TiledResult>;
122
+
123
+ export { type AtlasFrame, type AtlasPackerOptions, type AtlasResult, type FlareLayer, type FlareMap, type FlareObject, type FlareObjectLayer, type FlareTileLayer, type FlareTileset, type TiledConvertOptions, type TiledResult, convertTiled, packAtlas };
@@ -0,0 +1,123 @@
1
+ /** Options for `packAtlas` / `flare pack-atlas`. */
2
+ interface AtlasPackerOptions {
3
+ /** Directory containing source `.png` sprites (non-recursive). */
4
+ input: string;
5
+ /** Output directory for atlas JSON + image (default: `input`). */
6
+ out?: string;
7
+ /** Base filename (no extension) for the atlas pair (default: `atlas`). */
8
+ name?: string;
9
+ /** Pixel padding between sprites in the packed atlas (default: 2). */
10
+ padding?: number;
11
+ /** Maximum atlas side length in pixels (default: 2048). */
12
+ maxSize?: number;
13
+ /** Output image format (default: `png`). */
14
+ format?: 'png' | 'webp';
15
+ }
16
+ /** One packed frame in the resulting atlas. */
17
+ interface AtlasFrame {
18
+ /** Frame name — sprite filename without extension. */
19
+ name: string;
20
+ /** X position in atlas (px). */
21
+ x: number;
22
+ /** Y position in atlas (px). */
23
+ y: number;
24
+ /** Source sprite width (px). */
25
+ w: number;
26
+ /** Source sprite height (px). */
27
+ h: number;
28
+ }
29
+ /** Result returned by `packAtlas`. */
30
+ interface AtlasResult {
31
+ /** Absolute path to the written JSON descriptor. */
32
+ jsonPath: string;
33
+ /** Absolute path to the written atlas image. */
34
+ imagePath: string;
35
+ /** Packed frames. */
36
+ frames: readonly AtlasFrame[];
37
+ /** Final atlas width (px). */
38
+ width: number;
39
+ /** Final atlas height (px). */
40
+ height: number;
41
+ }
42
+ /** Options for `convertTiled` / `flare tiled-to-flare`. */
43
+ interface TiledConvertOptions {
44
+ /** Path to a Tiled `.tmj` (JSON) map file. */
45
+ input: string;
46
+ /** Output `.json` path (default: `<input>.flare.json`). */
47
+ out?: string;
48
+ /** Embed external tilesets inline rather than leaving references (default: true). */
49
+ embedTilesets?: boolean;
50
+ }
51
+ /** Normalized Flare tileset descriptor. */
52
+ interface FlareTileset {
53
+ name: string;
54
+ firstgid: number;
55
+ tilewidth: number;
56
+ tileheight: number;
57
+ columns: number;
58
+ tilecount: number;
59
+ image: string;
60
+ imagewidth: number;
61
+ imageheight: number;
62
+ }
63
+ /** Normalized Flare tile layer. */
64
+ interface FlareTileLayer {
65
+ kind: 'tile';
66
+ name: string;
67
+ width: number;
68
+ height: number;
69
+ data: number[];
70
+ visible: boolean;
71
+ opacity: number;
72
+ }
73
+ /** Normalized Flare object. */
74
+ interface FlareObject {
75
+ id: number;
76
+ name: string;
77
+ type: string;
78
+ x: number;
79
+ y: number;
80
+ width: number;
81
+ height: number;
82
+ properties: Record<string, string | number | boolean>;
83
+ }
84
+ /** Normalized Flare object layer. */
85
+ interface FlareObjectLayer {
86
+ kind: 'object';
87
+ name: string;
88
+ objects: FlareObject[];
89
+ visible: boolean;
90
+ opacity: number;
91
+ }
92
+ type FlareLayer = FlareTileLayer | FlareObjectLayer;
93
+ /** Normalized runtime JSON produced by `convertTiled`. */
94
+ interface FlareMap {
95
+ width: number;
96
+ height: number;
97
+ tilewidth: number;
98
+ tileheight: number;
99
+ tilesets: FlareTileset[];
100
+ layers: FlareLayer[];
101
+ }
102
+ /** Result returned by `convertTiled`. */
103
+ interface TiledResult {
104
+ outPath: string;
105
+ layers: FlareLayer[];
106
+ tilesets: FlareTileset[];
107
+ map: FlareMap;
108
+ }
109
+
110
+ /**
111
+ * Pack a directory of PNG sprites into a single TexturePacker-compatible
112
+ * atlas (JSON + image) consumable by `@flare-engine/assets`.
113
+ */
114
+ declare function packAtlas(opts: AtlasPackerOptions): Promise<AtlasResult>;
115
+
116
+ /**
117
+ * Convert a Tiled `.tmj` JSON map into Flare's normalized runtime format.
118
+ * Flattens group layers, resolves external tilesets (when `embedTilesets`),
119
+ * and drops image/editor-only layers.
120
+ */
121
+ declare function convertTiled(opts: TiledConvertOptions): Promise<TiledResult>;
122
+
123
+ export { type AtlasFrame, type AtlasPackerOptions, type AtlasResult, type FlareLayer, type FlareMap, type FlareObject, type FlareObjectLayer, type FlareTileLayer, type FlareTileset, type TiledConvertOptions, type TiledResult, convertTiled, packAtlas };