@city41/gba-convertpng 0.0.3 → 0.0.4

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.
package/dist/asm.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- declare function toAsm(data: number[], width: "b" | "w", numbersPerRow: number): string;
1
+ import { Format } from "./types";
2
+ declare function toAsm(data: number[], width: "b" | "w", numbersPerRow: number, format: Format): string;
2
3
  export { toAsm };
package/dist/asm.js CHANGED
@@ -2,18 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toAsm = toAsm;
4
4
  const toHex_1 = require("./toHex");
5
- function toAsm(data, width, numbersPerRow) {
5
+ function toAsm(data, width, numbersPerRow, format) {
6
+ if (format !== "asz80" && format !== "z80" && format !== "pyz80") {
7
+ throw new Error(`toAsm: given an incompatible format (${format})`);
8
+ }
6
9
  const hexFn = width === "b" ? toHex_1.toHexByte : toHex_1.toHexWord;
10
+ const dPrefix = format === "pyz80" ? "" : ".";
7
11
  const rows = [];
8
12
  let row = [];
9
13
  for (let i = 0; i < data.length; ++i) {
10
14
  if (row.length === numbersPerRow) {
11
- rows.push(` .d${width} ${row.join(",")}`);
15
+ rows.push(` ${dPrefix}d${width} ${row.join(",")}`);
12
16
  row = [];
13
17
  }
14
18
  row.push(hexFn(data[i]));
15
19
  }
16
- rows.push(` .d${width} ${row.join(",")}`);
20
+ rows.push(` ${dPrefix}d${width} ${row.join(",")}`);
17
21
  return rows.join("\r\n") + "\r\n";
18
22
  }
19
23
  //# sourceMappingURL=asm.js.map
@@ -1,8 +1,8 @@
1
- import { BackgroundSpec } from "./types";
1
+ import { BackgroundSpec, Format } from "./types";
2
2
  type ProcessBackgroundResult = {
3
3
  tilesAsmSrc: string;
4
4
  paletteAsmSrc: string;
5
5
  mapAsmSrc: string;
6
6
  };
7
- declare function processBackground(bg: BackgroundSpec): Promise<ProcessBackgroundResult>;
7
+ declare function processBackground(bg: BackgroundSpec, format: Format): Promise<ProcessBackgroundResult>;
8
8
  export { processBackground };
@@ -9,6 +9,7 @@ const canvas_1 = require("./canvas");
9
9
  const palette_1 = require("./palette");
10
10
  const tile_1 = require("./tile");
11
11
  const isEqual_1 = __importDefault(require("lodash/isEqual"));
12
+ const c_1 = require("./c");
12
13
  function extractMap(allTilesThatFormImage, dedupedTiles) {
13
14
  const map = [];
14
15
  allTilesThatFormImage.forEach((tile, i) => {
@@ -22,16 +23,17 @@ function extractMap(allTilesThatFormImage, dedupedTiles) {
22
23
  });
23
24
  return map;
24
25
  }
25
- async function processBackground(bg) {
26
+ async function processBackground(bg, format) {
26
27
  const canvas = await (0, canvas_1.reduceColors)(await (0, canvas_1.createCanvasFromPath)(bg.file), 16);
27
28
  const palette = (0, palette_1.extractPalette)(canvas, !bg.trimPalette);
28
29
  const allTilesThatFormImage = (0, tile_1.extractTiles)(canvas, palette, 1);
29
30
  const dedupedTiles = (0, tile_1.dedupeTiles)(allTilesThatFormImage);
30
31
  const map = extractMap(allTilesThatFormImage, dedupedTiles);
32
+ const toSrcFun = format === "C" ? c_1.toC : asm_1.toAsm;
31
33
  return {
32
- tilesAsmSrc: (0, asm_1.toAsm)(dedupedTiles.flat(1), "b", 4),
33
- paletteAsmSrc: (0, asm_1.toAsm)(palette, "w", 4),
34
- mapAsmSrc: (0, asm_1.toAsm)(map, "w", 8),
34
+ tilesAsmSrc: toSrcFun(dedupedTiles.flat(1), "b", 4, format),
35
+ paletteAsmSrc: toSrcFun(palette, "w", 4, format),
36
+ mapAsmSrc: toSrcFun(map, "w", 8, format),
35
37
  };
36
38
  }
37
39
  //# sourceMappingURL=background.js.map
package/dist/c.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- declare function toC(data: number[], width: "b" | "w", numbersPerRow: number): string;
1
+ import { Format } from "./types";
2
+ declare function toC(data: number[], width: "b" | "w", numbersPerRow: number, format: Format): string;
2
3
  export { toC };
package/dist/c.js CHANGED
@@ -2,7 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toC = toC;
4
4
  const toHex_1 = require("./toHex");
5
- function toC(data, width, numbersPerRow) {
5
+ function toC(data, width, numbersPerRow, format) {
6
+ if (format !== "C") {
7
+ throw new Error(`toC: given an incompatible format (${format})`);
8
+ }
6
9
  const hexFn = width === "b" ? toHex_1.toHexByte : toHex_1.toHexWord;
7
10
  const rows = [];
8
11
  let row = [];
package/dist/main.js CHANGED
@@ -82,11 +82,18 @@ function hydrateJsonSpec(jsonSpecPath) {
82
82
  }),
83
83
  };
84
84
  }
85
+ const formatToExt = {
86
+ C: "c.inc",
87
+ asz80: "asm",
88
+ z80: "asm",
89
+ pyz80: "asm",
90
+ bin: "bin",
91
+ };
85
92
  async function main(jsonSpec) {
86
93
  if (jsonSpec.format === "bin") {
87
94
  throw new Error("convertpng does not support bin format");
88
95
  }
89
- const ext = jsonSpec.format === "z80" ? "asm" : "c.inc";
96
+ const ext = formatToExt[jsonSpec.format];
90
97
  for (const sprite of jsonSpec.sprites) {
91
98
  const processResult = await (0, sprite_1.processSprite)(sprite, jsonSpec.format, sprite.forcePalette);
92
99
  if ((0, sprite_1.isBasicSpriteSpec)(sprite)) {
@@ -112,7 +119,7 @@ async function main(jsonSpec) {
112
119
  }
113
120
  }
114
121
  for (const bg of jsonSpec.backgrounds) {
115
- const processResult = await (0, background_1.processBackground)(bg);
122
+ const processResult = await (0, background_1.processBackground)(bg, jsonSpec.format);
116
123
  const fileRoot = path.basename(bg.file, path.extname(bg.file));
117
124
  const tilesAsmPath = path.resolve(jsonSpec.outputDir, `${fileRoot}.tiles.asm`);
118
125
  const paletteAsmPath = path.resolve(jsonSpec.outputDir, `${fileRoot}.palette.asm`);
package/dist/sprite.js CHANGED
@@ -28,12 +28,11 @@ async function processBasicSprite(sprite, format, forcedPalette) {
28
28
  paletteSrc: palette,
29
29
  };
30
30
  }
31
- const tileSrcFun = format === "z80" ? asm_1.toAsm : c_1.toC;
32
- const paletteSrcFun = format === "z80" ? asm_1.toAsm : c_1.toC;
31
+ const toSrcFun = format === "C" ? c_1.toC : asm_1.toAsm;
33
32
  return {
34
33
  canvas,
35
- tilesSrc: [tileSrcFun(tiles, "b", 4)],
36
- paletteSrc: paletteSrcFun(palette, "w", 4),
34
+ tilesSrc: [toSrcFun(tiles, "b", 4, format)],
35
+ paletteSrc: toSrcFun(palette, "w", 4, format),
37
36
  };
38
37
  }
39
38
  async function processSharedPaletteSprites(sharedPaletteSprite, format, forcedPalette) {
@@ -55,14 +54,13 @@ async function processSharedPaletteSprites(sharedPaletteSprite, format, forcedPa
55
54
  const t = (0, tile_1.extractTiles)(canvases[i], commonPalette, sharedPaletteSprite.sharedPalette[i].frames).flat(1);
56
55
  tiles.push(t);
57
56
  }
58
- const tileSrcFun = format === "z80" ? asm_1.toAsm : c_1.toC;
59
- const paletteSrcFun = format === "z80" ? asm_1.toAsm : c_1.toC;
57
+ const toSrcFun = format === "C" ? c_1.toC : asm_1.toAsm;
60
58
  return {
61
59
  // this is useless in this scenario, but canvas
62
60
  // really only exists for the puzzle generator
63
61
  canvas: canvases[0],
64
- tilesSrc: tiles.map((t) => tileSrcFun(t, "b", 4)),
65
- paletteSrc: paletteSrcFun(commonPalette, "w", 4),
62
+ tilesSrc: tiles.map((t) => toSrcFun(t, "b", 4, format)),
63
+ paletteSrc: toSrcFun(commonPalette, "w", 4, format),
66
64
  };
67
65
  }
68
66
  async function processSprite(sprite, format, forcedPalettePath) {
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type Format = "C" | "z80" | "bin";
1
+ export type Format = "C" | "z80" | "pyz80" | "asz80" | "bin";
2
2
  export type BasicSpriteSpec = {
3
3
  file: string;
4
4
  frames: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@city41/gba-convertpng",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Converts png images to GBA tile format",
5
5
  "main": "index.js",
6
6
  "repository": "github.com/city41/gba-convertpng",