mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
add add_card_to_set script function
make styling_data initializable in new_card script function
This commit is contained in:
@@ -37,7 +37,7 @@ SCRIPT_FUNCTION(new_card) {
|
||||
if (key == script_nil) continue;
|
||||
String key_name = key->toString();
|
||||
// check if the given value is for a built-in field
|
||||
if (set_builtin_container(game, new_card, value, key_name)) continue;
|
||||
if (set_builtin_container(game, new_card, value, key_name, ignore_field_not_found)) continue;
|
||||
// find the field value (container) that corresponds to the given value
|
||||
Value* container = get_container(game, new_card, key_name, ignore_field_not_found);
|
||||
if (container == nullptr) continue;
|
||||
@@ -59,7 +59,7 @@ SCRIPT_FUNCTION(new_card) {
|
||||
if (script_key == script_nil) continue;
|
||||
String script_key_name = script_key->toString();
|
||||
// check if the script value is for a built-in field
|
||||
if (set_builtin_container(game, new_card, script_value, script_key_name)) continue;
|
||||
if (set_builtin_container(game, new_card, script_value, script_key_name, ignore_field_not_found)) continue;
|
||||
// find the field value that corresponds to the script value
|
||||
Value* script_container = get_container(game, new_card, script_key_name, ignore_field_not_found);
|
||||
if (script_container == nullptr) continue;
|
||||
@@ -94,7 +94,7 @@ SCRIPT_FUNCTION(new_card) {
|
||||
if (script_key == script_nil) continue;
|
||||
String script_key_name = script_key->toString();
|
||||
// check if the script value is for a built-in field
|
||||
if (set_builtin_container(game, new_card, script_value, script_key_name)) continue;
|
||||
if (set_builtin_container(game, new_card, script_value, script_key_name, ignore_field_not_found)) continue;
|
||||
// find the field value that corresponds to the script value
|
||||
Value* script_container = get_container(game, new_card, script_key_name, ignore_field_not_found);
|
||||
if (script_container == nullptr) continue;
|
||||
@@ -110,9 +110,41 @@ SCRIPT_FUNCTION(new_card) {
|
||||
}
|
||||
SCRIPT_RETURN(new_card);
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(add_card_to_set) {
|
||||
SCRIPT_PARAM_C(ScriptValueP, input);
|
||||
SCRIPT_PARAM_C(ScriptValueP, set);
|
||||
ScriptObject<Set*>* s = dynamic_cast<ScriptObject<Set*>*>(set.get());
|
||||
if (s) {
|
||||
Set& _set = *s->getValue();
|
||||
ScriptObject<CardP>* c = dynamic_cast<ScriptObject<CardP>*>(input.get());
|
||||
if (c) {
|
||||
CardP _card = c->getValue();
|
||||
_set.actions.addAction(make_unique<AddCardAction>(ADD, _set, _card));
|
||||
SCRIPT_RETURN(true);
|
||||
}
|
||||
if (input->type() == SCRIPT_COLLECTION) {
|
||||
vector<CardP> _cards;
|
||||
ScriptValueP it = input->makeIterator();
|
||||
ScriptValueP key;
|
||||
while (ScriptValueP value = it->next(&key)) {
|
||||
c = dynamic_cast<ScriptObject<CardP>*>(value.get());
|
||||
if (c) {
|
||||
_cards.push_back(c->getValue());
|
||||
}
|
||||
}
|
||||
if (!_cards.empty()) {
|
||||
_set.actions.addAction(make_unique<AddCardAction>(ADD, _set, _cards));
|
||||
SCRIPT_RETURN(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
SCRIPT_RETURN(false);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Init
|
||||
|
||||
void init_script_construction_functions(Context& ctx) {
|
||||
ctx.setVariable(_("new_card"), script_new_card);
|
||||
ctx.setVariable(_("add_card_to_set"), script_add_card_to_set);
|
||||
}
|
||||
|
||||
@@ -61,24 +61,80 @@ static void set_container(Value* container, ScriptValueP& value, String key_name
|
||||
}
|
||||
}
|
||||
|
||||
static bool set_builtin_container(GameP& game, CardP& card, ScriptValueP& value, String key_name) {
|
||||
static bool set_builtin_container(GameP& game, CardP& card, ScriptValueP& value, String key_name, bool ignore_field_not_found) {
|
||||
// check if the given value is for a built-in field, if found set it and return true
|
||||
key_name = unified_form(key_name);
|
||||
if (key_name == _("notes") || key_name == _("note")) {
|
||||
card->notes = value->toString();
|
||||
return true;
|
||||
} else if (key_name == _("style") || key_name == _("stylesheet") || key_name == _("template")) {
|
||||
if (trim(value->toString()) != wxEmptyString) card->stylesheet = StyleSheet::byGameAndName(*game, value->toString());
|
||||
if (trim(value->toString()) != wxEmptyString) {
|
||||
card->stylesheet = StyleSheet::byGameAndName(*game, value->toString());
|
||||
if (card->stylesheet) card->styling_data.init(card->stylesheet->styling_fields);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// else if (key_name == _("id") || key_name == _("multiverse_id")) {
|
||||
// card->id = value->toString();
|
||||
//else if (key_name == _("id") || key_name == _("uid")) {
|
||||
// card->uid = value->toString();
|
||||
// return true;
|
||||
//}
|
||||
|
||||
//styling_data;
|
||||
//linked_card;
|
||||
//linked_relation_1;
|
||||
//else if (key_name == _("linked_card") || key_name == _("linked_card_1")) {
|
||||
// card->linked_card_1 = value->toString();
|
||||
// return true;
|
||||
//}
|
||||
//else if (key_name == _("linked_card_2")) {
|
||||
// card->linked_card_2 = value->toString();
|
||||
// return true;
|
||||
//}
|
||||
//else if (key_name == _("linked_card_3")) {
|
||||
// card->linked_card_3 = value->toString();
|
||||
// return true;
|
||||
//}
|
||||
//else if (key_name == _("linked_card_4")) {
|
||||
// card->linked_card_4 = value->toString();
|
||||
// return true;
|
||||
//}
|
||||
//else if (key_name == _("linked_relation") || key_name == _("linked_relation_1")) {
|
||||
// card->linked_relation_1 = value->toString();
|
||||
// return true;
|
||||
//}
|
||||
//else if (key_name == _("linked_relation_2")) {
|
||||
// card->linked_relation_2 = value->toString();
|
||||
// return true;
|
||||
//}
|
||||
//else if (key_name == _("linked_relation_3")) {
|
||||
// card->linked_relation_3 = value->toString();
|
||||
// return true;
|
||||
//}
|
||||
//else if (key_name == _("linked_relation_4")) {
|
||||
// card->linked_relation_4 = value->toString();
|
||||
// return true;
|
||||
//}
|
||||
else if (key_name == _("styling_data") || key_name == _("style_data") || key_name == _("stylesheet_data") || key_name == _("template_data") || key_name == _("styling")
|
||||
|| key_name == _("styling_fields") || key_name == _("style_fields") || key_name == _("stylesheet_fields") || key_name == _("template_fields")) {
|
||||
if (value->type() != SCRIPT_COLLECTION) {
|
||||
throw ScriptError(_ERROR_("styling data not map"));
|
||||
}
|
||||
ScriptValueP value_it = value->makeIterator();
|
||||
ScriptValueP value_key;
|
||||
while (ScriptValueP value_value = value_it->next(&value_key)) {
|
||||
assert(value_key);
|
||||
if (value_key == script_nil) continue;
|
||||
String value_key_name = value_key->toString();
|
||||
IndexMap<FieldP, ValueP>::const_iterator style_it = card->styling_data.find(value_key_name);
|
||||
if (style_it == card->styling_data.end()) {
|
||||
style_it = card->styling_data.find(value_key_name.Lower());
|
||||
if (style_it == card->styling_data.end()) {
|
||||
if (!ignore_field_not_found) throw ScriptError(_ERROR_1_("no style field with name", value_key_name));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Value* value_container = style_it->get();
|
||||
set_container(value_container, value_value, value_key_name);
|
||||
card->has_styling = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user