Permalink
Browse files

MUTATIONOFJB: Load local (room) scripts.

  • Loading branch information...
LubomirR committed Mar 20, 2018
1 parent b16a035 commit b5003d3940bba3fb73dac92292268f11d1fce1a9
@@ -26,6 +26,7 @@
namespace MutationOfJB {

void CommandParser::transition(ScriptParseContext &, Command *, Command *, CommandParser *) {}
void CommandParser::finish(ScriptParseContext &parseCtx) {}
CommandParser::~CommandParser() {}

Command::~Command() {}
@@ -43,6 +43,9 @@ class CommandParser {

/* Old command - created by this parser. */
virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser);

/* Called after parsing. */
virtual void finish(ScriptParseContext &parseCtx);
};

class Command {
@@ -38,6 +38,10 @@ void ConditionalCommandParser::transition(ScriptParseContext &parseContext, Comm
condCommand->setTrueCommand(newCommand);
}

void ConditionalCommandParser::finish(ScriptParseContext &) {
_lastTag = 0;
}


ConditionalCommand::ConditionalCommand() :
_trueCommand(nullptr),
@@ -30,7 +30,9 @@ namespace MutationOfJB {

class ConditionalCommandParser : public CommandParser {
public:
ConditionalCommandParser() : _lastTag(0) {}
virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser);
virtual void finish(ScriptParseContext &parseCtx) override;
protected:
char _lastTag;
};
@@ -121,6 +121,16 @@ void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *,
}
}

void EndBlockCommandParser::finish(ScriptParseContext &) {
_elseFound = false;
_ifTag = 0;

if (!_pendingActionInfos.empty()) {
debug("Problem: Pending action infos from end block parser is not empty!");
}
_pendingActionInfos.clear();
}

Command::ExecuteResult EndBlockCommand::execute(GameData &) {
return Finished;
}
@@ -35,9 +35,9 @@ class EndBlockCommandParser : public CommandParser {
public:
EndBlockCommandParser() : _elseFound(false), _ifTag(0) {}

virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command);
virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser);

virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) override;
virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser) override;
virtual void finish(ScriptParseContext &parseCtx) override;
private:
bool _elseFound;
char _ifTag;
@@ -26,7 +26,7 @@
#include "mutationofjb/script.h"

/*
GOTO <label>
"GOTO " <label>
Jumps to a label.
*/
@@ -38,7 +38,7 @@ bool GotoCommandParser::parse(const Common::String &line, ScriptParseContext &pa
return false;
}

Common::String label = line.c_str() + 6;
Common::String label = line.c_str() + 5;
GotoCommand *gotoCmd = new GotoCommand();

if (parseCtx._labels.contains(label)) {
@@ -79,6 +79,28 @@ bool Game::loadGameData(bool partB) {
void Game::changeScene(uint8 sceneId, bool partB) {
_gameData->_currentScene = sceneId;
_room->load(_gameData->_currentScene, partB);

if (_localScript) {
delete _localScript;
_localScript = nullptr;
}

EncryptedFile scriptFile;
Common::String fileName = Common::String::format("scrn%d%s.atn", sceneId, partB ? "b" : "");
scriptFile.open(fileName);
if (!scriptFile.isOpen()) {
reportFileMissingError(fileName.c_str());
return;
}

// TODO Actually parse this.
Common::String dummy;
dummy = scriptFile.readLine(); // Skip first line.
scriptFile.seek(126, SEEK_CUR); // Skip 126 bytes.

_localScript = new Script;
_localScript->loadFromStream(scriptFile);
scriptFile.close();
}

}
@@ -130,6 +130,10 @@ bool Script::loadFromStream(Common::SeekableReadStream &stream) {
lastParser = currentParser;
}

for (CommandParser **parser = parsers; *parser; ++parser) {
(*parser)->finish(parseCtx);
}

for (ActionInfos::iterator it = parseCtx._actionInfos.begin(); it != parseCtx._actionInfos.end(); ++it) {
if (it->_action == ActionInfo::Look) {
_lookActionInfos.push_back(*it);
@@ -28,7 +28,7 @@
namespace MutationOfJB {

void reportFileMissingError(const char *fileName) {
Common::String errorMessage = Common::String::format(_("Unable to locate the '%s' engine data file."), fileName);
Common::String errorMessage = Common::String::format(_("Unable to locate the '%s' engine data file"), fileName);
GUIErrorMessage(errorMessage);
warning("%s", errorMessage.c_str());
}

0 comments on commit b5003d3

Please sign in to comment.