Skip to content

Commit

Permalink
Scripting|libcore: Further variants of ScriptedInfo::isTrue/isFalse
Browse files Browse the repository at this point in the history
Easier to use in the case the variable may be missing completely.
  • Loading branch information
skyjake committed Aug 3, 2015
1 parent 6b79485 commit 71d9f62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion doomsday/sdk/libcore/include/de/scriptsys/scriptedinfo.h
Expand Up @@ -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</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDENG2_SCRIPTEDINFO_H
Expand Down Expand Up @@ -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);

Expand Down
24 changes: 21 additions & 3 deletions doomsday/sdk/libcore/src/scriptsys/scriptedinfo.cpp
Expand Up @@ -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</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/ScriptedInfo"
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -288,7 +288,7 @@ DENG2_PIMPL(ScriptedInfo)
else
varName = b->name().concatenateMember(varName);
}
}
}
return checkNamespaceForVariable(varName);
}

Expand Down Expand Up @@ -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<TextValue>())
Expand Down

0 comments on commit 71d9f62

Please sign in to comment.