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

84 lines
1.5 KiB
C++
Raw Normal View History

2019-04-20 07:12:32 -05:00
#include "CommandInterface.h"
#include <cstring>
#include <cstddef>
#if !defined(WIN) || defined(__GNUC__)
#include <strings.h>
#endif
2019-04-20 07:12:32 -05:00
#include "Misc.h"
2013-03-22 09:14:17 -05:00
#include "gui/game/GameModel.h"
2019-04-20 07:12:32 -05:00
#include "simulation/Particle.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(String command)
{
lastError = "No interpreter";
return -1;
}
String CommandInterface::FormatCommand(String command)
{
return command;
}
void CommandInterface::Log(LogType type, String message)
2012-03-03 11:58:33 -06:00
{
m->Log(message, type == LogError || type == LogNotice);
2012-03-03 11:58:33 -06:00
}
int CommandInterface::GetPropertyOffset(ByteString key, FormatType & format)
{
int offset = -1;
for (auto &alias : Particle::GetPropertyAliases())
{
if (key == alias.from)
{
key = alias.to;
}
}
for (auto &prop : Particle::GetProperties())
{
if (key == prop.Name)
{
offset = prop.Offset;
switch (prop.Type)
{
case StructProperty::ParticleType:
format = byteStringEqualsLiteral(key, "type") ? FormatElement : FormatInt; // FormatElement is tightly coupled with "type"
break;
case StructProperty::Integer:
case StructProperty::UInteger:
format = FormatInt;
break;
case StructProperty::Float:
format = FormatFloat;
break;
default:
break;
}
}
}
return offset;
}
String CommandInterface::GetLastError()
{
return lastError;
}
CommandInterface::~CommandInterface() {
}