2019-04-20 07:12:32 -05:00
|
|
|
#include "CommandInterface.h"
|
|
|
|
|
2016-07-17 22:37:24 -05:00
|
|
|
#include <cstring>
|
2019-06-12 15:51:55 -05:00
|
|
|
#include <cstddef>
|
2023-01-07 02:58:53 -06:00
|
|
|
#include <cassert>
|
2019-04-20 07:12:32 -05:00
|
|
|
|
2022-08-22 08:54:04 -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-02-05 10:37:36 -06:00
|
|
|
|
2023-01-07 02:58:53 -06:00
|
|
|
CommandInterface *commandInterface = nullptr;
|
|
|
|
|
|
|
|
CommandInterface::CommandInterface(GameController * c, GameModel * m)
|
|
|
|
{
|
|
|
|
assert(!commandInterface);
|
|
|
|
commandInterface = this;
|
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
|
|
|
}
|
|
|
|
|
2023-01-07 02:58:53 -06:00
|
|
|
CommandInterface::~CommandInterface()
|
2012-02-05 10:37:36 -06:00
|
|
|
{
|
2023-01-07 02:58:53 -06:00
|
|
|
commandInterface = nullptr;
|
|
|
|
}
|
2012-02-05 10:37:36 -06:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
int CommandInterface::Command(String command)
|
2012-02-05 10:37:36 -06:00
|
|
|
{
|
|
|
|
lastError = "No interpreter";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
String CommandInterface::FormatCommand(String command)
|
2012-02-05 10:37:36 -06:00
|
|
|
{
|
|
|
|
return command;
|
|
|
|
}
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
void CommandInterface::Log(LogType type, String message)
|
2012-03-03 11:58:33 -06:00
|
|
|
{
|
2015-08-31 22:51:50 -05:00
|
|
|
m->Log(message, type == LogError || type == LogNotice);
|
2012-03-03 11:58:33 -06:00
|
|
|
}
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
int CommandInterface::GetPropertyOffset(ByteString key, FormatType & format)
|
2012-02-05 10:37:36 -06:00
|
|
|
{
|
2014-11-20 20:51:45 -06:00
|
|
|
int offset = -1;
|
2022-08-08 01:55:32 -05:00
|
|
|
for (auto &alias : Particle::GetPropertyAliases())
|
2014-11-20 20:51:45 -06:00
|
|
|
{
|
2022-08-08 01:55:32 -05:00
|
|
|
if (key == alias.from)
|
|
|
|
{
|
|
|
|
key = alias.to;
|
|
|
|
}
|
2014-11-20 20:51:45 -06:00
|
|
|
}
|
2022-08-08 01:55:32 -05:00
|
|
|
for (auto &prop : Particle::GetProperties())
|
2014-11-20 20:51:45 -06:00
|
|
|
{
|
2022-08-08 01:55:32 -05:00
|
|
|
if (key == prop.Name)
|
|
|
|
{
|
|
|
|
offset = prop.Offset;
|
|
|
|
switch (prop.Type)
|
|
|
|
{
|
|
|
|
case StructProperty::ParticleType:
|
2022-08-22 08:54:04 -05:00
|
|
|
format = byteStringEqualsLiteral(key, "type") ? FormatElement : FormatInt; // FormatElement is tightly coupled with "type"
|
2022-08-08 01:55:32 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case StructProperty::Integer:
|
|
|
|
case StructProperty::UInteger:
|
|
|
|
format = FormatInt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case StructProperty::Float:
|
|
|
|
format = FormatFloat;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-05 10:37:36 -06:00
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
String CommandInterface::GetLastError()
|
2012-02-05 10:37:36 -06:00
|
|
|
{
|
|
|
|
return lastError;
|
|
|
|
}
|