The-Powder-Toy/src/lua/CommandInterface.cpp

137 lines
2.7 KiB
C++
Raw Normal View History

#include <iostream>
#include <string>
#include <string.h>
#if !defined(WIN) || defined(__GNUC__)
#include <strings.h>
#endif
#include "CommandInterface.h"
2013-03-22 09:14:17 -05:00
#include "gui/game/GameModel.h"
#include "gui/game/GameController.h"
2012-09-01 12:13:13 -05:00
CommandInterface::CommandInterface(GameController * c, GameModel * m) {
this->m = m;
2012-09-01 12:13:13 -05:00
this->c = c;
}
/*void CommandInterface::AttachGameModel(GameModel * m)
{
this->m = m;
}*/
int CommandInterface::Command(std::string command)
{
lastError = "No interpreter";
return -1;
}
std::string CommandInterface::FormatCommand(std::string command)
{
return command;
}
2012-03-03 11:58:33 -06:00
void CommandInterface::Log(LogType type, std::string message)
{
m->Log(message, type == LogError || type == LogNotice);
2012-03-03 11:58:33 -06:00
}
int CommandInterface::GetPropertyOffset(std::string key, FormatType & format)
{
int offset = -1;
if (!key.compare("type"))
{
offset = offsetof(Particle, type);
format = FormatElement;
}
else if (!key.compare("life"))
{
offset = offsetof(Particle, life);
format = FormatInt;
}
else if (!key.compare("ctype"))
{
offset = offsetof(Particle, ctype);
format = FormatInt;
}
else if (!key.compare("temp"))
{
offset = offsetof(Particle, temp);
format = FormatFloat;
}
else if (!key.compare("tmp2"))
{
offset = offsetof(Particle, tmp2);
format = FormatInt;
}
else if (!key.compare("tmp"))
{
offset = offsetof(Particle, tmp);
format = FormatInt;
}
else if (!key.compare("vy"))
{
offset = offsetof(Particle, vy);
format = FormatFloat;
}
else if (!key.compare("vx"))
{
offset = offsetof(Particle, vx);
format = FormatFloat;
}
else if (!key.compare("x"))
{
offset = offsetof(Particle, x);
format = FormatFloat;
}
else if (!key.compare("y"))
{
offset = offsetof(Particle, y);
format = FormatFloat;
}
else if (!key.compare("dcolor") || !key.compare("dcolour"))
{
offset = offsetof(Particle, dcolour);
format = FormatInt;
}
else if (!key.compare("pavg0"))
{
offset = offsetof(Particle, pavg[0]);
format = FormatFloat;
}
else if (!key.compare("pavg1"))
{
offset = offsetof(Particle, pavg[1]);
format = FormatFloat;
}
return offset;
}
int CommandInterface::GetParticleType(std::string type)
{
int i = -1;
char * txt = (char*)type.c_str();
//Scope
2012-05-07 11:59:50 -05:00
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++) {
2012-05-07 11:59:50 -05:00
if (strcasecmp(txt, elements[i].Name)==0 && elements[i].Enabled)
{
return i;
}
}
return -1;
}
std::string CommandInterface::GetLastError()
{
return lastError;
}
CommandInterface::~CommandInterface() {
}