diff options
| author | Alexander Gavrilov | 2012-09-07 11:36:45 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-09-07 11:36:45 +0400 |
| commit | e925d8f4d999817d3ccf7f3180e7abee382e03b4 (patch) | |
| tree | 5a48c08b6c8a45aa3cf85e7d4b05e79cc2d4e028 /library/LuaApi.cpp | |
| parent | c971a819def1c5cc29dc926f62456c336a1dfa17 (diff) | |
| download | dfhack-e925d8f4d999817d3ccf7f3180e7abee382e03b4.tar.gz dfhack-e925d8f4d999817d3ccf7f3180e7abee382e03b4.tar.bz2 dfhack-e925d8f4d999817d3ccf7f3180e7abee382e03b4.tar.xz | |
Add an API function for reading tiles from the screen buffers.
Diffstat (limited to 'library/LuaApi.cpp')
| -rw-r--r-- | library/LuaApi.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 63838d35..807cbf53 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1154,6 +1154,45 @@ static int screen_paintTile(lua_State *L) return 1; } +static int screen_readTile(lua_State *L) +{ + int x = luaL_checkint(L, 1); + int y = luaL_checkint(L, 2); + Pen pen = Screen::readTile(x, y); + + if (!pen.valid()) + { + lua_pushnil(L); + } + else + { + lua_newtable(L); + lua_pushinteger(L, pen.ch); lua_setfield(L, -2, "ch"); + lua_pushinteger(L, pen.fg); lua_setfield(L, -2, "fg"); + lua_pushinteger(L, pen.bg); lua_setfield(L, -2, "bg"); + lua_pushboolean(L, pen.bold); lua_setfield(L, -2, "bold"); + + if (pen.tile) + { + lua_pushinteger(L, pen.tile); lua_setfield(L, -2, "tile"); + + switch (pen.tile_mode) { + case Pen::CharColor: + lua_pushboolean(L, true); lua_setfield(L, -2, "tile_color"); + break; + case Pen::TileColor: + lua_pushinteger(L, pen.tile_fg); lua_setfield(L, -2, "tile_fg"); + lua_pushinteger(L, pen.tile_bg); lua_setfield(L, -2, "tile_bg"); + break; + default: + break; + } + } + } + + return 1; +} + static int screen_paintString(lua_State *L) { Pen pen; @@ -1258,6 +1297,7 @@ static const luaL_Reg dfhack_screen_funcs[] = { { "getMousePos", screen_getMousePos }, { "getWindowSize", screen_getWindowSize }, { "paintTile", screen_paintTile }, + { "readTile", screen_readTile }, { "paintString", screen_paintString }, { "fillRect", screen_fillRect }, { "findGraphicsTile", screen_findGraphicsTile }, |
