ability to use Celcius and Farenheit in console

This commit is contained in:
jacob1
2013-08-29 23:37:57 -04:00
parent a5cee8c393
commit b2957dc1c9

View File

@@ -255,8 +255,20 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
//Selector
int newValue;
if(value.GetType() == TypeNumber)
{
newValue = ((NumberType)value).Value();
}
else if(value.GetType() == TypeString)
{
if (property.Value() == "temp")
{
std::string newString = ((StringType)value).Value();
if (newString.at(newString.length()-1) == 'C')
newValue = atoi(newString.substr(0, newString.length()-1).c_str())+273;
else if (newString.at(newString.length()-1) == 'F')
newValue = (int)((atoi(newString.substr(0, newString.length()-1).c_str())-32.0f)*5/9+273.15f);
}
else
{
newValue = GetParticleType(((StringType)value).Value());
if (newValue < 0 || newValue >= PT_NUM)
@@ -267,6 +279,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
throw GeneralException("Invalid element");
}
}
}
else
throw GeneralException("Invalid value for assignment");
if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM))