From 41e136a07ce39ecb1f12a4e119f010bbdc65a1f2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 19 Jan 2012 13:29:06 -0700 Subject: the pure-gats interface works! --- src/gamestate.cpp | 2 +- src/gamestate.h | 2 +- src/interfacegats.cpp | 32 +++++++++++++++++++++++--------- src/interfacegats.h | 6 ++++++ src/options.cpp | 23 +++++++++++++++++++++++ src/options.h | 2 ++ 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 852926e..10cfafa 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -22,7 +22,7 @@ GameState::~GameState() { } -Gats::Object *GameState::toGats() const +Gats::Dictionary *GameState::toGats() const { Gats::Dictionary *pRoot = new Gats::Dictionary; diff --git a/src/gamestate.h b/src/gamestate.h index 2249c25..8ff92f5 100644 --- a/src/gamestate.h +++ b/src/gamestate.h @@ -22,7 +22,7 @@ public: GameState( Game *pGame, Interface *pIface ); virtual ~GameState(); - Gats::Object *toGats() const; + Gats::Dictionary *toGats() const; void fromGats( Gats::Dictionary *pRoot ); Interface *getInterface() { return pIface; } diff --git a/src/interfacegats.cpp b/src/interfacegats.cpp index b6ad859..9f6cf8d 100644 --- a/src/interfacegats.cpp +++ b/src/interfacegats.cpp @@ -2,6 +2,7 @@ #include "smlnode.h" #include "gamestate.h" +#include "options.h" #include "smlrendererhtml.h" @@ -16,7 +17,8 @@ using namespace Bu; PluginInterface3( plugin_interface_gats, gats, InterfaceGats, Interface, "Mike Buland", 1, 0 ); -InterfaceGats::InterfaceGats() +InterfaceGats::InterfaceGats() : + fResult( mbResult ) { } @@ -28,8 +30,8 @@ void InterfaceGats::run( class Game *pGame ) { GameState gs( pGame, this ); + Gats::GatsStream gsIn( sioRaw ); { - Gats::GatsStream gsIn( sioRaw ); Gats::Object *pObj = gsIn.readObject(); if( pObj ) @@ -37,6 +39,8 @@ void InterfaceGats::run( class Game *pGame ) gs.fromGats( dynamic_cast(pObj) ); delete pObj; + + gs.execCommand( Options::getInstance().sCommand ); } else { @@ -44,17 +48,27 @@ void InterfaceGats::run( class Game *pGame ) } } - gs.execCommand("status"); - - //{ - // Gats::GatsStream gs - //pObj = gs.toGats(); - + { + Gats::Dictionary *pDict; + if( gs.isRunning() ) + { + pDict = gs.toGats(); + pDict->insertBool("running", true ); + } + else + { + pDict = new Gats::Dictionary(); + pDict->insertBool("running", false ); + } + pDict->insert("result", mbResult.getString() ); + gsIn.writeObject( pDict ); + delete pDict; + } } void InterfaceGats::display( const SmlNode *pSml ) { SmlRendererHtml rend; - rend.render( sio, pSml ); + rend.render( fResult, pSml ); } diff --git a/src/interfacegats.h b/src/interfacegats.h index ff1f760..473d71c 100644 --- a/src/interfacegats.h +++ b/src/interfacegats.h @@ -2,6 +2,8 @@ #define INETRFACE_GATS_H #include "interface.h" +#include +#include class InterfaceGats : public Interface { @@ -12,6 +14,10 @@ public: virtual void run( class Game *pGame ); virtual void display( const class SmlNode *pSml ); + +private: + Bu::MemBuf mbResult; + Bu::Formatter fResult; }; #endif diff --git a/src/options.cpp b/src/options.cpp index ac43dfc..f8112c4 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "interfaceplugger.h" @@ -46,10 +48,15 @@ void Options::parse( int argc, char *argv[] ) opt.addOption( Bu::slot( this, &Options::smlTest ), "sml-test", "Test SML parser." ); + opt.addOption( sCommand, "command", + "Set the command to execute once the game is loaded. " + "This does not work with all interfaces."); opt.addOption( Bu::slot( this, &Options::version ), "version", "Show full version info." ); opt.addOption( Bu::slot( this, &Options::builtins ), "builtins", "List available builtins." ); + opt.addOption( Bu::slot( this, &Options::printResult ), "print-result", + "Print the result from a save file." ); opt.addOption( sInterface, 'i', "interface", "Select interface module. Default is " + sInterface + ". Available modules: " + sIFaces ); @@ -124,3 +131,19 @@ int Options::nonOption( Bu::Array aArgs ) return 0; } +int Options::printResult( Bu::Array aArgs ) +{ + Gats::GatsStream gsIn( sioRaw ); + Gats::Object *pObj = gsIn.readObject(); + Gats::Dictionary *pDict = dynamic_cast(pObj); + + sio << pDict->getStr("result") << sio.nl << sio.nl << "Running: " + << pDict->getBool("running") << sio.nl; + + delete pObj; + + exit( 0 ); + + return 0; +} + diff --git a/src/options.h b/src/options.h index 3012a58..bf9825f 100644 --- a/src/options.h +++ b/src/options.h @@ -17,12 +17,14 @@ public: Bu::String sFile; Bu::String sInterface; + Bu::String sCommand; protected: int version( Bu::Array aArgs ); int builtins( Bu::Array aArgs ); int smlTest( Bu::Array aArgs ); int nonOption( Bu::Array aArgs ); + int printResult( Bu::Array aArgs ); }; #endif -- cgit v1.2.3