dependency handling for keywords

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@265 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-04-18 22:59:03 +00:00
parent 99f44292d6
commit 9f24da8d02
5 changed files with 54 additions and 9 deletions
+9 -3
View File
@@ -219,8 +219,8 @@ SCRIPT_FUNCTION(number_of_items) {
// ----------------------------------------------------------------------------- : Keywords
SCRIPT_RULE_2_N(expand_keywords, ScriptValueP, _("default expand"), default_expand,
ScriptValueP, _("combine"), combine) {
SCRIPT_RULE_2_N_DEP(expand_keywords, ScriptValueP, _("default expand"), default_expand,
ScriptValueP, _("combine"), combine) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM(Set*, set);
KeywordDatabase& db = set->keyword_db;
@@ -232,7 +232,13 @@ SCRIPT_RULE_2_N(expand_keywords, ScriptValueP, _("default expand"), default_exp
}
SCRIPT_RETURN(db.expand(input, default_expand, combine, ctx));
}
SCRIPT_RULE_2_DEPENDENCIES(expand_keywords) {
default_expand->dependencies(ctx, dep);
combine ->dependencies(ctx, dep);
SCRIPT_PARAM(Set*, set);
set->game->dependent_scripts_keywords.add(dep); // this depends on the set's keywords
SCRIPT_RETURN(_(""));
}
// ----------------------------------------------------------------------------- : Rules : regex replace
+11
View File
@@ -143,6 +143,13 @@
SCRIPT_RULE_2_N(funname, type1, _(#name1), name1, type2, _(#name2), name2)
/// Utility for defining a script rule with two named parameters
#define SCRIPT_RULE_2_N(funname, type1, str1, name1, type2, str2, name2) \
SCRIPT_RULE_2_N_AUX(funname, type1, str1, name1, type2, str2, name2, ;)
/// Utility for defining a script rule with two named parameters, with dependencies
#define SCRIPT_RULE_2_N_DEP(funname, type1, str1, name1, type2, str2, name2)\
SCRIPT_RULE_2_N_AUX( funname, type1, str1, name1, type2, str2, name2,\
virtual ScriptValueP dependencies(Context&, const Dependency&) const;)
#define SCRIPT_RULE_2_N_AUX(funname, type1, str1, name1, type2, str2, name2, dep) \
class ScriptRule_##funname: public ScriptValue { \
public: \
inline ScriptRule_##funname(const type1& name1, const type2& name2) \
@@ -150,6 +157,7 @@
virtual ScriptType type() const { return SCRIPT_FUNCTION; } \
virtual String typeName() const { return _(#funname)_("_rule"); } \
virtual ScriptValueP eval(Context& ctx) const; \
dep \
private: \
type1 name1; \
type2 name2; \
@@ -166,6 +174,9 @@
} \
ScriptValueP ScriptRule_##funname::eval(Context& ctx) const
#define SCRIPT_RULE_2_DEPENDENCIES(name) \
ScriptValueP ScriptRule_##name::dependencies(Context& ctx, const Dependency& dep) const
// ----------------------------------------------------------------------------- : EOF
#endif
+16
View File
@@ -16,6 +16,7 @@
#include <data/field.hpp>
#include <data/action/set.hpp>
#include <data/action/value.hpp>
#include <data/action/keyword.hpp>
#include <util/error.hpp>
typedef map<const StyleSheet*,Context*> Contexts;
@@ -131,6 +132,12 @@ void SetScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) {
void SetScriptManager::onAction(const Action& action, bool undone) {
TYPE_CASE(action, ValueAction) {
// is it a keyword's fake value?
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
if (value) {
updateAllDependend(set.game->dependent_scripts_keywords);
return;
}
// find the affected card
FOR_EACH(card, set.cards) {
if (card->data.contains(action.valueP)) {
@@ -138,6 +145,7 @@ void SetScriptManager::onAction(const Action& action, bool undone) {
return;
}
}
// not a card value
updateValue(*action.valueP, CardP());
}
TYPE_CASE_(action, ScriptValueEvent) {
@@ -160,6 +168,14 @@ void SetScriptManager::onAction(const Action& action, bool undone) {
wxLogDebug(_("-------------------------------\n"));
#endif
}
TYPE_CASE_(action, KeywordListAction) {
updateAllDependend(set.game->dependent_scripts_keywords);
return;
}
TYPE_CASE_(action, ChangeKeywordModeAction) {
updateAllDependend(set.game->dependent_scripts_keywords);
return;
}
}
void SetScriptManager::updateStyles(const CardP& card) {