diff options
author | Ľubomír Remák | 2018-03-18 15:28:46 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-25 23:12:01 +0200 |
commit | 54c2c0aee6e371f8058c50e0a4113f5b5492169e (patch) | |
tree | ae551cedc20fa03f179340aae9f7497193c80b6e /engines/mutationofjb/commands | |
parent | 523f973e0a4ba16b278d546da9267a693924f957 (diff) | |
download | scummvm-rg350-54c2c0aee6e371f8058c50e0a4113f5b5492169e.tar.gz scummvm-rg350-54c2c0aee6e371f8058c50e0a4113f5b5492169e.tar.bz2 scummvm-rg350-54c2c0aee6e371f8058c50e0a4113f5b5492169e.zip |
MUTATIONOFJB: Add support for labels and goto.
Diffstat (limited to 'engines/mutationofjb/commands')
-rw-r--r-- | engines/mutationofjb/commands/gotocommand.cpp | 80 | ||||
-rw-r--r-- | engines/mutationofjb/commands/gotocommand.h | 55 | ||||
-rw-r--r-- | engines/mutationofjb/commands/labelcommand.cpp | 78 | ||||
-rw-r--r-- | engines/mutationofjb/commands/labelcommand.h | 51 |
4 files changed, 264 insertions, 0 deletions
diff --git a/engines/mutationofjb/commands/gotocommand.cpp b/engines/mutationofjb/commands/gotocommand.cpp new file mode 100644 index 0000000000..77c474b653 --- /dev/null +++ b/engines/mutationofjb/commands/gotocommand.cpp @@ -0,0 +1,80 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "mutationofjb/commands/gotocommand.h" +#include "mutationofjb/commands/labelcommand.h" +#include "mutationofjb/game.h" +#include "mutationofjb/script.h" + +/* + GOTO <label> + + Jumps to a label. +*/ + +namespace MutationOfJB { + +bool GotoCommandParser::parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) { + if (line.firstChar() != '_') { + return false; + } + + Common::String label = line.c_str() + 1; + GotoCommand *gotoCmd = new GotoCommand(); + + if (parseCtx._labels.contains(label)) { + // We already have the label, set it. + gotoCmd->setLabelCommand(parseCtx._labels[label]); + } else { + // Label is after goto, add to pending list. + parseCtx._pendingGotos[label].push_back(gotoCmd); + } + + command = gotoCmd; + + return true; +} + + +void GotoCommand::setLabelCommand(LabelCommand *labelCmd) { + _labelCommand = labelCmd; +} + +Command::ExecuteResult GotoCommand::execute(GameData &) { + // Intentionally empty. + + return Finished; +} + +Command *GotoCommand::next() const { + return _labelCommand; +} + +Common::String GotoCommand::debugString() const { + if (!_labelCommand) { + return "GOTO (null)"; + } + + return Common::String::format("GOTO %s", _labelCommand->getName().c_str()); +} + +} diff --git a/engines/mutationofjb/commands/gotocommand.h b/engines/mutationofjb/commands/gotocommand.h new file mode 100644 index 0000000000..436dd44fb3 --- /dev/null +++ b/engines/mutationofjb/commands/gotocommand.h @@ -0,0 +1,55 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef MUTATIONOFJB_GOTOCOMMAND_H +#define MUTATIONOFJB_GOTOCOMMAND_H + +#include "mutationofjb/commands/command.h" +#include "common/str.h" + +namespace MutationOfJB { + +class LabelCommand; + +class GotoCommandParser : public CommandParser { +public: + GotoCommandParser() {} + + virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command); +}; + +class GotoCommand : public Command { +public: + GotoCommand() : _labelCommand(nullptr) {} + + void setLabelCommand(LabelCommand *labelCmd); + + virtual ExecuteResult execute(GameData &gameData) override; + virtual Command *next() const override; + virtual Common::String debugString() const override; +private: + LabelCommand *_labelCommand; +}; + +} + +#endif diff --git a/engines/mutationofjb/commands/labelcommand.cpp b/engines/mutationofjb/commands/labelcommand.cpp new file mode 100644 index 0000000000..4540a83aa3 --- /dev/null +++ b/engines/mutationofjb/commands/labelcommand.cpp @@ -0,0 +1,78 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "mutationofjb/commands/labelcommand.h" +#include "mutationofjb/commands/gotocommand.h" +#include "mutationofjb/game.h" +#include "mutationofjb/script.h" + +/* + <label> ":" + + Creates a label. +*/ + +namespace MutationOfJB { + +bool LabelCommandParser::parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) { + if (line.lastChar() != ':') { + return false; + } + + Common::String label = line; + label.deleteLastChar(); + + LabelCommand *labelCmd = new LabelCommand(label); + if (!parseCtx._labels.contains(line)) { + parseCtx._labels[line] = labelCmd; + } else { + warning("Label '%s' already exists", label.c_str()); + } + + if (parseCtx._pendingGotos.contains(label)) { + GotoCommands &gotos = parseCtx._pendingGotos[label]; + for (GotoCommands::const_iterator it = gotos.begin(); it != gotos.end(); ++it) { + (*it)->setLabelCommand(labelCmd); + } + gotos.clear(); + } + + command = labelCmd; + return true; +} + +const Common::String &LabelCommand::getName() const +{ + return _name; +} + +Command::ExecuteResult LabelCommand::execute(GameData &) { + // Intentionally empty. + + return Finished; +} + +Common::String LabelCommand::debugString() const { + return Common::String::format("LABEL %s", _name.c_str()); +} + +} diff --git a/engines/mutationofjb/commands/labelcommand.h b/engines/mutationofjb/commands/labelcommand.h new file mode 100644 index 0000000000..389c759946 --- /dev/null +++ b/engines/mutationofjb/commands/labelcommand.h @@ -0,0 +1,51 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef MUTATIONOFJB_LABELCOMMAND_H +#define MUTATIONOFJB_LABELCOMMAND_H + +#include "mutationofjb/commands/seqcommand.h" +#include "common/str.h" + +namespace MutationOfJB { + +class LabelCommandParser : public SeqCommandParser { +public: + LabelCommandParser() {} + + virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command); +}; + +class LabelCommand : public SeqCommand { +public: + LabelCommand(const Common::String &name) : _name(name) {} + const Common::String &getName() const; + + virtual ExecuteResult execute(GameData &gameData) override; + virtual Common::String debugString() const override; +private: + Common::String _name; +}; + +} + +#endif |