mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Implement CSV / TSV import (#45)
- add csv/tsv importer - add `make_map` script function - add `alt name` field property - add `construction script` field property - add `construction script` game property
This commit is contained in:
@@ -40,6 +40,7 @@ Field::~Field() {}
|
||||
|
||||
void Field::initDependencies(Context& ctx, const Dependency& dep) const {
|
||||
sort_script.initDependencies(ctx, dep);
|
||||
construction_script.initDependencies(ctx, dep);
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION(Field) {
|
||||
@@ -48,6 +49,7 @@ IMPLEMENT_REFLECTION(Field) {
|
||||
REFLECT(type);
|
||||
}
|
||||
REFLECT(name);
|
||||
REFLECT(alt_names);
|
||||
REFLECT_LOCALIZED(caption);
|
||||
REFLECT_LOCALIZED(description); // FIXME: This field is both unused and uninitialized.
|
||||
REFLECT_N("icon", icon_filename);
|
||||
@@ -62,6 +64,7 @@ IMPLEMENT_REFLECTION(Field) {
|
||||
REFLECT(card_list_allow);
|
||||
REFLECT_LOCALIZED(card_list_name);
|
||||
REFLECT(sort_script);
|
||||
REFLECT(construction_script);
|
||||
REFLECT_N("card_list_alignment", card_list_align);
|
||||
}
|
||||
|
||||
|
||||
+21
-19
@@ -42,25 +42,27 @@ public:
|
||||
Field();
|
||||
virtual ~Field();
|
||||
|
||||
size_t index; ///< Used by IndexMap
|
||||
String name; ///< Name of the field, for refering to it from scripts and files
|
||||
LocalizedString caption; ///< Caption for NativeLookEditor
|
||||
LocalizedString description;///< Description, used in status bar
|
||||
String icon_filename; ///< Filename for an icon (for list of fields)
|
||||
bool editable; ///< Can values of this field be edited?
|
||||
bool save_value; ///< Should values of this field be written to files? Can be false for script generated fields.
|
||||
bool show_statistics; ///< Should this field appear as a group by choice in the statistics panel?
|
||||
int position_hint; ///< Position in the statistics list
|
||||
bool identifying; ///< Does this field give Card::identification()?
|
||||
int card_list_column; ///< What column to use in the card list?
|
||||
UInt card_list_width; ///< Width of the card list column (pixels).
|
||||
bool card_list_visible;///< Is this field shown in the card list?
|
||||
bool card_list_allow; ///< Is this field allowed to appear in the card list?
|
||||
LocalizedString card_list_name; ///< Name to use in card list.
|
||||
Alignment card_list_align; ///< Alignment of the card list colummn.
|
||||
OptionalScript sort_script; ///< The script to use when sorting this, if not the value.
|
||||
Dependencies dependent_scripts; ///< Scripts that depend on values of this field
|
||||
String package_relative_filename;
|
||||
size_t index; ///< Used by IndexMap
|
||||
String name; ///< Name of the field, for refering to it from scripts and files
|
||||
vector<String> alt_names; ///< Other names this field might go by, mainly in CSV files
|
||||
LocalizedString caption; ///< Caption for NativeLookEditor
|
||||
LocalizedString description; ///< Description, used in status bar
|
||||
String icon_filename; ///< Filename for an icon (for list of fields)
|
||||
bool editable; ///< Can values of this field be edited?
|
||||
bool save_value; ///< Should values of this field be written to files? Can be false for script generated fields.
|
||||
bool show_statistics; ///< Should this field appear as a group by choice in the statistics panel?
|
||||
int position_hint; ///< Position in the statistics list
|
||||
bool identifying; ///< Does this field give Card::identification()?
|
||||
int card_list_column; ///< What column to use in the card list?
|
||||
UInt card_list_width; ///< Width of the card list column (pixels).
|
||||
bool card_list_visible; ///< Is this field shown in the card list?
|
||||
bool card_list_allow; ///< Is this field allowed to appear in the card list?
|
||||
LocalizedString card_list_name; ///< Name to use in card list.
|
||||
Alignment card_list_align; ///< Alignment of the card list colummn.
|
||||
OptionalScript sort_script; ///< The script to use when sorting this, if not the value.
|
||||
OptionalScript construction_script; ///< The script to apply to the supplied value, when creating a new card.
|
||||
Dependencies dependent_scripts; ///< Scripts that depend on values of this field
|
||||
String package_relative_filename;
|
||||
|
||||
/// Creates a new Value corresponding to this Field
|
||||
virtual ValueP newValue() = 0;
|
||||
|
||||
+24
-1
@@ -49,6 +49,7 @@ IMPLEMENT_REFLECTION(Game) {
|
||||
REFLECT_NO_SCRIPT(default_set_style);
|
||||
REFLECT_NO_SCRIPT(card_fields);
|
||||
REFLECT_NO_SCRIPT(card_list_color_script);
|
||||
REFLECT_NO_SCRIPT(construction_script);
|
||||
REFLECT_NO_SCRIPT(statistics_dimensions);
|
||||
REFLECT_NO_SCRIPT(statistics_categories);
|
||||
REFLECT_COMPAT(<308, "pack_item", pack_types);
|
||||
@@ -93,6 +94,28 @@ void Game::validate(Version v) {
|
||||
pack->filter = OptionalScript(_("true"));
|
||||
pack->select = SELECT_NO_REPLACE;
|
||||
pack_types.push_back(pack);
|
||||
}
|
||||
// alternate card field names map
|
||||
for (auto it = card_fields.begin(); it != card_fields.end(); ++it) {
|
||||
FieldP field = *it;
|
||||
String unified_name = unified_form(field->name);
|
||||
if (card_fields_alt_names.count(unified_name)) {
|
||||
queue_message(MESSAGE_WARNING, _("Duplicate alternate card field name: ") + unified_name);
|
||||
}
|
||||
else {
|
||||
card_fields_alt_names.emplace(unified_name, field->name);
|
||||
}
|
||||
//String column_name = field->card_list_name.get();
|
||||
//card_fields_alt_names.emplace(unified_form(column_name), field->name);
|
||||
for (auto it2 = field->alt_names.begin(); it2 != field->alt_names.end(); ++it2) {
|
||||
unified_name = unified_form(*it2);
|
||||
if (card_fields_alt_names.count(unified_name)) {
|
||||
queue_message(MESSAGE_WARNING, _("Duplicate alternate card field name: ") + unified_name);
|
||||
}
|
||||
else {
|
||||
card_fields_alt_names.emplace(unified_name, field->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +137,7 @@ void Game::initCardListColorScript() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// special behaviour of reading/writing GamePs: only read/write the name
|
||||
|
||||
|
||||
+12
-10
@@ -12,7 +12,7 @@
|
||||
#include <util/io/package.hpp>
|
||||
#include <script/scriptable.hpp>
|
||||
#include <script/dependency.hpp>
|
||||
#include <util/dynamic_arg.hpp>
|
||||
#include <util/dynamic_arg.hpp>
|
||||
|
||||
DECLARE_POINTER_TYPE(Field);
|
||||
DECLARE_POINTER_TYPE(Style);
|
||||
@@ -41,24 +41,26 @@ public:
|
||||
vector<FieldP> set_fields; ///< Fields for set information
|
||||
IndexMap<FieldP,StyleP> default_set_style; ///< Default style for the set fields, because it is often the same
|
||||
vector<FieldP> card_fields; ///< Fields on each card
|
||||
OptionalScript card_list_color_script; ///< Script that determines the color of items in the card list
|
||||
OptionalScript card_list_color_script; ///< Script that determines the color of items in the card list
|
||||
OptionalScript construction_script; ///< Script applied as the last step of the new_card function
|
||||
vector<StatsDimensionP> statistics_dimensions; ///< (Additional) statistics dimensions
|
||||
vector<StatsCategoryP> statistics_categories; ///< (Additional) statistics categories
|
||||
vector<PackTypeP> pack_types; ///< Types of random card packs to generate
|
||||
vector<WordListP> word_lists; ///< Word lists for editing with a drop down list
|
||||
vector<AddCardsScriptP> add_cards_scripts; ///< Scripts for adding multiple cards to the set
|
||||
vector<AutoReplaceP> auto_replaces; ///< Things to autoreplace in textboxes
|
||||
|
||||
vector<PackTypeP> pack_types; ///< Types of random card packs to generate
|
||||
vector<WordListP> word_lists; ///< Word lists for editing with a drop down list
|
||||
vector<AddCardsScriptP> add_cards_scripts; ///< Scripts for adding multiple cards to the set
|
||||
vector<AutoReplaceP> auto_replaces; ///< Things to autoreplace in textboxes
|
||||
map<String,String> card_fields_alt_names; ///< Other names that fields might go by, for example in CSV files
|
||||
|
||||
bool has_keywords; ///< Does this game use keywords?
|
||||
OptionalScript keyword_match_script; ///< For the keyword editor
|
||||
OptionalScript keyword_match_script; ///< For the keyword editor
|
||||
vector<KeywordParamP> keyword_parameter_types;///< Types of keyword parameters
|
||||
vector<KeywordModeP> keyword_modes; ///< Modes of keywords
|
||||
vector<KeywordP> keywords; ///< Keywords for use in text
|
||||
|
||||
Dependencies dependent_scripts_cards; ///< scripts that depend on the card list
|
||||
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?
|
||||
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?
|
||||
|
||||
/// Loads the game with a particular name, for example "magic"
|
||||
static GameP byName(const String& name);
|
||||
|
||||
@@ -26,7 +26,9 @@ StyleSheet::StyleSheet()
|
||||
StyleSheetP StyleSheet::byGameAndName(const Game& game, const String& name) {
|
||||
/// Alternative stylesheets for game
|
||||
static map<String, String> stylesheet_alternatives;
|
||||
String full_name = game.name() + _("-") + name + _(".mse-style");
|
||||
String full_name = name;
|
||||
if (!full_name.EndsWith(_(".mse-style"))) full_name = full_name + _(".mse-style");
|
||||
if (!full_name.StartsWith(game.name() + _("-"))) full_name = game.name() + _("-") + full_name;
|
||||
try {
|
||||
map<String, String>::const_iterator it = stylesheet_alternatives.find(full_name);
|
||||
if (it != stylesheet_alternatives.end()) {
|
||||
|
||||
Reference in New Issue
Block a user