diff --git a/src/data/action/value.cpp b/src/data/action/value.cpp index 6c638de9..0dac795f 100644 --- a/src/data/action/value.cpp +++ b/src/data/action/value.cpp @@ -69,7 +69,7 @@ String TextValueAction::getName(bool to_undo) const { return name; } void TextValueAction::perform(bool to_undo) { swap(value().value, new_value); -// if (value().value.age < new_value.age) value().value.age = Age(); + value().last_update.update(); swap(selection_end, new_selection_end); } diff --git a/src/data/card.cpp b/src/data/card.cpp index c89a2396..235d2770 100644 --- a/src/data/card.cpp +++ b/src/data/card.cpp @@ -48,7 +48,7 @@ void mark_dependency_member(const CardP& card, const String& name, const Depende // Find field with that name IndexMap::const_iterator it = card->data.find(name); if (it != card->data.end()) { - (*it)->fieldP->dependent_scripts.push_back(dep); + (*it)->fieldP->dependent_scripts.add(dep); } } diff --git a/src/data/field.hpp b/src/data/field.hpp index b5a95b57..35522205 100644 --- a/src/data/field.hpp +++ b/src/data/field.hpp @@ -50,7 +50,7 @@ class Field { String card_list_name; ///< Alternate name to use in card list. Alignment card_list_align; ///< Alignment of the card list colummn. int tab_index; ///< Tab index in editor - vector dependent_scripts; ///< Scripts that depend on values of this field + Dependencies dependent_scripts; ///< Scripts that depend on values of this field /// Creates a new Value corresponding to this Field /** thisP is a smart pointer to this */ diff --git a/src/data/field/text.cpp b/src/data/field/text.cpp index 743fdb8d..14def149 100644 --- a/src/data/field/text.cpp +++ b/src/data/field/text.cpp @@ -95,8 +95,11 @@ String TextValue::toString() const { } bool TextValue::update(Context& ctx) { Value::update(ctx); - return field().default_script.invokeOnDefault(ctx, value) - | field(). script.invokeOn(ctx, value); + WITH_DYNAMIC_ARG(last_update_age, last_update.get()); + bool change = field().default_script.invokeOnDefault(ctx, value) + | field(). script.invokeOn(ctx, value); + if (change) last_update.update(); + return change; } IMPLEMENT_REFLECTION_NAMELESS(TextValue) { diff --git a/src/data/field/text.hpp b/src/data/field/text.hpp index 52a069d0..49047bbe 100644 --- a/src/data/field/text.hpp +++ b/src/data/field/text.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,7 @@ class TextValue : public Value { typedef Defaultable ValueType; ValueType value; ///< The text of this value + Age last_update; ///< When was the text last changed? virtual String toString() const; virtual bool update(Context&); diff --git a/src/data/game.hpp b/src/data/game.hpp index 37330306..9c058ff6 100644 --- a/src/data/game.hpp +++ b/src/data/game.hpp @@ -45,9 +45,9 @@ class Game : public Packaged { vector keyword_modes; ///< Modes of keywords vector keywords; ///< Keywords for use in text - vector dependent_scripts_cards; ///< scripts that depend on the card list - vector dependent_scripts_keywords; ///< scripts that depend on the keywords - bool dependencies_initialized; ///< are the script dependencies comming from this game all initialized? + Dependencies dependent_scripts_cards; ///< scripts that depend on the card list + Dependencies dependent_scripts_keywords; ///< scripts that depend on the keywords + bool dependencies_initialized; ///< are the script dependencies comming from this game all initialized? /// Loads the game with a particular name, for example "magic" static GameP byName(const String& name); diff --git a/src/data/set.cpp b/src/data/set.cpp index 6997faab..ae2498eb 100644 --- a/src/data/set.cpp +++ b/src/data/set.cpp @@ -135,18 +135,18 @@ ScriptValueP make_iterator(const Set& set) { void mark_dependency_member(Set* value, const String& name, const Dependency& dep) { // is it the card list? if (name == _("cards")) { - value->game->dependent_scripts_cards.push_back(dep); + value->game->dependent_scripts_cards.add(dep); return; } // is it the keywords? if (name == _("keywords")) { - value->game->dependent_scripts_keywords.push_back(dep); + value->game->dependent_scripts_keywords.add(dep); return; } // is it in the set data? IndexMap::const_iterator it = value->data.find(name); if (it != value->data.end()) { - (*it)->fieldP->dependent_scripts.push_back(dep); + (*it)->fieldP->dependent_scripts.add(dep); } } void mark_dependency_member(const SetP& value, const String& name, const Dependency& dep) { diff --git a/src/gui/value/text.cpp b/src/gui/value/text.cpp index e72bc355..35a5a049 100644 --- a/src/gui/value/text.cpp +++ b/src/gui/value/text.cpp @@ -261,7 +261,7 @@ void TextValueEditor::onValueChange() { selection_start_i = selection_end_i = 0; } -void TextValueEditor::onAction(const ValueAction& action, bool undone) { +void TextValueEditor::onAction(const Action& action, bool undone) { TextValueViewer::onAction(action, undone); TYPE_CASE(action, TextValueAction) { selection_start_i = action.selection_start; diff --git a/src/gui/value/text.hpp b/src/gui/value/text.hpp index 55a7558a..7e29ee21 100644 --- a/src/gui/value/text.hpp +++ b/src/gui/value/text.hpp @@ -51,7 +51,7 @@ class TextValueEditor : public TextValueViewer, public ValueEditor { // --------------------------------------------------- : Actions virtual void onValueChange(); - virtual void onAction(const ValueAction&, bool undone); + virtual void onAction(const Action&, bool undone); // --------------------------------------------------- : Clipboard diff --git a/src/render/card/viewer.cpp b/src/render/card/viewer.cpp index 5de39658..f8cc0d28 100644 --- a/src/render/card/viewer.cpp +++ b/src/render/card/viewer.cpp @@ -134,4 +134,16 @@ void DataViewer::onAction(const Action& action, bool undone) { } } } + TYPE_CASE(action, ScriptValueEvent) { + if (action.card == card.get()) { + FOR_EACH(v, viewers) { + if (v->getValue().get() == action.value) { + // refresh the viewer + v->onAction(action, undone); + onChange(); + return; + } + } + } + } } diff --git a/src/render/value/viewer.hpp b/src/render/value/viewer.hpp index 0e038f76..a418389d 100644 --- a/src/render/value/viewer.hpp +++ b/src/render/value/viewer.hpp @@ -16,7 +16,7 @@ class Set; class DataViewer; -class ValueAction; +class Action; DECLARE_POINTER_TYPE(Style); DECLARE_POINTER_TYPE(Value); @@ -55,7 +55,7 @@ class ValueViewer { /// Called when a (scripted) property of the associated style has changed virtual void onStyleChange() {} /// Called when an action is performed on the associated value - virtual void onAction(const ValueAction&, bool undone) { onValueChange(); } + virtual void onAction(const Action&, bool undone) { onValueChange(); } /// Convert this viewer to an editor, if possible virtual ValueEditor* getEditor() { return 0; } diff --git a/src/script/context.cpp b/src/script/context.cpp index 56fdcd5d..0c39309b 100644 --- a/src/script/context.cpp +++ b/src/script/context.cpp @@ -168,7 +168,7 @@ void Context::setVariable(const String& name, const ScriptValueP& value) { void Context::setVariable(int name, const ScriptValueP& value) { Variable& var = variables[name]; - if (var.value && var.level < level) { + if (var.level < level) { // keep shadow copy Binding bind = {name, var}; shadowed.push_back(bind); diff --git a/src/script/context.hpp b/src/script/context.hpp index 159a48c2..d3227b30 100644 --- a/src/script/context.hpp +++ b/src/script/context.hpp @@ -60,6 +60,7 @@ class Context { public:// public for FOR_EACH /// Record of a variable struct Variable { + Variable() : level(0) {} unsigned int level; ///< Scope level on which this variable was set ScriptValueP value; ///< Value of this variable }; diff --git a/src/script/dependency.hpp b/src/script/dependency.hpp index 79ce6ef6..9aa935c6 100644 --- a/src/script/dependency.hpp +++ b/src/script/dependency.hpp @@ -38,6 +38,25 @@ class Dependency { inline Dependency makeCardIndependend() const { return Dependency(type == DEP_CARD_FIELD ? DEP_CARDS_FIELD : type, index, data); } + + inline bool operator == (const Dependency& d) const { + return type == d.type && index == d.index && data == d.data; + } +}; + +// ----------------------------------------------------------------------------- : Dependencies + +/// A list of dependencies +class Dependencies : public vector { + public: + /// Add a dependency, prevents duplicates + inline void add(const Dependency& d) { + if (find(begin(),end(),d) == end()) { + push_back(d); + } + } + private: + using vector::push_back; }; // ----------------------------------------------------------------------------- : EOF diff --git a/src/script/functions.cpp b/src/script/functions.cpp index 029dfa89..10c4f859 100644 --- a/src/script/functions.cpp +++ b/src/script/functions.cpp @@ -11,9 +11,14 @@ #include