mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Changed scroll size of PackageList;
Added 'collapse' option for card notes; Made variant of DECLARE_TYPEOF for maps (two template arguments). git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@202 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -9,10 +9,8 @@
|
||||
#include <data/action/symbol.hpp>
|
||||
#include <data/action/symbol_part.hpp>
|
||||
|
||||
typedef pair<SymbolPartP,SymbolPartCombine> pair_part_combine_t;
|
||||
typedef pair<SymbolPartP,size_t > pair_part_size_t;
|
||||
DECLARE_TYPEOF_COLLECTION(pair_part_combine_t);
|
||||
DECLARE_TYPEOF_COLLECTION(pair_part_size_t);
|
||||
DECLARE_TYPEOF_COLLECTION2(pair<SymbolPartP,SymbolPartCombine>);
|
||||
DECLARE_TYPEOF_COLLECTION2(pair<SymbolPartP,size_t >);
|
||||
DECLARE_TYPEOF_COLLECTION(SymbolPartP);
|
||||
DECLARE_TYPEOF_COLLECTION(ControlPointP);
|
||||
|
||||
|
||||
+1
-2
@@ -13,8 +13,7 @@
|
||||
#include <util/reflect.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(FieldP);
|
||||
typedef IndexMap<FieldP,ValueP> IndexMap_FieldP_ValueP;
|
||||
DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_ValueP);
|
||||
DECLARE_TYPEOF_NO_REV2(IndexMap<FieldP,ValueP>);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Card
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
#include <util/io/package.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(ChoiceField::ChoiceP);
|
||||
typedef map<String,ScriptableImage> map_String_ScriptableImage;
|
||||
DECLARE_TYPEOF(map_String_ScriptableImage);
|
||||
DECLARE_TYPEOF2(map<String,ScriptableImage>);
|
||||
|
||||
// ----------------------------------------------------------------------------- : ChoiceField
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ IMPLEMENT_DYNAMIC_ARG(Game*, game_for_reading, nullptr);
|
||||
|
||||
Game::Game()
|
||||
: dependencies_initialized(false)
|
||||
, has_keywords(false)
|
||||
{}
|
||||
|
||||
GameP Game::byName(const String& name) {
|
||||
@@ -42,6 +43,7 @@ IMPLEMENT_REFLECTION(Game) {
|
||||
REFLECT(card_fields);
|
||||
REFLECT(statistics_dimensions);
|
||||
REFLECT(statistics_categories);
|
||||
REFLECT(has_keywords);
|
||||
REFLECT(keyword_parameter_types);
|
||||
REFLECT(keyword_modes);
|
||||
REFLECT(keywords);
|
||||
|
||||
@@ -39,6 +39,7 @@ class Game : public Packaged {
|
||||
vector<StatsDimensionP> statistics_dimensions; ///< (Additional) statistics dimensions
|
||||
vector<StatsCategoryP> statistics_categories; ///< (Additional) statistics categories
|
||||
|
||||
bool has_keywords; ///< Does this game use keywords?
|
||||
vector<KeywordParamP> keyword_parameter_types;///< Types of keyword parameters
|
||||
vector<KeywordModeP> keyword_modes; ///< Modes of keywords
|
||||
vector<KeywordP> keywords; ///< Keywords for use in text
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <data/keyword.hpp>
|
||||
#include <util/tagged_string.hpp>
|
||||
|
||||
class KeywordTrie;
|
||||
DECLARE_TYPEOF2(map<Char, KeywordTrie*>);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Reflection
|
||||
|
||||
@@ -57,4 +61,106 @@ IMPLEMENT_REFLECTION(Keyword) {
|
||||
REFLECT(mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordTrie
|
||||
|
||||
/// A node in a trie to match keywords
|
||||
class KeywordTrie {
|
||||
public:
|
||||
KeywordTrie();
|
||||
~KeywordTrie();
|
||||
|
||||
map<Char, KeywordTrie*> children; ///< children after a given character (owned)
|
||||
KeywordTrie* on_any_star; ///< children on /.*/ (owned)
|
||||
Keyword* finished; ///< keywords that end in this node
|
||||
|
||||
/// Insert nodes representing the given string
|
||||
/** return the node where the evaluation will be after matching the string */
|
||||
KeywordTrie* insert(const String& match);
|
||||
|
||||
/// Insert nodes representing the regex /.*/
|
||||
/** return the node where the evaluation will be after matching that regex */
|
||||
KeywordTrie* insertAnyStar();
|
||||
};
|
||||
|
||||
|
||||
KeywordTrie::KeywordTrie()
|
||||
: on_any_star(nullptr)
|
||||
, finished(nullptr)
|
||||
{}
|
||||
|
||||
KeywordTrie::~KeywordTrie() {
|
||||
FOR_EACH(c, children) {
|
||||
delete c.second;
|
||||
}
|
||||
delete on_any_star;
|
||||
}
|
||||
|
||||
KeywordTrie* KeywordTrie::insert(const String& match) {
|
||||
KeywordTrie* cur = this;
|
||||
FOR_EACH_CONST(c, match) {
|
||||
KeywordTrie*& child = cur->children[c];
|
||||
if (!child) child = new KeywordTrie;
|
||||
cur = child;
|
||||
}
|
||||
return cur;
|
||||
}
|
||||
|
||||
KeywordTrie* KeywordTrie::insertAnyStar() {
|
||||
if (!on_any_star) on_any_star = new KeywordTrie;
|
||||
return on_any_star;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordMatcher
|
||||
|
||||
/// State of the matching algorithm
|
||||
class KeywordMatcher {
|
||||
public:
|
||||
KeywordMatcher(const String& s);
|
||||
private:
|
||||
String str;
|
||||
size_t pos;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordDatabase
|
||||
|
||||
/// A database of keywords to allow for fast matching
|
||||
/** NOTE: keywords may not be altered after they are added to the database,
|
||||
* The database should be rebuild.
|
||||
*/
|
||||
class KeywordDatabase {
|
||||
public:
|
||||
/// Add a keyword to be matched
|
||||
void addKeyword(const Keyword&);
|
||||
|
||||
/// Find the first matching keyword, return its position
|
||||
size_t firstMatch(const String& input, Keyword* keyword);
|
||||
|
||||
private:
|
||||
KeywordTrie root;
|
||||
};
|
||||
|
||||
void KeywordDatabase::addKeyword(const Keyword& kw) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Using keywords
|
||||
|
||||
KeywordDatabaseP new_keyword_database() {
|
||||
return new_shared<KeywordDatabase>();
|
||||
}
|
||||
void add_keyword(KeywordDatabase& db, const Keyword& kw) {
|
||||
db.addKeyword(kw);
|
||||
}
|
||||
|
||||
|
||||
String expand_keywords(const KeywordDatabase& db, const String& text) {
|
||||
// 1. Remove all old reminder texts
|
||||
String s = remove_tag_contents(text, _("<atom-keyword>"));
|
||||
// 2. Process keywords
|
||||
|
||||
// TODO
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
+16
-1
@@ -27,6 +27,7 @@ class KeywordParam {
|
||||
String match; ///< Uncompiled regex
|
||||
wxRegEx matchRe; ///< Regular expression to match
|
||||
OptionalScript script; ///< Transformation of the value for showing in the reminder text
|
||||
String example; ///< Example for preview dialog
|
||||
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
@@ -68,10 +69,24 @@ class Keyword {
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : Using keywords
|
||||
|
||||
/// A class that allows for fast matching of keywords
|
||||
class KeywordDatabase;
|
||||
DECLARE_POINTER_TYPE(KeywordDatabase);
|
||||
|
||||
/// Create a new keyword database
|
||||
KeywordDatabaseP new_keyword_database();
|
||||
|
||||
/// Add a keyword to a KeywordDatabase
|
||||
/** NOTE: keywords may not be altered after they are added to the database,
|
||||
* The database should be rebuild.
|
||||
*/
|
||||
void add_keyword(KeywordDatabase& db, const Keyword& kw);
|
||||
|
||||
/// Expand/update all keywords in the given string
|
||||
String expand_keywords(const String& text);
|
||||
String expand_keywords(const KeywordDatabase& db, const String& text);
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
|
||||
+1
-2
@@ -19,8 +19,7 @@
|
||||
#include <wx/sstream.h>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(CardP);
|
||||
typedef IndexMap<FieldP,ValueP> IndexMap_FieldP_ValueP;
|
||||
DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_ValueP);
|
||||
DECLARE_TYPEOF_NO_REV2(IndexMap<FieldP,ValueP>);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Set
|
||||
|
||||
|
||||
Reference in New Issue
Block a user