mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Use toSomeType() instead of operator SomeType in ScriptValue.
This means that we are more explicit about type conversions. Also use override specifiers for overriden virtual functions in ScriptValue.
This commit is contained in:
+11
-10
@@ -665,7 +665,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
|
||||
ctx.setVariable(_("used_placeholders"), to_script(used_placeholders));
|
||||
|
||||
// Final check whether the keyword matches
|
||||
if (match_condition && (bool)*match_condition->eval(ctx) == false) {
|
||||
if (match_condition && match_condition->eval(ctx)->toBool() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -673,7 +673,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
|
||||
bool expand = expand_type == _('1');
|
||||
if (!expand && expand_type != _('0')) {
|
||||
// default expand, determined by script
|
||||
expand = expand_default ? (bool)*expand_default->eval(ctx) : true;
|
||||
expand = expand_default ? expand_default->eval(ctx)->toBool() : true;
|
||||
expand_type = expand ? _('A') : _('a');
|
||||
}
|
||||
|
||||
@@ -711,7 +711,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
|
||||
ScriptType KeywordParamValue::type() const { return SCRIPT_STRING; }
|
||||
String KeywordParamValue::typeName() const { return _("keyword parameter"); }
|
||||
|
||||
KeywordParamValue::operator String() const {
|
||||
String KeywordParamValue::toString() const {
|
||||
String safe_type = replace_all(replace_all(replace_all(type_name,
|
||||
_("("),_("-")),
|
||||
_(")"),_("-")),
|
||||
@@ -719,16 +719,17 @@ KeywordParamValue::operator String() const {
|
||||
return _("<param-") + safe_type + _(">") + value + _("</param-") + safe_type + _(">");
|
||||
}
|
||||
|
||||
KeywordParamValue::operator int() const { return *to_script(value); } // a bit of a hack
|
||||
KeywordParamValue::operator double() const { return *to_script(value); }
|
||||
KeywordParamValue::operator bool() const { return *to_script(value); }
|
||||
KeywordParamValue::operator Color() const { return *to_script(value); }
|
||||
int KeywordParamValue::itemCount() const { return to_script(value)->itemCount(); }
|
||||
// a bit of a hack: use the ScriptString implementation
|
||||
int KeywordParamValue::toInt() const { return to_script(value)->toInt(); }
|
||||
double KeywordParamValue::toDouble() const { return to_script(value)->toDouble(); }
|
||||
bool KeywordParamValue::toBool() const { return to_script(value)->toBool(); }
|
||||
Color KeywordParamValue::toColor() const { return to_script(value)->toColor(); }
|
||||
int KeywordParamValue::itemCount() const { return to_script(value)->itemCount(); }
|
||||
|
||||
ScriptValueP KeywordParamValue::getMember(const String& name) const {
|
||||
if (name == _("type")) return to_script(type_name);
|
||||
if (name == _("separator before")) return to_script(separator_before);
|
||||
if (name == _("separator after")) return to_script(separator_after);
|
||||
if (name == _("separator_before")) return to_script(separator_before);
|
||||
if (name == _("separator_after")) return to_script(separator_after);
|
||||
if (name == _("value")) return to_script(value);
|
||||
if (name == _("param")) return to_script(value);
|
||||
return ScriptValue::getMember(name);
|
||||
|
||||
@@ -190,14 +190,14 @@ class KeywordParamValue : public ScriptValue {
|
||||
String separator_before, separator_after;
|
||||
String value;
|
||||
|
||||
virtual ScriptType type() const;
|
||||
virtual String typeName() const;
|
||||
virtual operator String() const;
|
||||
virtual operator int() const;
|
||||
virtual operator bool() const;
|
||||
virtual operator double() const;
|
||||
virtual operator Color() const;
|
||||
virtual int itemCount() const;
|
||||
virtual ScriptValueP getMember(const String& name) const;
|
||||
ScriptType type() const override;
|
||||
String typeName() const override;
|
||||
String toString() const override;
|
||||
int toInt() const override;
|
||||
bool toBool() const override;
|
||||
double toDouble() const override;
|
||||
Color toColor() const override;
|
||||
int itemCount() const override;
|
||||
ScriptValueP getMember(const String& name) const override;
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ PackInstance::PackInstance(const PackType& pack_type, PackGenerator& parent)
|
||||
if (pack_type.filter) {
|
||||
FOR_EACH(card, parent.set->cards) {
|
||||
Context& ctx = parent.set->getContext(card);
|
||||
bool keep = *pack_type.filter.invoke(ctx);
|
||||
bool keep = pack_type.filter.invoke(ctx)->toBool();
|
||||
if (keep) {
|
||||
cards.push_back(card);
|
||||
}
|
||||
|
||||
+3
-3
@@ -267,9 +267,9 @@ int Set::positionOfCard(const CardP& card, const ScriptValueP& order_by, const S
|
||||
vector<int> keep; if(filter) keep.reserve(cards.size());
|
||||
FOR_EACH_CONST(c, cards) {
|
||||
Context& ctx = getContext(c);
|
||||
values.push_back(*order_by->eval(ctx));
|
||||
values.push_back(order_by->eval(ctx)->toString());
|
||||
if (filter) {
|
||||
keep.push_back((bool)*filter->eval(ctx));
|
||||
keep.push_back(filter->eval(ctx)->toBool());
|
||||
}
|
||||
}
|
||||
#if USE_SCRIPT_PROFILING
|
||||
@@ -289,7 +289,7 @@ int Set::numberOfCards(const ScriptValueP& filter) {
|
||||
} else {
|
||||
int n = 0;
|
||||
FOR_EACH_CONST(c, cards) {
|
||||
if (*filter->eval(getContext(c))) ++n;
|
||||
if (filter->eval(getContext(c))->toBool()) ++n;
|
||||
}
|
||||
filter_cache.insert(make_pair(filter,n));
|
||||
return n;
|
||||
|
||||
Reference in New Issue
Block a user