@city41/gba-convertpng 0.0.2 → 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/README.md +20 -0
- package/dist/asm.d.ts +2 -1
- package/dist/asm.js +7 -3
- package/dist/background.d.ts +2 -2
- package/dist/background.js +6 -4
- package/dist/c.d.ts +2 -1
- package/dist/c.js +4 -1
- package/dist/main.js +9 -2
- package/dist/sprite.js +6 -8
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,3 +3,23 @@
|
|
|
3
3
|
This is a nodejs based tool for converting png images to the tile data format used in GBA games.
|
|
4
4
|
|
|
5
5
|
HEADS UP: I make games for the e-Reader, and so far have not done mainstream GBA development. So possibly this tool is missing things for GBA dev. If so, please let me know.
|
|
6
|
+
|
|
7
|
+
## Publishing
|
|
8
|
+
|
|
9
|
+
gba-convertpng uses [semantic versioning](https://semver.org/)
|
|
10
|
+
|
|
11
|
+
Publishing a new version is done by bumping the version in package.json
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
yarn version
|
|
15
|
+
yarn version v1.22.19
|
|
16
|
+
info Current version: 0.0.2
|
|
17
|
+
question New version: 0.0.3
|
|
18
|
+
info New version: 0.0.3
|
|
19
|
+
Done in 16.19s.
|
|
20
|
+
|
|
21
|
+
git push
|
|
22
|
+
git push --tags
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Once [the Publish action](https://github.com/city41/ereader-tools/actions/workflows/publish.yml) notices the version has changed, it will run a build and publish to npm.
|
package/dist/asm.d.ts
CHANGED
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(`
|
|
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(`
|
|
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
|
package/dist/background.d.ts
CHANGED
|
@@ -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 };
|
package/dist/background.js
CHANGED
|
@@ -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: (
|
|
33
|
-
paletteAsmSrc: (
|
|
34
|
-
mapAsmSrc: (
|
|
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
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
|
|
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
|
|
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: [
|
|
36
|
-
paletteSrc:
|
|
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
|
|
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) =>
|
|
65
|
-
paletteSrc:
|
|
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