mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-16 22:08:28 +01:00
Store tool identifier to index mapping in tools.index
This mimics sim.walls.* rather than elem.*_PT_*. The latter is fine because element identifiers follow the *_PT_* pattern, but tool identifiers don't, so they'd be a pain to tell apart from the rest of the API.
This commit is contained in:
parent
c03c2f3fd0
commit
b26d057783
@ -365,6 +365,8 @@ void LuaTools::Open(lua_State *L)
|
||||
};
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, reg);
|
||||
lua_newtable(L);
|
||||
lua_setfield(L, -2, "index");
|
||||
lua_setglobal(L, "tools");
|
||||
auto &toolList = lsi->gameModel->GetTools();
|
||||
for (int i = 0; i < int(toolList.size()); ++i)
|
||||
@ -380,6 +382,7 @@ void LuaTools::Open(lua_State *L)
|
||||
void LuaTools::SetToolIndex(lua_State *L, ByteString identifier, std::optional<int> index)
|
||||
{
|
||||
lua_getglobal(L, "tools");
|
||||
lua_getfield(L, -1, "index");
|
||||
tpt_lua_pushByteString(L, identifier);
|
||||
if (index)
|
||||
{
|
||||
@ -390,5 +393,5 @@ void LuaTools::SetToolIndex(lua_State *L, ByteString identifier, std::optional<i
|
||||
lua_pushnil(L);
|
||||
}
|
||||
lua_settable(L, -3);
|
||||
lua_pop(L, 1);
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user