summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-03 20:48:45 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-03 20:48:45 (GMT)
commit61739018759847c4d356a7596926652856030306 (patch)
tree59dd50893ecb47bfab709d778b8a8a02dfc83331 /src
parentf586a5585f3838e78cf6880b84d4c369040b5f67 (diff)
downloadpowder-61739018759847c4d356a7596926652856030306.zip
powder-61739018759847c4d356a7596926652856030306.tar.gz
Old TPT console commands with "!" prefix
Diffstat (limited to 'src')
-rw-r--r--src/cat/LuaScriptInterface.cpp32
-rw-r--r--src/cat/LuaScriptInterface.h2
-rw-r--r--src/cat/TPTSTypes.h57
-rw-r--r--src/cat/TPTScriptInterface.cpp4
-rw-r--r--src/interface/Textbox.cpp2
5 files changed, 76 insertions, 21 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index edd111f..5aa6a73 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -8,13 +8,15 @@
#include <string>
#include "Config.h"
#include "LuaScriptInterface.h"
+#include "TPTScriptInterface.h"
#include "simulation/Simulation.h"
#include "game/GameModel.h"
#include "LuaScriptHelper.h"
LuaScriptInterface::LuaScriptInterface(GameModel * m):
CommandInterface(m),
- currentCommand(false)
+ currentCommand(false),
+ legacy(new TPTScriptInterface(m))
{
int i = 0, j;
char tmpname[12];
@@ -284,16 +286,26 @@ void LuaScriptInterface::OnTick()
int LuaScriptInterface::Command(std::string command)
{
- int ret;
- lastError = "";
- currentCommand = true;
- if((ret = luaL_dostring(l, command.c_str())))
+ if(command[0] == '!')
{
- lastError = luacon_geterror();
- //Log(LogError, lastError);
+ lastError = "";
+ int ret = legacy->Command(command.substr(1));
+ lastError = legacy->GetLastError();
+ return ret;
+ }
+ else
+ {
+ int ret;
+ lastError = "";
+ currentCommand = true;
+ if((ret = luaL_dostring(l, command.c_str())))
+ {
+ lastError = luacon_geterror();
+ //Log(LogError, lastError);
+ }
+ currentCommand = false;
+ return ret;
}
- currentCommand = false;
- return ret;
}
std::string LuaScriptInterface::FormatCommand(std::string command)
@@ -302,7 +314,7 @@ std::string LuaScriptInterface::FormatCommand(std::string command)
}
LuaScriptInterface::~LuaScriptInterface() {
- // TODO Auto-generated destructor stub
+ delete legacy;
}
#ifndef FFI
diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h
index 3d6f0b9..44ad279 100644
--- a/src/cat/LuaScriptInterface.h
+++ b/src/cat/LuaScriptInterface.h
@@ -33,10 +33,12 @@ extern "C"
#define LUACON_EL_MODIFIED_GRAPHICS 0x2
#define LUACON_EL_MODIFIED_MENUS 0x4
+class TPTScriptInterface;
class LuaScriptInterface: public CommandInterface {
int luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_mousebutton, luacon_brushx, luacon_brushy;
bool luacon_mousedown;
bool currentCommand;
+ TPTScriptInterface * legacy;
public:
lua_State *l;
LuaScriptInterface(GameModel * m);
diff --git a/src/cat/TPTSTypes.h b/src/cat/TPTSTypes.h
index ad08f0b..dfea425 100644
--- a/src/cat/TPTSTypes.h
+++ b/src/cat/TPTSTypes.h
@@ -9,6 +9,7 @@
#define TPTSTYPES_H_
#include <string>
+#include <typeinfo>
#include "interface/Point.h"
enum ValueType { TypeNumber, TypePoint, TypeString, TypeNull, TypeFunction };
@@ -26,15 +27,6 @@ public:
}
};
-class InvalidConversionException: public GeneralException
-{
-private:
- ValueType from;
- ValueType to;
-public:
- InvalidConversionException(ValueType from_, ValueType to_): GeneralException("Invalid conversion"), from(from_), to(to_) {
- }
-};
class NumberType;
class StringType;
@@ -52,9 +44,56 @@ public:
operator StringType();
operator PointType();
ValueType GetType();
+ std::string TypeName()
+ {
+ switch(type)
+ {
+ case TypeNumber:
+ return "Number";
+ case TypePoint:
+ return "Point";
+ case TypeString:
+ return "String";
+ case TypeNull:
+ return "Null";
+ case TypeFunction:
+ return "Function";
+ default:
+ return "Unknown";
+ }
+ }
+ static std::string TypeName(ValueType type)
+ {
+ switch(type)
+ {
+ case TypeNumber:
+ return "Number";
+ case TypePoint:
+ return "Point";
+ case TypeString:
+ return "String";
+ case TypeNull:
+ return "Null";
+ case TypeFunction:
+ return "Function";
+ default:
+ return "Unknown";
+ }
+ }
~AnyType();
};
+class InvalidConversionException: public GeneralException
+{
+private:
+ ValueType from;
+ ValueType to;
+public:
+ InvalidConversionException(ValueType from_, ValueType to_):
+ GeneralException("Invalid conversion from " + AnyType::TypeName(from_) + " to " + AnyType::TypeName(to_)), from(from_), to(to_) {
+ }
+};
+
class NumberType: public AnyType
{
public:
diff --git a/src/cat/TPTScriptInterface.cpp b/src/cat/TPTScriptInterface.cpp
index 137ad58..44f5d2e 100644
--- a/src/cat/TPTScriptInterface.cpp
+++ b/src/cat/TPTScriptInterface.cpp
@@ -167,8 +167,8 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
{
//Arguments from stack
StringType property = eval(words);
- AnyType value = eval(words);
AnyType selector = eval(words);
+ AnyType value = eval(words);
Simulation * sim = m->GetSimulation();
@@ -187,7 +187,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
{
ui::Point tempPoint = ((PointType)selector).Value();
if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES)
- throw GeneralException("Invalid particle");
+ throw GeneralException("Invalid position");
}
else
diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp
index e4a1261..4916c64 100644
--- a/src/interface/Textbox.cpp
+++ b/src/interface/Textbox.cpp
@@ -65,6 +65,8 @@ void Textbox::SetText(std::string newText)
else
Label::SetText(newText);
+ cursor = newText.length();
+
if(cursor)
{
Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY);