From 307d91fbd303b3088587ae9c4c1102714654bc53 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 6 Feb 2012 13:32:53 -0700 Subject: Gats interface supports option input. --- src/interfacegats.cpp | 37 ++++++++++++++++++++++++++++++++++++- src/situation.h | 4 ++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/interfacegats.cpp b/src/interfacegats.cpp index 9f6cf8d..2e33aee 100644 --- a/src/interfacegats.cpp +++ b/src/interfacegats.cpp @@ -3,6 +3,8 @@ #include "smlnode.h" #include "gamestate.h" #include "options.h" +#include "situation.h" +#include "command.h" #include "smlrendererhtml.h" @@ -11,6 +13,7 @@ #include #include #include +#include using namespace Bu; @@ -40,7 +43,17 @@ void InterfaceGats::run( class Game *pGame ) delete pObj; - gs.execCommand( Options::getInstance().sCommand ); + Situation *pSit = gs.getCurSituation(); + switch( pSit->getInputType() ) + { + case Situation::inputCommand: + gs.execCommand( Options::getInstance().sCommand ); + break; + + case Situation::inputOption: + gs.execOption( strtol( Options::getInstance().sCommand.getStr(), NULL, 10 ) ); + break; + } } else { @@ -60,6 +73,28 @@ void InterfaceGats::run( class Game *pGame ) pDict = new Gats::Dictionary(); pDict->insertBool("running", false ); } + + Situation *pSit = gs.getCurSituation(); + pDict->insert("input", (int)pSit->getInputType() ); + switch( pSit->getInputType() ) + { + case Situation::inputCommand: + break; + + case Situation::inputOption: + { + Gats::List *pLst = pDict->insertList("options"); + const CommandSet::CommandList &cl = + pSit->getCommandSet().getCommandList(); + for( CommandSet::CommandList::const_iterator i = cl.begin(); + i; i++ ) + { + pLst->append( (*i)->getRoot() ); + } + } + break; + } + pDict->insert("result", mbResult.getString() ); gsIn.writeObject( pDict ); delete pDict; diff --git a/src/situation.h b/src/situation.h index 794b308..b859c0f 100644 --- a/src/situation.h +++ b/src/situation.h @@ -11,8 +11,8 @@ friend class GameBuilder; public: enum InputType { - inputCommand, - inputOption, + inputCommand = 1, + inputOption = 2, }; Situation( const Bu::String &sName, InputType tInput ); -- cgit v1.2.3