mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-27 09:54:36 +02:00
Fix elem.loadDefault handling element tools wrong
Firstly, it would not remove custom element tools when appropriate, reproduce with elem.allocate("CUSTOM", "FAKE") elem.element(elem.CUSTOM_PT_FAKE, elem.element(elem.DEFAULT_PT_SLCN)) elem.loadDefault() elem.allocate("CUSTOM", "FAKE") elem.element(elem.CUSTOM_PT_FAKE, elem.element(elem.DEFAULT_PT_SLCN)) There will be two FAKE element tools, one of them in the Tools section, called NULL, and looking very default. Broken sinceff4500620e
, where I assumed that builtinElements's size reflected the amount of enabled built-in elements. This has not been the case at all sincedd875987b9
, where GetElements was made to return a PT_NUM-sized array instead of a vector with only built-in elements, and so its size increased to PT_NUM, including all possible element numbers. But, strictly speaking, even before that it had not been a correct assumption, because some entries (e.g. 146) of builtinElements could have been disabled, but were possible to allocate from Lua. Secondly, it would not update built-in element tools when appropriate, reproduce with elem.property(elem.DEFAULT_PT_SLCN, "Name", "FAKE") elem.loadDefault() SLCN's tool will still be called FAKE. Also broken sinceff4500620e
, where I neglected to deal with element tools whose elements got updated under them. At the time this would have been done by calling AllocElementTool on them again, but today the appropriate way is UpdateElementTool.
This commit is contained in:
@@ -787,13 +787,22 @@ static int loadDefault(lua_State *L)
|
||||
lua_settable(L, -3);
|
||||
|
||||
manageElementIdentifier(L, id, false);
|
||||
if (id < (int)builtinElements.size())
|
||||
auto oldEnabled = elements[id].Enabled;
|
||||
if (id < (int)builtinElements.size() && builtinElements[id].Enabled)
|
||||
{
|
||||
elements[id] = builtinElements[id];
|
||||
}
|
||||
else
|
||||
{
|
||||
elements[id] = Element();
|
||||
}
|
||||
// TODO: somehow unify element and corresponding element tool management in a way that makes it hard to mess up
|
||||
if (oldEnabled && elements[id].Enabled)
|
||||
{
|
||||
lsi->gameModel->UpdateElementTool(id);
|
||||
}
|
||||
else if (oldEnabled && !elements[id].Enabled)
|
||||
{
|
||||
lsi->gameModel->FreeTool(lsi->gameModel->GetToolFromIdentifier(identifier));
|
||||
}
|
||||
manageElementIdentifier(L, id, true);
|
||||
|
Reference in New Issue
Block a user