summaryrefslogtreecommitdiff
path: root/src/cat/CommandInterface.cpp
blob: e8fc7b8c41ae9a0ad33270c009a78d9f4996720b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Kitty.cpp
 *
 *  Created on: Feb 2, 2012
 *      Author: Simon
 */

#include <iostream>
#include <string>
#include <string.h>
#include "CommandInterface.h"
#include "game/GameModel.h"

CommandInterface::CommandInterface(GameModel * m) {
	this->m = m;
}

/*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;
}

void CommandInterface::Log(LogType type, std::string message)
{
	m->Log(message);
}

int CommandInterface::GetPropertyOffset(std::string key_, FormatType & format)
{
	char * key = (char *)key_.c_str();
	int offset;
	if (strcmp(key, "type")==0){
		offset = offsetof(Particle, type);
		format = FormatInt;
	} else if (strcmp(key, "life")==0){
		offset = offsetof(Particle, life);
		format = FormatInt;
	} else if (strcmp(key, "ctype")==0){
		offset = offsetof(Particle, ctype);
		format = FormatInt;
	} else if (strcmp(key, "temp")==0){
		offset = offsetof(Particle, temp);
		format = FormatFloat;
	} else if (strcmp(key, "tmp")==0){
		offset = offsetof(Particle, tmp);
		format = FormatInt;
	} else if (strcmp(key, "tmp2")==0){
		offset = offsetof(Particle, tmp2);
		format = FormatInt;
	} else if (strcmp(key, "vy")==0){
		offset = offsetof(Particle, vy);
		format = FormatFloat;
	} else if (strcmp(key, "vx")==0){
		offset = offsetof(Particle, vx);
		format = FormatFloat;
	} else if (strcmp(key, "x")==0){
		offset = offsetof(Particle, x);
		format = FormatFloat;
	} else if (strcmp(key, "y")==0){
		offset = offsetof(Particle, y);
		format = FormatFloat;
	} else if (strcmp(key, "dcolour")==0){
		offset = offsetof(Particle, dcolour);
		format = FormatInt;
	} else if (strcmp(key, "dcolor")==0){
		offset = offsetof(Particle, dcolour);
		format = FormatInt;
	} else {
		offset = -1;
	}
	return offset;
}

int CommandInterface::GetParticleType(std::string type)
{
	int i = -1;
	char * txt = (char*)type.c_str();

	//Scope
	Element * elements = m->GetSimulation()->elements;

	// alternative names for some elements
	if (strcasecmp(txt,"C4")==0) i = PT_PLEX;
	else if (strcasecmp(txt,"C5")==0) i = PT_C5;
	else if (strcasecmp(txt,"NONE")==0) i = PT_NONE;
	for (i=1; i<PT_NUM; i++) {
		if (strcasecmp(txt, elements[i].Name)==0 && elements[i].Enabled)
		{
			return i;
		}
	}
	return i;
}

std::string CommandInterface::GetLastError()
{
	return lastError;
}

CommandInterface::~CommandInterface() {
}