From 71d9f62a3afdd20b6191c72932f57f1677d75757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Mon, 3 Aug 2015 20:59:05 +0300 Subject: [PATCH] Scripting|libcore: Further variants of ScriptedInfo::isTrue/isFalse Easier to use in the case the variable may be missing completely. --- .../include/de/scriptsys/scriptedinfo.h | 8 ++++++- .../libcore/src/scriptsys/scriptedinfo.cpp | 24 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/doomsday/sdk/libcore/include/de/scriptsys/scriptedinfo.h b/doomsday/sdk/libcore/include/de/scriptsys/scriptedinfo.h index 654c58581a..07c0e844c4 100644 --- a/doomsday/sdk/libcore/include/de/scriptsys/scriptedinfo.h +++ b/doomsday/sdk/libcore/include/de/scriptsys/scriptedinfo.h @@ -13,7 +13,7 @@ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * General Public License for more details. You should have received a copy of * the GNU Lesser General Public License along with this program; if not, see: - * http://www.gnu.org/licenses + * http://www.gnu.org/licenses */ #ifndef LIBDENG2_SCRIPTEDINFO_H @@ -197,8 +197,14 @@ class DENG2_PUBLIC ScriptedInfo */ static bool isFalse(Value const &value); + static bool isFalse(RecordAccessor const &rec, String const &name, + bool defaultValue = true /* assume false if missing */); + static bool isTrue(Value const &value); + static bool isTrue(RecordAccessor const &rec, String const &name, + bool defaultValue = false /* assume false if missing */); + public: static Paths allBlocksOfType(String const &blockType, Record const &root); diff --git a/doomsday/sdk/libcore/src/scriptsys/scriptedinfo.cpp b/doomsday/sdk/libcore/src/scriptsys/scriptedinfo.cpp index 2e47f0c2fb..fea427e28e 100644 --- a/doomsday/sdk/libcore/src/scriptsys/scriptedinfo.cpp +++ b/doomsday/sdk/libcore/src/scriptsys/scriptedinfo.cpp @@ -13,7 +13,7 @@ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * General Public License for more details. You should have received a copy of * the GNU Lesser General Public License along with this program; if not, see: - * http://www.gnu.org/licenses + * http://www.gnu.org/licenses */ #include "de/ScriptedInfo" @@ -127,7 +127,7 @@ DENG2_PIMPL(ScriptedInfo) String varName = variableName(block); if(!varName.isEmpty()) { - Record &ns = process.globals(); + Record &ns = process.globals(); String targetName = checkNamespaceForVariable(target); if(!ns.has(targetName)) { @@ -288,7 +288,7 @@ DENG2_PIMPL(ScriptedInfo) else varName = b->name().concatenateMember(varName); } - } + } return checkNamespaceForVariable(varName); } @@ -476,6 +476,24 @@ bool ScriptedInfo::isTrue(Value const &value) // static return value.isTrue(); } +bool ScriptedInfo::isTrue(RecordAccessor const &rec, String const &name, bool defaultValue) +{ + if(rec.has(name)) + { + return isTrue(rec.get(name)); + } + return defaultValue; +} + +bool ScriptedInfo::isFalse(RecordAccessor const &rec, String const &name, bool defaultValue) +{ + if(rec.has(name)) + { + return isFalse(rec.get(name)); + } + return defaultValue; +} + bool ScriptedInfo::isFalse(Value const &value) // static { if(TextValue const *textValue = value.maybeAs())