diff --git a/CHANGES.md b/CHANGES.md index bb224eca..a31f4fcb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) + * Add `extra_data("field name")` script function for accessing Extra Card Fields. (haganbmj/#2) * 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) diff --git a/src/script/script.cpp b/src/script/script.cpp index 976f449c..2679d1d9 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -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); diff --git a/src/script/script.hpp b/src/script/script.hpp index 96a71e68..12db619e 100644 --- a/src/script/script.hpp +++ b/src/script/script.hpp @@ -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 diff --git a/src/script/script_manager.cpp b/src/script/script_manager.cpp index ec1c481c..32a762d3 100644 --- a/src/script/script_manager.cpp +++ b/src/script/script_manager.cpp @@ -39,9 +39,16 @@ Context& SetScriptContext::getContext(const StyleSheetP& stylesheet) { ctx.setVariable(SCRIPT_VAR_set, make_intrusive>(&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; }