remove duplicate function, fix Simulation::GetParticleType, fixes #402
This commit is contained in:
parent
01d17cb860
commit
866289c179
@ -105,27 +105,6 @@ int CommandInterface::GetPropertyOffset(std::string key, FormatType & format)
|
||||
return offset;
|
||||
}
|
||||
|
||||
int CommandInterface::GetParticleType(std::string type)
|
||||
{
|
||||
int i = -1;
|
||||
char * txt = (char*)type.c_str();
|
||||
|
||||
//Scope
|
||||
Element * elements = m->GetSimulation()->elements;
|
||||
|
||||
// alternative names for some elements
|
||||
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 -1;
|
||||
}
|
||||
|
||||
std::string CommandInterface::GetLastError()
|
||||
{
|
||||
return lastError;
|
||||
|
@ -18,7 +18,6 @@ public:
|
||||
enum FormatType { FormatInt, FormatString, FormatChar, FormatFloat, FormatElement };
|
||||
CommandInterface(GameController * c, GameModel * m);
|
||||
int GetPropertyOffset(std::string key, FormatType & format);
|
||||
int GetParticleType(std::string type);
|
||||
void Log(LogType type, std::string message);
|
||||
//void AttachGameModel(GameModel * m);
|
||||
virtual bool OnActiveToolChanged(int toolSelection, Tool * tool) {return true;}
|
||||
|
@ -413,7 +413,7 @@ int luacon_elementwrite(lua_State* l)
|
||||
//Convert to upper case
|
||||
for (size_t j = 0; j < strlen(tempstring); j++)
|
||||
tempstring[j] = toupper(tempstring[j]);
|
||||
if(luacon_ci->GetParticleType(tempstring) != -1)
|
||||
if(luacon_sim->GetParticleType(tempstring) != -1)
|
||||
{
|
||||
free(tempstring);
|
||||
return luaL_error(l, "Name in use");
|
||||
@ -664,7 +664,7 @@ int luatpt_getelement(lua_State *l)
|
||||
{
|
||||
luaL_checktype(l, 1, LUA_TSTRING);
|
||||
const char* name = luaL_optstring(l, 1, "");
|
||||
if ((t = luacon_ci->GetParticleType(name))==-1)
|
||||
if ((t = luacon_sim->GetParticleType(name))==-1)
|
||||
return luaL_error(l, "Unrecognised element '%s'", name);
|
||||
lua_pushinteger(l, t);
|
||||
}
|
||||
@ -852,7 +852,7 @@ int luatpt_create(lua_State* l)
|
||||
return luaL_error(l, "Unrecognised element number '%d'", t);
|
||||
} else {
|
||||
const char* name = luaL_optstring(l, 3, "dust");
|
||||
if ((t = luacon_ci->GetParticleType(std::string(name))) == -1)
|
||||
if ((t = luacon_sim->GetParticleType(std::string(name))) == -1)
|
||||
return luaL_error(l,"Unrecognised element '%s'", name);
|
||||
}
|
||||
retid = luacon_sim->create_part(-1, x, y, t);
|
||||
@ -1065,7 +1065,7 @@ int luatpt_set_property(lua_State* l)
|
||||
if(!lua_isnumber(l, acount) && lua_isstring(l, acount))
|
||||
{
|
||||
name = luaL_optstring(l, acount, "none");
|
||||
if ((partsel = luacon_ci->GetParticleType(std::string(name))) == -1)
|
||||
if ((partsel = luacon_sim->GetParticleType(std::string(name))) == -1)
|
||||
return luaL_error(l, "Unrecognised element '%s'", name);
|
||||
}
|
||||
}
|
||||
@ -1082,7 +1082,7 @@ int luatpt_set_property(lua_State* l)
|
||||
else
|
||||
{
|
||||
name = luaL_checklstring(l, 2, NULL);
|
||||
if ((t = luacon_ci->GetParticleType(std::string(name)))==-1)
|
||||
if ((t = luacon_sim->GetParticleType(std::string(name)))==-1)
|
||||
return luaL_error(l, "Unrecognised element '%s'", name);
|
||||
}
|
||||
if (!lua_isnumber(l, 3) || acount >= 6)
|
||||
|
@ -296,7 +296,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
||||
}
|
||||
else
|
||||
{
|
||||
newValue = GetParticleType(((StringType)value).Value());
|
||||
newValue = m->GetSimulation()->GetParticleType(((StringType)value).Value());
|
||||
if (newValue < 0 || newValue >= PT_NUM)
|
||||
{
|
||||
// TODO: add element CAKE to invalidate this
|
||||
@ -386,7 +386,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
||||
if (selector.GetType() == TypeNumber)
|
||||
type = ((NumberType)selector).Value();
|
||||
else if (selector.GetType() == TypeString)
|
||||
type = GetParticleType(((StringType)selector).Value());
|
||||
type = m->GetSimulation()->GetParticleType(((StringType)selector).Value());
|
||||
|
||||
if (type<0 || type>=PT_NUM)
|
||||
throw GeneralException("Invalid particle type");
|
||||
@ -446,7 +446,7 @@ AnyType TPTScriptInterface::tptS_create(std::deque<std::string> * words)
|
||||
if(createType.GetType() == TypeNumber)
|
||||
type = ((NumberType)createType).Value();
|
||||
else if(createType.GetType() == TypeString)
|
||||
type = GetParticleType(((StringType)createType).Value());
|
||||
type = m->GetSimulation()->GetParticleType(((StringType)createType).Value());
|
||||
else
|
||||
throw GeneralException("Invalid type");
|
||||
|
||||
|
@ -4726,15 +4726,18 @@ movedone:
|
||||
|
||||
int Simulation::GetParticleType(std::string type)
|
||||
{
|
||||
int i = -1;
|
||||
char * txt = (char*)type.c_str();
|
||||
|
||||
// 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;
|
||||
for (i=1; i<PT_NUM; i++) {
|
||||
if (strcasecmp(txt, elements[i].Name)==0 && strlen(elements[i].Name) && elements[i].Enabled)
|
||||
if (!strcasecmp(txt, "C4"))
|
||||
return PT_PLEX;
|
||||
else if (!strcasecmp(txt, "C5"))
|
||||
return PT_C5;
|
||||
else if (!strcasecmp(txt, "NONE"))
|
||||
return PT_NONE;
|
||||
for (int i = 1; i < PT_NUM; i++)
|
||||
{
|
||||
if (!strcasecmp(txt, elements[i].Name) && strlen(elements[i].Name) && elements[i].Enabled)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
Reference in New Issue
Block a user