Skip to content

Commit

Permalink
MUTATIONOFJB: Load local (room) scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
LubomirR authored and sev- committed Aug 25, 2018
1 parent 1d84041 commit 7a081f0
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 6 deletions.
1 change: 1 addition & 0 deletions engines/mutationofjb/commands/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace MutationOfJB {

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

Command::~Command() {}
Expand Down
3 changes: 3 additions & 0 deletions engines/mutationofjb/commands/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions engines/mutationofjb/commands/conditionalcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ void ConditionalCommandParser::transition(ScriptParseContext &parseContext, Comm
condCommand->setTrueCommand(newCommand);
}

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


ConditionalCommand::ConditionalCommand() :
_trueCommand(nullptr),
Expand Down
2 changes: 2 additions & 0 deletions engines/mutationofjb/commands/conditionalcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
10 changes: 10 additions & 0 deletions engines/mutationofjb/commands/endblockcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions engines/mutationofjb/commands/endblockcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions engines/mutationofjb/commands/gotocommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "mutationofjb/script.h"

/*
GOTO <label>
"GOTO " <label>
Jumps to a label.
*/
Expand All @@ -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)) {
Expand Down
22 changes: 22 additions & 0 deletions engines/mutationofjb/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
4 changes: 4 additions & 0 deletions engines/mutationofjb/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion engines/mutationofjb/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 7a081f0

Please sign in to comment.