mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Merge pull request #20 from haganbmj/extra_card_fields
feat: expose extra_card and extra_card_style script accessible variables
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ Features:
|
||||
* Center align the loaded image by default in the Image Slice Window.
|
||||
* Add Buttons to Align the loaded image in the Image Slice Window. (haganbmj/#18)
|
||||
* Add filter box to Game and Stylesheet selection. (haganbmj/#1)
|
||||
* Add `extra_card("field name")` script function for accessing Extra Card Fields. (haganbmj/#2)
|
||||
* Expose `extra_card` and `extra_card_style` script for accessing Extra Card Fields/Styles. (haganbmj/#20)
|
||||
* Add Clear button to console panel. (haganbmj/#4)
|
||||
* Store images internally with PNG extension for ease of manual tinkering. (haganbmj/#5)
|
||||
* Add ability to change scale (relative to template) of internally stored images. (haganbmj/#6, haganbmj/#15)
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
Function: extra_data
|
||||
|
||||
DOC_MSE_VERSION: since 2.2.0
|
||||
|
||||
--Usage--
|
||||
> extra_data("field_name")
|
||||
|
||||
Access the value of extra card fields.
|
||||
|
||||
Due to lazy initialization of stylesheet specific Extra Card Fields they are not exposed directly from the card using `card.field_name` syntax.
|
||||
As a workaround this function returns the Value of the specified field name for the active card using an access pattern that supports late resolution of the value for the active stylesheet.
|
||||
|
||||
--Parameters--
|
||||
! Parameter Type Description
|
||||
| @input@ [[type:string]] Field name, with or without underscores.
|
||||
|
||||
--Examples--
|
||||
|
||||
>extra card field:
|
||||
> ...
|
||||
> name: my first extra field
|
||||
>
|
||||
>extra card field:
|
||||
> ...
|
||||
> name: my second extra field
|
||||
> script:
|
||||
>> space_to_comma(extra_data("my first extra field")) + "!"
|
||||
@@ -65,8 +65,7 @@ These functions are built into the program, other [[type:function]]s can be defi
|
||||
| [[fun:english_plural|english_singular]] Find the singular of a word, @"cards" -> "card"@.
|
||||
| [[fun:process_english_hints]] Process the hints left by english_ functions in a keyword's reminder text.
|
||||
|
||||
! Fields and values <<<
|
||||
| [[fun:extra_data]] Access the value of extra card fields.
|
||||
! Fields and values <<<
|
||||
| [[fun:combined_editor|forward_editor]] Use one field to edit another.
|
||||
| [[fun:combined_editor]] Use one field to edit multiple others.
|
||||
| [[fun:primary_choice]] Return the top level choice chosen from a choice field.
|
||||
|
||||
@@ -9,7 +9,9 @@ Aside from the [[fun:index|built in functions]] the following variables are prov
|
||||
The current stylesheet
|
||||
| @card@ [[type:card]] not in @init script@s or when exporting
|
||||
The current card.
|
||||
| @card_style@ [[type:indexmap]] of [[type:style]]s where @card@ is available Style properties for the current card, the same as @stylesheet.card_style@.
|
||||
| @card_style@ [[type:indexmap]] of [[type:style]]s where @card@ is available Style properties for the current card, the same as @stylesheet.card_style@.
|
||||
| @extra_card@ [[type:indexmap]] of [[type:value]]s field values for the current card as defined by the stylesheet.
|
||||
| @extra_card_style@ [[type:indexmap]] of [[type:style]] where @card@ is available Style properties for the current card as added by the stylesheet.
|
||||
| @styling@ [[type:indexmap]] of [[type:value]]s where @card@ is available Styling options for the stylesheet/card.
|
||||
| @value@ [[type:value]] when evaluating a [[type:field]]'s @script@ or @default@ script Current value in the field.
|
||||
| @options@ [[type:indexmap]] of [[type:value]]s when exporting Options of the [[type:export template]].
|
||||
|
||||
@@ -382,26 +382,6 @@ SCRIPT_FUNCTION(count_chosen) {
|
||||
SCRIPT_RETURN(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Extra Card Fields
|
||||
|
||||
SCRIPT_FUNCTION(extra_data) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
SCRIPT_PARAM_C(CardP, card);
|
||||
SCRIPT_PARAM_C(StyleSheetP, stylesheet);
|
||||
|
||||
// Transform input to standard field name syntax.
|
||||
// Other functions are doing lookups for ValuePs, which I assume is doing some of this automatically.
|
||||
String canonical_field_name = canonical_name_form(input);
|
||||
|
||||
FOR_EACH(valueP, card->extraDataFor(*stylesheet)) {
|
||||
if (valueP->fieldP->name == canonical_field_name) {
|
||||
SCRIPT_RETURN(valueP);
|
||||
}
|
||||
}
|
||||
|
||||
return delay_error(ScriptErrorNoMember("extra_data()", input));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Init
|
||||
@@ -415,6 +395,5 @@ void init_script_editor_functions(Context& ctx) {
|
||||
ctx.setVariable(_("require_choice"), script_require_choice);
|
||||
ctx.setVariable(_("exclusive_choice"), script_exclusive_choice);
|
||||
ctx.setVariable(_("require_exclusive_choice"), script_require_exclusive_choice);
|
||||
ctx.setVariable(_("remove_choice"), script_remove_choice);
|
||||
ctx.setVariable(_("extra_data"), script_extra_data);
|
||||
ctx.setVariable(_("remove_choice"), script_remove_choice);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,9 @@ void init_script_variables() {
|
||||
Var(stylesheet);
|
||||
Var(card_style);
|
||||
Var(card);
|
||||
Var(styling);
|
||||
Var(styling);
|
||||
Var(extra_card_style);
|
||||
Var(extra_card);
|
||||
Var(value);
|
||||
Var(condition);
|
||||
Var(language);
|
||||
|
||||
@@ -141,7 +141,9 @@ enum Variable
|
||||
, SCRIPT_VAR_stylesheet
|
||||
, SCRIPT_VAR_card_style
|
||||
, SCRIPT_VAR_card
|
||||
, SCRIPT_VAR_styling
|
||||
, SCRIPT_VAR_styling
|
||||
, SCRIPT_VAR_extra_card_style
|
||||
, SCRIPT_VAR_extra_card
|
||||
, SCRIPT_VAR_value
|
||||
, SCRIPT_VAR_condition
|
||||
, SCRIPT_VAR_language
|
||||
|
||||
@@ -39,9 +39,16 @@ Context& SetScriptContext::getContext(const StyleSheetP& stylesheet) {
|
||||
ctx.setVariable(SCRIPT_VAR_set, make_intrusive<ScriptObject<Set*>>(&set));
|
||||
ctx.setVariable(SCRIPT_VAR_game, to_script(set.game));
|
||||
ctx.setVariable(SCRIPT_VAR_stylesheet, to_script(stylesheet));
|
||||
ctx.setVariable(SCRIPT_VAR_card_style, to_script(&stylesheet->card_style));
|
||||
ctx.setVariable(SCRIPT_VAR_card, set.cards.empty() ? script_nil : to_script(set.cards.front())); // dummy value
|
||||
ctx.setVariable(SCRIPT_VAR_styling, to_script(&set.stylingDataFor(*stylesheet)));
|
||||
ctx.setVariable(SCRIPT_VAR_card_style, to_script(&stylesheet->card_style));
|
||||
|
||||
// I'm not entirely clear on why a "dummy value" is necessary here.
|
||||
// It doesn't appear that these are getting accessed until a card is found anyways, so they don't trip any errors that I could see.
|
||||
// Retaining the format just for consistency in case there's something that I missed.
|
||||
ctx.setVariable(SCRIPT_VAR_card, set.cards.empty() ? script_nil : to_script(set.cards.front())); // dummy value
|
||||
ctx.setVariable(SCRIPT_VAR_styling, to_script(&set.stylingDataFor(*stylesheet)));
|
||||
ctx.setVariable(SCRIPT_VAR_extra_card_style, to_script(&stylesheet->extra_card_style)); // dummy value
|
||||
ctx.setVariable(SCRIPT_VAR_extra_card, set.cards.empty() ? script_nil : to_script(&set.cards.front()->extraDataFor(*stylesheet))); // dummy value
|
||||
|
||||
try {
|
||||
// perform init scripts, don't use a scope, variables stay bound in the context
|
||||
try {
|
||||
@@ -66,10 +73,14 @@ Context& SetScriptContext::getContext(const CardP& card) {
|
||||
Context& ctx = getContext(stylesheet);
|
||||
if (card) {
|
||||
ctx.setVariable(SCRIPT_VAR_card, to_script(card));
|
||||
ctx.setVariable(SCRIPT_VAR_styling, to_script(&set.stylingDataFor(card)));
|
||||
ctx.setVariable(SCRIPT_VAR_styling, to_script(&set.stylingDataFor(card)));
|
||||
ctx.setVariable(SCRIPT_VAR_extra_card_style, to_script(&stylesheet->extra_card_style));
|
||||
ctx.setVariable(SCRIPT_VAR_extra_card, to_script(&card->extraDataFor(*stylesheet)));
|
||||
} else {
|
||||
ctx.setVariable(SCRIPT_VAR_card, ScriptValueP());
|
||||
ctx.setVariable(SCRIPT_VAR_styling, to_script(&set.stylingDataFor(*stylesheet)));
|
||||
ctx.setVariable(SCRIPT_VAR_styling, to_script(&set.stylingDataFor(*stylesheet)));
|
||||
ctx.setVariable(SCRIPT_VAR_extra_card_style, script_nil);
|
||||
ctx.setVariable(SCRIPT_VAR_extra_card, script_nil);
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user