diff options
Diffstat (limited to 'src/gamestate.cpp')
-rw-r--r-- | src/gamestate.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/gamestate.cpp b/src/gamestate.cpp index b87f658..e2ab61a 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp | |||
@@ -27,6 +27,91 @@ Gats::Object *GameState::toGats() const | |||
27 | Gats::Dictionary *pRoot = new Gats::Dictionary; | 27 | Gats::Dictionary *pRoot = new Gats::Dictionary; |
28 | 28 | ||
29 | Gats::Dictionary *pSit = pRoot->insertDict("situations"); | 29 | Gats::Dictionary *pSit = pRoot->insertDict("situations"); |
30 | for( ScopeHash::const_iterator i = hsSituation.begin(); i; i++ ) | ||
31 | { | ||
32 | pSit->insert( i.getKey(), scopeToGats( *i ) ); | ||
33 | } | ||
34 | pRoot->insert("global", scopeToGats( &sGlobal ) ); | ||
35 | pRoot->insert("player", scopeToGats( &sPlayer ) ); | ||
36 | pRoot->insert("curSituation", sCurSituation ); | ||
37 | pRoot->insert("curPrompt", sPrompt ); | ||
38 | |||
39 | return pRoot; | ||
40 | } | ||
41 | |||
42 | Gats::Object *GameState::scopeToGats( const Scope *pSrc ) const | ||
43 | { | ||
44 | Gats::Dictionary *pDst = new Gats::Dictionary(); | ||
45 | for( Scope::const_iterator i = pSrc->begin(); i; i++ ) | ||
46 | { | ||
47 | pDst->insert( i.getKey(), variableToGats( *i ) ); | ||
48 | } | ||
49 | |||
50 | return pDst; | ||
51 | } | ||
52 | |||
53 | Gats::Object *GameState::variableToGats( const Variable &rVar ) const | ||
54 | { | ||
55 | Gats::List *pLst = new Gats::List(); | ||
56 | pLst->append( rVar.getType() ); | ||
57 | switch( rVar.getType() ) | ||
58 | { | ||
59 | case Variable::tNull: | ||
60 | break; | ||
61 | |||
62 | case Variable::tBool: | ||
63 | pLst->append( rVar.getBool() ); | ||
64 | break; | ||
65 | |||
66 | case Variable::tInt: | ||
67 | pLst->append( rVar.getInt() ); | ||
68 | break; | ||
69 | |||
70 | case Variable::tFloat: | ||
71 | pLst->append( rVar.getFloat() ); | ||
72 | break; | ||
73 | |||
74 | case Variable::tSituation: | ||
75 | pLst->append( rVar.getString() ); | ||
76 | break; | ||
77 | |||
78 | case Variable::tVariable: | ||
79 | pLst->append( rVar.getVariableRef().sid ); | ||
80 | pLst->append( rVar.getVariableRef().sName ); | ||
81 | break; | ||
82 | |||
83 | case Variable::tVarPtr: | ||
84 | sio << "No!!!" << sio.nl; | ||
85 | break; | ||
86 | |||
87 | case Variable::tList: | ||
88 | { | ||
89 | Gats::List *pSub = pLst->appendList(); | ||
90 | for( Variable::VariableArray::const_iterator i = | ||
91 | rVar.getList().begin(); i; i++ ) | ||
92 | { | ||
93 | pSub->append( variableToGats( *i ) ); | ||
94 | } | ||
95 | } | ||
96 | break; | ||
97 | |||
98 | case Variable::tDictionary: | ||
99 | { | ||
100 | Gats::List *pSub = pLst->appendList(); | ||
101 | for( Variable::VariableHash::const_iterator i = | ||
102 | rVar.getHash().begin(); i; i++ ) | ||
103 | { | ||
104 | pSub->append( variableToGats( i.getKey() ) ); | ||
105 | pSub->append( variableToGats( *i ) ); | ||
106 | } | ||
107 | } | ||
108 | break; | ||
109 | |||
110 | case Variable::tString: | ||
111 | pLst->append( rVar.getString() ); | ||
112 | break; | ||
113 | } | ||
114 | return pLst; | ||
30 | } | 115 | } |
31 | 116 | ||
32 | void GameState::parse( class AstBranch *pAst ) | 117 | void GameState::parse( class AstBranch *pAst ) |