Skip to content

Commit d43fb3a

Browse files
committed
change how frames are loaded
1 parent b27a61a commit d43fb3a

File tree

1 file changed

+49
-39
lines changed

1 file changed

+49
-39
lines changed

plugins/building-hacks.cpp

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,44 @@ void clear_mapping()
391391
{
392392
hacked_workshops.clear();
393393
}
394+
static void load_graphics_tile(lua_State* L,graphic_tile& t)
395+
{
396+
lua_getfield(L, -1, "ch");
397+
t.tile = luaL_optinteger(L, -1, -1);
398+
lua_pop(L, 1);
399+
400+
lua_getfield(L, -1, "fg");
401+
t.fore = luaL_optinteger(L, -1, -1);
402+
lua_pop(L, 1);
403+
404+
lua_getfield(L, -1, "bg");
405+
t.back = luaL_optinteger(L, -1, -1);
406+
lua_pop(L, 1);
407+
408+
lua_getfield(L, -1, "bold");
409+
t.bright = luaL_optinteger(L, -1, 0);
410+
lua_pop(L, 1);
411+
412+
lua_getfield(L, -1, "tile");
413+
t.graphics_tile = luaL_optinteger(L, -1, invalid_tile);
414+
lua_pop(L, 1);
415+
416+
lua_getfield(L, -1, "tile_overlay");
417+
t.overlay_tile = luaL_optinteger(L, -1, invalid_tile);
418+
lua_pop(L, 1);
419+
420+
lua_getfield(L, -1, "tile_signpost");
421+
t.signpost_tile = luaL_optinteger(L, -1, invalid_tile);
422+
lua_pop(L, 1);
423+
424+
lua_getfield(L, -1, "tile_item");
425+
t.item_tile = luaL_optinteger(L, -1, invalid_tile);
426+
lua_pop(L, 1);
427+
}
394428
static void loadFrames(lua_State* L,workshop_hack_data& def,int stack_pos)
395429
{
396-
const int max_idx = 31 * 31;
430+
const int max_side = 31;
431+
const int max_idx = max_side * max_side;
397432

398433
luaL_checktype(L,stack_pos,LUA_TTABLE);
399434

@@ -403,56 +438,31 @@ static void loadFrames(lua_State* L,workshop_hack_data& def,int stack_pos)
403438
while (lua_geti(L,stack_pos,frame_index) != LUA_TNIL) { //get frame[i]
404439
luaL_checktype(L,-1,LUA_TTABLE); //ensure that it's a table
405440
std::vector<graphic_tile> frame(max_idx);
406-
407-
for (int idx = 0; idx < max_idx; idx++)
441+
for (int x = 1; x <= max_side; x++)
408442
{
409-
auto& t = frame[idx];
410-
lua_geti(L, -1, idx); //get tile at idx i.e. frame[i][idx] where idx=x+y*31
411-
443+
lua_geti(L, -1, x); //get row at x
412444
if (lua_isnil(L, -1))//allow sparse indexing
413445
{
414446
lua_pop(L, 1); //pop current tile (nil in this case)
415447
continue;
416448
}
417-
else
418-
{
419-
//load up tile, color, optionally graphics stuff
420-
lua_geti(L, -1, 1);
421-
//not sure why would anyone do nil tile, but for api consitency lets allow it
422-
t.tile= luaL_optinteger(L,-1,-1);
423-
lua_pop(L,1);
424-
425-
lua_geti(L, -1, 2);
426-
t.fore= luaL_optinteger(L,-1,0);
427-
lua_pop(L,1);
428-
429-
lua_geti(L, -1, 3);
430-
t.back= luaL_optinteger(L,-1,0);
431-
lua_pop(L,1);
432449

433-
lua_geti(L, -1, 4);
434-
t.bright=luaL_optinteger(L,-1,0);
435-
lua_pop(L,1);
436-
437-
lua_geti(L, -1, 5);
438-
t.graphics_tile = luaL_optinteger(L, -1,invalid_tile);
439-
lua_pop(L, 1);
440-
441-
lua_geti(L, -1, 6);
442-
t.overlay_tile = luaL_optinteger(L, -1, invalid_tile);
443-
lua_pop(L, 1);
444-
445-
lua_geti(L, -1, 7);
446-
t.signpost_tile = luaL_optinteger(L, -1, invalid_tile);
447-
lua_pop(L, 1);
450+
for (int y = 1; y <= max_side; y++)
451+
{
452+
lua_geti(L, -1, y); //get cell at y
453+
if (lua_isnil(L, -1))//allow sparse indexing
454+
{
455+
lua_pop(L, 1); //pop current tile (nil in this case)
456+
continue;
457+
}
448458

449-
lua_geti(L, -1, 8);
450-
t.item_tile = luaL_optinteger(L, -1, invalid_tile);
451-
lua_pop(L, 1);
459+
load_graphics_tile(L, frame[(x-1)+(y-1)*max_side]);
452460

453461
lua_pop(L, 1); //pop current tile
454462
}
463+
lua_pop(L, 1); //pop current row
455464
}
465+
456466
def.frames.push_back(frame);
457467
frame_index++;
458468
lua_pop(L, 1); //pop current frame

0 commit comments

Comments
 (0)