Use underscores instead of spaces for all internal names. And renamed some script functions at the same time.

* cannocial_name_form now outputs "_", where it used to use " "
* this simplifies reflectio and scripting code, because now C++ names are also MSE internal names
* added 'caption' property to fields. This is used instead of the name in NativeLookEditor, since the latter will now contain underscores.
* renamed text related script functions for consistency, since we were touching that part of the code anyway.
This commit is contained in:
Twan van Laarhoven
2020-04-22 23:33:06 +02:00
parent be4bb8d8ed
commit 713a9e4a40
33 changed files with 240 additions and 197 deletions
+3 -1
View File
@@ -51,6 +51,7 @@ IMPLEMENT_REFLECTION(Field) {
}
REFLECT(name);
REFLECT_IF_READING name = canonical_name_form(name);
REFLECT(caption);
REFLECT(description);
REFLECT_N("icon", icon_filename);
REFLECT(editable);
@@ -64,9 +65,10 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT(card_list_allow);
REFLECT(card_list_name);
REFLECT(sort_script);
REFLECT_IF_READING if(card_list_name.empty()) card_list_name = name;
REFLECT_N("card_list_alignment", card_list_align);
REFLECT(tab_index);
REFLECT_IF_READING if(caption.empty()) caption = name_to_caption(name);
REFLECT_IF_READING if(card_list_name.empty()) card_list_name = capitalize(caption);
}
template <>
+2 -1
View File
@@ -44,8 +44,9 @@ class Field : public IntrusivePtrVirtualBase {
size_t index; ///< Used by IndexMap
String name; ///< Name of the field, for refering to it from scripts and files
String caption; ///< Caption for NativeLookEditor
String description; ///< Description, used in status bar
String icon_filename; ///< Filename for an icon (for list of fields)
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?
+3 -2
View File
@@ -192,7 +192,8 @@ void ChoiceStyle::initImage() {
// OR_ELSE
ScriptCustomCollectionP lookup(new ScriptCustomCollection());
FOR_EACH(ci, choice_images) {
lookup->key_value[ci.first] = ci.second.getValidScriptP();
lookup->key_value[uncanonical_name_form(ci.first)] =
lookup->key_value[ci.first] = ci.second.getValidScriptP();
}
Script& script = image.getMutableScript();
script.addInstruction(I_PUSH_CONST, lookup);
@@ -270,7 +271,7 @@ template <> void reflect_content(GetMember& tag, const ChoiceStyle& cs
}
IMPLEMENT_REFLECTION(ChoiceStyle) {
REFLECT_ALIAS(300, "card list colors", "colors card list");
REFLECT_ALIAS(300, "card_list_colors", "colors_card_list");
REFLECT_BASE(Style);
REFLECT(popup_style);
REFLECT(render_style);
+1 -1
View File
@@ -63,7 +63,7 @@ String InfoValue::toString() const {
return value;
}
bool InfoValue::update(Context& ctx) {
if (value.empty()) value = field().name;
if (value.empty()) value = field().caption;
bool change = field().script.invokeOn(ctx, value);
Value::update(ctx);
return change;
+1 -1
View File
@@ -53,7 +53,7 @@ IMPLEMENT_REFLECTION_NAMELESS(MultipleChoiceValue) {
bool MultipleChoiceValue::update(Context& ctx) {
String old_value = value();
ctx.setVariable(_("last change"), to_script(last_change));
ctx.setVariable(_("last_change"), to_script(last_change));
ChoiceValue::update(ctx);
normalForm();
return value() != old_value;
+5 -5
View File
@@ -423,12 +423,12 @@ class ApprCardRecord : public IntrusivePtrBase<ApprCardRecord> {
ApprCardRecord::ApprCardRecord(const Card& card, const String& sets_) {
name = untag_appr(card.value<TextValue>(_("name")).value);
sets = sets_ + _("-") + card_rarity_code(card.value<ChoiceValue>(_("rarity")).value);
cc = untag_appr(card.value<TextValue>(_("casting cost")).value);
type = untag_appr(card.value<TextValue>(_("super type")).value);
String subType = untag(card.value<TextValue>(_("sub type")).value);
cc = untag_appr(card.value<TextValue>(_("casting_cost")).value);
type = untag_appr(card.value<TextValue>(_("super_type")).value);
String subType = untag(card.value<TextValue>(_("sub_type")).value);
if (!subType.empty()) type += _(" - ") + subType;
text = untag_appr(card.value<TextValue>(_("rule text")).value);
flavor = untag_appr(card.value<TextValue>(_("flavor text")).value);
text = untag_appr(card.value<TextValue>(_("rule_text")).value);
flavor = untag_appr(card.value<TextValue>(_("flavor_text")).value);
pt = untag_appr(card.value<TextValue>(_("pt")).value);
}
+1 -1
View File
@@ -54,7 +54,7 @@ IMPLEMENT_REFLECTION(Game) {
REFLECT_NO_SCRIPT(card_list_color_script);
REFLECT_NO_SCRIPT(statistics_dimensions);
REFLECT_NO_SCRIPT(statistics_categories);
REFLECT_ALIAS(308, "pack item", "pack type");
REFLECT_ALIAS(308, "pack_item", "pack_type");
REFLECT_NO_SCRIPT(pack_types);
REFLECT_NO_SCRIPT(keyword_match_script);
REFLECT(has_keywords);
+1 -1
View File
@@ -248,7 +248,7 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(PackageDescription) {
REFLECT(installer_group);
REFLECT(position_hint);
REFLECT(description);
REFLECT_N("depends ons", dependencies);
REFLECT_N("depends_ons", dependencies);
}
void PackageDescription::merge(const PackageDescription& p2) {
+2 -2
View File
@@ -675,8 +675,8 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
part_start = part_end;
}
ctx.setVariable(_("mode"), to_script(kw.mode));
ctx.setVariable(_("correct case"), to_script(correct_case));
ctx.setVariable(_("used placeholders"), to_script(used_placeholders));
ctx.setVariable(_("correct_case"), to_script(correct_case));
ctx.setVariable(_("used_placeholders"), to_script(used_placeholders));
// Final check whether the keyword matches
if (match_condition && (bool)*match_condition->eval(ctx) == false) {
+5 -2
View File
@@ -89,9 +89,12 @@ String warn_and_identity(const String& key) {
queue_message(MESSAGE_WARNING, _("Missing key in locale: ") + key);
return key;
}
String identity(const String& key) {
return key;
}
String SubLocale::tr(const String& key, DefaultLocaleFun def) {
map<String,String>::const_iterator it = translations.find(key);
map<String,String>::const_iterator it = translations.find(canonical_name_form(key));
if (it == translations.end()) {
return def(key);
} else {
@@ -99,7 +102,7 @@ String SubLocale::tr(const String& key, DefaultLocaleFun def) {
}
}
String SubLocale::tr(const String& subcat, const String& key, DefaultLocaleFun def) {
map<String,String>::const_iterator it = translations.find(subcat + _(" ") + key);
map<String,String>::const_iterator it = translations.find(subcat + _("_") + canonical_name_form(key));
if (it == translations.end()) {
return def(key);
} else {
+3 -3
View File
@@ -171,7 +171,7 @@ void Set::validate(Version file_app_version) {
IMPLEMENT_REFLECTION(Set) {
REFLECT_ALIAS(300, "style", "stylesheet"); // < 0.3.0 used style instead of stylesheet
REFLECT_ALIAS(300, "extra set info", "styling");
REFLECT_ALIAS(300, "extra_set_info", "styling");
REFLECT(game);
if (game) {
REFLECT_IF_READING {
@@ -190,7 +190,7 @@ IMPLEMENT_REFLECTION(Set) {
REFLECT(pack_types);
}
reflect_set_info_get_member(tag,data);
REFLECT_NO_SCRIPT_N("version control", vcs);
REFLECT_NO_SCRIPT_N("version_control", vcs);
REFLECT(apprentice_code);
}
@@ -226,7 +226,7 @@ void Set::reflect_cards<Writer> (Writer& tag) {
Writer writer(openOut(full_name), app_version);
writer.handle(_("card"), card);
referenceFile(full_name);
REFLECT_N("include file", full_name);
REFLECT_N("include_file", full_name);
}
}
}
+5 -5
View File
@@ -109,7 +109,7 @@ void GameSettings::initDefaults(const Game& game) {
IMPLEMENT_REFLECTION_NO_SCRIPT(GameSettings) {
REFLECT(default_stylesheet);
REFLECT(default_export);
REFLECT_N("cardlist columns", columns);
REFLECT(cardlist_columns);
REFLECT(sort_cards_by);
REFLECT(sort_cards_ascending);
REFLECT(images_export_filename);
@@ -211,7 +211,7 @@ ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field
// Get game info
GameSettings& gs = gameSettingsFor(game);
// Get column info
ColumnSettings& cs = gs.columns[field.name];
ColumnSettings& cs = gs.cardlist_columns[field.name];
if (cs.position == COLUMN_NOT_INITIALIZED) {
// column info not set, initialize based on the game
cs.visible = field.card_list_visible;
@@ -244,8 +244,8 @@ String Settings::settingsFile() {
}
IMPLEMENT_REFLECTION_NO_SCRIPT(Settings) {
REFLECT_ALIAS(300, "style settings", "stylesheet settings");
REFLECT_ALIAS(300, "default style settings", "default stylesheet settings");
REFLECT_ALIAS(300, "style_settings", "stylesheet_settings");
REFLECT_ALIAS(300, "default_style_settings", "default_stylesheet_settings");
REFLECT(locale);
REFLECT(recent_sets);
REFLECT(default_set_dir);
@@ -266,7 +266,7 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Settings) {
#if USE_OLD_STYLE_UPDATE_CHECKER
REFLECT(updates_url);
#else
REFLECT_IGNORE(306,"updates url");
REFLECT_IGNORE(306,"updates_url");
#endif
REFLECT(package_versions_url);
REFLECT(installer_list_url);
+1 -1
View File
@@ -76,7 +76,7 @@ class GameSettings : public IntrusivePtrBase<GameSettings> {
String default_stylesheet;
String default_export;
map<String, ColumnSettings> columns;
map<String, ColumnSettings> cardlist_columns;
String sort_cards_by;
bool sort_cards_ascending;
String images_export_filename;
+7 -7
View File
@@ -95,14 +95,14 @@ void mark_dependency_value(const StyleSheet& stylesheet, const Dependency& dep)
IMPLEMENT_REFLECTION(StyleSheet) {
// < 0.3.0 didn't use card_ prefix
REFLECT_ALIAS(300, "width", "card width");
REFLECT_ALIAS(300, "height", "card height");
REFLECT_ALIAS(300, "dpi", "card dpi");
REFLECT_ALIAS(300, "background", "card background");
REFLECT_ALIAS(300, "info style", "set info style");
REFLECT_ALIAS(300, "width", "card_width");
REFLECT_ALIAS(300, "height", "card_height");
REFLECT_ALIAS(300, "dpi", "card_dpi");
REFLECT_ALIAS(300, "background", "card_background");
REFLECT_ALIAS(300, "info_style", "set_info_style");
REFLECT_ALIAS(300, "align", "alignment");
REFLECT_ALIAS(300, "extra field", "styling field");
REFLECT_ALIAS(300, "extra style", "styling style");
REFLECT_ALIAS(300, "extra_field", "styling_field");
REFLECT_ALIAS(300, "extra_style", "styling_style");
REFLECT(game);
REFLECT_BASE(Packaged);
+5 -5
View File
@@ -51,11 +51,11 @@ SymbolFontP SymbolFont::byName(const String& name) {
IMPLEMENT_REFLECTION(SymbolFont) {
REFLECT_BASE(Packaged);
REFLECT_ALIAS(300, "text align", "text alignment");
REFLECT_ALIAS(300, "text_align", "text_alignment");
REFLECT_N("image font size", img_size);
REFLECT_N("horizontal space", spacing.width);
REFLECT_N("vertical space", spacing.height);
REFLECT_N("image_font_size", img_size);
REFLECT_N("horizontal_space", spacing.width);
REFLECT_N("vertical_space", spacing.height);
WITH_DYNAMIC_ARG(symbol_font_for_reading, this);
REFLECT(symbols);
REFLECT(scale_text);
@@ -189,7 +189,7 @@ IMPLEMENT_REFLECTION(SymbolInFont) {
REFLECT(text_margin_bottom);
REFLECT(image);
REFLECT(enabled);
REFLECT_N("image font size", img_size);
REFLECT_N("image_font_size", img_size);
}
// ----------------------------------------------------------------------------- : SymbolFont : splitting