aboutsummaryrefslogtreecommitdiff
path: root/engines/mutationofjb/commands/labelcommand.cpp
diff options
context:
space:
mode:
authorĽubomír Remák2018-03-18 15:28:46 +0100
committerEugene Sandulenko2018-08-25 23:12:01 +0200
commit54c2c0aee6e371f8058c50e0a4113f5b5492169e (patch)
treeae551cedc20fa03f179340aae9f7497193c80b6e /engines/mutationofjb/commands/labelcommand.cpp
parent523f973e0a4ba16b278d546da9267a693924f957 (diff)
downloadscummvm-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/labelcommand.cpp')
-rw-r--r--engines/mutationofjb/commands/labelcommand.cpp78
1 files changed, 78 insertions, 0 deletions
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());
+}
+
+}