diff options
author | Alyssa Milburn | 2011-12-08 23:15:48 +0100 |
---|---|---|
committer | Alyssa Milburn | 2011-12-08 23:15:48 +0100 |
commit | ef224759888ae627743c64cb4a47fc6a30874189 (patch) | |
tree | b96b278559b0f032819c2860b4cf58700272004d | |
parent | 0d71aa7969dd1f235ff87b399b00d645ce63ccc5 (diff) | |
download | scummvm-rg350-ef224759888ae627743c64cb4a47fc6a30874189.tar.gz scummvm-rg350-ef224759888ae627743c64cb4a47fc6a30874189.tar.bz2 scummvm-rg350-ef224759888ae627743c64cb4a47fc6a30874189.zip |
MOHAWK: Implement LB getProperty/setProperty.
-rw-r--r-- | engines/mohawk/livingbooks.h | 3 | ||||
-rw-r--r-- | engines/mohawk/livingbooks_code.cpp | 43 | ||||
-rw-r--r-- | engines/mohawk/livingbooks_code.h | 2 |
3 files changed, 46 insertions, 2 deletions
diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h index 1ab6e4d89c..cde6357788 100644 --- a/engines/mohawk/livingbooks.h +++ b/engines/mohawk/livingbooks.h @@ -424,6 +424,9 @@ public: Common::List<LBItem *>::iterator _iterator; + // TODO: make private + Common::HashMap<Common::String, LBValue, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _variables; + protected: MohawkEngine_LivingBooks *_vm; LBPage *_page; diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp index 8e7c69b070..e821e7e54d 100644 --- a/engines/mohawk/livingbooks_code.cpp +++ b/engines/mohawk/livingbooks_code.cpp @@ -847,8 +847,8 @@ CodeCommandInfo generalCommandInfo[NUM_GENERAL_COMMANDS] = { { "deleteAt", &LBCode::cmdDeleteAt }, { "clearList", &LBCode::cmdUnimplemented }, { "setWorld", 0 }, - { "setProperty", 0 }, - { "getProperty", 0 }, + { "setProperty", &LBCode::cmdSetProperty }, + { "getProperty", &LBCode::cmdGetProperty }, { "copyList", 0 }, { "invoke", 0 }, { "exec", &LBCode::cmdExec }, @@ -1189,6 +1189,45 @@ void LBCode::cmdDeleteAt(const Common::Array<LBValue> ¶ms) { params[0].list->array.remove_at(params[1].integer - 1); } +void LBCode::cmdSetProperty(const Common::Array<LBValue> ¶ms) { + if (params.size() < 2 || params.size() > 3) + error("incorrect number of parameters (%d) to setProperty", params.size()); + + Common::String name; + LBValue val; + LBItem *target = _currSource; + if (params.size() == 3) { + target = resolveItem(params[0]); + if (!target) + error("attempted setProperty on invalid item (%s)", params[0].toString().c_str()); + name = params[1].toString(); + val = params[2]; + } else { + name = params[0].toString(); + val = params[1]; + } + + target->_variables[name] = val; +} + +void LBCode::cmdGetProperty(const Common::Array<LBValue> ¶ms) { + if (params.size() < 1 || params.size() > 2) + error("incorrect number of parameters (%d) to getProperty", params.size()); + + Common::String name; + LBItem *target = _currSource; + if (params.size() == 2) { + target = resolveItem(params[0]); + if (!target) + error("attempted getProperty on invalid item (%s)", params[0].toString().c_str()); + name = params[1].toString(); + } else { + name = params[0].toString(); + } + + _stack.push(target->_variables[name]); +} + void LBCode::cmdExec(const Common::Array<LBValue> ¶ms) { if (params.size() != 1) error("incorrect number of parameters (%d) to exec", params.size()); diff --git a/engines/mohawk/livingbooks_code.h b/engines/mohawk/livingbooks_code.h index 2cb1994492..a8d5e2d2dc 100644 --- a/engines/mohawk/livingbooks_code.h +++ b/engines/mohawk/livingbooks_code.h @@ -270,6 +270,8 @@ public: void cmdSetAt(const Common::Array<LBValue> ¶ms); void cmdListLen(const Common::Array<LBValue> ¶ms); void cmdDeleteAt(const Common::Array<LBValue> ¶ms); + void cmdSetProperty(const Common::Array<LBValue> ¶ms); + void cmdGetProperty(const Common::Array<LBValue> ¶ms); void cmdExec(const Common::Array<LBValue> ¶ms); void cmdReturn(const Common::Array<LBValue> ¶ms); void cmdSetPlayParams(const Common::Array<LBValue> ¶ms); |