Skip to content

Commit

Permalink
Add support for auto colouring logo scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaltby committed Apr 24, 2024
1 parent 3fb3666 commit 9f411d3
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/lib/compiler/compileImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ enum ImageColorMode {
AUTO_COLOR_WITH_DMG,
}

const buildAttr = (
tileColors: number[],
autoTileColors: number[],
tileMapSize: number
) => {
return padArrayEnd(tileColors || [], tileMapSize, 0).map(
(manualAttr, index) => {
return autoTileColors[index] !== undefined
? (manualAttr & 0xf8) + (autoTileColors[index] & 0x7)
: manualAttr;
}
);
};

const compileImage = async (
img: BackgroundData,
commonTileset: TilesetData | undefined,
Expand All @@ -143,19 +157,6 @@ const compileImage = async (
? dmgFilename
: filename;

if (is360) {
const tileData = await readFileToTilesDataArray(tilesFileName);
const tilemap = Array.from(Array(360)).map((_, i) => i);
const tiles = tileArrayToTileData(tileData);
const attr = padArrayEnd(img.tileColors || [], tilemap.length, 0);
return {
...img,
vramData: [[...tiles], []],
tilemap,
attr,
};
}

const tileAllocationStrategy = cgbOnly
? imageTileAllocationColorOnly
: imageTileAllocationDefault;
Expand Down Expand Up @@ -201,6 +202,19 @@ const compileImage = async (
);
}

if (is360) {
const tilemap = Array.from(Array(360)).map((_, i) => i);
const tiles = tileArrayToTileData(tileData);
const attr = buildAttr(img.tileColors, autoTileColors, tilemap.length);
return {
...img,
vramData: [[...tiles], []],
tilemap,
attr,
autoPalettes,
};
}

const tileDataWithCommon = await mergeCommonTiles(
tileData,
commonTileset,
Expand Down Expand Up @@ -234,12 +248,8 @@ const compileImage = async (
});

// Determine tilemap attrs
const attr = padArrayEnd(img.tileColors || [], tilemap.length, 0).map(
(manualAttr, index) => {
const attr =
autoTileColors[index] !== undefined
? (manualAttr & 0xf8) + (autoTileColors[index] & 0x7)
: manualAttr;
const attr = buildAttr(img.tileColors, autoTileColors, tilemap.length).map(
(attr, index) => {
const tile = tilemap[index];
const { inVRAM2, tileIndex } = tileAllocationStrategy(
tile,
Expand Down

0 comments on commit 9f411d3

Please sign in to comment.