mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
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
This commit is contained in:
@@ -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--
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -75,7 +75,7 @@ void OptionalScript::initDependencies(Context& ctx, const Dependency& dep) const
|
||||
}
|
||||
}
|
||||
|
||||
Script& OptionalScript::getScript() {
|
||||
Script& OptionalScript::getMutableScript() {
|
||||
if (!script) script = new_intrusive<Script>();
|
||||
return *script;
|
||||
}
|
||||
|
||||
@@ -84,11 +84,13 @@ class OptionalScript {
|
||||
void initDependencies(Context&, const Dependency& dep) const;
|
||||
|
||||
/// Get access to the script, be careful
|
||||
Script& getScript();
|
||||
inline ScriptP& getScriptP() { return script; }
|
||||
Script& getMutableScript();
|
||||
inline ScriptP getScriptP() const { return script; }
|
||||
inline void setScriptP(const ScriptP& new_script) { script = new_script; }
|
||||
/// Get access to the unparsed value
|
||||
inline String& getUnparsed() { return unparsed; }
|
||||
inline const String& getUnparsed() const { return unparsed; }
|
||||
inline const String& getUnparsed() const { return unparsed; }
|
||||
inline String& getMutableUnparsed() { return unparsed; }
|
||||
inline void setUnparsed(String& new_unparsed) { unparsed = new_unparsed; }
|
||||
|
||||
protected:
|
||||
ScriptP script; ///< The script, may be null if there is no script
|
||||
|
||||
Reference in New Issue
Block a user