#include "interfacegats.h" #include "smlnode.h" #include "gamestate.h" #include "options.h" #include "situation.h" #include "command.h" #include "smlrendererhtml.h" #include #include #include #include #include #include #include using namespace Bu; PluginInterface3( plugin_interface_gats, gats, InterfaceGats, Interface, "Mike Buland", 1, 0 ); InterfaceGats::InterfaceGats() : fResult( mbResult ) { } InterfaceGats::~InterfaceGats() { } void InterfaceGats::run( class Game *pGame ) { GameState gs( pGame, this ); Gats::GatsStream gsIn( sioRaw ); { Gats::Object *pObj = gsIn.readObject(); if( pObj ) { gs.fromGats( dynamic_cast(pObj) ); delete pObj; 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 { gs.init(); } } { Gats::Dictionary *pDict; if( gs.isRunning() ) { pDict = gs.toGats(); pDict->insertBool("running", true ); } else { 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; } } void InterfaceGats::display( const SmlNode *pSml ) { SmlRendererHtml rend; rend.render( fResult, pSml ); }