Fix assert converting Color{index} to a tile from tilemap.lua test

We must be able to convert a app::Color::IndexType to a tile index.
This commit is contained in:
David Capello 2023-08-10 11:35:33 -03:00
parent 78cda70ab6
commit 39bdba4a7d
3 changed files with 21 additions and 5 deletions

View File

@ -893,6 +893,9 @@ doc::tile_t Color::getTile() const
{ {
switch (getType()) { switch (getType()) {
case Color::IndexType:
return m_value.index;
case Color::TileType: case Color::TileType:
return m_value.tile; return m_value.tile;
@ -929,6 +932,9 @@ int Color::getAlpha() const
return 0; return 0;
} }
case Color::TileType:
return 255;
} }
ASSERT(false); ASSERT(false);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2018 David Capello // Copyright (C) 2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -145,6 +145,16 @@ app::Color Color_new(lua_State* L, int index)
} }
else else
lua_pop(L, 1); lua_pop(L, 1);
// Convert { tile } into a Color
if (lua_getfield(L, index, "tile") != LUA_TNIL) {
tile_t t = lua_tointeger(L, -1);
color = app::Color::fromTile(t);
lua_pop(L, 1);
return color;
}
else
lua_pop(L, 1);
} }
// raw color into app color // raw color into app color
else if (!lua_isnone(L, index)) { else if (!lua_isnone(L, index)) {

View File

@ -228,7 +228,7 @@ do
app.useTool{ app.useTool{
tool='pencil', tool='pencil',
color=Color{ index=1 }, color=Color{ index=1 }, -- We can use a Color{ index } to paint tiles too
tilemapMode=TilemapMode.TILES, tilemapMode=TilemapMode.TILES,
tilesetMode=TilesetMode.STACK, tilesetMode=TilesetMode.STACK,
points={ Point(0, 16) }} -- y=16 is the first pixel of 3rd row of tiles points={ Point(0, 16) }} -- y=16 is the first pixel of 3rd row of tiles
@ -240,7 +240,7 @@ do
app.useTool{ app.useTool{
tool='pencil', tool='pencil',
color=Color{ index=1 }, color=Color{ tile=1 }, -- Color{ tile } is the new constructor to paint tiles + flags
tilemapMode=TilemapMode.TILES, tilemapMode=TilemapMode.TILES,
tilesetMode=TilesetMode.STACK, tilesetMode=TilesetMode.STACK,
points={ Point(0, 0), Point(16, 0) }} -- x=16 is the first pixel of 3rd column of tiles points={ Point(0, 0), Point(16, 0) }} -- x=16 is the first pixel of 3rd column of tiles
@ -255,7 +255,7 @@ do
expect_eq(Point{ 10, 8 }, cel.position) expect_eq(Point{ 10, 8 }, cel.position)
app.useTool{ app.useTool{
tool='pencil', tool='pencil',
color=Color{ index=0 }, color=Color{ tile=0 },
tilemapMode=TilemapMode.TILES, tilemapMode=TilemapMode.TILES,
tilesetMode=TilesetMode.STACK, tilesetMode=TilesetMode.STACK,
points={ { 10, 8 }, { 18, 16 } }} -- {10,8} is the first existent tile in the tilemap points={ { 10, 8 }, { 18, 16 } }} -- {10,8} is the first existent tile in the tilemap
@ -268,7 +268,7 @@ do
app.useTool{ app.useTool{
tool='pencil', tool='pencil',
color=Color{ index=1 }, color=Color{ tile=1 },
tilemapMode=TilemapMode.TILES, tilemapMode=TilemapMode.TILES,
tilesetMode=TilesetMode.STACK, tilesetMode=TilesetMode.STACK,
points={ Point(1, 7), Point(2, 8) }} -- Tile 0,0 and 1,1 points={ Point(1, 7), Point(2, 8) }} -- Tile 0,0 and 1,1