WAGE: Handle NULL value Operands

This commit is contained in:
Eugene Sandulenko 2015-12-23 11:08:04 +01:00
parent 60ce5fa557
commit a2ac4ea859
2 changed files with 31 additions and 11 deletions

View File

@ -88,7 +88,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
{
Operand *op = readOperand();
// TODO check op type is string or number, or something good...
appendText(op->_str);
appendText(op->toString());
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
@ -99,7 +99,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
Operand *op = readOperand();
// TODO check op type is string.
_handled = true;
callbacks->playSound(op->_str);
callbacks->playSound(op->toString());
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
@ -112,7 +112,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
{
Operand *op = readStringOperand(); // allows empty menu
// TODO check op type is string.
_callbacks->setMenu(op->_str);
_callbacks->setMenu(op->toString());
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
@ -196,7 +196,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
Script::Operand *Script::readOperand() {
byte operandType = _data->readByte();
debug(2, "readOperand: 0x%x", operandType);
debug(2, "%x: readOperand: 0x%x", _data->pos(), operandType);
Context *cont = &_world->_player->_context;
switch (operandType) {

View File

@ -87,43 +87,63 @@ private:
Designed *inputClick;
} _value;
OperandTypes _type;
String _str;
Common::String _str;
Operand(Obj *value, OperandTypes type) {
_value.obj = value;
_str = value->toString();
_type = type;
}
Operand(Chr *value, OperandTypes type) {
_value.chr = value;
_str = value->toString();
_type = type;
}
Operand(Scene *value, OperandTypes type) {
_value.scene = value;
_str = value->toString();
_type = type;
}
Operand(int value, OperandTypes type) {
_value.number = value;
_str = value;
_type = type;
}
Operand(String *value, OperandTypes type) {
_value.string = value;
_str = *value;
_type = type;
}
Operand(Designed *value, OperandTypes type) {
_value.inputClick = value;
_str = value->toString();
_type = type;
}
Common::String toString() {
char buf[128];
if (_value.obj == NULL)
_str = "";
switch(_type) {
case NUMBER:
_str = snprintf(buf, 128, "%d", _value.number);
return _str;
case STRING:
case TEXT_INPUT:
return *_value.string;
case OBJ:
return _value.obj->toString();
case CHR:
return _value.chr->toString();
case SCENE:
return _value.scene->toString();
case CLICK_INPUT:
return _value.inputClick->toString();
default:
error("Unhandled operand type: _type");
}
}
};
public: