2012-02-05 10:37:36 -06:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <string.h>
|
2012-09-03 19:09:53 -05:00
|
|
|
#if !defined(WIN) || defined(__GNUC__)
|
2012-08-14 11:29:59 -05:00
|
|
|
#include <strings.h>
|
2012-09-03 19:09:53 -05:00
|
|
|
#endif
|
2012-02-05 10:37:36 -06:00
|
|
|
#include "CommandInterface.h"
|
2013-03-22 09:14:17 -05:00
|
|
|
#include "gui/game/GameModel.h"
|
|
|
|
#include "gui/game/GameController.h"
|
2012-02-05 10:37:36 -06:00
|
|
|
|
2012-09-01 12:13:13 -05:00
|
|
|
CommandInterface::CommandInterface(GameController * c, GameModel * m) {
|
2012-02-12 06:53:11 -06:00
|
|
|
this->m = m;
|
2012-09-01 12:13:13 -05:00
|
|
|
this->c = c;
|
2012-02-05 10:37:36 -06:00
|
|
|
}
|
|
|
|
|
2012-02-12 06:53:11 -06:00
|
|
|
/*void CommandInterface::AttachGameModel(GameModel * m)
|
2012-02-05 10:37:36 -06:00
|
|
|
{
|
|
|
|
this->m = m;
|
2012-02-12 06:53:11 -06:00
|
|
|
}*/
|
2012-02-05 10:37:36 -06:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2015-08-31 22:51:50 -05:00
|
|
|
m->Log(message, type == LogError || type == LogNotice);
|
2012-03-03 11:58:33 -06:00
|
|
|
}
|
|
|
|
|
2014-11-20 20:51:45 -06:00
|
|
|
int CommandInterface::GetPropertyOffset(std::string key, FormatType & format)
|
2012-02-05 10:37:36 -06:00
|
|
|
{
|
2014-11-20 20:51:45 -06:00
|
|
|
int offset = -1;
|
|
|
|
if (!key.compare("type"))
|
|
|
|
{
|
2012-02-05 10:37:36 -06:00
|
|
|
offset = offsetof(Particle, type);
|
2014-11-20 20:51:45 -06:00
|
|
|
format = FormatElement;
|
|
|
|
}
|
|
|
|
else if (!key.compare("life"))
|
|
|
|
{
|
2012-02-05 10:37:36 -06:00
|
|
|
offset = offsetof(Particle, life);
|
|
|
|
format = FormatInt;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("ctype"))
|
|
|
|
{
|
2012-02-05 10:37:36 -06:00
|
|
|
offset = offsetof(Particle, ctype);
|
|
|
|
format = FormatInt;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("temp"))
|
|
|
|
{
|
2012-02-05 10:37:36 -06:00
|
|
|
offset = offsetof(Particle, temp);
|
|
|
|
format = FormatFloat;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("tmp2"))
|
|
|
|
{
|
2012-02-05 10:37:36 -06:00
|
|
|
offset = offsetof(Particle, tmp2);
|
|
|
|
format = FormatInt;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("tmp"))
|
|
|
|
{
|
2012-06-12 10:07:02 -05:00
|
|
|
offset = offsetof(Particle, tmp);
|
|
|
|
format = FormatInt;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("vy"))
|
|
|
|
{
|
2012-02-05 10:37:36 -06:00
|
|
|
offset = offsetof(Particle, vy);
|
|
|
|
format = FormatFloat;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("vx"))
|
|
|
|
{
|
2012-02-05 10:37:36 -06:00
|
|
|
offset = offsetof(Particle, vx);
|
|
|
|
format = FormatFloat;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("x"))
|
|
|
|
{
|
2012-02-05 10:37:36 -06:00
|
|
|
offset = offsetof(Particle, x);
|
|
|
|
format = FormatFloat;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("y"))
|
|
|
|
{
|
2012-02-05 10:37:36 -06:00
|
|
|
offset = offsetof(Particle, y);
|
|
|
|
format = FormatFloat;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("dcolor") || !key.compare("dcolour"))
|
|
|
|
{
|
2012-02-05 10:37:36 -06:00
|
|
|
offset = offsetof(Particle, dcolour);
|
|
|
|
format = FormatInt;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("pavg0"))
|
|
|
|
{
|
2014-10-26 17:11:46 -05:00
|
|
|
offset = offsetof(Particle, pavg[0]);
|
|
|
|
format = FormatFloat;
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
|
|
|
else if (!key.compare("pavg1"))
|
|
|
|
{
|
2014-10-26 17:11:46 -05:00
|
|
|
offset = offsetof(Particle, pavg[1]);
|
|
|
|
format = FormatFloat;
|
2012-02-05 10:37:36 -06:00
|
|
|
}
|
|
|
|
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;
|
2012-02-05 10:37:36 -06:00
|
|
|
|
|
|
|
// alternative names for some elements
|
2012-10-02 17:30:02 -05:00
|
|
|
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;
|
2012-02-05 10:37:36 -06:00
|
|
|
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)
|
2012-02-05 10:37:36 -06:00
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2012-10-02 17:30:02 -05:00
|
|
|
return -1;
|
2012-02-05 10:37:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CommandInterface::GetLastError()
|
|
|
|
{
|
|
|
|
return lastError;
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandInterface::~CommandInterface() {
|
|
|
|
}
|
|
|
|
|