feat: expose extra_card and extra_card_style script accessible variables

This commit is contained in:
Brendan Hagan
2022-07-14 17:30:45 -04:00
parent 42a973e6f7
commit 4f7fa585f7
4 changed files with 23 additions and 8 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ Features:
* Center align the loaded image by default in the Image Slice Window. * 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 Buttons to Align the loaded image in the Image Slice Window. (haganbmj/#18)
* Add filter box to Game and Stylesheet selection. (haganbmj/#1) * Add filter box to Game and Stylesheet selection. (haganbmj/#1)
* Add `extra_card("field name")` script function for accessing Extra Card Fields. (haganbmj/#2) * Add `extra_data("field name")` script function for accessing Extra Card Fields. (haganbmj/#2)
* Add Clear button to console panel. (haganbmj/#4) * Add Clear button to console panel. (haganbmj/#4)
* Store images internally with PNG extension for ease of manual tinkering. (haganbmj/#5) * 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) * Add ability to change scale (relative to template) of internally stored images. (haganbmj/#6, haganbmj/#15)
+3 -1
View File
@@ -73,7 +73,9 @@ void init_script_variables() {
Var(stylesheet); Var(stylesheet);
Var(card_style); Var(card_style);
Var(card); Var(card);
Var(styling); Var(styling);
Var(extra_card_style);
Var(extra_card);
Var(value); Var(value);
Var(condition); Var(condition);
Var(language); Var(language);
+3 -1
View File
@@ -141,7 +141,9 @@ enum Variable
, SCRIPT_VAR_stylesheet , SCRIPT_VAR_stylesheet
, SCRIPT_VAR_card_style , SCRIPT_VAR_card_style
, SCRIPT_VAR_card , SCRIPT_VAR_card
, SCRIPT_VAR_styling , SCRIPT_VAR_styling
, SCRIPT_VAR_extra_card_style
, SCRIPT_VAR_extra_card
, SCRIPT_VAR_value , SCRIPT_VAR_value
, SCRIPT_VAR_condition , SCRIPT_VAR_condition
, SCRIPT_VAR_language , SCRIPT_VAR_language
+16 -5
View File
@@ -39,9 +39,16 @@ Context& SetScriptContext::getContext(const StyleSheetP& stylesheet) {
ctx.setVariable(SCRIPT_VAR_set, make_intrusive<ScriptObject<Set*>>(&set)); ctx.setVariable(SCRIPT_VAR_set, make_intrusive<ScriptObject<Set*>>(&set));
ctx.setVariable(SCRIPT_VAR_game, to_script(set.game)); ctx.setVariable(SCRIPT_VAR_game, to_script(set.game));
ctx.setVariable(SCRIPT_VAR_stylesheet, to_script(stylesheet)); ctx.setVariable(SCRIPT_VAR_stylesheet, to_script(stylesheet));
ctx.setVariable(SCRIPT_VAR_card_style, to_script(&stylesheet->card_style)); 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))); // 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 { try {
// perform init scripts, don't use a scope, variables stay bound in the context // perform init scripts, don't use a scope, variables stay bound in the context
try { try {
@@ -66,10 +73,14 @@ Context& SetScriptContext::getContext(const CardP& card) {
Context& ctx = getContext(stylesheet); Context& ctx = getContext(stylesheet);
if (card) { if (card) {
ctx.setVariable(SCRIPT_VAR_card, to_script(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 { } else {
ctx.setVariable(SCRIPT_VAR_card, ScriptValueP()); 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; return ctx;
} }