mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-13 14:07:01 -04:00
Dependencies on stylesheet are marked, and updated when the stylesheet changes
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1087 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -58,6 +58,7 @@ class Game : public Packaged {
|
|||||||
|
|
||||||
Dependencies dependent_scripts_cards; ///< scripts that depend on the card list
|
Dependencies dependent_scripts_cards; ///< scripts that depend on the card list
|
||||||
Dependencies dependent_scripts_keywords; ///< scripts that depend on the keywords
|
Dependencies dependent_scripts_keywords; ///< scripts that depend on the keywords
|
||||||
|
Dependencies dependent_scripts_stylesheet; ///< scripts that depend on the card's stylesheet
|
||||||
bool dependencies_initialized; ///< are the script dependencies comming from this game all initialized?
|
bool dependencies_initialized; ///< are the script dependencies comming from this game all initialized?
|
||||||
|
|
||||||
/// Loads the game with a particular name, for example "magic"
|
/// Loads the game with a particular name, for example "magic"
|
||||||
|
|||||||
@@ -88,6 +88,11 @@ StyleP StyleSheet::styleFor(const FieldP& field) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mark_dependency_value(const StyleSheet& stylesheet, const Dependency& dep) {
|
||||||
|
stylesheet.game->dependent_scripts_stylesheet.add(dep);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
IMPLEMENT_REFLECTION(StyleSheet) {
|
IMPLEMENT_REFLECTION(StyleSheet) {
|
||||||
// < 0.3.0 didn't use card_ prefix
|
// < 0.3.0 didn't use card_ prefix
|
||||||
REFLECT_ALIAS(300, "width", "card width");
|
REFLECT_ALIAS(300, "width", "card width");
|
||||||
|
|||||||
@@ -77,5 +77,7 @@ inline String type_name(const StyleSheet&) {
|
|||||||
return _TYPE_("stylesheet");
|
return _TYPE_("stylesheet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mark_dependency_value(const StyleSheet& value, const Dependency& dep);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : EOF
|
// ----------------------------------------------------------------------------- : EOF
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -269,6 +269,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
|
|||||||
if (!value) {
|
if (!value) {
|
||||||
value = new_intrusive1<ScriptMissingVariable>(variable_to_string((Variable)i.data)); // no errors here
|
value = new_intrusive1<ScriptMissingVariable>(variable_to_string((Variable)i.data)); // no errors here
|
||||||
}
|
}
|
||||||
|
value->dependencyThis(dep);
|
||||||
stack.push_back(value);
|
stack.push_back(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ enum DependencyType
|
|||||||
{ DEP_CARD_FIELD ///< dependency of a script in a "card" field
|
{ DEP_CARD_FIELD ///< dependency of a script in a "card" field
|
||||||
, DEP_CARDS_FIELD ///< dependency of a script in a "card" field for all cards
|
, DEP_CARDS_FIELD ///< dependency of a script in a "card" field for all cards
|
||||||
, DEP_SET_FIELD ///< dependency of a script in a "set" field
|
, DEP_SET_FIELD ///< dependency of a script in a "set" field
|
||||||
, DEP_STYLE ///< dependency of a script in a "style" property, data gives the stylesheet
|
, DEP_CARD_STYLE ///< dependency of a script in a "style" property, data gives the stylesheet
|
||||||
, DEP_EXTRA_CARD_FIELD ///< dependency of a script in an extra stylesheet specific card field
|
, DEP_EXTRA_CARD_FIELD ///< dependency of a script in an extra stylesheet specific card field
|
||||||
, DEP_CARD_COPY_DEP ///< copy the dependencies from a card field
|
, DEP_CARD_COPY_DEP ///< copy the dependencies from a card field
|
||||||
, DEP_SET_COPY_DEP ///< copy the dependencies from a set field
|
, DEP_SET_COPY_DEP ///< copy the dependencies from a set field
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ void SetScriptManager::initDependencies(Context& ctx, StyleSheet& 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_CARD_STYLE, s->fieldP->index, &stylesheet));
|
||||||
// are there dependencies of this style on other style properties?
|
// are there dependencies of this style on other style properties?
|
||||||
Dependency test(DEP_DUMMY, false);
|
Dependency test(DEP_DUMMY, false);
|
||||||
s->checkContentDependencies(ctx, test);
|
s->checkContentDependencies(ctx, test);
|
||||||
@@ -219,6 +219,13 @@ void SetScriptManager::onAction(const Action& action, bool undone) {
|
|||||||
updateAllDependend(set.game->dependent_scripts_keywords);
|
updateAllDependend(set.game->dependent_scripts_keywords);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
TYPE_CASE(action, ChangeCardStyleAction) {
|
||||||
|
updateAllDependend(set.game->dependent_scripts_stylesheet, action.card);
|
||||||
|
}
|
||||||
|
TYPE_CASE_(action, ChangeSetStyleAction) {
|
||||||
|
updateAllDependend(set.game->dependent_scripts_stylesheet);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetScriptManager::updateStyles(const CardP& card, bool only_content_dependent) {
|
void SetScriptManager::updateStyles(const CardP& card, bool only_content_dependent) {
|
||||||
@@ -310,14 +317,15 @@ void SetScriptManager::updateAll() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetScriptManager::updateAllDependend(const vector<Dependency>& dependent_scripts) {
|
void SetScriptManager::updateAllDependend(const vector<Dependency>& dependent_scripts, const CardP& card) {
|
||||||
deque<ToUpdate> to_update;
|
deque<ToUpdate> to_update;
|
||||||
Age starting_age;
|
Age starting_age;
|
||||||
alsoUpdate(to_update, dependent_scripts, CardP());
|
alsoUpdate(to_update, dependent_scripts, card);
|
||||||
updateRecursive(to_update, starting_age);
|
updateRecursive(to_update, starting_age);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetScriptManager::updateRecursive(deque<ToUpdate>& to_update, Age starting_age) {
|
void SetScriptManager::updateRecursive(deque<ToUpdate>& to_update, Age starting_age) {
|
||||||
|
if (to_update.empty()) return;
|
||||||
set.clearOrderCache(); // clear caches before evaluating a round of scripts
|
set.clearOrderCache(); // clear caches before evaluating a round of scripts
|
||||||
while (!to_update.empty()) {
|
while (!to_update.empty()) {
|
||||||
updateToUpdate(to_update.front(), to_update, starting_age);
|
updateToUpdate(to_update.front(), to_update, starting_age);
|
||||||
@@ -373,7 +381,7 @@ void SetScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Depen
|
|||||||
to_update.push_back(ToUpdate(value.get(), card));
|
to_update.push_back(ToUpdate(value.get(), card));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} case DEP_STYLE: {
|
} case DEP_CARD_STYLE: {
|
||||||
// a generated image has become invalid, there is not much we can do
|
// a generated image has become invalid, there is not much we can do
|
||||||
// because the index is not exact enough, it only gives the field
|
// because the index is not exact enough, it only gives the field
|
||||||
StyleSheet* stylesheet = reinterpret_cast<StyleSheet*>(d.data);
|
StyleSheet* stylesheet = reinterpret_cast<StyleSheet*>(d.data);
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class SetScriptManager : public SetScriptContext, public ActionListener {
|
|||||||
/** if the value changes any dependend values are updated as well */
|
/** if the value changes any dependend values are updated as well */
|
||||||
void updateValue(Value& value, const CardP& card);
|
void updateValue(Value& value, const CardP& card);
|
||||||
// Update all values with a specific dependency
|
// Update all values with a specific dependency
|
||||||
void updateAllDependend(const vector<Dependency>& dependent_scripts);
|
void updateAllDependend(const vector<Dependency>& dependent_scripts, const CardP& card = CardP());
|
||||||
|
|
||||||
// Something that needs to be updated
|
// Something that needs to be updated
|
||||||
struct ToUpdate {
|
struct ToUpdate {
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ ScriptValueP make_iterator(const T& v) {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void mark_dependency_member(const T& value, const String& name, const Dependency& dep) {}
|
void mark_dependency_member(const T& value, const String& name, const Dependency& dep) {}
|
||||||
|
|
||||||
|
/// Mark a dependency on an object, can be overloaded
|
||||||
|
template <typename T>
|
||||||
|
void mark_dependency_value(const T& value, const Dependency& dep) {}
|
||||||
|
|
||||||
/// Type name of an object, for error messages
|
/// Type name of an object, for error messages
|
||||||
template <typename T> inline String type_name(const T&) {
|
template <typename T> inline String type_name(const T&) {
|
||||||
return _TYPE_("object");
|
return _TYPE_("object");
|
||||||
@@ -276,6 +280,9 @@ class ScriptObject : public ScriptValue {
|
|||||||
mark_dependency_member(*value, name, dep);
|
mark_dependency_member(*value, name, dep);
|
||||||
return getMember(name);
|
return getMember(name);
|
||||||
}
|
}
|
||||||
|
virtual void dependencyThis(const Dependency& dep) {
|
||||||
|
mark_dependency_value(*value, dep);
|
||||||
|
}
|
||||||
virtual ScriptValueP makeIterator(const ScriptValueP& thisP) const {
|
virtual ScriptValueP makeIterator(const ScriptValueP& thisP) const {
|
||||||
ScriptValueP it = make_iterator(*value);
|
ScriptValueP it = make_iterator(*value);
|
||||||
if (it) return it;
|
if (it) return it;
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ ScriptValueP ScriptValue::dependencyName(const ScriptValue& container, const Dep
|
|||||||
return container.dependencyMember(toString(),dep);
|
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; }
|
||||||
|
void ScriptValue::dependencyThis(const Dependency& dep) {}
|
||||||
|
|
||||||
bool approx_equal(double a, double b) {
|
bool approx_equal(double a, double b) {
|
||||||
return a == b || fabs(a - b) < 1e-14;
|
return a == b || fabs(a - b) < 1e-14;
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ class ScriptValue : public IntrusivePtrBaseWithDelete {
|
|||||||
|
|
||||||
/// Get a member variable from this value
|
/// Get a member variable from this value
|
||||||
virtual ScriptValueP getMember(const String& name) const;
|
virtual ScriptValueP getMember(const String& name) const;
|
||||||
|
|
||||||
|
/// Signal that a script depends on this value itself
|
||||||
|
virtual void dependencyThis(const Dependency& dep);
|
||||||
/// 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user