diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-01-19 13:29:06 -0700 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-01-19 13:29:06 -0700 |
| commit | 41e136a07ce39ecb1f12a4e119f010bbdc65a1f2 (patch) | |
| tree | e617b99c16de65347ae20bee999ffd7d085f43fb /src | |
| parent | d790ced1f7af3a96c7dba96ea4eb9262f70eb58b (diff) | |
| download | stage-41e136a07ce39ecb1f12a4e119f010bbdc65a1f2.tar.gz stage-41e136a07ce39ecb1f12a4e119f010bbdc65a1f2.tar.bz2 stage-41e136a07ce39ecb1f12a4e119f010bbdc65a1f2.tar.xz stage-41e136a07ce39ecb1f12a4e119f010bbdc65a1f2.zip | |
the pure-gats interface works!
Diffstat (limited to 'src')
| -rw-r--r-- | src/gamestate.cpp | 2 | ||||
| -rw-r--r-- | src/gamestate.h | 2 | ||||
| -rw-r--r-- | src/interfacegats.cpp | 32 | ||||
| -rw-r--r-- | src/interfacegats.h | 6 | ||||
| -rw-r--r-- | src/options.cpp | 23 | ||||
| -rw-r--r-- | 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() | |||
| 22 | { | 22 | { |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | Gats::Object *GameState::toGats() const | 25 | Gats::Dictionary *GameState::toGats() const |
| 26 | { | 26 | { |
| 27 | Gats::Dictionary *pRoot = new Gats::Dictionary; | 27 | Gats::Dictionary *pRoot = new Gats::Dictionary; |
| 28 | 28 | ||
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: | |||
| 22 | GameState( Game *pGame, Interface *pIface ); | 22 | GameState( Game *pGame, Interface *pIface ); |
| 23 | virtual ~GameState(); | 23 | virtual ~GameState(); |
| 24 | 24 | ||
| 25 | Gats::Object *toGats() const; | 25 | Gats::Dictionary *toGats() const; |
| 26 | void fromGats( Gats::Dictionary *pRoot ); | 26 | void fromGats( Gats::Dictionary *pRoot ); |
| 27 | 27 | ||
| 28 | Interface *getInterface() { return pIface; } | 28 | 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 @@ | |||
| 2 | 2 | ||
| 3 | #include "smlnode.h" | 3 | #include "smlnode.h" |
| 4 | #include "gamestate.h" | 4 | #include "gamestate.h" |
| 5 | #include "options.h" | ||
| 5 | 6 | ||
| 6 | #include "smlrendererhtml.h" | 7 | #include "smlrendererhtml.h" |
| 7 | 8 | ||
| @@ -16,7 +17,8 @@ using namespace Bu; | |||
| 16 | PluginInterface3( plugin_interface_gats, gats, InterfaceGats, | 17 | PluginInterface3( plugin_interface_gats, gats, InterfaceGats, |
| 17 | Interface, "Mike Buland", 1, 0 ); | 18 | Interface, "Mike Buland", 1, 0 ); |
| 18 | 19 | ||
| 19 | InterfaceGats::InterfaceGats() | 20 | InterfaceGats::InterfaceGats() : |
| 21 | fResult( mbResult ) | ||
| 20 | { | 22 | { |
| 21 | } | 23 | } |
| 22 | 24 | ||
| @@ -28,8 +30,8 @@ void InterfaceGats::run( class Game *pGame ) | |||
| 28 | { | 30 | { |
| 29 | GameState gs( pGame, this ); | 31 | GameState gs( pGame, this ); |
| 30 | 32 | ||
| 33 | Gats::GatsStream gsIn( sioRaw ); | ||
| 31 | { | 34 | { |
| 32 | Gats::GatsStream gsIn( sioRaw ); | ||
| 33 | Gats::Object *pObj = gsIn.readObject(); | 35 | Gats::Object *pObj = gsIn.readObject(); |
| 34 | 36 | ||
| 35 | if( pObj ) | 37 | if( pObj ) |
| @@ -37,6 +39,8 @@ void InterfaceGats::run( class Game *pGame ) | |||
| 37 | gs.fromGats( dynamic_cast<Gats::Dictionary *>(pObj) ); | 39 | gs.fromGats( dynamic_cast<Gats::Dictionary *>(pObj) ); |
| 38 | 40 | ||
| 39 | delete pObj; | 41 | delete pObj; |
| 42 | |||
| 43 | gs.execCommand( Options::getInstance().sCommand ); | ||
| 40 | } | 44 | } |
| 41 | else | 45 | else |
| 42 | { | 46 | { |
| @@ -44,17 +48,27 @@ void InterfaceGats::run( class Game *pGame ) | |||
| 44 | } | 48 | } |
| 45 | } | 49 | } |
| 46 | 50 | ||
| 47 | gs.execCommand("status"); | 51 | { |
| 48 | 52 | Gats::Dictionary *pDict; | |
| 49 | //{ | 53 | if( gs.isRunning() ) |
| 50 | // Gats::GatsStream gs | 54 | { |
| 51 | //pObj = gs.toGats(); | 55 | pDict = gs.toGats(); |
| 52 | 56 | pDict->insertBool("running", true ); | |
| 57 | } | ||
| 58 | else | ||
| 59 | { | ||
| 60 | pDict = new Gats::Dictionary(); | ||
| 61 | pDict->insertBool("running", false ); | ||
| 62 | } | ||
| 63 | pDict->insert("result", mbResult.getString() ); | ||
| 64 | gsIn.writeObject( pDict ); | ||
| 65 | delete pDict; | ||
| 66 | } | ||
| 53 | } | 67 | } |
| 54 | 68 | ||
| 55 | void InterfaceGats::display( const SmlNode *pSml ) | 69 | void InterfaceGats::display( const SmlNode *pSml ) |
| 56 | { | 70 | { |
| 57 | SmlRendererHtml rend; | 71 | SmlRendererHtml rend; |
| 58 | rend.render( sio, pSml ); | 72 | rend.render( fResult, pSml ); |
| 59 | } | 73 | } |
| 60 | 74 | ||
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 @@ | |||
| 2 | #define INETRFACE_GATS_H | 2 | #define INETRFACE_GATS_H |
| 3 | 3 | ||
| 4 | #include "interface.h" | 4 | #include "interface.h" |
| 5 | #include <bu/membuf.h> | ||
| 6 | #include <bu/formatter.h> | ||
| 5 | 7 | ||
| 6 | class InterfaceGats : public Interface | 8 | class InterfaceGats : public Interface |
| 7 | { | 9 | { |
| @@ -12,6 +14,10 @@ public: | |||
| 12 | virtual void run( class Game *pGame ); | 14 | virtual void run( class Game *pGame ); |
| 13 | 15 | ||
| 14 | virtual void display( const class SmlNode *pSml ); | 16 | virtual void display( const class SmlNode *pSml ); |
| 17 | |||
| 18 | private: | ||
| 19 | Bu::MemBuf mbResult; | ||
| 20 | Bu::Formatter fResult; | ||
| 15 | }; | 21 | }; |
| 16 | 22 | ||
| 17 | #endif | 23 | #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 @@ | |||
| 9 | #include <bu/file.h> | 9 | #include <bu/file.h> |
| 10 | #include <bu/optparser.h> | 10 | #include <bu/optparser.h> |
| 11 | #include <bu/sio.h> | 11 | #include <bu/sio.h> |
| 12 | #include <gats/gatsstream.h> | ||
| 13 | #include <gats/types.h> | ||
| 12 | 14 | ||
| 13 | #include "interfaceplugger.h" | 15 | #include "interfaceplugger.h" |
| 14 | 16 | ||
| @@ -46,10 +48,15 @@ void Options::parse( int argc, char *argv[] ) | |||
| 46 | 48 | ||
| 47 | opt.addOption( Bu::slot( this, &Options::smlTest ), "sml-test", | 49 | opt.addOption( Bu::slot( this, &Options::smlTest ), "sml-test", |
| 48 | "Test SML parser." ); | 50 | "Test SML parser." ); |
| 51 | opt.addOption( sCommand, "command", | ||
| 52 | "Set the command to execute once the game is loaded. " | ||
| 53 | "This does not work with all interfaces."); | ||
| 49 | opt.addOption( Bu::slot( this, &Options::version ), "version", | 54 | opt.addOption( Bu::slot( this, &Options::version ), "version", |
| 50 | "Show full version info." ); | 55 | "Show full version info." ); |
| 51 | opt.addOption( Bu::slot( this, &Options::builtins ), "builtins", | 56 | opt.addOption( Bu::slot( this, &Options::builtins ), "builtins", |
| 52 | "List available builtins." ); | 57 | "List available builtins." ); |
| 58 | opt.addOption( Bu::slot( this, &Options::printResult ), "print-result", | ||
| 59 | "Print the result from a save file." ); | ||
| 53 | opt.addOption( sInterface, 'i', "interface", | 60 | opt.addOption( sInterface, 'i', "interface", |
| 54 | "Select interface module. Default is " + sInterface + | 61 | "Select interface module. Default is " + sInterface + |
| 55 | ". Available modules: " + sIFaces ); | 62 | ". Available modules: " + sIFaces ); |
| @@ -124,3 +131,19 @@ int Options::nonOption( Bu::Array<Bu::String> aArgs ) | |||
| 124 | return 0; | 131 | return 0; |
| 125 | } | 132 | } |
| 126 | 133 | ||
| 134 | int Options::printResult( Bu::Array<Bu::String> aArgs ) | ||
| 135 | { | ||
| 136 | Gats::GatsStream gsIn( sioRaw ); | ||
| 137 | Gats::Object *pObj = gsIn.readObject(); | ||
| 138 | Gats::Dictionary *pDict = dynamic_cast<Gats::Dictionary *>(pObj); | ||
| 139 | |||
| 140 | sio << pDict->getStr("result") << sio.nl << sio.nl << "Running: " | ||
| 141 | << pDict->getBool("running") << sio.nl; | ||
| 142 | |||
| 143 | delete pObj; | ||
| 144 | |||
| 145 | exit( 0 ); | ||
| 146 | |||
| 147 | return 0; | ||
| 148 | } | ||
| 149 | |||
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: | |||
| 17 | 17 | ||
| 18 | Bu::String sFile; | 18 | Bu::String sFile; |
| 19 | Bu::String sInterface; | 19 | Bu::String sInterface; |
| 20 | Bu::String sCommand; | ||
| 20 | 21 | ||
| 21 | protected: | 22 | protected: |
| 22 | int version( Bu::Array<Bu::String> aArgs ); | 23 | int version( Bu::Array<Bu::String> aArgs ); |
| 23 | int builtins( Bu::Array<Bu::String> aArgs ); | 24 | int builtins( Bu::Array<Bu::String> aArgs ); |
| 24 | int smlTest( Bu::Array<Bu::String> aArgs ); | 25 | int smlTest( Bu::Array<Bu::String> aArgs ); |
| 25 | int nonOption( Bu::Array<Bu::String> aArgs ); | 26 | int nonOption( Bu::Array<Bu::String> aArgs ); |
| 27 | int printResult( Bu::Array<Bu::String> aArgs ); | ||
| 26 | }; | 28 | }; |
| 27 | 29 | ||
| 28 | #endif | 30 | #endif |
