mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -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:
@@ -269,6 +269,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
|
||||
if (!value) {
|
||||
value = new_intrusive1<ScriptMissingVariable>(variable_to_string((Variable)i.data)); // no errors here
|
||||
}
|
||||
value->dependencyThis(dep);
|
||||
stack.push_back(value);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ enum DependencyType
|
||||
{ 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_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_CARD_COPY_DEP ///< copy the dependencies from a card 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
|
||||
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?
|
||||
Dependency test(DEP_DUMMY, false);
|
||||
s->checkContentDependencies(ctx, test);
|
||||
@@ -219,6 +219,13 @@ void SetScriptManager::onAction(const Action& action, bool undone) {
|
||||
updateAllDependend(set.game->dependent_scripts_keywords);
|
||||
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) {
|
||||
@@ -310,14 +317,15 @@ void SetScriptManager::updateAll() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void SetScriptManager::updateAllDependend(const vector<Dependency>& dependent_scripts) {
|
||||
void SetScriptManager::updateAllDependend(const vector<Dependency>& dependent_scripts, const CardP& card) {
|
||||
deque<ToUpdate> to_update;
|
||||
Age starting_age;
|
||||
alsoUpdate(to_update, dependent_scripts, CardP());
|
||||
alsoUpdate(to_update, dependent_scripts, card);
|
||||
updateRecursive(to_update, 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
|
||||
while (!to_update.empty()) {
|
||||
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));
|
||||
}
|
||||
break;
|
||||
} case DEP_STYLE: {
|
||||
} case DEP_CARD_STYLE: {
|
||||
// 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
|
||||
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 */
|
||||
void updateValue(Value& value, const CardP& card);
|
||||
// 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
|
||||
struct ToUpdate {
|
||||
|
||||
@@ -33,6 +33,10 @@ ScriptValueP make_iterator(const T& v) {
|
||||
template <typename T>
|
||||
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
|
||||
template <typename T> inline String type_name(const T&) {
|
||||
return _TYPE_("object");
|
||||
@@ -276,6 +280,9 @@ class ScriptObject : public ScriptValue {
|
||||
mark_dependency_member(*value, name, dep);
|
||||
return getMember(name);
|
||||
}
|
||||
virtual void dependencyThis(const Dependency& dep) {
|
||||
mark_dependency_value(*value, dep);
|
||||
}
|
||||
virtual ScriptValueP makeIterator(const ScriptValueP& thisP) const {
|
||||
ScriptValueP it = make_iterator(*value);
|
||||
if (it) return it;
|
||||
|
||||
@@ -54,6 +54,7 @@ ScriptValueP ScriptValue::dependencyName(const ScriptValue& container, const Dep
|
||||
return container.dependencyMember(toString(),dep);
|
||||
}
|
||||
ScriptValueP ScriptValue::dependencies(Context&, const Dependency&) const { return dependency_dummy; }
|
||||
void ScriptValue::dependencyThis(const Dependency& dep) {}
|
||||
|
||||
bool approx_equal(double a, double b) {
|
||||
return a == b || fabs(a - b) < 1e-14;
|
||||
|
||||
@@ -80,6 +80,9 @@ class ScriptValue : public IntrusivePtrBaseWithDelete {
|
||||
|
||||
/// Get a member variable from this value
|
||||
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
|
||||
/** It is the abstract version of getMember*/
|
||||
virtual ScriptValueP dependencyMember(const String& name, const Dependency&) const;
|
||||
|
||||
Reference in New Issue
Block a user