wxString TemplateParser::ParseTemplate() { try { while (!m_in.Eof()) { Token token = GetNextToken(); switch (token) { case TOK_MACRO: ParseMacro(); break; case TOK_PROPERTY: ParseProperty(); break; case TOK_TEXT: ParseText(); break; default: return wxT(""); } } } catch ( wxFBException& ex ) { wxLogError( ex.what() ); } return m_out; }
Property* Condition::LoadLeft(const char* value, behaviac::string& typeName) { Property* opl = NULL; if (value[0] != '0') { opl = ParseProperty(value, typeName); } return opl; }
std::unordered_map<std::string,std::string> PropertyFile::ParseConfigurationFile(const std::string &configuration_file_path){ std::unordered_map<std::string,std::string> properties; if (!configuration_file_path.empty()){ // get configuration file data. std::ifstream ifs(configuration_file_path); if (ifs.good()){ std::string configuration( (std::istreambuf_iterator<char>(ifs) ), (std::istreambuf_iterator<char>()) ); // read configuration string line by line and parse properties. std::istringstream f(configuration); std::string line; while (std::getline(f, line)) { ParseProperty(line,properties); } } } return properties; }
Property* Condition::LoadRight(const char* value, behaviac::string& typeName) { Property* opr = 0; if (value && value[0] != '\0') { if (StringUtils::StartsWith(value, "const")) { //const Int32 0 const int kConstLength = 5; const char* strRemaining = value + (kConstLength + 1); const char* p = StringUtils::FirstToken(strRemaining, ' ', typeName); const char* strVale = (p + 1); opr = Property::Create(typeName.c_str(), strVale); } else { opr = ParseProperty(value, typeName); } } return opr; }
// Convert binary CDX to text CDXML QString ChemData::CDXToCDXML( QString fn ) { QFile f( fn ); QString wholefile, proptag, stag; QStack<QString *> tagstack; QString *ts; if ( !f.open( QIODevice::ReadOnly ) ) return wholefile; qDebug() << "CDX ChemDraw binary file format."; //QMessageBox::warning(r, "Can't read binary format", // "This file is a ChemDraw (CDX) binary file, but this program cannot read it (yet :)"); // make a QByteArray QByteArray cdxfile = f.readAll(); // for ( int c = 0; c < f.size(); c++ ) { // cdxfile[c] = f.getch(); // } bool opentag = false; // start reading tags. int ptr; ptr = 28; // theoretically, position 28 is where the Document tag is // the Document tag doesn't really matter to us; we ignore most of that // stuff anyways... wholefile.append( "<CDXML>" ); if ( ( cdxfile[ptr] == '0' ) && ( cdxfile[ptr + 1] == 'b' ) ) ptr = 30; do { // until a <colortable>, <fonttable>, or <page> tag is found if ( ( cdxfile[ptr] == '0' ) && ( cdxfile[ptr + 1] == '0' ) ) { // end tag? if ( tagstack.count() > 0 ) { if ( opentag ) wholefile.append( ">" ); ts = tagstack.top(); if ( ( *ts == "</t>" ) && ( stag.length() > 1 ) ) { wholefile.append( stag ); stag = ""; } ts = tagstack.pop(); wholefile.append( *ts ); ptr += 2; opentag = false; } else { ptr += 2; } continue; } if ( cdxfile[ptr + 1] >= '0' ) { // it's a property int moveforward = cdxfile[ptr + 3] * 256; // TODO + cdxfile[ptr+2] + 4; QByteArray b( moveforward, '0' ); for ( int d = 0; d < moveforward; d++ ) b[d] = cdxfile[ptr + d]; proptag = ParseProperty( b ); if ( ( cdxfile[ptr] == '0' ) && ( cdxfile[ptr + 1] == '7' ) ) { stag = proptag; ptr += moveforward; // move past data continue; } if ( proptag.length() > 1 ) { wholefile.append( " " ); wholefile.append( proptag ); } ptr += moveforward; // move past data continue; } if ( ( unsigned char ) cdxfile[ptr + 1] == 'c' ) { // it's an object if ( ( tagstack.count() > 0 ) && opentag ) wholefile.append( ">" ); opentag = true; int local_id = 0; local_id = local_id + ( unsigned char ) cdxfile[ptr + 2]; local_id = local_id + ( unsigned char ) cdxfile[ptr + 3] * 256; QString s_id; s_id.setNum( local_id ); if ( cdxfile[ptr] == '1' ) { // page object wholefile.append( "<page " ); wholefile.append( "id=\"" ); wholefile.append( s_id ); wholefile.append( "\"" ); ts = new QString( "</page>" ); tagstack.push( ts ); ptr += 6; // move past tag and ID continue; } if ( cdxfile[ptr] == '3' ) { // fragment object wholefile.append( "<fragment " ); wholefile.append( "id=\"" ); wholefile.append( s_id ); wholefile.append( "\"" ); ts = new QString( "</fragment>" ); tagstack.push( ts ); ptr += 6; // move past tag and ID continue; } if ( cdxfile[ptr] == '4' ) { // node object wholefile.append( "<n " ); wholefile.append( "id=\"" ); wholefile.append( s_id ); wholefile.append( "\"" ); ts = new QString( "</n>" ); tagstack.push( ts ); ptr += 6; // move past tag and ID continue; } if ( cdxfile[ptr] == '5' ) { // bond object wholefile.append( "<b " ); wholefile.append( "id=\"" ); wholefile.append( s_id ); wholefile.append( "\"" ); opentag = false; ts = new QString( "/>" ); tagstack.push( ts ); ptr += 6; // move past tag and ID continue; } if ( cdxfile[ptr] == '6' ) { // text object wholefile.append( "<t " ); wholefile.append( "id=\"" ); wholefile.append( s_id ); wholefile.append( "\"" ); ts = new QString( "</t>" ); tagstack.push( ts ); ptr += 6; // move past tag and ID continue; } if ( cdxfile[ptr] == '7' ) { // graphic object wholefile.append( "<graphic " ); wholefile.append( "id=\"" ); wholefile.append( s_id ); wholefile.append( "\"" ); opentag = false; ts = new QString( "/>" ); tagstack.push( ts ); ptr += 6; // move past tag and ID continue; } } } while ( ptr < cdxfile.size() ); wholefile.append( "</CDXML>" ); qDebug() << wholefile; return wholefile; }
bool Workspace::HandleRequests() { bool bContinue = false; #if !BEHAVIAC_RELEASE if (Config::IsSocketing()) { behaviac::string command; if (Socket::ReadText(command)) { const char* kBreakpoint = "[breakpoint]"; const char* kProperty = "[property]"; const char* kProfiling = "[profiling]"; const char* kStart = "[start]"; const char* kAppLogFilter = "[applogfilter]"; const char* kContinue = "[continue]"; const char* kCloseConnection = "[closeconnection]"; behaviac::vector<behaviac::string> cs; behaviac::StringUtils::SplitIntoArray(command.c_str(), "\n", cs); for (behaviac::vector<behaviac::string>::iterator it = cs.begin(); it != cs.end(); ++it) { behaviac::string& c = *it; if (c.empty()) { continue; } behaviac::vector<behaviac::string> tokens; behaviac::StringUtils::SplitIntoArray(c.c_str(), " ", tokens); if (tokens[0] == kBreakpoint) { ParseBreakpoint(tokens); } else if (tokens[0] == kProperty) { ParseProperty(tokens); } else if (tokens[0] == kProfiling) { ParseProfiling(tokens); } else if (tokens[0] == kStart) { m_breakpoints.clear(); bContinue = true; } else if (tokens[0] == kAppLogFilter) { ParseAppLogFilter(tokens); } else if (tokens[0] == kContinue) { bContinue = true; } else if (tokens[0] == kCloseConnection) { m_breakpoints.clear(); bContinue = true; } else { BEHAVIAC_ASSERT(0); } }//end of for }//end of if (Socket::ReadText(command)) } else { bContinue = true; } #endif//BEHAVIAC_RELEASE return bContinue; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// HRESULT CAdWaypointGroup::LoadBuffer(BYTE * Buffer, bool Complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE (WAYPOINTS) TOKEN_TABLE (TEMPLATE) TOKEN_TABLE (NAME) TOKEN_TABLE (POINT) TOKEN_TABLE (EDITOR_SELECTED_POINT) TOKEN_TABLE (EDITOR_SELECTED) TOKEN_TABLE (PROPERTY) TOKEN_TABLE (EDITOR_PROPERTY) TOKEN_TABLE_END BYTE* params; int cmd; CBParser parser(Game); if(Complete){ if(parser.GetCommand ((char**)&Buffer, commands, (char**)¶ms)!=TOKEN_WAYPOINTS){ Game->LOG(0, "'WAYPOINTS' keyword expected."); return E_FAIL; } Buffer = params; } while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC; break; case TOKEN_NAME: SetName((char*)params); break; case TOKEN_POINT: { int x,y; parser.ScanStr((char*)params, "%d,%d", &x, &y); m_Points.Add(new CBPoint(x, y)); } break; case TOKEN_EDITOR_SELECTED: parser.ScanStr((char*)params, "%b", &m_EditorSelected); break; case TOKEN_EDITOR_SELECTED_POINT: parser.ScanStr((char*)params, "%d", &m_EditorSelectedPoint); break; case TOKEN_PROPERTY: ParseProperty(params, false); break; case TOKEN_EDITOR_PROPERTY: ParseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND){ Game->LOG(0, "Syntax error in WAYPOINTS definition"); return E_FAIL; } return S_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// HRESULT CAdRegion::LoadBuffer(byte *Buffer, bool Complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(REGION) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(NAME) TOKEN_TABLE(ACTIVE) TOKEN_TABLE(ZOOM) TOKEN_TABLE(SCALE) TOKEN_TABLE(BLOCKED) TOKEN_TABLE(DECORATION) TOKEN_TABLE(POINT) TOKEN_TABLE(ALPHA_COLOR) TOKEN_TABLE(ALPHA) TOKEN_TABLE(EDITOR_SELECTED_POINT) TOKEN_TABLE(EDITOR_SELECTED) TOKEN_TABLE(SCRIPT) TOKEN_TABLE(CAPTION) TOKEN_TABLE(PROPERTY) TOKEN_TABLE(EDITOR_PROPERTY) TOKEN_TABLE_END byte *params; int cmd; CBParser parser(Game); if (Complete) { if (parser.GetCommand((char **)&Buffer, commands, (char **)¶ms) != TOKEN_REGION) { Game->LOG(0, "'REGION' keyword expected."); return E_FAIL; } Buffer = params; } int i; for (i = 0; i < m_Points.GetSize(); i++) delete m_Points[i]; m_Points.RemoveAll(); int ar = 255, ag = 255, ab = 255, alpha = 255; while ((cmd = parser.GetCommand((char **)&Buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC; break; case TOKEN_NAME: SetName((char *)params); break; case TOKEN_CAPTION: SetCaption((char *)params); break; case TOKEN_ACTIVE: parser.ScanStr((char *)params, "%b", &m_Active); break; case TOKEN_BLOCKED: parser.ScanStr((char *)params, "%b", &m_Blocked); break; case TOKEN_DECORATION: parser.ScanStr((char *)params, "%b", &m_Decoration); break; case TOKEN_ZOOM: case TOKEN_SCALE: { int i; parser.ScanStr((char *)params, "%d", &i); m_Zoom = (float)i; } break; case TOKEN_POINT: { int x, y; parser.ScanStr((char *)params, "%d,%d", &x, &y); m_Points.Add(new CBPoint(x, y)); } break; case TOKEN_ALPHA_COLOR: parser.ScanStr((char *)params, "%d,%d,%d", &ar, &ag, &ab); break; case TOKEN_ALPHA: parser.ScanStr((char *)params, "%d", &alpha); break; case TOKEN_EDITOR_SELECTED: parser.ScanStr((char *)params, "%b", &m_EditorSelected); break; case TOKEN_EDITOR_SELECTED_POINT: parser.ScanStr((char *)params, "%d", &m_EditorSelectedPoint); break; case TOKEN_SCRIPT: AddScript((char *)params); break; case TOKEN_PROPERTY: ParseProperty(params, false); break; case TOKEN_EDITOR_PROPERTY: ParseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { Game->LOG(0, "Syntax error in REGION definition"); return E_FAIL; } CreateRegion(); m_Alpha = DRGBA(ar, ag, ab, alpha); return S_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// HRESULT CAdLayer::LoadBuffer(BYTE * Buffer, bool Complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE (LAYER) TOKEN_TABLE (TEMPLATE) TOKEN_TABLE (NAME) TOKEN_TABLE (WIDTH) TOKEN_TABLE (HEIGHT) TOKEN_TABLE (MAIN) TOKEN_TABLE (ENTITY) TOKEN_TABLE (REGION) TOKEN_TABLE (ACTIVE) TOKEN_TABLE (EDITOR_SELECTED) TOKEN_TABLE (SCRIPT) TOKEN_TABLE (CAPTION) TOKEN_TABLE (PROPERTY) TOKEN_TABLE (CLOSE_UP) TOKEN_TABLE (EDITOR_PROPERTY) TOKEN_TABLE_END BYTE* params; int cmd; CBParser parser(Game); if(Complete){ if(parser.GetCommand ((char**)&Buffer, commands, (char**)¶ms)!=TOKEN_LAYER){ Game->LOG(0, "'LAYER' keyword expected."); return E_FAIL; } Buffer = params; } while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC; break; case TOKEN_NAME: SetName((char*)params); break; case TOKEN_CAPTION: SetCaption((char*)params); break; case TOKEN_MAIN: parser.ScanStr((char*)params, "%b", &m_Main); break; case TOKEN_CLOSE_UP: parser.ScanStr((char*)params, "%b", &m_CloseUp); break; case TOKEN_WIDTH: parser.ScanStr((char*)params, "%d", &m_Width); break; case TOKEN_HEIGHT: parser.ScanStr((char*)params, "%d", &m_Height); break; case TOKEN_ACTIVE: parser.ScanStr((char*)params, "%b", &m_Active); break; case TOKEN_REGION: { CAdRegion* region = new CAdRegion(Game); CAdSceneNode* node = new CAdSceneNode(Game); if(!region || !node || FAILED(region->LoadBuffer(params, false))){ cmd = PARSERR_GENERIC; SAFE_DELETE(region); SAFE_DELETE(node); } else{ node->SetRegion(region); m_Nodes.Add(node); } } break; case TOKEN_ENTITY: { CAdEntity* entity = new CAdEntity(Game); CAdSceneNode* node = new CAdSceneNode(Game); if(entity) entity->m_Zoomable = false; // scene entites default to NOT zoom if(!entity || !node || FAILED(entity->LoadBuffer(params, false))){ cmd = PARSERR_GENERIC; SAFE_DELETE(entity); SAFE_DELETE(node); } else{ node->SetEntity(entity); m_Nodes.Add(node); } } break; case TOKEN_EDITOR_SELECTED: parser.ScanStr((char*)params, "%b", &m_EditorSelected); break; case TOKEN_SCRIPT: AddScript((char*)params); break; case TOKEN_PROPERTY: ParseProperty(params, false); break; case TOKEN_EDITOR_PROPERTY: ParseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND){ Game->LOG(0, "Syntax error in LAYER definition"); return E_FAIL; } return S_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// HRESULT CAdActor::LoadBuffer(BYTE * Buffer, bool Complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE (ACTOR) TOKEN_TABLE (X) TOKEN_TABLE (Y) TOKEN_TABLE (TEMPLATE) TOKEN_TABLE (NAME) TOKEN_TABLE (SCALABLE) TOKEN_TABLE (REGISTRABLE) TOKEN_TABLE (INTERACTIVE) TOKEN_TABLE (SHADOWABLE) TOKEN_TABLE (COLORABLE) TOKEN_TABLE (ACTIVE) TOKEN_TABLE (WALK) TOKEN_TABLE (STAND) TOKEN_TABLE (TALK_SPECIAL) TOKEN_TABLE (TALK) TOKEN_TABLE (TURN_LEFT) TOKEN_TABLE (TURN_RIGHT) TOKEN_TABLE (EVENTS) TOKEN_TABLE (FONT) TOKEN_TABLE (CURSOR) TOKEN_TABLE (SCRIPT) TOKEN_TABLE (SOUND_VOLUME) TOKEN_TABLE (SOUND_PANNING) TOKEN_TABLE (CAPTION) TOKEN_TABLE (PROPERTY) TOKEN_TABLE (BLOCKED_REGION) TOKEN_TABLE (WAYPOINTS) TOKEN_TABLE (IGNORE_ITEMS) TOKEN_TABLE (ROTABLE) TOKEN_TABLE (ROTATABLE) TOKEN_TABLE (ALPHA_COLOR) TOKEN_TABLE (SCALE) TOKEN_TABLE (RELATIVE_SCALE) TOKEN_TABLE (ALPHA) TOKEN_TABLE (EDITOR_PROPERTY) TOKEN_TABLE (ANIMATION) TOKEN_TABLE_END BYTE* params; int cmd; CBParser parser(Game); if(Complete) { if(parser.GetCommand ((char**)&Buffer, commands, (char**)¶ms)!=TOKEN_ACTOR) { Game->LOG(0, "'ACTOR' keyword expected."); return E_FAIL; } Buffer = params; } CAdGame* AdGame = (CAdGame*)Game; CAdSpriteSet* spr = NULL; int ar=0, ag=0, ab=0, alpha=0; while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC; break; case TOKEN_X: parser.ScanStr((char*)params, "%d", &m_PosX); break; case TOKEN_Y: parser.ScanStr((char*)params, "%d", &m_PosY); break; case TOKEN_NAME: SetName((char*)params); break; case TOKEN_CAPTION: SetCaption((char*)params); break; case TOKEN_FONT: SetFont((char*)params); break; case TOKEN_SCALABLE: parser.ScanStr((char*)params, "%b", &m_Zoomable); break; case TOKEN_ROTABLE: case TOKEN_ROTATABLE: parser.ScanStr((char*)params, "%b", &m_Rotatable); break; case TOKEN_REGISTRABLE: case TOKEN_INTERACTIVE: parser.ScanStr((char*)params, "%b", &m_Registrable); break; case TOKEN_SHADOWABLE: case TOKEN_COLORABLE: parser.ScanStr((char*)params, "%b", &m_Shadowable); break; case TOKEN_ACTIVE: parser.ScanStr((char*)params, "%b", &m_Active); break; case TOKEN_WALK: SAFE_DELETE(m_WalkSprite); spr = new CAdSpriteSet(Game, this); if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexWalkLifeTime, CACHE_HALF))) cmd = PARSERR_GENERIC; else m_WalkSprite = spr; break; case TOKEN_TALK: spr = new CAdSpriteSet(Game, this); if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC; else m_TalkSprites.Add(spr); break; case TOKEN_TALK_SPECIAL: spr = new CAdSpriteSet(Game, this); if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC; else m_TalkSpritesEx.Add(spr); break; case TOKEN_STAND: SAFE_DELETE(m_StandSprite); spr = new CAdSpriteSet(Game, this); if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexStandLifeTime))) cmd = PARSERR_GENERIC; else m_StandSprite = spr; break; case TOKEN_TURN_LEFT: SAFE_DELETE(m_TurnLeftSprite); spr = new CAdSpriteSet(Game, this); if(!spr || FAILED(spr->LoadBuffer(params, true))) cmd = PARSERR_GENERIC; else m_TurnLeftSprite = spr; break; case TOKEN_TURN_RIGHT: SAFE_DELETE(m_TurnRightSprite); spr = new CAdSpriteSet(Game, this); if(!spr || FAILED(spr->LoadBuffer(params, true))) cmd = PARSERR_GENERIC; else m_TurnRightSprite = spr; break; case TOKEN_SCRIPT: AddScript((char*)params); break; case TOKEN_CURSOR: SAFE_DELETE(m_Cursor); m_Cursor = new CBSprite(Game); if(!m_Cursor || FAILED(m_Cursor->LoadFile((char*)params))) { SAFE_DELETE(m_Cursor); cmd = PARSERR_GENERIC; } break; case TOKEN_SOUND_VOLUME: parser.ScanStr((char*)params, "%d", &m_SFXVolume); break; case TOKEN_SCALE: { int s; parser.ScanStr((char*)params, "%d", &s); m_Scale = (float)s; } break; case TOKEN_RELATIVE_SCALE: { int s; parser.ScanStr((char*)params, "%d", &s); m_RelativeScale = (float)s; } break; case TOKEN_SOUND_PANNING: parser.ScanStr((char*)params, "%b", &m_AutoSoundPanning); break; case TOKEN_PROPERTY: ParseProperty(params, false); break; case TOKEN_BLOCKED_REGION: { SAFE_DELETE(m_BlockRegion); SAFE_DELETE(m_CurrentBlockRegion); CBRegion* rgn = new CBRegion(Game); CBRegion* crgn = new CBRegion(Game); if(!rgn || !crgn || FAILED(rgn->LoadBuffer(params, false))) { SAFE_DELETE(m_BlockRegion); SAFE_DELETE(m_CurrentBlockRegion); cmd = PARSERR_GENERIC; } else{ m_BlockRegion = rgn; m_CurrentBlockRegion = crgn; m_CurrentBlockRegion->Mimic(m_BlockRegion); } } break; case TOKEN_WAYPOINTS: { SAFE_DELETE(m_WptGroup); SAFE_DELETE(m_CurrentWptGroup); CAdWaypointGroup* wpt = new CAdWaypointGroup(Game); CAdWaypointGroup* cwpt = new CAdWaypointGroup(Game); if(!wpt || !cwpt || FAILED(wpt->LoadBuffer(params, false))) { SAFE_DELETE(m_WptGroup); SAFE_DELETE(m_CurrentWptGroup); cmd = PARSERR_GENERIC; } else{ m_WptGroup = wpt; m_CurrentWptGroup = cwpt; m_CurrentWptGroup->Mimic(m_WptGroup); } } break; case TOKEN_IGNORE_ITEMS: parser.ScanStr((char*)params, "%b", &m_IgnoreItems); break; case TOKEN_ALPHA_COLOR: parser.ScanStr((char*)params, "%d,%d,%d", &ar, &ag, &ab); break; case TOKEN_ALPHA: parser.ScanStr((char*)params, "%d", &alpha); break; case TOKEN_EDITOR_PROPERTY: ParseEditorProperty(params, false); break; case TOKEN_ANIMATION: { CAdSpriteSet* Anim = new CAdSpriteSet(Game, this); if(!Anim || FAILED(Anim->LoadBuffer(params, false))) cmd = PARSERR_GENERIC; else m_Anims.Add(Anim); } break; } } if (cmd == PARSERR_TOKENNOTFOUND) { Game->LOG(0, "Syntax error in ACTOR definition"); return E_FAIL; } if (cmd == PARSERR_GENERIC) { if(spr) delete spr; Game->LOG(0, "Error loading ACTOR definition"); return E_FAIL; } if(alpha != 0 && ar==0 && ag == 0 && ab == 0) { ar = ag = ab = 255; } m_AlphaColor = DRGBA(ar, ag, ab, alpha); m_State = m_NextState = STATE_READY; return S_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// HRESULT CAdItem::LoadBuffer(BYTE* Buffer, bool Complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE (ITEM) TOKEN_TABLE (TEMPLATE) TOKEN_TABLE (CURSOR_HOVER) TOKEN_TABLE (CURSOR_COMBINED) TOKEN_TABLE (CURSOR) TOKEN_TABLE (NAME) TOKEN_TABLE (IMAGE_HOVER) TOKEN_TABLE (IMAGE) TOKEN_TABLE (EVENTS) TOKEN_TABLE (SCRIPT) TOKEN_TABLE (CAPTION) TOKEN_TABLE (PROPERTY) TOKEN_TABLE (EDITOR_PROPERTY) TOKEN_TABLE (FONT) TOKEN_TABLE (ALPHA_COLOR) TOKEN_TABLE (ALPHA) TOKEN_TABLE (TALK_SPECIAL) TOKEN_TABLE (TALK) TOKEN_TABLE (SPRITE_HOVER) TOKEN_TABLE (SPRITE) TOKEN_TABLE (DISPLAY_AMOUNT) TOKEN_TABLE (AMOUNT_OFFSET_X) TOKEN_TABLE (AMOUNT_OFFSET_Y) TOKEN_TABLE (AMOUNT_ALIGN) TOKEN_TABLE (AMOUNT_STRING) TOKEN_TABLE (AMOUNT) TOKEN_TABLE_END BYTE* params; int cmd=2; CBParser parser(Game); if(Complete){ if(parser.GetCommand ((char**)&Buffer, commands, (char**)¶ms)!=TOKEN_ITEM){ Game->LOG(0, "'ITEM' keyword expected."); return E_FAIL; } Buffer = params; } int ar=0, ag=0, ab=0, alpha=255; while (cmd>0 && (cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC; break; case TOKEN_NAME: SetName((char*)params); break; case TOKEN_FONT: SetFont((char*)params); break; case TOKEN_CAPTION: SetCaption((char*)params); break; case TOKEN_IMAGE: case TOKEN_SPRITE: SAFE_DELETE(m_Sprite); m_Sprite = new CBSprite(Game, this); if(!m_Sprite || FAILED(m_Sprite->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){ SAFE_DELETE(m_Sprite); cmd = PARSERR_GENERIC; } break; case TOKEN_IMAGE_HOVER: case TOKEN_SPRITE_HOVER: SAFE_DELETE(m_SpriteHover); m_SpriteHover = new CBSprite(Game, this); if(!m_SpriteHover || FAILED(m_SpriteHover->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){ SAFE_DELETE(m_SpriteHover); cmd = PARSERR_GENERIC; } break; case TOKEN_AMOUNT: parser.ScanStr((char*)params, "%d", &m_Amount); break; case TOKEN_DISPLAY_AMOUNT: parser.ScanStr((char*)params, "%b", &m_DisplayAmount); break; case TOKEN_AMOUNT_OFFSET_X: parser.ScanStr((char*)params, "%d", &m_AmountOffsetX); break; case TOKEN_AMOUNT_OFFSET_Y: parser.ScanStr((char*)params, "%d", &m_AmountOffsetY); break; case TOKEN_AMOUNT_ALIGN: if(CBPlatform::stricmp((char*)params, "left")==0) m_AmountAlign = TAL_LEFT; else if(CBPlatform::stricmp((char*)params, "right")==0) m_AmountAlign = TAL_RIGHT; else m_AmountAlign = TAL_CENTER; break; case TOKEN_AMOUNT_STRING: CBUtils::SetString(&m_AmountString, (char*)params); break; case TOKEN_TALK: { CBSprite* spr = new CBSprite(Game, this); if(!spr || FAILED(spr->LoadFile((char*)params, ((CAdGame*)Game)->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC; else m_TalkSprites.Add(spr); } break; case TOKEN_TALK_SPECIAL: { CBSprite* spr = new CBSprite(Game, this); if(!spr || FAILED(spr->LoadFile((char*)params, ((CAdGame*)Game)->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC; else m_TalkSpritesEx.Add(spr); } break; case TOKEN_CURSOR: SAFE_DELETE(m_CursorNormal); m_CursorNormal = new CBSprite(Game); if(!m_CursorNormal || FAILED(m_CursorNormal->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){ SAFE_DELETE(m_CursorNormal); cmd = PARSERR_GENERIC; } break; case TOKEN_CURSOR_HOVER: SAFE_DELETE(m_CursorHover); m_CursorHover = new CBSprite(Game); if(!m_CursorHover || FAILED(m_CursorHover->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){ SAFE_DELETE(m_CursorHover); cmd = PARSERR_GENERIC; } break; case TOKEN_CURSOR_COMBINED: parser.ScanStr((char*)params, "%b", &m_CursorCombined); break; case TOKEN_SCRIPT: AddScript((char*)params); break; case TOKEN_PROPERTY: ParseProperty(params, false); break; case TOKEN_ALPHA_COLOR: parser.ScanStr((char*)params, "%d,%d,%d", &ar, &ag, &ab); break; case TOKEN_ALPHA: parser.ScanStr((char*)params, "%d", &alpha); break; case TOKEN_EDITOR_PROPERTY: ParseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND){ Game->LOG(0, "Syntax error in ITEM definition"); return E_FAIL; } if (cmd == PARSERR_GENERIC){ Game->LOG(0, "Error loading ITEM definition"); return E_FAIL; } if(alpha != 0 && ar==0 && ag == 0 && ab == 0){ ar = ag = ab = 255; } m_AlphaColor = DRGBA(ar, ag, ab, alpha); return S_OK; }