From 61739018759847c4d356a7596926652856030306 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 3 Aug 2012 21:48:45 +0100 Subject: Old TPT console commands with "!" prefix 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 #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 +#include #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 * 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 * 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); -- cgit v0.9.2-21-gd62e