From 9f411d3efb49dd61b2a3f9b3205a9f0f66227996 Mon Sep 17 00:00:00 2001 From: Chris Maltby Date: Wed, 24 Apr 2024 09:37:31 +0100 Subject: [PATCH] Add support for auto colouring logo scenes --- src/lib/compiler/compileImages.ts | 48 +++++++++++++++++++------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/lib/compiler/compileImages.ts b/src/lib/compiler/compileImages.ts index 05e184f13..cee63f147 100644 --- a/src/lib/compiler/compileImages.ts +++ b/src/lib/compiler/compileImages.ts @@ -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, @@ -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; @@ -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, @@ -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,