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
+3 -1
View File
@@ -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);
+3 -1
View File
@@ -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
+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_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;
}