mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-01 12:02:40 +02:00
prevent setting invalid types, fix setting type to "NONE", "C4", & "C5"
This commit is contained in:
@@ -96,16 +96,16 @@ int CommandInterface::GetParticleType(std::string type)
|
||||
Element * elements = m->GetSimulation()->elements;
|
||||
|
||||
// alternative names for some elements
|
||||
if (strcasecmp(txt,"C4")==0) i = PT_PLEX;
|
||||
else if (strcasecmp(txt,"C5")==0) i = PT_C5;
|
||||
else if (strcasecmp(txt,"NONE")==0) i = PT_NONE;
|
||||
if (strcasecmp(txt,"C4")==0) return PT_PLEX;
|
||||
else if (strcasecmp(txt,"C5")==0) return PT_C5;
|
||||
else if (strcasecmp(txt,"NONE")==0) return PT_NONE;
|
||||
for (i=1; i<PT_NUM; i++) {
|
||||
if (strcasecmp(txt, elements[i].Name)==0 && elements[i].Enabled)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string CommandInterface::GetLastError()
|
||||
|
@@ -211,9 +211,15 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
||||
if(value.GetType() == TypeNumber)
|
||||
newValue = ((NumberType)value).Value();
|
||||
else if(value.GetType() == TypeString)
|
||||
{
|
||||
newValue = GetParticleType(((StringType)value).Value());
|
||||
if (newValue < 0 || newValue >= PT_NUM)
|
||||
throw GeneralException("Invalid element");
|
||||
}
|
||||
else
|
||||
throw GeneralException("Invalid value for assignment");
|
||||
if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM))
|
||||
throw GeneralException("Invalid element");
|
||||
|
||||
if(selector.GetType() == TypePoint || selector.GetType() == TypeNumber)
|
||||
{
|
||||
|
Reference in New Issue
Block a user