Permalink
Browse files

MUTATIONOFJB: Implement SETCOL command.

  • Loading branch information...
LubomirR committed Jul 21, 2018
1 parent 46bb90e commit 728905563c26cf6a1ff154af834133b053b90444
@@ -0,0 +1,60 @@
/* 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/setcolorcommand.h"

#include "mutationofjb/game.h"
#include "mutationofjb/gamedata.h"
#include "mutationofjb/script.h"

#include "common/str.h"

/** @file
* "SETCOL " <colorString>
*
* Sets subtitle color used by SayCommand.
*/

namespace MutationOfJB {

bool SetColorCommandParser::parse(const Common::String &line, ScriptParseContext &, Command *&command) {
if (line.size() < 8 || !line.hasPrefix("SETCOL")) {
return false;
}

const char *const colorStr = line.c_str() + 7;
const uint8 color = Game::colorFromString(colorStr);

command = new SetColorCommand(color);
return true;
}

Command::ExecuteResult SetColorCommand::execute(ScriptExecutionContext &scriptExecCtx) {
scriptExecCtx.getGameData()._color = _color;
return Finished;
}

Common::String SetColorCommand::debugString() const {
return Common::String::format("SETCOL %u", _color);
}

}
@@ -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_SETCOLORCOMMAND_H
#define MUTATIONOFJB_SETCOLORCOMMAND_H

#include "mutationofjb/commands/seqcommand.h"

#include "common/scummsys.h"

namespace MutationOfJB {

class SetColorCommandParser : public SeqCommandParser {
public:
virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) override;
};


class SetColorCommand : public SeqCommand {
public:
SetColorCommand(uint8 color) : _color(color) {}

virtual Command::ExecuteResult execute(ScriptExecutionContext &scriptExecCtx) override;
virtual Common::String debugString() const override;

private:
uint8 _color;
};

}

#endif
@@ -228,6 +228,10 @@ uint8 Game::colorFromString(const char *colorStr) {
}
}

if (*colorStr == 'n') {
return static_cast<uint8>(atoi(colorStr + 1));
}

warning(_("Color not found"));
return 0x00;
}
@@ -20,6 +20,7 @@ MODULE_OBJS := \
commands/renamecommand.o \
commands/saycommand.o \
commands/seqcommand.o \
commands/setcolorcommand.o \
commands/talkcommand.o \
commands/randomcommand.o \
tasks/conversationtask.o \
@@ -46,6 +46,7 @@
#include "mutationofjb/commands/definestructcommand.h"
#include "mutationofjb/commands/talkcommand.h"
#include "mutationofjb/commands/randomcommand.h"
#include "mutationofjb/commands/setcolorcommand.h"
#include "mutationofjb/game.h"

namespace MutationOfJB {
@@ -74,6 +75,7 @@ static CommandParser **getParsers() {
new LabelCommandParser,
new RandomCommandParser,
new RandomBlockStartParser,
new SetColorCommandParser,
nullptr
};

0 comments on commit 7289055

Please sign in to comment.