TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool AdScaleLevel::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(SCALE_LEVEL) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(Y) TOKEN_TABLE(SCALE) TOKEN_TABLE(EDITOR_PROPERTY) TOKEN_TABLE_END byte *params; int cmd; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCALE_LEVEL) { _gameRef->LOG(0, "'SCALE_LEVEL' keyword expected."); return STATUS_FAILED; } buffer = params; } while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_Y: parser.scanStr((char *)params, "%d", &_posY); break; case TOKEN_SCALE: { int i; parser.scanStr((char *)params, "%d", &i); _scale = (float)i; } break; case TOKEN_EDITOR_PROPERTY: parseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in SCALE_LEVEL definition"); return STATUS_FAILED; } return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool BaseRegion::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(REGION) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(NAME) TOKEN_TABLE(ACTIVE) TOKEN_TABLE(POINT) TOKEN_TABLE(CAPTION) TOKEN_TABLE(SCRIPT) TOKEN_TABLE(EDITOR_SELECTED_POINT) TOKEN_TABLE(PROPERTY) TOKEN_TABLE_END byte *params; int cmd; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { _gameRef->LOG(0, "'REGION' keyword expected."); return STATUS_FAILED; } buffer = params; } for (uint32 i = 0; i < _points.size(); i++) { delete _points[i]; } _points.clear(); while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (DID_FAIL(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", &_active); break; case TOKEN_POINT: { int x, y; parser.scanStr((char *)params, "%d,%d", &x, &y); _points.add(new BasePoint(x, y)); } break; case TOKEN_SCRIPT: addScript((char *)params); break; case TOKEN_EDITOR_SELECTED_POINT: parser.scanStr((char *)params, "%d", &_editorSelectedPoint); break; case TOKEN_PROPERTY: parseProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in REGION definition"); return STATUS_FAILED; } createRegion(); return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool UIEdit::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(DISABLED) TOKEN_TABLE(VISIBLE) TOKEN_TABLE(BACK) TOKEN_TABLE(IMAGE) TOKEN_TABLE(FONT_SELECTED) TOKEN_TABLE(FONT) TOKEN_TABLE(TEXT) TOKEN_TABLE(X) TOKEN_TABLE(Y) TOKEN_TABLE(WIDTH) TOKEN_TABLE(HEIGHT) TOKEN_TABLE(CURSOR_BLINK_RATE) TOKEN_TABLE(CURSOR) TOKEN_TABLE(FRAME_WIDTH) TOKEN_TABLE(NAME) TOKEN_TABLE(SCRIPT) TOKEN_TABLE(PARENT_NOTIFY) TOKEN_TABLE(MAX_LENGTH) TOKEN_TABLE(EDITOR_PROPERTY) TOKEN_TABLE(EDIT) TOKEN_TABLE(CAPTION) TOKEN_TABLE_END byte *params; int cmd = 2; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_EDIT) { _gameRef->LOG(0, "'EDIT' keyword expected."); return STATUS_FAILED; } buffer = params; } while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_NAME: setName((char *)params); break; case TOKEN_BACK: delete _back; _back = new UITiledImage(_gameRef); if (!_back || DID_FAIL(_back->loadFile((char *)params))) { delete _back; _back = NULL; cmd = PARSERR_GENERIC; } break; case TOKEN_IMAGE: delete _image; _image = new BaseSprite(_gameRef); if (!_image || DID_FAIL(_image->loadFile((char *)params))) { delete _image; _image = NULL; cmd = PARSERR_GENERIC; } break; case TOKEN_FONT: if (_font) { _gameRef->_fontStorage->removeFont(_font); } _font = _gameRef->_fontStorage->addFont((char *)params); if (!_font) { cmd = PARSERR_GENERIC; } break; case TOKEN_FONT_SELECTED: if (_fontSelected) { _gameRef->_fontStorage->removeFont(_fontSelected); } _fontSelected = _gameRef->_fontStorage->addFont((char *)params); if (!_fontSelected) { cmd = PARSERR_GENERIC; } break; case TOKEN_TEXT: setText((char *)params); _gameRef->_stringTable->expand(&_text); break; case TOKEN_X: parser.scanStr((char *)params, "%d", &_posX); break; case TOKEN_Y: parser.scanStr((char *)params, "%d", &_posY); break; case TOKEN_WIDTH: parser.scanStr((char *)params, "%d", &_width); break; case TOKEN_HEIGHT: parser.scanStr((char *)params, "%d", &_height); break; case TOKEN_MAX_LENGTH: parser.scanStr((char *)params, "%d", &_maxLength); break; case TOKEN_CAPTION: setCaption((char *)params); break; case TOKEN_CURSOR: delete _cursor; _cursor = new BaseSprite(_gameRef); if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { delete _cursor; _cursor = NULL; cmd = PARSERR_GENERIC; } break; case TOKEN_CURSOR_BLINK_RATE: parser.scanStr((char *)params, "%d", &_cursorBlinkRate); break; case TOKEN_FRAME_WIDTH: parser.scanStr((char *)params, "%d", &_frameWidth); break; case TOKEN_SCRIPT: addScript((char *)params); break; case TOKEN_PARENT_NOTIFY: parser.scanStr((char *)params, "%b", &_parentNotify); break; case TOKEN_DISABLED: parser.scanStr((char *)params, "%b", &_disable); break; case TOKEN_VISIBLE: parser.scanStr((char *)params, "%b", &_visible); break; case TOKEN_EDITOR_PROPERTY: parseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in EDIT definition"); return STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading EDIT definition"); return STATUS_FAILED; } correctSize(); return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool AdActor::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; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTOR) { _gameRef->LOG(0, "'ACTOR' keyword expected."); return STATUS_FAILED; } buffer = params; } AdGame *adGame = (AdGame *)_gameRef; AdSpriteSet *spr = nullptr; 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 (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_X: parser.scanStr((char *)params, "%d", &_posX); break; case TOKEN_Y: parser.scanStr((char *)params, "%d", &_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", &_zoomable); break; case TOKEN_ROTABLE: case TOKEN_ROTATABLE: parser.scanStr((char *)params, "%b", &_rotatable); break; case TOKEN_REGISTRABLE: case TOKEN_INTERACTIVE: parser.scanStr((char *)params, "%b", &_registrable); break; case TOKEN_SHADOWABLE: case TOKEN_COLORABLE: parser.scanStr((char *)params, "%b", &_shadowable); break; case TOKEN_ACTIVE: parser.scanStr((char *)params, "%b", &_active); break; case TOKEN_WALK: delete _walkSprite; _walkSprite = nullptr; spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) { cmd = PARSERR_GENERIC; } else { _walkSprite = spr; } break; case TOKEN_TALK: spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) { cmd = PARSERR_GENERIC; } else { _talkSprites.add(spr); } break; case TOKEN_TALK_SPECIAL: spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) { cmd = PARSERR_GENERIC; } else { _talkSpritesEx.add(spr); } break; case TOKEN_STAND: delete _standSprite; _standSprite = nullptr; spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) { cmd = PARSERR_GENERIC; } else { _standSprite = spr; } break; case TOKEN_TURN_LEFT: delete _turnLeftSprite; _turnLeftSprite = nullptr; spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true))) { cmd = PARSERR_GENERIC; } else { _turnLeftSprite = spr; } break; case TOKEN_TURN_RIGHT: delete _turnRightSprite; _turnRightSprite = nullptr; spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true))) { cmd = PARSERR_GENERIC; } else { _turnRightSprite = spr; } break; case TOKEN_SCRIPT: addScript((char *)params); break; case TOKEN_CURSOR: delete _cursor; _cursor = new BaseSprite(_gameRef); if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { delete _cursor; _cursor = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_SOUND_VOLUME: parser.scanStr((char *)params, "%d", &_sFXVolume); break; case TOKEN_SCALE: { int s; parser.scanStr((char *)params, "%d", &s); _scale = (float)s; } break; case TOKEN_RELATIVE_SCALE: { int s; parser.scanStr((char *)params, "%d", &s); _relativeScale = (float)s; } break; case TOKEN_SOUND_PANNING: parser.scanStr((char *)params, "%b", &_autoSoundPanning); break; case TOKEN_PROPERTY: parseProperty(params, false); break; case TOKEN_BLOCKED_REGION: { delete _blockRegion; delete _currentBlockRegion; _blockRegion = nullptr; _currentBlockRegion = nullptr; BaseRegion *rgn = new BaseRegion(_gameRef); BaseRegion *crgn = new BaseRegion(_gameRef); if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { delete _blockRegion; delete _currentBlockRegion; _blockRegion = nullptr; _currentBlockRegion = nullptr; cmd = PARSERR_GENERIC; } else { _blockRegion = rgn; _currentBlockRegion = crgn; _currentBlockRegion->mimic(_blockRegion); } } break; case TOKEN_WAYPOINTS: { delete _wptGroup; delete _currentWptGroup; _wptGroup = nullptr; _currentWptGroup = nullptr; AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); AdWaypointGroup *cwpt = new AdWaypointGroup(_gameRef); if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { delete _wptGroup; delete _currentWptGroup; _wptGroup = nullptr; _currentWptGroup = nullptr; cmd = PARSERR_GENERIC; } else { _wptGroup = wpt; _currentWptGroup = cwpt; _currentWptGroup->mimic(_wptGroup); } } break; case TOKEN_IGNORE_ITEMS: parser.scanStr((char *)params, "%b", &_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: { AdSpriteSet *anim = new AdSpriteSet(_gameRef, this); if (!anim || DID_FAIL(anim->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; } else { _anims.add(anim); } } break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in ACTOR definition"); return STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { if (spr) { delete spr; } _gameRef->LOG(0, "Error loading ACTOR definition"); return STATUS_FAILED; } if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { ar = ag = ab = 255; } _alphaColor = BYTETORGBA(ar, ag, ab, alpha); _state = _nextState = STATE_READY; return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool AdRegion::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; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { _gameRef->LOG(0, "'REGION' keyword expected."); return STATUS_FAILED; } buffer = params; } for (uint32 i = 0; i < _points.size(); i++) { delete _points[i]; } _points.clear(); 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 (DID_FAIL(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", &_active); break; case TOKEN_BLOCKED: parser.scanStr((char *)params, "%b", &_blocked); break; case TOKEN_DECORATION: parser.scanStr((char *)params, "%b", &_decoration); break; case TOKEN_ZOOM: case TOKEN_SCALE: { int j; parser.scanStr((char *)params, "%d", &j); _zoom = (float)j; } break; case TOKEN_POINT: { int x, y; parser.scanStr((char *)params, "%d,%d", &x, &y); _points.add(new BasePoint(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", &_editorSelected); break; case TOKEN_EDITOR_SELECTED_POINT: parser.scanStr((char *)params, "%d", &_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) { _gameRef->LOG(0, "Syntax error in REGION definition"); return STATUS_FAILED; } createRegion(); _alpha = BYTETORGBA(ar, ag, ab, alpha); return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(RESPONSE_BOX) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(FONT_HOVER) TOKEN_TABLE(FONT) TOKEN_TABLE(AREA) TOKEN_TABLE(HORIZONTAL) TOKEN_TABLE(SPACING) TOKEN_TABLE(WINDOW) TOKEN_TABLE(CURSOR) TOKEN_TABLE(TEXT_ALIGN) TOKEN_TABLE(VERTICAL_ALIGN) TOKEN_TABLE(EDITOR_PROPERTY) TOKEN_TABLE_END byte *params; int cmd; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_RESPONSE_BOX) { _gameRef->LOG(0, "'RESPONSE_BOX' keyword expected."); return STATUS_FAILED; } buffer = params; } while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_WINDOW: delete _window; _window = new UIWindow(_gameRef); if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { delete _window; _window = nullptr; cmd = PARSERR_GENERIC; } else if (_shieldWindow) { _shieldWindow->_parent = _window; } break; case TOKEN_FONT: if (_font) { _gameRef->_fontStorage->removeFont(_font); } _font = _gameRef->_fontStorage->addFont((char *)params); if (!_font) { cmd = PARSERR_GENERIC; } break; case TOKEN_FONT_HOVER: if (_fontHover) { _gameRef->_fontStorage->removeFont(_fontHover); } _fontHover = _gameRef->_fontStorage->addFont((char *)params); if (!_fontHover) { cmd = PARSERR_GENERIC; } break; case TOKEN_AREA: parser.scanStr((char *)params, "%d,%d,%d,%d", &_responseArea.left, &_responseArea.top, &_responseArea.right, &_responseArea.bottom); break; case TOKEN_HORIZONTAL: parser.scanStr((char *)params, "%b", &_horizontal); break; case TOKEN_TEXT_ALIGN: if (scumm_stricmp((char *)params, "center") == 0) { _align = TAL_CENTER; } else if (scumm_stricmp((char *)params, "right") == 0) { _align = TAL_RIGHT; } else { _align = TAL_LEFT; } break; case TOKEN_VERTICAL_ALIGN: if (scumm_stricmp((char *)params, "top") == 0) { _verticalAlign = VAL_TOP; } else if (scumm_stricmp((char *)params, "center") == 0) { _verticalAlign = VAL_CENTER; } else { _verticalAlign = VAL_BOTTOM; } break; case TOKEN_SPACING: parser.scanStr((char *)params, "%d", &_spacing); break; case TOKEN_EDITOR_PROPERTY: parseEditorProperty(params, false); break; case TOKEN_CURSOR: delete _cursor; _cursor = new BaseSprite(_gameRef); if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { delete _cursor; _cursor = nullptr; cmd = PARSERR_GENERIC; } break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in RESPONSE_BOX definition"); return STATUS_FAILED; } if (_window) { for (uint32 i = 0; i < _window->_widgets.size(); i++) { if (!_window->_widgets[i]->_listenerObject) { _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); } } } return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool BaseGameSettings::loadSettings(const char *filename) { TOKEN_TABLE_START(commands) TOKEN_TABLE(SETTINGS) TOKEN_TABLE(GAME) TOKEN_TABLE(STRING_TABLE) TOKEN_TABLE(RESOLUTION) TOKEN_TABLE(REQUIRE_3D_ACCELERATION) TOKEN_TABLE(REQUIRE_SOUND) TOKEN_TABLE(HWTL_MODE) TOKEN_TABLE(ALLOW_WINDOWED_MODE) TOKEN_TABLE(ALLOW_ACCESSIBILITY_TAB) TOKEN_TABLE(ALLOW_ABOUT_TAB) TOKEN_TABLE(ALLOW_ADVANCED) TOKEN_TABLE(ALLOW_DESKTOP_RES) TOKEN_TABLE(REGISTRY_PATH) TOKEN_TABLE(RICH_SAVED_GAMES) TOKEN_TABLE(SAVED_GAME_EXT) TOKEN_TABLE(GUID) TOKEN_TABLE_END byte *origBuffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (origBuffer == nullptr) { BaseEngine::LOG(0, "BaseGame::LoadSettings failed for file '%s'", filename); return STATUS_FAILED; } bool ret = STATUS_OK; byte *buffer = origBuffer; byte *params; int cmd; BaseParser parser; if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SETTINGS) { BaseEngine::LOG(0, "'SETTINGS' keyword expected in game settings file."); return STATUS_FAILED; } buffer = params; while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_GAME: delete[] _gameFile; _gameFile = new char[strlen((char *)params) + 1]; if (_gameFile) { strcpy(_gameFile, (char *)params); } break; case TOKEN_STRING_TABLE: if (DID_FAIL(_stringTable->loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_RESOLUTION: parser.scanStr((char *)params, "%d,%d", &_resWidth, &_resHeight); break; case TOKEN_REQUIRE_3D_ACCELERATION: parser.scanStr((char *)params, "%b", &_requireAcceleration); break; case TOKEN_REQUIRE_SOUND: parser.scanStr((char *)params, "%b", &_requireSound); break; case TOKEN_HWTL_MODE: parser.scanStr((char *)params, "%d", &_TLMode); break; case TOKEN_ALLOW_WINDOWED_MODE: parser.scanStr((char *)params, "%b", &_allowWindowed); break; case TOKEN_ALLOW_DESKTOP_RES: parser.scanStr((char *)params, "%b", &_allowDesktopRes); break; case TOKEN_ALLOW_ADVANCED: parser.scanStr((char *)params, "%b", &_allowAdvanced); break; case TOKEN_ALLOW_ACCESSIBILITY_TAB: parser.scanStr((char *)params, "%b", &_allowAccessTab); break; case TOKEN_ALLOW_ABOUT_TAB: parser.scanStr((char *)params, "%b", &_allowAboutTab); break; case TOKEN_REGISTRY_PATH: //BaseEngine::instance().getRegistry()->setBasePath((char *)params); break; case TOKEN_RICH_SAVED_GAMES: parser.scanStr((char *)params, "%b", &_richSavedGames); break; case TOKEN_SAVED_GAME_EXT: _savedGameExt = (char *)params; break; case TOKEN_GUID: break; } } if (cmd == PARSERR_TOKENNOTFOUND) { BaseEngine::LOG(0, "Syntax error in game settings '%s'", filename); ret = STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { BaseEngine::LOG(0, "Error loading game settings '%s'", filename); ret = STATUS_FAILED; } _allowWindowed = true; // TODO: These two settings should probably be cleaned out altogether. _compressedSavegames = true; delete[] origBuffer; return ret; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool UIEntity::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ENTITY_CONTAINER) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(DISABLED) TOKEN_TABLE(VISIBLE) TOKEN_TABLE(X) TOKEN_TABLE(Y) TOKEN_TABLE(NAME) TOKEN_TABLE(ENTITY) TOKEN_TABLE(SCRIPT) TOKEN_TABLE(EDITOR_PROPERTY) TOKEN_TABLE_END byte *params; int cmd = 2; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ENTITY_CONTAINER) { _gameRef->LOG(0, "'ENTITY_CONTAINER' keyword expected."); return STATUS_FAILED; } buffer = params; } while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_NAME: setName((char *)params); break; case TOKEN_X: parser.scanStr((char *)params, "%d", &_posX); break; case TOKEN_Y: parser.scanStr((char *)params, "%d", &_posY); break; case TOKEN_DISABLED: parser.scanStr((char *)params, "%b", &_disable); break; case TOKEN_VISIBLE: parser.scanStr((char *)params, "%b", &_visible); break; case TOKEN_ENTITY: if (DID_FAIL(setEntity((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_SCRIPT: addScript((char *)params); break; case TOKEN_EDITOR_PROPERTY: parseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in ENTITY_CONTAINER definition"); return STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading ENTITY_CONTAINER definition"); return STATUS_FAILED; } correctSize(); if (_gameRef->_editorMode) { _width = 50; _height = 50; } return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool UIText::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(STATIC) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(DISABLED) TOKEN_TABLE(VISIBLE) TOKEN_TABLE(BACK) TOKEN_TABLE(IMAGE) TOKEN_TABLE(FONT) TOKEN_TABLE(TEXT_ALIGN) TOKEN_TABLE(VERTICAL_ALIGN) TOKEN_TABLE(TEXT) TOKEN_TABLE(X) TOKEN_TABLE(Y) TOKEN_TABLE(WIDTH) TOKEN_TABLE(HEIGHT) TOKEN_TABLE(CURSOR) TOKEN_TABLE(NAME) TOKEN_TABLE(SCRIPT) TOKEN_TABLE(CAPTION) TOKEN_TABLE(PARENT_NOTIFY) TOKEN_TABLE(EDITOR_PROPERTY) TOKEN_TABLE_END byte *params; int cmd = 2; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_STATIC) { _gameRef->LOG(0, "'STATIC' keyword expected."); return STATUS_FAILED; } buffer = params; } while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_NAME: setName((char *)params); break; case TOKEN_CAPTION: setCaption((char *)params); break; case TOKEN_BACK: delete _back; _back = new UITiledImage(_gameRef); if (!_back || DID_FAIL(_back->loadFile((char *)params))) { delete _back; _back = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_IMAGE: delete _image; _image = new BaseSprite(_gameRef); if (!_image || DID_FAIL(_image->loadFile((char *)params))) { delete _image; _image = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_FONT: if (_font) { _gameRef->_fontStorage->removeFont(_font); } _font = _gameRef->_fontStorage->addFont((char *)params); if (!_font) { cmd = PARSERR_GENERIC; } break; case TOKEN_TEXT: setText((char *)params); _gameRef->expandStringByStringTable(&_text); break; case TOKEN_TEXT_ALIGN: if (scumm_stricmp((char *)params, "left") == 0) { _textAlign = TAL_LEFT; } else if (scumm_stricmp((char *)params, "right") == 0) { _textAlign = TAL_RIGHT; } else { _textAlign = TAL_CENTER; } break; case TOKEN_VERTICAL_ALIGN: if (scumm_stricmp((char *)params, "top") == 0) { _verticalAlign = VAL_TOP; } else if (scumm_stricmp((char *)params, "bottom") == 0) { _verticalAlign = VAL_BOTTOM; } else { _verticalAlign = VAL_CENTER; } break; case TOKEN_X: parser.scanStr((char *)params, "%d", &_posX); break; case TOKEN_Y: parser.scanStr((char *)params, "%d", &_posY); break; case TOKEN_WIDTH: parser.scanStr((char *)params, "%d", &_width); break; case TOKEN_HEIGHT: parser.scanStr((char *)params, "%d", &_height); break; case TOKEN_CURSOR: delete _cursor; _cursor = new BaseSprite(_gameRef); if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { delete _cursor; _cursor = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_SCRIPT: addScript((char *)params); break; case TOKEN_PARENT_NOTIFY: parser.scanStr((char *)params, "%b", &_parentNotify); break; case TOKEN_DISABLED: parser.scanStr((char *)params, "%b", &_disable); break; case TOKEN_VISIBLE: parser.scanStr((char *)params, "%b", &_visible); break; case TOKEN_EDITOR_PROPERTY: parseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in STATIC definition"); return STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading STATIC definition"); return STATUS_FAILED; } correctSize(); return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool UIButton::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(BUTTON) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(DISABLED) TOKEN_TABLE(VISIBLE) TOKEN_TABLE(FOCUSABLE) TOKEN_TABLE(BACK_HOVER) TOKEN_TABLE(BACK_PRESS) TOKEN_TABLE(BACK_DISABLE) TOKEN_TABLE(BACK_FOCUS) TOKEN_TABLE(BACK) TOKEN_TABLE(CENTER_IMAGE) TOKEN_TABLE(IMAGE_HOVER) TOKEN_TABLE(IMAGE_PRESS) TOKEN_TABLE(IMAGE_DISABLE) TOKEN_TABLE(IMAGE_FOCUS) TOKEN_TABLE(IMAGE) TOKEN_TABLE(FONT_HOVER) TOKEN_TABLE(FONT_PRESS) TOKEN_TABLE(FONT_DISABLE) TOKEN_TABLE(FONT_FOCUS) TOKEN_TABLE(FONT) TOKEN_TABLE(TEXT_ALIGN) TOKEN_TABLE(TEXT) TOKEN_TABLE(X) TOKEN_TABLE(Y) TOKEN_TABLE(WIDTH) TOKEN_TABLE(HEIGHT) TOKEN_TABLE(CURSOR) TOKEN_TABLE(NAME) TOKEN_TABLE(EVENTS) TOKEN_TABLE(SCRIPT) TOKEN_TABLE(CAPTION) TOKEN_TABLE(PARENT_NOTIFY) TOKEN_TABLE(PRESSED) TOKEN_TABLE(PIXEL_PERFECT) TOKEN_TABLE(EDITOR_PROPERTY) TOKEN_TABLE_END byte *params; int cmd = 2; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_BUTTON) { _gameRef->LOG(0, "'BUTTON' keyword expected."); return STATUS_FAILED; } buffer = params; } while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_NAME: setName((char *)params); break; case TOKEN_CAPTION: setCaption((char *)params); break; case TOKEN_BACK: delete _back; _back = new UITiledImage(_gameRef); if (!_back || DID_FAIL(_back->loadFile((char *)params))) { delete _back; _back = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_BACK_HOVER: delete _backHover; _backHover = new UITiledImage(_gameRef); if (!_backHover || DID_FAIL(_backHover->loadFile((char *)params))) { delete _backHover; _backHover = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_BACK_PRESS: delete _backPress; _backPress = new UITiledImage(_gameRef); if (!_backPress || DID_FAIL(_backPress->loadFile((char *)params))) { delete _backPress; _backPress = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_BACK_DISABLE: delete _backDisable; _backDisable = new UITiledImage(_gameRef); if (!_backDisable || DID_FAIL(_backDisable->loadFile((char *)params))) { delete _backDisable; _backDisable = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_BACK_FOCUS: delete _backFocus; _backFocus = new UITiledImage(_gameRef); if (!_backFocus || DID_FAIL(_backFocus->loadFile((char *)params))) { delete _backFocus; _backFocus = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_IMAGE: delete _image; _image = new BaseSprite(_gameRef); if (!_image || DID_FAIL(_image->loadFile((char *)params))) { delete _image; _image = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_IMAGE_HOVER: delete _imageHover; _imageHover = new BaseSprite(_gameRef); if (!_imageHover || DID_FAIL(_imageHover->loadFile((char *)params))) { delete _imageHover; _imageHover = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_IMAGE_PRESS: delete _imagePress; _imagePress = new BaseSprite(_gameRef); if (!_imagePress || DID_FAIL(_imagePress->loadFile((char *)params))) { delete _imagePress; _imagePress = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_IMAGE_DISABLE: delete _imageDisable; _imageDisable = new BaseSprite(_gameRef); if (!_imageDisable || DID_FAIL(_imageDisable->loadFile((char *)params))) { delete _imageDisable; _imageDisable = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_IMAGE_FOCUS: delete _imageFocus; _imageFocus = new BaseSprite(_gameRef); if (!_imageFocus || DID_FAIL(_imageFocus->loadFile((char *)params))) { delete _imageFocus; _imageFocus = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_FONT: if (_font) { _gameRef->_fontStorage->removeFont(_font); } _font = _gameRef->_fontStorage->addFont((char *)params); if (!_font) { cmd = PARSERR_GENERIC; } break; case TOKEN_FONT_HOVER: if (_fontHover) { _gameRef->_fontStorage->removeFont(_fontHover); } _fontHover = _gameRef->_fontStorage->addFont((char *)params); if (!_fontHover) { cmd = PARSERR_GENERIC; } break; case TOKEN_FONT_PRESS: if (_fontPress) { _gameRef->_fontStorage->removeFont(_fontPress); } _fontPress = _gameRef->_fontStorage->addFont((char *)params); if (!_fontPress) { cmd = PARSERR_GENERIC; } break; case TOKEN_FONT_DISABLE: if (_fontDisable) { _gameRef->_fontStorage->removeFont(_fontDisable); } _fontDisable = _gameRef->_fontStorage->addFont((char *)params); if (!_fontDisable) { cmd = PARSERR_GENERIC; } break; case TOKEN_FONT_FOCUS: if (_fontFocus) { _gameRef->_fontStorage->removeFont(_fontFocus); } _fontFocus = _gameRef->_fontStorage->addFont((char *)params); if (!_fontFocus) { cmd = PARSERR_GENERIC; } break; case TOKEN_TEXT: setText((char *)params); _gameRef->_stringTable->expand(&_text); break; case TOKEN_TEXT_ALIGN: if (scumm_stricmp((char *)params, "left") == 0) { _align = TAL_LEFT; } else if (scumm_stricmp((char *)params, "right") == 0) { _align = TAL_RIGHT; } else { _align = TAL_CENTER; } break; case TOKEN_X: parser.scanStr((char *)params, "%d", &_posX); break; case TOKEN_Y: parser.scanStr((char *)params, "%d", &_posY); break; case TOKEN_WIDTH: parser.scanStr((char *)params, "%d", &_width); break; case TOKEN_HEIGHT: parser.scanStr((char *)params, "%d", &_height); break; case TOKEN_CURSOR: delete _cursor; _cursor = new BaseSprite(_gameRef); if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { delete _cursor; _cursor = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_SCRIPT: addScript((char *)params); break; case TOKEN_PARENT_NOTIFY: parser.scanStr((char *)params, "%b", &_parentNotify); break; case TOKEN_DISABLED: parser.scanStr((char *)params, "%b", &_disable); break; case TOKEN_VISIBLE: parser.scanStr((char *)params, "%b", &_visible); break; case TOKEN_FOCUSABLE: parser.scanStr((char *)params, "%b", &_canFocus); break; case TOKEN_CENTER_IMAGE: parser.scanStr((char *)params, "%b", &_centerImage); break; case TOKEN_PRESSED: parser.scanStr((char *)params, "%b", &_stayPressed); break; case TOKEN_PIXEL_PERFECT: parser.scanStr((char *)params, "%b", &_pixelPerfect); break; case TOKEN_EDITOR_PROPERTY: parseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in BUTTON definition"); return STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading BUTTON definition"); return STATUS_FAILED; } correctSize(); return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool AdEntity::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ENTITY) TOKEN_TABLE(SPRITE) 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(EVENTS) TOKEN_TABLE(FONT) TOKEN_TABLE(TALK_SPECIAL) TOKEN_TABLE(TALK) TOKEN_TABLE(CURSOR) TOKEN_TABLE(REGION) TOKEN_TABLE(BLOCKED_REGION) TOKEN_TABLE(EDITOR_SELECTED) TOKEN_TABLE(SCRIPT) TOKEN_TABLE(SOUND_START_TIME) TOKEN_TABLE(SOUND_VOLUME) TOKEN_TABLE(SOUND_PANNING) TOKEN_TABLE(SOUND) TOKEN_TABLE(SUBTYPE) TOKEN_TABLE(CAPTION) TOKEN_TABLE(PROPERTY) 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(ITEM) TOKEN_TABLE(WALK_TO_X) TOKEN_TABLE(WALK_TO_Y) TOKEN_TABLE(WALK_TO_DIR) TOKEN_TABLE(SAVE_STATE) TOKEN_TABLE_END byte *params; int cmd; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ENTITY) { _gameRef->LOG(0, "'ENTITY' keyword expected."); return STATUS_FAILED; } buffer = params; } AdGame *adGame = (AdGame *)_gameRef; BaseSprite *spr = nullptr; 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 (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_X: parser.scanStr((char *)params, "%d", &_posX); break; case TOKEN_Y: parser.scanStr((char *)params, "%d", &_posY); break; case TOKEN_SPRITE: { delete _sprite; _sprite = nullptr; spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile((char *)params))) { cmd = PARSERR_GENERIC; } else { _sprite = spr; } } break; case TOKEN_TALK: { spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) { cmd = PARSERR_GENERIC; } else { _talkSprites.add(spr); } } break; case TOKEN_TALK_SPECIAL: { spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) { cmd = PARSERR_GENERIC; } else { _talkSpritesEx.add(spr); } } break; case TOKEN_NAME: setName((char *)params); break; case TOKEN_ITEM: setItem((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", &_zoomable); break; case TOKEN_SCALE: { int s; parser.scanStr((char *)params, "%d", &s); _scale = (float)s; } break; case TOKEN_RELATIVE_SCALE: { int s; parser.scanStr((char *)params, "%d", &s); _relativeScale = (float)s; } break; case TOKEN_ROTABLE: case TOKEN_ROTATABLE: parser.scanStr((char *)params, "%b", &_rotatable); break; case TOKEN_REGISTRABLE: case TOKEN_INTERACTIVE: parser.scanStr((char *)params, "%b", &_registrable); break; case TOKEN_SHADOWABLE: case TOKEN_COLORABLE: parser.scanStr((char *)params, "%b", &_shadowable); break; case TOKEN_ACTIVE: parser.scanStr((char *)params, "%b", &_active); break; case TOKEN_CURSOR: delete _cursor; _cursor = new BaseSprite(_gameRef); if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { delete _cursor; _cursor = nullptr; cmd = PARSERR_GENERIC; } break; case TOKEN_EDITOR_SELECTED: parser.scanStr((char *)params, "%b", &_editorSelected); break; case TOKEN_REGION: { if (_region) { _gameRef->unregisterObject(_region); } _region = nullptr; BaseRegion *rgn = new BaseRegion(_gameRef); if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; } else { _region = rgn; _gameRef->registerObject(_region); } } break; case TOKEN_BLOCKED_REGION: { delete _blockRegion; _blockRegion = nullptr; delete _currentBlockRegion; _currentBlockRegion = nullptr; BaseRegion *rgn = new BaseRegion(_gameRef); BaseRegion *crgn = new BaseRegion(_gameRef); if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { delete _blockRegion; _blockRegion = nullptr; delete _currentBlockRegion; _currentBlockRegion = nullptr; cmd = PARSERR_GENERIC; } else { _blockRegion = rgn; _currentBlockRegion = crgn; _currentBlockRegion->mimic(_blockRegion); } } break; case TOKEN_WAYPOINTS: { delete _wptGroup; _wptGroup = nullptr; delete _currentWptGroup; _currentWptGroup = nullptr; AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); AdWaypointGroup *cwpt = new AdWaypointGroup(_gameRef); if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { delete _wptGroup; _wptGroup = nullptr; delete _currentWptGroup; _currentWptGroup = nullptr; cmd = PARSERR_GENERIC; } else { _wptGroup = wpt; _currentWptGroup = cwpt; _currentWptGroup->mimic(_wptGroup); } } break; case TOKEN_SCRIPT: addScript((char *)params); break; case TOKEN_SUBTYPE: { if (scumm_stricmp((char *)params, "sound") == 0) { delete _sprite; _sprite = nullptr; if (_gameRef->_editorMode) { spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) { cmd = PARSERR_GENERIC; } else { _sprite = spr; } } if (_gameRef->_editorMode) { _editorOnly = true; } _zoomable = false; _rotatable = false; _registrable = _gameRef->_editorMode; _shadowable = false; _subtype = ENTITY_SOUND; } } break; case TOKEN_SOUND: playSFX((char *)params, false, false); break; case TOKEN_SOUND_START_TIME: parser.scanStr((char *)params, "%d", &_sFXStart); break; case TOKEN_SOUND_VOLUME: parser.scanStr((char *)params, "%d", &_sFXVolume); break; case TOKEN_SOUND_PANNING: parser.scanStr((char *)params, "%b", &_autoSoundPanning); break; case TOKEN_SAVE_STATE: parser.scanStr((char *)params, "%b", &_saveState); break; case TOKEN_PROPERTY: parseProperty(params, false); break; case TOKEN_IGNORE_ITEMS: parser.scanStr((char *)params, "%b", &_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_WALK_TO_X: parser.scanStr((char *)params, "%d", &_walkToX); break; case TOKEN_WALK_TO_Y: parser.scanStr((char *)params, "%d", &_walkToY); break; case TOKEN_WALK_TO_DIR: { int i; parser.scanStr((char *)params, "%d", &i); if (i < 0) { i = 0; } if (i >= NUM_DIRECTIONS) { i = DI_NONE; } _walkToDir = (TDirection)i; } break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in ENTITY definition"); return STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading ENTITY definition"); if (spr) { delete spr; } return STATUS_FAILED; } if (_region && _sprite) { _gameRef->LOG(0, "Warning: Entity '%s' has both sprite and region.", getName()); } updatePosition(); if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { ar = ag = ab = 255; } _alphaColor = BYTETORGBA(ar, ag, ab, alpha); _state = STATE_READY; if (_item && ((AdGame *)_gameRef)->isItemTaken(_item)) { _active = false; } return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool AdTalkNode::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ACTION) TOKEN_TABLE(SPRITESET_FILE) TOKEN_TABLE(SPRITESET) TOKEN_TABLE(SPRITE) TOKEN_TABLE(START_TIME) TOKEN_TABLE(END_TIME) TOKEN_TABLE(COMMENT) TOKEN_TABLE(PRECACHE) TOKEN_TABLE(EDITOR_PROPERTY) TOKEN_TABLE_END byte *params; int cmd; BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTION) { _gameRef->LOG(0, "'ACTION' keyword expected."); return STATUS_FAILED; } buffer = params; } _endTime = 0; _playToEnd = false; _preCache = false; while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_SPRITE: BaseUtils::setString(&_spriteFilename, (char *)params); break; case TOKEN_SPRITESET_FILE: BaseUtils::setString(&_spriteSetFilename, (char *)params); break; case TOKEN_SPRITESET: { delete _spriteSet; _spriteSet = new AdSpriteSet(_gameRef); if (!_spriteSet || DID_FAIL(_spriteSet->loadBuffer(params, false))) { delete _spriteSet; _spriteSet = nullptr; cmd = PARSERR_GENERIC; } } break; case TOKEN_START_TIME: parser.scanStr((char *)params, "%d", &_startTime); break; case TOKEN_END_TIME: parser.scanStr((char *)params, "%d", &_endTime); break; case TOKEN_PRECACHE: parser.scanStr((char *)params, "%b", &_preCache); break; case TOKEN_COMMENT: if (_gameRef->_editorMode) { BaseUtils::setString(&_comment, (char *)params); } break; case TOKEN_EDITOR_PROPERTY: parseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in ACTION definition"); return STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading ACTION definition"); return STATUS_FAILED; } if (_endTime == 0) { _playToEnd = true; } else { _playToEnd = false; } if (_preCache && _spriteFilename) { delete _sprite; _sprite = new BaseSprite(_gameRef); if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { return STATUS_FAILED; } } if (_preCache && _spriteSetFilename) { delete _spriteSet; _spriteSet = new AdSpriteSet(_gameRef); if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { return STATUS_FAILED; } } return STATUS_OK; }
TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(INVENTORY_BOX) TOKEN_TABLE(TEMPLATE) TOKEN_TABLE(WINDOW) TOKEN_TABLE(EXCLUSIVE) TOKEN_TABLE(ALWAYS_VISIBLE) TOKEN_TABLE(AREA) TOKEN_TABLE(SPACING) TOKEN_TABLE(ITEM_WIDTH) TOKEN_TABLE(ITEM_HEIGHT) TOKEN_TABLE(SCROLL_BY) TOKEN_TABLE(NAME) TOKEN_TABLE(CAPTION) TOKEN_TABLE(HIDE_SELECTED) TOKEN_TABLE(EDITOR_PROPERTY) TOKEN_TABLE_END byte *params; int cmd = 2; BaseParser parser; bool alwaysVisible = false; _exclusive = false; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_INVENTORY_BOX) { _gameRef->LOG(0, "'INVENTORY_BOX' keyword expected."); return STATUS_FAILED; } buffer = params; } while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: if (DID_FAIL(loadFile((char *)params))) { cmd = PARSERR_GENERIC; } break; case TOKEN_NAME: setName((char *)params); break; case TOKEN_CAPTION: setCaption((char *)params); break; case TOKEN_WINDOW: delete _window; _window = new UIWindow(_gameRef); if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { delete _window; _window = nullptr; cmd = PARSERR_GENERIC; } else { _gameRef->registerObject(_window); } break; case TOKEN_AREA: parser.scanStr((char *)params, "%d,%d,%d,%d", &_itemsArea.left, &_itemsArea.top, &_itemsArea.right, &_itemsArea.bottom); break; case TOKEN_EXCLUSIVE: parser.scanStr((char *)params, "%b", &_exclusive); break; case TOKEN_HIDE_SELECTED: parser.scanStr((char *)params, "%b", &_hideSelected); break; case TOKEN_ALWAYS_VISIBLE: parser.scanStr((char *)params, "%b", &alwaysVisible); break; case TOKEN_SPACING: parser.scanStr((char *)params, "%d", &_spacing); break; case TOKEN_ITEM_WIDTH: parser.scanStr((char *)params, "%d", &_itemWidth); break; case TOKEN_ITEM_HEIGHT: parser.scanStr((char *)params, "%d", &_itemHeight); break; case TOKEN_SCROLL_BY: parser.scanStr((char *)params, "%d", &_scrollBy); break; case TOKEN_EDITOR_PROPERTY: parseEditorProperty(params, false); break; } } if (cmd == PARSERR_TOKENNOTFOUND) { _gameRef->LOG(0, "Syntax error in INVENTORY_BOX definition"); return STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading INVENTORY_BOX definition"); return STATUS_FAILED; } if (_exclusive) { delete _closeButton; _closeButton = new UIButton(_gameRef); if (_closeButton) { _closeButton->setName("close"); _closeButton->setListener(this, _closeButton, 0); _closeButton->_parent = _window; } } _visible = alwaysVisible; if (_window) { for (uint32 i = 0; i < _window->_widgets.size(); i++) { if (!_window->_widgets[i]->_listenerObject) { _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); } } } return STATUS_OK; }