mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-03-23 07:39:50 +01:00
sim.signs.delete() api function
This commit is contained in:
parent
6d141b0722
commit
b8ce522779
@ -623,7 +623,11 @@ int LuaScriptInterface::simulation_signNewIndex(lua_State *l)
|
||||
if (!key.compare("text"))
|
||||
{
|
||||
const char *temp = luaL_checkstring(l, 3);
|
||||
luacon_sim->signs[id].text = format::CleanString(temp, false, true, true).substr(0, 45);
|
||||
std::string cleaned = format::CleanString(temp, false, true, true).substr(0, 45);
|
||||
if (!cleaned.empty())
|
||||
luacon_sim->signs[id].text = cleaned;
|
||||
else
|
||||
luaL_error(l, "Text is empty");
|
||||
return 0;
|
||||
}
|
||||
else if (!key.compare("justification"))
|
||||
@ -660,7 +664,7 @@ int LuaScriptInterface::simulation_signNewIndex(lua_State *l)
|
||||
return 0;
|
||||
}
|
||||
|
||||
//creates a new sign at the first open index
|
||||
// Creates a new sign at the first open index
|
||||
int LuaScriptInterface::simulation_newsign(lua_State *l)
|
||||
{
|
||||
if (luacon_sim->signs.size() >= MAXSIGNS)
|
||||
@ -683,6 +687,17 @@ int LuaScriptInterface::simulation_newsign(lua_State *l)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Deletes a sign
|
||||
int simulation_deletesign(lua_State *l)
|
||||
{
|
||||
int signID = luaL_checkinteger(l, 1);
|
||||
if (signID <= 0 || signID > (int)luacon_sim->signs.size())
|
||||
return luaL_error(l, "Sign doesn't exist");
|
||||
|
||||
luacon_sim->signs.erase(luacon_sim->signs.begin()+signID-1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//// Begin Simulation API
|
||||
|
||||
StructProperty * LuaScriptInterface::particleProperties;
|
||||
@ -814,6 +829,8 @@ void LuaScriptInterface::initSimulationAPI()
|
||||
}
|
||||
lua_pushcfunction(l, simulation_newsign);
|
||||
lua_setfield(l, -2, "new");
|
||||
lua_pushcfunction(l, simulation_deletesign);
|
||||
lua_setfield(l, -2, "delete");
|
||||
lua_setfield(l, -2, "signs");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user