summaryrefslogtreecommitdiff
path: root/src/gamebuilder.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-12-29 10:27:38 -0700
committerMike Buland <eichlan@xagasoft.com>2011-12-29 10:27:38 -0700
commitbae6192c54533e8da95d8ae1ed4d4eccee28c39a (patch)
treef27b03b518894420992ad1a3ed3ee1a07935ca4b /src/gamebuilder.cpp
parent550d4f13ace49e3d442e43d46cd066f174709400 (diff)
downloadstage-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.cpp73
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
8using namespace Bu; 11using namespace Bu;
9 12
10GameBuilder::GameBuilder() : 13GameBuilder::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
16GameBuilder::~GameBuilder() 24GameBuilder::~GameBuilder()
@@ -24,20 +32,28 @@ void GameBuilder::setLiteral( const Variable &v )
24 32
25void GameBuilder::setGameParam( const Bu::String &sName ) 33void 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
31void GameBuilder::beginFunction( const Bu::String &sName ) 38void 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
45void GameBuilder::addFunctionParam( const Bu::String &sName )
46{
47 pCurFnc->addParam( sName );
48 sio << " - Param added '" << sName << "'" << sio.nl;
49}
50
38void GameBuilder::endFunction() 51void 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
43void GameBuilder::beginSituation( const Bu::String &sName ) 59void 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
53void GameBuilder::addParam( const Bu::String &sName )
54{
55 sio << " - Param added '" << sName << "'" << sio.nl;
56}
57
58void GameBuilder::addNode( AstNode::Type iType ) 69void 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
105void GameBuilder::addFuncCall( const Bu::String &sName )
106{
107 if( pCurNode )
108 {
109 pCurNode->addNode( new AstLeafLiteral( AstNode::tFuncCall, sName ) );
110 }
111}
112
113void GameBuilder::beginGlobal()
114{
115 bGlobal = true;
116}
117
118void GameBuilder::closeGlobal()
119{
120 bGlobal = false;
121}
122
123void GameBuilder::beginCommand( const Bu::String &sValue )
124{
125 pCurNode = pCurRoot = new AstBranch( AstNode::tScope );
126 pCurCmd = new Command();
127 pCurCmd->addLiteral( sValue );
128}
129
130void GameBuilder::addCommandLiteral( const Bu::String &sValue )
131{
132 pCurCmd->addLiteral( sValue );
133}
134
135void GameBuilder::addCommandParam( const Bu::String &sValue )
136{
137 pCurCmd->addParam( sValue );
138}
139
140void GameBuilder::closeCommand()
141{
142 pCurCmd->print();
143 sio << *pCurRoot << sio.nl;
144 pCurCmd->setAst( pCurRoot );
145 delete pCurCmd;
146 pCurCmd = NULL;
147}
148