map-diff: fix paint tile when there is no only-base version
This commit is contained in:
parent
2d00b7ebd4
commit
3bb7f887b6
2 changed files with 16 additions and 15 deletions
|
@ -26,19 +26,21 @@ const getTileImageCoordenates = (tileX: number, tileY: number) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const producePainters = (output: Jimp, images: ImagesDict, leftPadding: number) => {
|
const producePainters = (output: Jimp, images: ImagesDict, leftPadding: number) => {
|
||||||
const paintTile = (x: number, y: number, baseCode: string) => {
|
const paintTile = (x: number, y: number, baseCode: string, miscCode?: string) => {
|
||||||
const baseImage = images.tile[baseCode]
|
if (miscCode && images.tile[`${baseCode}^${miscCode}`]) {
|
||||||
output.composite(baseImage, x + leftPadding, y)
|
const compoundImage = images.tile[`${baseCode}^${miscCode}`]
|
||||||
}
|
output.composite(compoundImage, x + leftPadding, y)
|
||||||
|
|
||||||
// todo: we should use the defaultBase correctly
|
|
||||||
const paintMisc = (x: number, y: number, baseCode: string, miscCode: string) => {
|
|
||||||
if (!miscCode) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const misctileImage = images.tile[`${baseCode}^${miscCode}`] || images.tile[`^${miscCode}`]
|
const baseImage = images.tile[baseCode]
|
||||||
output.composite(misctileImage, x + leftPadding, y)
|
output.composite(baseImage, x + leftPadding, y)
|
||||||
|
|
||||||
|
// todo: we should use the defaultBase correctly
|
||||||
|
if (miscCode) {
|
||||||
|
const miscImage = images.tile[`^${miscCode}`]
|
||||||
|
output.composite(miscImage, x + leftPadding, y)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: the flag color should follow the player number
|
// todo: the flag color should follow the player number
|
||||||
|
@ -50,7 +52,7 @@ const producePainters = (output: Jimp, images: ImagesDict, leftPadding: number)
|
||||||
output.composite(images.flag, x + leftPadding, y)
|
output.composite(images.flag, x + leftPadding, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { paintTile, paintMisc, paintPlayer }
|
return { paintTile, paintPlayer }
|
||||||
}
|
}
|
||||||
|
|
||||||
const paint = async (
|
const paint = async (
|
||||||
|
@ -70,13 +72,12 @@ const paint = async (
|
||||||
? 0
|
? 0
|
||||||
: width + tileImageSize
|
: width + tileImageSize
|
||||||
|
|
||||||
const { paintTile, paintMisc, paintPlayer } = producePainters(output, images, leftPadding)
|
const { paintTile, paintPlayer } = producePainters(output, images, leftPadding)
|
||||||
|
|
||||||
tilemap.walkthrough(map, ({ x, y, baseCode, miscCode, player }) => {
|
tilemap.walkthrough(map, ({ x, y, baseCode, miscCode, player }) => {
|
||||||
const [imageX, imageY] = getTileImageCoordenates(x, y)
|
const [imageX, imageY] = getTileImageCoordenates(x, y)
|
||||||
|
|
||||||
paintTile(imageX, imageY, baseCode)
|
paintTile(imageX, imageY, baseCode, miscCode)
|
||||||
paintMisc(imageX, imageY, baseCode, miscCode)
|
|
||||||
paintPlayer(imageX, imageY, player)
|
paintPlayer(imageX, imageY, player)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ type WalkthroughCallback =
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
baseCode: string,
|
baseCode: string,
|
||||||
miscCode: string,
|
miscCode: string | undefined,
|
||||||
player: string,
|
player: string,
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
|
|
Loading…
Add table
Reference in a new issue