Commit c11bcc1f authored by twanvl's avatar twanvl

dependencies of extra card fields are now also added and updated;

this fixes combined_editor in extra fields.
parent 2e9d52df
...@@ -20,6 +20,8 @@ DECLARE_TYPEOF_COLLECTION(Context::Binding); ...@@ -20,6 +20,8 @@ DECLARE_TYPEOF_COLLECTION(Context::Binding);
// ----------------------------------------------------------------------------- : Dummy values // ----------------------------------------------------------------------------- : Dummy values
extern ScriptValueP dependency_dummy;
// A dummy type used during dependency analysis, // A dummy type used during dependency analysis,
// it simply supresses all error messages. // it simply supresses all error messages.
class DependencyDummy : public ScriptIterator { class DependencyDummy : public ScriptIterator {
...@@ -27,6 +29,7 @@ class DependencyDummy : public ScriptIterator { ...@@ -27,6 +29,7 @@ class DependencyDummy : public ScriptIterator {
virtual ScriptType type() const { return SCRIPT_DUMMY; } virtual ScriptType type() const { return SCRIPT_DUMMY; }
virtual String typeName() const { return _("dummy"); } virtual String typeName() const { return _("dummy"); }
virtual ScriptValueP next() { return ScriptValueP(); } virtual ScriptValueP next() { return ScriptValueP(); }
virtual ScriptValueP dependencyName(const ScriptValue&, const Dependency&) const { return dependency_dummy; }
}; };
ScriptValueP dependency_dummy(new DependencyDummy); ScriptValueP dependency_dummy(new DependencyDummy);
...@@ -55,6 +58,9 @@ class DependencyUnion : public ScriptValue { ...@@ -55,6 +58,9 @@ class DependencyUnion : public ScriptValue {
virtual ScriptValueP dependencyMember(const String& name, const Dependency& dep) const { virtual ScriptValueP dependencyMember(const String& name, const Dependency& dep) const {
return unified(a->dependencyMember(name,dep), b->dependencyMember(name,dep)); return unified(a->dependencyMember(name,dep), b->dependencyMember(name,dep));
} }
virtual ScriptValueP dependencyName(const ScriptValue& container, const Dependency& dep) const {
return unified(a->dependencyName(container,dep), b->dependencyName(container,dep));
}
private: private:
ScriptValueP a, b; ScriptValueP a, b;
}; };
...@@ -297,8 +303,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script) ...@@ -297,8 +303,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
a = rangeIterator(0,0); // values don't matter a = rangeIterator(0,0); // values don't matter
break; break;
case I_MEMBER: { case I_MEMBER: {
String name = *b; a = b->dependencyName(*a, dep); // dependency on member
a = a->dependencyMember(name, dep); // dependency on member
break; break;
} case I_ADD: } case I_ADD:
unify(a, b); // may be function composition unify(a, b); // may be function composition
......
...@@ -102,6 +102,13 @@ SCRIPT_FUNCTION(to_int) { ...@@ -102,6 +102,13 @@ SCRIPT_FUNCTION(to_int) {
} else if (t == SCRIPT_COLOR) { } else if (t == SCRIPT_COLOR) {
AColor c = (AColor)*input; AColor c = (AColor)*input;
result = (c.Red() + c.Blue() + c.Green()) / 3; result = (c.Red() + c.Blue() + c.Green()) / 3;
} else if (t == SCRIPT_STRING) {
long l;
if (input->toString().ToLong(&l)) {
result = l;
} else {
return new_intrusive1<ScriptDelayedError>(_ERROR_3_("can't convert value", input->toString(), input->typeName(), _TYPE_("integer")));
}
} else { } else {
result = (int)*input; result = (int)*input;
} }
......
...@@ -12,9 +12,12 @@ ...@@ -12,9 +12,12 @@
#include <util/tagged_string.hpp> #include <util/tagged_string.hpp>
#include <data/set.hpp> #include <data/set.hpp>
#include <data/game.hpp> #include <data/game.hpp>
#include <data/card.hpp>
#include <data/stylesheet.hpp>
#include <data/field/text.hpp> #include <data/field/text.hpp>
#include <data/field/choice.hpp> #include <data/field/choice.hpp>
#include <data/field/multiple_choice.hpp> #include <data/field/multiple_choice.hpp>
#include <data/action/value.hpp>
DECLARE_TYPEOF_COLLECTION(FieldP); DECLARE_TYPEOF_COLLECTION(FieldP);
DECLARE_TYPEOF_COLLECTION(TextValue*); DECLARE_TYPEOF_COLLECTION(TextValue*);
...@@ -81,8 +84,16 @@ SCRIPT_FUNCTION_WITH_DEP(combined_editor) { ...@@ -81,8 +84,16 @@ SCRIPT_FUNCTION_WITH_DEP(combined_editor) {
FOR_EACH_2(v, values, nv, value_parts) { FOR_EACH_2(v, values, nv, value_parts) {
//if (v->value() != nv.first && v->last_update < new_value_update) { //if (v->value() != nv.first && v->last_update < new_value_update) {
if (v->last_update < new_value_update) { if (v->last_update < new_value_update) {
bool changed = v->value() != nv.first;
v->value.assign(nv.first); v->value.assign(nv.first);
v->update(ctx); changed |= v->update(ctx);
v->last_update = new_value_update;
if (changed) { // notify of change
SCRIPT_OPTIONAL_PARAM_(CardP, card);
SCRIPT_PARAM(Set*, set);
ScriptValueEvent change(card.get(), v);
set->actions.tellListeners(change, false);
}
} }
nv.first = v->value(); nv.first = v->value();
nv.second = index_to_untagged(nv.first, nv.first.size()) == 0; nv.second = index_to_untagged(nv.first, nv.first.size()) == 0;
...@@ -153,6 +164,10 @@ SCRIPT_FUNCTION_DEPENDENCIES(combined_editor) { ...@@ -153,6 +164,10 @@ SCRIPT_FUNCTION_DEPENDENCIES(combined_editor) {
FieldP target_field; FieldP target_field;
if (dep.type == DEP_CARD_FIELD) target_field = game->card_fields[dep.index]; if (dep.type == DEP_CARD_FIELD) target_field = game->card_fields[dep.index];
else if (dep.type == DEP_SET_FIELD) target_field = game->set_fields[dep.index]; else if (dep.type == DEP_SET_FIELD) target_field = game->set_fields[dep.index];
else if (dep.type == DEP_EXTRA_CARD_FIELD) {
SCRIPT_PARAM_C(StyleSheetP, stylesheet);
target_field = stylesheet->extra_card_fields[dep.index];
}
else throw InternalError(_("Finding dependencies of combined error for non card/set field")); else throw InternalError(_("Finding dependencies of combined error for non card/set field"));
// Add dependencies, from target_field on field# // Add dependencies, from target_field on field#
// For card fields // For card fields
......
...@@ -129,9 +129,9 @@ void SetScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) { ...@@ -129,9 +129,9 @@ void SetScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) {
if (stylesheet.dependencies_initialized) return; if (stylesheet.dependencies_initialized) return;
stylesheet.dependencies_initialized = true; stylesheet.dependencies_initialized = true;
// find dependencies of extra card fields // find dependencies of extra card fields
/*FOR_EACH(f, stylesheet.extra_card_fields) { FOR_EACH(f, stylesheet.extra_card_fields) {
f->initDependencies(ctx, Dependency(DEP_EXTRA_CARD_FIELD, f->index, &stylesheet)); f->initDependencies(ctx, Dependency(DEP_EXTRA_CARD_FIELD, f->index, &stylesheet));
}*/ }
// find dependencies of choice images and other style stuff // find dependencies of choice images and other style stuff
FOR_EACH(s, stylesheet.card_style) { FOR_EACH(s, stylesheet.card_style) {
s->initDependencies(ctx, Dependency(DEP_STYLE, s->fieldP->index, &stylesheet)); s->initDependencies(ctx, Dependency(DEP_STYLE, s->fieldP->index, &stylesheet));
...@@ -229,7 +229,11 @@ void SetScriptManager::updateStyles(const CardP& card, bool only_content_depende ...@@ -229,7 +229,11 @@ void SetScriptManager::updateStyles(const CardP& card, bool only_content_depende
// update extra card fields // update extra card fields
IndexMap<FieldP,ValueP>& extra_data = card->extraDataFor(stylesheet); IndexMap<FieldP,ValueP>& extra_data = card->extraDataFor(stylesheet);
FOR_EACH(v, extra_data) { FOR_EACH(v, extra_data) {
v->update(ctx); if (v->update(ctx)) {
// changed, send event
ScriptValueEvent change(card.get(), v.get());
set.actions.tellListeners(change, false);
}
} }
} }
// update all styles // update all styles
...@@ -379,8 +383,8 @@ void SetScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Depen ...@@ -379,8 +383,8 @@ void SetScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Depen
ScriptStyleEvent change(stylesheet, style.get()); ScriptStyleEvent change(stylesheet, style.get());
set.actions.tellListeners(change, false); set.actions.tellListeners(change, false);
break; break;
/*} case DEP_EXTRA_CARD_FIELD: { } case DEP_EXTRA_CARD_FIELD: {
// Not needed, extra card fields are handled in updateStyles() /* // Not needed, extra card fields are handled in updateStyles()
if (card) { if (card) {
StyleSheet* stylesheet = reinterpret_cast<StyleSheet*>(d.data); StyleSheet* stylesheet = reinterpret_cast<StyleSheet*>(d.data);
StyleSheet* stylesheet_card = &set.stylesheetFor(card); StyleSheet* stylesheet_card = &set.stylesheetFor(card);
...@@ -388,8 +392,8 @@ void SetScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Depen ...@@ -388,8 +392,8 @@ void SetScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Depen
ValueP value = card->extra_data.at(d.index); ValueP value = card->extra_data.at(d.index);
to_update.push_back(ToUpdate(value.get(), card)); to_update.push_back(ToUpdate(value.get(), card));
} }
} }*/
break;*/ break;
} case DEP_CARD_COPY_DEP: { } case DEP_CARD_COPY_DEP: {
// propagate dependencies from another field // propagate dependencies from another field
FieldP f = set.game->card_fields[d.index]; FieldP f = set.game->card_fields[d.index];
......
...@@ -48,6 +48,9 @@ ScriptValueP ScriptValue::getIndex(int index) const { ...@@ -48,6 +48,9 @@ ScriptValueP ScriptValue::getIndex(int index) const {
ScriptValueP ScriptValue::simplifyClosure(ScriptClosure&) const { return ScriptValueP(); } ScriptValueP ScriptValue::simplifyClosure(ScriptClosure&) const { return ScriptValueP(); }
ScriptValueP ScriptValue::dependencyMember(const String& name, const Dependency&) const { return dependency_dummy; } ScriptValueP ScriptValue::dependencyMember(const String& name, const Dependency&) const { return dependency_dummy; }
ScriptValueP ScriptValue::dependencyName(const ScriptValue& container, const Dependency& dep) const {
return container.dependencyMember(toString(),dep);
}
ScriptValueP ScriptValue::dependencies(Context&, const Dependency&) const { return dependency_dummy; } ScriptValueP ScriptValue::dependencies(Context&, const Dependency&) const { return dependency_dummy; }
bool approx_equal(double a, double b) { bool approx_equal(double a, double b) {
......
...@@ -80,6 +80,9 @@ class ScriptValue : public IntrusivePtrBaseWithDelete { ...@@ -80,6 +80,9 @@ class ScriptValue : public IntrusivePtrBaseWithDelete {
/// Signal that a script depends on a member of this value /// Signal that a script depends on a member of this value
/** It is the abstract version of getMember*/ /** It is the abstract version of getMember*/
virtual ScriptValueP dependencyMember(const String& name, const Dependency&) const; virtual ScriptValueP dependencyMember(const String& name, const Dependency&) const;
/// Signal that a script depends on a member of container, with the name of this
/** This function allows for a kind of visitor pattern over dependencyMember */
virtual ScriptValueP dependencyName(const ScriptValue& container, const Dependency&) const;
/// Evaluate this value (if it is a function) /// Evaluate this value (if it is a function)
virtual ScriptValueP eval(Context&) const; virtual ScriptValueP eval(Context&) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment