From c6fe6634dd1e61b900380baf58fd224153887651 Mon Sep 17 00:00:00 2001 From: twanvl Date: Thu, 7 Aug 2008 01:54:13 +0000 Subject: [PATCH] Tweaked the way to use getScript() like functions; Made condition and default_expand parameters of expand_keywords optional. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1080 0fc631ac-6414-0410-93d0-97cfa31319b6 --- doc/function/expand_keywords.txt | 12 ++++++------ src/data/action/keyword.cpp | 6 +++--- src/data/field/choice.cpp | 4 ++-- src/data/game.cpp | 2 +- src/data/keyword.cpp | 2 +- src/data/statistics.cpp | 4 ++-- src/gui/value/choice.cpp | 2 +- src/script/functions/basic.cpp | 10 +++++----- src/script/image.cpp | 2 +- src/script/image.hpp | 4 ++-- src/script/scriptable.cpp | 2 +- src/script/scriptable.hpp | 10 ++++++---- 12 files changed, 31 insertions(+), 29 deletions(-) diff --git a/doc/function/expand_keywords.txt b/doc/function/expand_keywords.txt index 65d8f024..b4b8304e 100644 --- a/doc/function/expand_keywords.txt +++ b/doc/function/expand_keywords.txt @@ -28,12 +28,12 @@ For example, in the case of magic: is used. This shows reminder text by default based on a [[type:set]] option, and it combined the keyword as @"keyword (reminder)"@. --Parameters-- -! Parameter Type Description -| @input@ [[type:tagged string]] String to expand keywords in. -| @condition@ [[type:function]] DOC_MSE_VERSION: since 0.3.7 - When should a keyword be recognized at all? -| @default_expand@ [[type:function]] Should reminder text be shown by default? -| @combine@ [[type:function]] How to combine keywords with the reminder text? +! Parameter Type Default Description +| @input@ [[type:tagged string]] String to expand keywords in. +| @condition@ [[type:function]] @{true}@ DOC_MSE_VERSION: since 0.3.7 + When should a keyword be recognized at all? +| @default_expand@ [[type:function]] @{true}@ Should reminder text be shown by default? +| @combine@ [[type:function]] How to combine keywords with the reminder text? --Arguments-- diff --git a/src/data/action/keyword.cpp b/src/data/action/keyword.cpp index ba2383c4..40c409a6 100644 --- a/src/data/action/keyword.cpp +++ b/src/data/action/keyword.cpp @@ -53,7 +53,7 @@ void AddKeywordAction::perform(bool to_undo) { // ----------------------------------------------------------------------------- : Changing keywords KeywordReminderTextValue::KeywordReminderTextValue(Set& set, const TextFieldP& field, Keyword* keyword, bool editable) - : KeywordTextValue(field, keyword, &keyword->reminder.getUnparsed(), editable) + : KeywordTextValue(field, keyword, &keyword->reminder.getMutableUnparsed(), editable) , set(set) , keyword(*keyword) {} @@ -72,8 +72,8 @@ void KeywordReminderTextValue::store() { // parsed okay if (checkScript(new_script)) { // also runs okay, assign - keyword.reminder.getScriptP() = new_script; - keyword.reminder.getUnparsed() = new_value; + keyword.reminder.setScriptP(new_script); + keyword.reminder.setUnparsed(new_value); } } else { // parse errors, report diff --git a/src/data/field/choice.cpp b/src/data/field/choice.cpp index 490e9337..bc211e1d 100644 --- a/src/data/field/choice.cpp +++ b/src/data/field/choice.cpp @@ -200,9 +200,9 @@ void ChoiceStyle::initImage() { // OR_ELSE ScriptCustomCollectionP lookup(new ScriptCustomCollection()); FOR_EACH(ci, choice_images) { - lookup->key_value[ci.first] = ci.second.getScriptP(); + lookup->key_value[ci.first] = ci.second.getValidScriptP(); } - Script& script = image.getScript(); + Script& script = image.getMutableScript(); script.addInstruction(I_PUSH_CONST, lookup); script.addInstruction(I_GET_VAR, SCRIPT_VAR_input); script.addInstruction(I_BINARY, I_MEMBER); diff --git a/src/data/game.cpp b/src/data/game.cpp index 91f46a9e..7380f11b 100644 --- a/src/data/game.cpp +++ b/src/data/game.cpp @@ -94,7 +94,7 @@ void Game::initCardListColorScript() { if (cf && !cf->choice_colors_cardlist.empty()) { // found the field to use // initialize script: field.colors[card.field-name] or else rgb(0,0,0) - Script& s = card_list_color_script.getScript(); + Script& s = card_list_color_script.getMutableScript(); s.addInstruction(I_PUSH_CONST, to_script(&cf->choice_colors_cardlist)); s.addInstruction(I_GET_VAR, SCRIPT_VAR_card); s.addInstruction(I_MEMBER_C, cf->name); diff --git a/src/data/keyword.cpp b/src/data/keyword.cpp index 1d69c51e..00d3b120 100644 --- a/src/data/keyword.cpp +++ b/src/data/keyword.cpp @@ -670,7 +670,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw, bool expand = expand_type == _('1'); if (!expand && expand_type != _('0')) { // default expand, determined by script - expand = expand_default && (bool)*expand_default->eval(ctx); + expand = expand_default ? (bool)*expand_default->eval(ctx) : true; expand_type = expand ? _('A') : _('a'); } diff --git a/src/data/statistics.cpp b/src/data/statistics.cpp index fc4a61b0..101e396b 100644 --- a/src/data/statistics.cpp +++ b/src/data/statistics.cpp @@ -51,7 +51,7 @@ StatsDimension::StatsDimension(const Field& field) groups.push_back(g->name); } // initialize script: primary_choice(card.{field_name}) - Script& s = script.getScript(); + Script& s = script.getMutableScript(); s.addInstruction(I_PUSH_CONST, script_primary_choice); s.addInstruction(I_GET_VAR, SCRIPT_VAR_card); s.addInstruction(I_MEMBER_C, field.name); @@ -59,7 +59,7 @@ StatsDimension::StatsDimension(const Field& field) s.addInstruction(I_NOP, SCRIPT_VAR_input); } else { // initialize script, card.{field_name} - Script& s = script.getScript(); + Script& s = script.getMutableScript(); s.addInstruction(I_GET_VAR, SCRIPT_VAR_card); s.addInstruction(I_MEMBER_C, field.name); } diff --git a/src/gui/value/choice.cpp b/src/gui/value/choice.cpp index add51cd1..3c52ff16 100644 --- a/src/gui/value/choice.cpp +++ b/src/gui/value/choice.cpp @@ -183,7 +183,7 @@ void DropDownChoiceListBase::generateThumbnailImages() { try { String name = cannocial_name_form(field().choices->choiceName(i)); ctx.setVariable(_("input"), to_script(name)); - GeneratedImageP img = image_from_script(style().image.getScript().eval(ctx)); + GeneratedImageP img = image_from_script(style().image.getValidScriptP()->eval(ctx)); style().choice_images.insert(make_pair(name, ScriptableImage(img))); } catch (const Error& e) { handle_error(Error(e.what() + _("\n while generating choice images for drop down list")),true,false); diff --git a/src/script/functions/basic.cpp b/src/script/functions/basic.cpp index 0ff6e9e1..65916be0 100644 --- a/src/script/functions/basic.cpp +++ b/src/script/functions/basic.cpp @@ -542,8 +542,8 @@ SCRIPT_FUNCTION(random_select) { SCRIPT_FUNCTION_WITH_DEP(expand_keywords) { SCRIPT_PARAM_C(String, input); SCRIPT_PARAM_C(Set*, set); - SCRIPT_PARAM_N(ScriptValueP, _("condition"), match_condition); - SCRIPT_PARAM_N(ScriptValueP, _("default expand"), default_expand); + SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("condition"), match_condition); + SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("default expand"), default_expand); SCRIPT_PARAM_N(ScriptValueP, _("combine"), combine); KeywordDatabase& db = set->keyword_db; if (db.empty()) { @@ -562,10 +562,10 @@ SCRIPT_FUNCTION_WITH_DEP(expand_keywords) { } SCRIPT_FUNCTION_DEPENDENCIES(expand_keywords) { SCRIPT_PARAM_C(Set*, set); - SCRIPT_PARAM_N(ScriptValueP, _("condition"), match_condition); - SCRIPT_PARAM_N(ScriptValueP, _("default expand"), default_expand); + SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("condition"), match_condition); + SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("default expand"), default_expand); SCRIPT_PARAM_N(ScriptValueP, _("combine"), combine); - match_condition->dependencies(ctx,dep); + if (match_condition) match_condition->dependencies(ctx,dep); default_expand ->dependencies(ctx,dep); combine ->dependencies(ctx,dep); set->game->dependent_scripts_keywords.add(dep); // this depends on the set's keywords diff --git a/src/script/image.cpp b/src/script/image.cpp index e10d2afe..0837c5b8 100644 --- a/src/script/image.cpp +++ b/src/script/image.cpp @@ -77,7 +77,7 @@ bool ScriptableImage::update(Context& ctx) { } } -ScriptP ScriptableImage::getScriptP() { +ScriptP ScriptableImage::getValidScriptP() { if (script) return script.getScriptP(); // return value or a blank image ScriptP s(new Script); diff --git a/src/script/image.hpp b/src/script/image.hpp index 9498cd0d..ab1761a0 100644 --- a/src/script/image.hpp +++ b/src/script/image.hpp @@ -54,9 +54,9 @@ class ScriptableImage { inline bool local() const { return value && value->local(); } /// Get access to the script, be careful - inline Script& getScript() { return script.getScript(); } + inline Script& getMutableScript() { return script.getMutableScript(); } /// Get access to the script, always returns a valid script - ScriptP getScriptP(); + ScriptP getValidScriptP(); protected: OptionalScript script; ///< The script, not really optional diff --git a/src/script/scriptable.cpp b/src/script/scriptable.cpp index 8ea4ed50..6f343063 100644 --- a/src/script/scriptable.cpp +++ b/src/script/scriptable.cpp @@ -75,7 +75,7 @@ void OptionalScript::initDependencies(Context& ctx, const Dependency& dep) const } } -Script& OptionalScript::getScript() { +Script& OptionalScript::getMutableScript() { if (!script) script = new_intrusive