rewrite isTruthy

This commit is contained in:
2025-10-30 20:12:01 -05:00
parent 1630beb8c1
commit e7aeb991bc

View File

@@ -157,26 +157,16 @@ class HInterface {
var node:StoryNode = cast(v, StoryNode);
return viewCounts[node] > 0;
}
switch (Type.typeof(v)) {
case TBool:
if (Std.isOfType(v, Bool)) {
return v;
case TInt | TFloat:
} else if (Std.isOfType(v, Int) || Std.isOfType(v, Float)) {
return v > 0;
// 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
default:
if (Std.is(v, String)) {
var val = cast(v, String);
switch (val) {
case "true":
return true;
case "false":
} else if (Std.isOfType(v, String)) {
if (v == "false") return false;
else return v.length > 0;
}
throw '$v cannot be coerced to a boolean';
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';
}
}
public function addVariable(identifier:String, value:Dynamic) {