rewrite isTruthy
This commit is contained in:
@@ -157,26 +157,16 @@ class HInterface {
|
|||||||
var node:StoryNode = cast(v, StoryNode);
|
var node:StoryNode = cast(v, StoryNode);
|
||||||
return viewCounts[node] > 0;
|
return viewCounts[node] > 0;
|
||||||
}
|
}
|
||||||
switch (Type.typeof(v)) {
|
if (Std.isOfType(v, Bool)) {
|
||||||
case TBool:
|
return v;
|
||||||
return v;
|
} else if (Std.isOfType(v, Int) || Std.isOfType(v, Float)) {
|
||||||
case TInt | TFloat:
|
return v > 0;
|
||||||
return v > 0;
|
} else if (Std.isOfType(v, String)) {
|
||||||
// TODO I would love to do away with this hack, but C++ type coercion turns random things into strings. This workaround fixes a specific bug
|
if (v == "false") return false;
|
||||||
default:
|
else return v.length > 0;
|
||||||
if (Std.is(v, String)) {
|
|
||||||
var val = cast(v, String);
|
|
||||||
switch (val) {
|
|
||||||
case "true":
|
|
||||||
return true;
|
|
||||||
case "false":
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
throw '$v: ${Type.typeof(v)} cannot be coerced to a boolean';
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
throw '$v: ${Type.typeof(v)} cannot be coerced to a boolean';
|
|
||||||
}
|
}
|
||||||
|
throw '$v cannot be coerced to a boolean';
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addVariable(identifier:String, value:Dynamic) {
|
public function addVariable(identifier:String, value:Dynamic) {
|
||||||
|
|||||||
Reference in New Issue
Block a user