diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-12-29 10:27:38 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-12-29 10:27:38 -0700 |
commit | bae6192c54533e8da95d8ae1ed4d4eccee28c39a (patch) | |
tree | f27b03b518894420992ad1a3ed3ee1a07935ca4b /src/gamebuilder.cpp | |
parent | 550d4f13ace49e3d442e43d46cd066f174709400 (diff) | |
download | stage-bae6192c54533e8da95d8ae1ed4d4eccee28c39a.tar.gz stage-bae6192c54533e8da95d8ae1ed4d4eccee28c39a.tar.bz2 stage-bae6192c54533e8da95d8ae1ed4d4eccee28c39a.tar.xz stage-bae6192c54533e8da95d8ae1ed4d4eccee28c39a.zip |
Getting close to realy running.
Diffstat (limited to 'src/gamebuilder.cpp')
-rw-r--r-- | src/gamebuilder.cpp | 73 |
1 files changed, 64 insertions, 9 deletions
diff --git a/src/gamebuilder.cpp b/src/gamebuilder.cpp index 47de17d..e6c1f38 100644 --- a/src/gamebuilder.cpp +++ b/src/gamebuilder.cpp | |||
@@ -1,16 +1,24 @@ | |||
1 | #include "gamebuilder.h" | 1 | #include "gamebuilder.h" |
2 | #include <bu/sio.h> | 2 | #include <bu/sio.h> |
3 | 3 | ||
4 | #include "game.h" | ||
4 | #include "astbranch.h" | 5 | #include "astbranch.h" |
5 | #include "astleaf.h" | 6 | #include "astleaf.h" |
6 | #include "astleafliteral.h" | 7 | #include "astleafliteral.h" |
8 | #include "astfunction.h" | ||
9 | #include "command.h" | ||
7 | 10 | ||
8 | using namespace Bu; | 11 | using namespace Bu; |
9 | 12 | ||
10 | GameBuilder::GameBuilder() : | 13 | GameBuilder::GameBuilder() : |
14 | pGame( NULL ), | ||
15 | bGlobal( false ), | ||
11 | pCurNode( NULL ), | 16 | pCurNode( NULL ), |
12 | pCurRoot( NULL ) | 17 | pCurRoot( NULL ), |
18 | pCurCmd( NULL ), | ||
19 | pCurFnc( NULL ) | ||
13 | { | 20 | { |
21 | pGame = new Game(); | ||
14 | } | 22 | } |
15 | 23 | ||
16 | GameBuilder::~GameBuilder() | 24 | GameBuilder::~GameBuilder() |
@@ -24,20 +32,28 @@ void GameBuilder::setLiteral( const Variable &v ) | |||
24 | 32 | ||
25 | void GameBuilder::setGameParam( const Bu::String &sName ) | 33 | void GameBuilder::setGameParam( const Bu::String &sName ) |
26 | { | 34 | { |
27 | sio << "Set game param '" << sName << "' to " << vLiteral << sio.nl; | 35 | pGame->hGlobalParam.insert( sName, vLiteral ); |
28 | hGameParams.insert( sName, vLiteral ); | ||
29 | } | 36 | } |
30 | 37 | ||
31 | void GameBuilder::beginFunction( const Bu::String &sName ) | 38 | void GameBuilder::beginFunction( const Bu::String &sName ) |
32 | { | 39 | { |
33 | pCurNode = pCurRoot = new AstBranch( AstNode::tScope ); | 40 | pCurNode = pCurRoot = new AstBranch( AstNode::tScope ); |
34 | 41 | pCurFnc = new AstFunction( sName ); | |
35 | sio << "New function: " << sName << sio.nl; | 42 | sio << "New function: " << sName << sio.nl; |
36 | } | 43 | } |
37 | 44 | ||
45 | void GameBuilder::addFunctionParam( const Bu::String &sName ) | ||
46 | { | ||
47 | pCurFnc->addParam( sName ); | ||
48 | sio << " - Param added '" << sName << "'" << sio.nl; | ||
49 | } | ||
50 | |||
38 | void GameBuilder::endFunction() | 51 | void GameBuilder::endFunction() |
39 | { | 52 | { |
40 | sio << "Function ended: " << *pCurRoot << sio.nl; | 53 | sio << "Function ended: " << *pCurRoot << sio.nl; |
54 | pCurFnc->setAst( pCurRoot ); | ||
55 | pCurRoot = pCurNode = NULL; | ||
56 | pGame->hFunction.insert( pCurFnc->getName(), pCurFnc ); | ||
41 | } | 57 | } |
42 | 58 | ||
43 | void GameBuilder::beginSituation( const Bu::String &sName ) | 59 | void GameBuilder::beginSituation( const Bu::String &sName ) |
@@ -50,11 +66,6 @@ void GameBuilder::endSituation() | |||
50 | sio << "Situation ended." << sio.nl; | 66 | sio << "Situation ended." << sio.nl; |
51 | } | 67 | } |
52 | 68 | ||
53 | void GameBuilder::addParam( const Bu::String &sName ) | ||
54 | { | ||
55 | sio << " - Param added '" << sName << "'" << sio.nl; | ||
56 | } | ||
57 | |||
58 | void GameBuilder::addNode( AstNode::Type iType ) | 69 | void GameBuilder::addNode( AstNode::Type iType ) |
59 | { | 70 | { |
60 | switch( iType&AstNode::tTypeMask ) | 71 | switch( iType&AstNode::tTypeMask ) |
@@ -91,3 +102,47 @@ void GameBuilder::addVarRef( const Bu::String &sName ) | |||
91 | } | 102 | } |
92 | } | 103 | } |
93 | 104 | ||
105 | void GameBuilder::addFuncCall( const Bu::String &sName ) | ||
106 | { | ||
107 | if( pCurNode ) | ||
108 | { | ||
109 | pCurNode->addNode( new AstLeafLiteral( AstNode::tFuncCall, sName ) ); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | void GameBuilder::beginGlobal() | ||
114 | { | ||
115 | bGlobal = true; | ||
116 | } | ||
117 | |||
118 | void GameBuilder::closeGlobal() | ||
119 | { | ||
120 | bGlobal = false; | ||
121 | } | ||
122 | |||
123 | void GameBuilder::beginCommand( const Bu::String &sValue ) | ||
124 | { | ||
125 | pCurNode = pCurRoot = new AstBranch( AstNode::tScope ); | ||
126 | pCurCmd = new Command(); | ||
127 | pCurCmd->addLiteral( sValue ); | ||
128 | } | ||
129 | |||
130 | void GameBuilder::addCommandLiteral( const Bu::String &sValue ) | ||
131 | { | ||
132 | pCurCmd->addLiteral( sValue ); | ||
133 | } | ||
134 | |||
135 | void GameBuilder::addCommandParam( const Bu::String &sValue ) | ||
136 | { | ||
137 | pCurCmd->addParam( sValue ); | ||
138 | } | ||
139 | |||
140 | void GameBuilder::closeCommand() | ||
141 | { | ||
142 | pCurCmd->print(); | ||
143 | sio << *pCurRoot << sio.nl; | ||
144 | pCurCmd->setAst( pCurRoot ); | ||
145 | delete pCurCmd; | ||
146 | pCurCmd = NULL; | ||
147 | } | ||
148 | |||