@city41/gba-convertpng 0.0.33 → 0.0.34

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.
Files changed (2) hide show
  1. package/dist/background.js +27 -4
  2. package/package.json +1 -1
@@ -57,10 +57,33 @@ function buildMap(tiles, bgWidthPx, bgHeightPx) {
57
57
  const map = [];
58
58
  const bgWidthT = bgWidthPx / 8;
59
59
  const bgHeightT = bgHeightPx / 8;
60
- for (let y = 0; y < bgHeightT; ++y) {
61
- for (let x = 0; x < bgWidthT; ++x) {
62
- const tile = tiles[y * bgWidthT + x];
63
- map.push((tile.paletteIndex << 12) | tile.tileIndex);
60
+ if (bgWidthT % 32 !== 0) {
61
+ throw new Error(`buildMap: bg is of unexpected tile width: ${bgWidthT}`);
62
+ }
63
+ if (bgHeightT % 32 !== 0) {
64
+ throw new Error(`buildMap: bg is of unexpected tile height: ${bgHeightT}`);
65
+ }
66
+ // when backgrounds are 64 tiles high/wide
67
+ // then the map gets divided into quadrants,
68
+ // the quads are laid out colunm first
69
+ //
70
+ // [1][2]
71
+ //
72
+ // [1]
73
+ // [2]
74
+ //
75
+ // [1][2]
76
+ // [3][4]
77
+ const quadranteColumns = bgWidthT / 32;
78
+ const quadranteRows = bgHeightT / 32;
79
+ for (let qc = 0; qc < quadranteColumns; ++qc) {
80
+ for (let qy = 0; qy < quadranteRows; ++qy) {
81
+ for (let y = qy * 32; y < (qy + 1) * 32; ++y) {
82
+ for (let x = qc * 32; x < (qc + 1) * 32; ++x) {
83
+ const tile = tiles[y * bgWidthT + x];
84
+ map.push((tile.paletteIndex << 12) | tile.tileIndex);
85
+ }
86
+ }
64
87
  }
65
88
  }
66
89
  return map;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@city41/gba-convertpng",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "Converts png images to GBA tile format",
5
5
  "main": "index.js",
6
6
  "repository": "github.com/city41/gba-convertpng",