mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-11 19:04:05 +02: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:
@@ -365,6 +365,8 @@ void LuaTools::Open(lua_State *L)
|
|||||||
};
|
};
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
luaL_register(L, NULL, reg);
|
luaL_register(L, NULL, reg);
|
||||||
|
lua_newtable(L);
|
||||||
|
lua_setfield(L, -2, "index");
|
||||||
lua_setglobal(L, "tools");
|
lua_setglobal(L, "tools");
|
||||||
auto &toolList = lsi->gameModel->GetTools();
|
auto &toolList = lsi->gameModel->GetTools();
|
||||||
for (int i = 0; i < int(toolList.size()); ++i)
|
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)
|
void LuaTools::SetToolIndex(lua_State *L, ByteString identifier, std::optional<int> index)
|
||||||
{
|
{
|
||||||
lua_getglobal(L, "tools");
|
lua_getglobal(L, "tools");
|
||||||
|
lua_getfield(L, -1, "index");
|
||||||
tpt_lua_pushByteString(L, identifier);
|
tpt_lua_pushByteString(L, identifier);
|
||||||
if (index)
|
if (index)
|
||||||
{
|
{
|
||||||
@@ -390,5 +393,5 @@ void LuaTools::SetToolIndex(lua_State *L, ByteString identifier, std::optional<i
|
|||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 2);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user