Prop tool - only check GoL rulestings / names for ctype

They are meaningless when applied to any other property, even .type
This commit is contained in:
jacob1 2021-05-19 00:04:16 -04:00
parent e26ec36fe9
commit 14be92c013
No known key found for this signature in database
GPG Key ID: 4E58A32D510E1995
2 changed files with 29 additions and 17 deletions

View File

@ -108,31 +108,43 @@ void PropertyWindow::SetProperty()
//#C0FFEE //#C0FFEE
v = value.Substr(1).ToNumber<unsigned int>(Format::Hex()); v = value.Substr(1).ToNumber<unsigned int>(Format::Hex());
} }
else if (value.length() > 1 && value.BeginsWith("B") && value.Contains("/"))
{
v = ParseGOLString(value);
if (v == -1)
{
class InvalidGOLString : public std::exception
{
};
throw InvalidGOLString();
}
}
else else
{ {
// Try to parse as particle name
v = sim->GetParticleType(value.ToUtf8()); v = sim->GetParticleType(value.ToUtf8());
if (v == -1)
// Try to parse special GoL rules
if (v == -1 && properties[property->GetOption().second].Name == "ctype")
{ {
for (auto *elementTool : tool->gameModel->GetMenuList()[SC_LIFE]->GetToolList()) if (value.length() > 1 && value.BeginsWith("B") && value.Contains("/"))
{ {
if (elementTool && elementTool->GetName() == value) v = ParseGOLString(value);
if (v == -1)
{ {
v = ID(elementTool->GetToolID()); class InvalidGOLString : public std::exception
break; {
};
throw InvalidGOLString();
}
}
else
{
v = sim->GetParticleType(value.ToUtf8());
if (v == -1)
{
for (auto *elementTool : tool->gameModel->GetMenuList()[SC_LIFE]->GetToolList())
{
if (elementTool && elementTool->GetName() == value)
{
v = ID(elementTool->GetToolID());
break;
}
}
} }
} }
} }
// Parse as plain number
if (v == -1) if (v == -1)
{ {
v = value.ToNumber<int>(); v = value.ToNumber<int>();

View File

@ -5,7 +5,7 @@ std::vector<StructProperty> const &Particle::GetProperties()
{ {
static std::vector<StructProperty> properties = { static std::vector<StructProperty> properties = {
{ "type" , StructProperty::ParticleType, (intptr_t)(offsetof(Particle, type )) }, { "type" , StructProperty::ParticleType, (intptr_t)(offsetof(Particle, type )) },
{ "life" , StructProperty::ParticleType, (intptr_t)(offsetof(Particle, life )) }, { "life" , StructProperty::Integer , (intptr_t)(offsetof(Particle, life )) },
{ "ctype" , StructProperty::ParticleType, (intptr_t)(offsetof(Particle, ctype )) }, { "ctype" , StructProperty::ParticleType, (intptr_t)(offsetof(Particle, ctype )) },
{ "x" , StructProperty::Float , (intptr_t)(offsetof(Particle, x )) }, { "x" , StructProperty::Float , (intptr_t)(offsetof(Particle, x )) },
{ "y" , StructProperty::Float , (intptr_t)(offsetof(Particle, y )) }, { "y" , StructProperty::Float , (intptr_t)(offsetof(Particle, y )) },