Commit ccbbe432 authored by twanvl's avatar twanvl

Fixed dependencies for 'styling';

Fixed: specific character prefered over .* for keywords
parent 73f84fdc
...@@ -43,12 +43,8 @@ String Card::identification() const { ...@@ -43,12 +43,8 @@ String Card::identification() const {
} }
} }
void mark_dependency_member(const CardP& card, const String& name, const Dependency& dep) { void mark_dependency_member(const Card& card, const String& name, const Dependency& dep) {
// Find field with that name mark_dependency_member(card.data, name, dep);
IndexMap<FieldP,ValueP>::const_iterator it = card->data.find(name);
if (it != card->data.end()) {
(*it)->fieldP->dependent_scripts.add(dep);
}
} }
IMPLEMENT_REFLECTION(Card) { IMPLEMENT_REFLECTION(Card) {
......
...@@ -69,7 +69,7 @@ class Card { ...@@ -69,7 +69,7 @@ class Card {
DECLARE_REFLECTION(); DECLARE_REFLECTION();
}; };
void mark_dependency_member(const CardP& value, const String& name, const Dependency& dep); void mark_dependency_member(const Card& value, const String& name, const Dependency& dep);
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
...@@ -137,3 +137,12 @@ void init_object(const FieldP& field, ValueP& value) { ...@@ -137,3 +137,12 @@ void init_object(const FieldP& field, ValueP& value) {
template <> ValueP read_new<Value>(Reader&) { template <> ValueP read_new<Value>(Reader&) {
throw InternalError(_("IndexMap contains nullptr ValueP the application should have crashed already")); throw InternalError(_("IndexMap contains nullptr ValueP the application should have crashed already"));
} }
void mark_dependency_member(const IndexMap<FieldP,ValueP>& value, const String& name, const Dependency& dep) {
IndexMap<FieldP,ValueP>::const_iterator it = value.find(name);
if (it != value.end()) {
(*it)->fieldP->dependent_scripts.add(dep);
}
}
...@@ -186,5 +186,7 @@ template <> ValueP read_new<Value>(Reader&); ...@@ -186,5 +186,7 @@ template <> ValueP read_new<Value>(Reader&);
return *static_cast<Type ## Field*>(fieldP.get()); \ return *static_cast<Type ## Field*>(fieldP.get()); \
} }
void mark_dependency_member(const IndexMap<FieldP,ValueP>& value, const String& name, const Dependency& dep);
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
...@@ -361,13 +361,14 @@ String KeywordDatabase::expand(const String& text, ...@@ -361,13 +361,14 @@ String KeywordDatabase::expand(const String& text,
} }
// find 'next' trie node set matching c // find 'next' trie node set matching c
FOR_EACH(kt, current) { FOR_EACH(kt, current) {
if (kt->on_any_star) {
next.push_back(kt->on_any_star);
}
map<Char,KeywordTrie*>::const_iterator it = kt->children.find(c); map<Char,KeywordTrie*>::const_iterator it = kt->children.find(c);
if (it != kt->children.end()) { if (it != kt->children.end()) {
next.push_back(it->second); next.push_back(it->second);
} }
// TODO: on any star first or last?
if (kt->on_any_star) {
next.push_back(kt->on_any_star);
}
} }
// next becomes current // next becomes current
swap(current, next); swap(current, next);
......
...@@ -154,25 +154,19 @@ ScriptValueP make_iterator(const Set& set) { ...@@ -154,25 +154,19 @@ ScriptValueP make_iterator(const Set& set) {
return new_intrusive1<ScriptCollectionIterator<vector<CardP> > >(&set.cards); return new_intrusive1<ScriptCollectionIterator<vector<CardP> > >(&set.cards);
} }
void mark_dependency_member(Set* value, const String& name, const Dependency& dep) { void mark_dependency_member(const Set& set, const String& name, const Dependency& dep) {
// is it the card list? // is it the card list?
if (name == _("cards")) { if (name == _("cards")) {
value->game->dependent_scripts_cards.add(dep); set.game->dependent_scripts_cards.add(dep);
return; return;
} }
// is it the keywords? // is it the keywords?
if (name == _("keywords")) { if (name == _("keywords")) {
value->game->dependent_scripts_keywords.add(dep); set.game->dependent_scripts_keywords.add(dep);
return; return;
} }
// is it in the set data? // is it in the set data?
IndexMap<FieldP,ValueP>::const_iterator it = value->data.find(name); mark_dependency_member(set.data, name, dep);
if (it != value->data.end()) {
(*it)->fieldP->dependent_scripts.add(dep);
}
}
void mark_dependency_member(const SetP& value, const String& name, const Dependency& dep) {
mark_dependency_member(value.get(), name, dep);
} }
// in scripts, set.something is read from the set_info // in scripts, set.something is read from the set_info
......
...@@ -122,8 +122,7 @@ inline int item_count(const Set& set) { ...@@ -122,8 +122,7 @@ inline int item_count(const Set& set) {
} }
ScriptValueP make_iterator(const Set& set); ScriptValueP make_iterator(const Set& set);
void mark_dependency_member(const SetP& value, const String& name, const Dependency& dep); void mark_dependency_member(const Set& set, const String& name, const Dependency& dep);
void mark_dependency_member(Set* value, const String& name, const Dependency& dep);
// ----------------------------------------------------------------------------- : SetView // ----------------------------------------------------------------------------- : SetView
......
...@@ -84,8 +84,8 @@ void KeywordList::onAction(const Action& action, bool undone) { ...@@ -84,8 +84,8 @@ void KeywordList::onAction(const Action& action, bool undone) {
String match_string(const Keyword& a) { String match_string(const Keyword& a) {
return untag(replace_all(replace_all( return untag(replace_all(replace_all(
a.match, a.match,
_("<atom-param>"), _("<")), _("<atom-param>"), LEFT_ANGLE_BRACKET),
_("</atom-param>"), _(">")) _("</atom-param>"), RIGHT_ANGLE_BRACKET)
); );
} }
......
...@@ -174,7 +174,7 @@ struct TextElementsFromString { ...@@ -174,7 +174,7 @@ struct TextElementsFromString {
line > 0 ? BREAK_LINE : BREAK_HARD); line > 0 ? BREAK_LINE : BREAK_HARD);
} }
if (bracket) { if (bracket) {
e->content = String(_("<")) + c + _(">"); e->content = String(LEFT_ANGLE_BRACKET) + c + RIGHT_ANGLE_BRACKET;
} else { } else {
e->content = c; e->content = c;
} }
......
...@@ -202,7 +202,7 @@ SCRIPT_FUNCTION_DEPENDENCIES(position_of) { ...@@ -202,7 +202,7 @@ SCRIPT_FUNCTION_DEPENDENCIES(position_of) {
ScriptObject<CardP>* c = dynamic_cast<ScriptObject<CardP>*>(of.get()); ScriptObject<CardP>* c = dynamic_cast<ScriptObject<CardP>*>(of.get());
if (s && c) { if (s && c) {
// dependency on cards // dependency on cards
mark_dependency_member(s->getValue(), _("cards"), dep); mark_dependency_member(*s->getValue(), _("cards"), dep);
if (order_by) { if (order_by) {
// dependency on order_by function // dependency on order_by function
order_by->dependencies(ctx, dep.makeCardIndependend()); order_by->dependencies(ctx, dep.makeCardIndependend());
......
...@@ -14,6 +14,23 @@ ...@@ -14,6 +14,23 @@
#include <util/error.hpp> #include <util/error.hpp>
#include <util/io/get_member.hpp> #include <util/io/get_member.hpp>
// ----------------------------------------------------------------------------- : Overloadable templates
/// Number of items in some collection like object, can be overloaded
template <typename T>
int item_count(const T& v) {
return -1;
}
/// Return an iterator for some collection, can be overloaded
template <typename T>
ScriptValueP make_iterator(const T& v) {
return ScriptValueP();
}
/// Mark a dependency on a member of value, can be overloaded
template <typename T>
void mark_dependency_member(const T& value, const String& name, const Dependency& dep) {}
// ----------------------------------------------------------------------------- : Iterators // ----------------------------------------------------------------------------- : Iterators
// Iterator over a collection // Iterator over a collection
...@@ -108,6 +125,10 @@ class ScriptMap : public ScriptValue { ...@@ -108,6 +125,10 @@ class ScriptMap : public ScriptValue {
virtual int itemCount() const { return (int)value->size(); } virtual int itemCount() const { return (int)value->size(); }
/// Collections can be compared by comparing pointers /// Collections can be compared by comparing pointers
virtual const void* comparePointer() const { return value; } virtual const void* comparePointer() const { return value; }
virtual ScriptValueP dependencyMember(const String& name, const Dependency& dep) const {
mark_dependency_member(*value, name, dep);
return getMember(name);
}
private: private:
/// Store a pointer to a collection, collections are only ever used for structures owned outside the script /// Store a pointer to a collection, collections are only ever used for structures owned outside the script
const Collection* value; const Collection* value;
...@@ -132,21 +153,6 @@ class ScriptCustomCollection : public ScriptValue { ...@@ -132,21 +153,6 @@ class ScriptCustomCollection : public ScriptValue {
// ----------------------------------------------------------------------------- : Objects // ----------------------------------------------------------------------------- : Objects
/// Number of items in some collection like object, can be overloaded
template <typename T>
int item_count(const T& v) {
return -1;
}
/// Return an iterator for some collection, can be overloaded
template <typename T>
ScriptValueP make_iterator(const T& v) {
return ScriptValueP();
}
/// Mark a dependency on a member of value, can be overloaded
template <typename T>
void mark_dependency_member(const T& value, const String& name, const Dependency& dep) {}
/// Script value containing an object (pointer) /// Script value containing an object (pointer)
template <typename T> template <typename T>
class ScriptObject : public ScriptValue { class ScriptObject : public ScriptValue {
...@@ -173,7 +179,7 @@ class ScriptObject : public ScriptValue { ...@@ -173,7 +179,7 @@ class ScriptObject : public ScriptValue {
} }
} }
virtual ScriptValueP dependencyMember(const String& name, const Dependency& dep) const { virtual ScriptValueP dependencyMember(const String& name, const Dependency& dep) const {
mark_dependency_member(value, name, dep); mark_dependency_member(*value, name, dep);
return getMember(name); return getMember(name);
} }
virtual ScriptValueP makeIterator(const ScriptValueP& thisP) const { virtual ScriptValueP makeIterator(const ScriptValueP& thisP) 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