mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Implement unique IDs and card linking
This commit is contained in:
@@ -279,14 +279,14 @@ void Context::setVariable(Variable name, const ScriptValueP& value) {
|
||||
// keep shadow copy
|
||||
Binding bind = {name, var};
|
||||
shadowed.push_back(bind);
|
||||
}
|
||||
if (!var.global_scope) {
|
||||
var.global_scope = false;
|
||||
}
|
||||
if (!var.global_scope) {
|
||||
var.global_scope = false;
|
||||
}
|
||||
var.level = level;
|
||||
var.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Context::setGlobalVariable(Variable name, const ScriptValueP& value) {
|
||||
#ifdef _DEBUG
|
||||
assert((size_t)name < variable_names.size());
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
/// Set a variable to a new value (in the current scope)
|
||||
void setVariable(const String& name, const ScriptValueP& value);
|
||||
/// Set a variable to a new value (in the current scope)
|
||||
void setVariable(Variable name, const ScriptValueP& value);
|
||||
void setVariable(Variable name, const ScriptValueP& value);
|
||||
void setGlobalVariable(Variable name, const ScriptValueP& value);
|
||||
|
||||
/// Get the value of a variable, throws if it not set
|
||||
@@ -89,7 +89,7 @@ public:// public for FOR_EACH
|
||||
struct VariableValue {
|
||||
VariableValue() : level(0) {}
|
||||
unsigned int level; ///< Scope level on which this variable was set
|
||||
ScriptValueP value; ///< Value of this variable
|
||||
ScriptValueP value; ///< Value of this variable
|
||||
bool global_scope = false; ///< Is this variable globally scoped?
|
||||
};
|
||||
/// Record of a variable binding that is being shadowed (overwritten) by another binding
|
||||
|
||||
@@ -25,21 +25,24 @@
|
||||
#include <wx/stdpaths.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <boost/json.hpp>
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : Debugging
|
||||
|
||||
SCRIPT_FUNCTION(get_mse_version) {
|
||||
SCRIPT_RETURN(app_version.toString());
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(get_mse_path) {
|
||||
wxFileName app_path(wxStandardPaths::Get().GetExecutablePath());
|
||||
String app_folder = app_path.GetPath();
|
||||
SCRIPT_FUNCTION(get_mse_path) {
|
||||
wxFileName app_path(wxStandardPaths::Get().GetExecutablePath());
|
||||
String app_folder = app_path.GetPath();
|
||||
app_folder.Replace("\\", "/");
|
||||
SCRIPT_RETURN(app_folder);
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(get_mse_locale) {
|
||||
SCRIPT_RETURN(settings.locale);
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(trace) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
#if defined(_DEBUG) && 0
|
||||
@@ -82,13 +85,13 @@ SCRIPT_FUNCTION(error) {
|
||||
queue_message(MESSAGE_ERROR, input);
|
||||
}
|
||||
return script_nil;
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(exists_in_package) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
bool result = package_manager.existsInPackage(input);
|
||||
SCRIPT_RETURN(result);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Conversion
|
||||
|
||||
@@ -264,11 +267,11 @@ SCRIPT_FUNCTION(to_code) {
|
||||
SCRIPT_FUNCTION(to_json) {
|
||||
SCRIPT_PARAM_C(ScriptValueP, input);
|
||||
SCRIPT_PARAM_C(Set*, set);
|
||||
SCRIPT_PARAM_DEFAULT(bool, pretty_print, true);
|
||||
boost::json::value jv = mse_to_json(input, set);
|
||||
SCRIPT_PARAM_DEFAULT(bool, pretty_print, true);
|
||||
boost::json::value jv = mse_to_json(input, set);
|
||||
|
||||
queue_message(MESSAGE_ERROR, json_pretty_print(jv));
|
||||
|
||||
queue_message(MESSAGE_ERROR, json_pretty_print(jv));
|
||||
|
||||
if (pretty_print) return to_script(json_pretty_print(jv));
|
||||
else return to_script(json_ugly_print(jv));
|
||||
}
|
||||
@@ -704,31 +707,31 @@ SCRIPT_FUNCTION(random_select_many) {
|
||||
ret->value.resize(count);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(make_map) {
|
||||
SCRIPT_PARAM(ScriptValueP, keys);
|
||||
SCRIPT_PARAM(ScriptValueP, values);
|
||||
ScriptValueP keys_it = keys->makeIterator();
|
||||
ScriptValueP key;
|
||||
ScriptValueP key;
|
||||
ScriptValueP values_it = values->makeIterator();
|
||||
ScriptValueP value;
|
||||
ScriptCustomCollectionP map = make_intrusive<ScriptCustomCollection>();
|
||||
while (key = keys_it->next()) {
|
||||
if (key == script_nil) continue;
|
||||
if (value = values_it->next()) {
|
||||
ScriptValueP value;
|
||||
ScriptCustomCollectionP map = make_intrusive<ScriptCustomCollection>();
|
||||
while (key = keys_it->next()) {
|
||||
if (key == script_nil) continue;
|
||||
if (value = values_it->next()) {
|
||||
map->key_value[key->toString()] = value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
queue_message(MESSAGE_WARNING, "More keys than values given in function make_map!");
|
||||
queue_message(MESSAGE_WARNING, "More keys than values given in function make_map!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (value = values_it->next()) {
|
||||
}
|
||||
if (value = values_it->next()) {
|
||||
queue_message(MESSAGE_WARNING, "More values than keys given in function make_map!");
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(get_card_styling) {
|
||||
SCRIPT_PARAM_C(ScriptValueP, input);
|
||||
@@ -752,6 +755,45 @@ SCRIPT_FUNCTION(get_card_stylesheet) {
|
||||
throw ScriptError(_("invalid set or card argument"));
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(get_card_from_uid) {
|
||||
SCRIPT_PARAM_C(Set*, set);
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
FOR_EACH(other_card, set->cards) {
|
||||
if (other_card->uid == input) SCRIPT_RETURN(other_card);
|
||||
}
|
||||
return script_nil;
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(get_card_from_link) {
|
||||
SCRIPT_PARAM_C(Set*, set);
|
||||
SCRIPT_PARAM_C(CardP, card);
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
String trimmed_input = input.Trim().Trim(false);
|
||||
String uid = card->linked_relation_1 == trimmed_input ? card->linked_card_1 :
|
||||
card->linked_relation_2 == trimmed_input ? card->linked_card_2 :
|
||||
card->linked_relation_3 == trimmed_input ? card->linked_card_3 :
|
||||
card->linked_relation_4 == trimmed_input ? card->linked_card_4 :
|
||||
wxEmptyString;
|
||||
if (uid == wxEmptyString) return script_nil;
|
||||
FOR_EACH(other_card, set->cards) {
|
||||
if (other_card->uid == uid) SCRIPT_RETURN(other_card);
|
||||
}
|
||||
return script_nil;
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(has_link) {
|
||||
SCRIPT_PARAM_C(CardP, card);
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
String trimmed_input = input.Trim().Trim(false);
|
||||
if (
|
||||
card->linked_relation_1 == trimmed_input ||
|
||||
card->linked_relation_2 == trimmed_input ||
|
||||
card->linked_relation_3 == trimmed_input ||
|
||||
card->linked_relation_4 == trimmed_input
|
||||
) SCRIPT_RETURN(true);
|
||||
SCRIPT_RETURN(false);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Keywords
|
||||
|
||||
|
||||
@@ -826,6 +868,7 @@ SCRIPT_FUNCTION(rule) {
|
||||
void init_script_basic_functions(Context& ctx) {
|
||||
// debugging
|
||||
ctx.setVariable(_("get_mse_version"), script_get_mse_version);
|
||||
ctx.setVariable(_("get_mse_locale"), script_get_mse_locale);
|
||||
ctx.setVariable(_("get_mse_path"), script_get_mse_path);
|
||||
ctx.setVariable(_("trace"), script_trace);
|
||||
ctx.setVariable(_("warning"), script_warning);
|
||||
@@ -842,8 +885,8 @@ void init_script_basic_functions(Context& ctx) {
|
||||
ctx.setVariable(_("to_code"), script_to_code);
|
||||
ctx.setVariable(_("to_json"), script_to_json);
|
||||
ctx.setVariable(_("from_json"), script_from_json);
|
||||
ctx.setVariable(_("type_name"), script_type_name);
|
||||
ctx.setVariable(_("make_map"), script_make_map);
|
||||
ctx.setVariable(_("type_name"), script_type_name);
|
||||
ctx.setVariable(_("make_map"), script_make_map);
|
||||
ctx.setVariable(_("get_card_styling"), script_get_card_styling);
|
||||
ctx.setVariable(_("get_card_stylesheet"), script_get_card_stylesheet);
|
||||
// math
|
||||
@@ -891,6 +934,9 @@ void init_script_basic_functions(Context& ctx) {
|
||||
ctx.setVariable(_("random_shuffle"), script_random_shuffle);
|
||||
ctx.setVariable(_("random_select"), script_random_select);
|
||||
ctx.setVariable(_("random_select_many"), script_random_select_many);
|
||||
ctx.setVariable(_("get_card_from_uid"), script_get_card_from_uid);
|
||||
ctx.setVariable(_("get_card_from_link"), script_get_card_from_link);
|
||||
ctx.setVariable(_("has_link"), script_has_link);
|
||||
// keyword
|
||||
ctx.setVariable(_("expand_keywords"), script_expand_keywords);
|
||||
ctx.setVariable(_("expand_keywords_rule"), make_intrusive<ScriptRule>(script_expand_keywords));
|
||||
|
||||
@@ -15,131 +15,131 @@
|
||||
#include <data/field/choice.hpp>
|
||||
#include <data/field/package_choice.hpp>
|
||||
#include <data/field/color.hpp>
|
||||
#include <data/field/image.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/field/image.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/card.hpp>
|
||||
#include <util/error.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : new_card
|
||||
// ----------------------------------------------------------------------------- : new_card
|
||||
|
||||
SCRIPT_FUNCTION(new_card) {
|
||||
SCRIPT_PARAM(GameP, game);
|
||||
SCRIPT_PARAM(GameP, game);
|
||||
SCRIPT_OPTIONAL_PARAM_(bool, ignore_field_not_found);
|
||||
// create a new card object
|
||||
CardP new_card = make_intrusive<Card>(*game);
|
||||
// iterate on the given key/value pairs
|
||||
SCRIPT_PARAM(ScriptValueP, input);
|
||||
ScriptValueP it = input->makeIterator();
|
||||
ScriptValueP key;
|
||||
ScriptValueP key;
|
||||
while (ScriptValueP value = it->next(&key)) {
|
||||
assert(key);
|
||||
if (key == script_nil) continue;
|
||||
String key_name = key->toString();
|
||||
// check if the given value is for a built-in field
|
||||
assert(key);
|
||||
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, ignore_field_not_found)) continue;
|
||||
// find the field value (container) that corresponds to the given value
|
||||
Value* container = get_card_field_container(*game, new_card->data, key_name, ignore_field_not_found);
|
||||
if (container == nullptr) continue;
|
||||
FieldP field = container->fieldP;
|
||||
// if the field has a construction script, set the value and card context variables to be the given value and this card, run script
|
||||
// find the field value (container) that corresponds to the given value
|
||||
Value* container = get_card_field_container(*game, new_card->data, key_name, ignore_field_not_found);
|
||||
if (container == nullptr) continue;
|
||||
FieldP field = container->fieldP;
|
||||
// if the field has a construction script, set the value and card context variables to be the given value and this card, run script
|
||||
if (field->import_script) {
|
||||
ScriptValueP ctx_value = ctx.getVariableOpt(SCRIPT_VAR_value);
|
||||
ScriptValueP ctx_card = ctx.getVariableOpt(SCRIPT_VAR_card);
|
||||
ctx.setVariable(SCRIPT_VAR_value, value);
|
||||
ctx.setVariable(SCRIPT_VAR_card, to_script(new_card));
|
||||
ScriptValueP script_input = field->import_script.invoke(ctx, true);
|
||||
// if the script result is a collection, iterate on the key/value pairs
|
||||
// treat the keys as field names and the values as what to populate those fields with
|
||||
if (script_input->type() == SCRIPT_COLLECTION) {
|
||||
ctx.setVariable(SCRIPT_VAR_value, value);
|
||||
ctx.setVariable(SCRIPT_VAR_card, to_script(new_card));
|
||||
ScriptValueP script_input = field->import_script.invoke(ctx, true);
|
||||
// if the script result is a collection, iterate on the key/value pairs
|
||||
// treat the keys as field names and the values as what to populate those fields with
|
||||
if (script_input->type() == SCRIPT_COLLECTION) {
|
||||
ScriptValueP script_it = script_input->makeIterator();
|
||||
ScriptValueP script_key;
|
||||
while (ScriptValueP script_value = script_it->next(&script_key)) {
|
||||
assert(script_key);
|
||||
ScriptValueP script_key;
|
||||
while (ScriptValueP script_value = script_it->next(&script_key)) {
|
||||
assert(script_key);
|
||||
if (script_key == script_nil) continue;
|
||||
String script_key_name = script_key->toString();
|
||||
// check if the script value is for a built-in field
|
||||
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, ignore_field_not_found)) continue;
|
||||
// find the field value that corresponds to the script value
|
||||
Value* script_container = get_card_field_container(*game, new_card->data, script_key_name, ignore_field_not_found);
|
||||
if (script_container == nullptr) continue;
|
||||
// set the field value to the script value
|
||||
set_container(script_container, script_value, script_key_name);
|
||||
}
|
||||
}
|
||||
// if the script result is not a collection, simply set the field value to the script value
|
||||
else {
|
||||
set_container(container, script_input, key_name);
|
||||
}
|
||||
// restore old value and card context variables
|
||||
if (ctx_value) ctx.setVariable(SCRIPT_VAR_value, ctx_value);
|
||||
// find the field value that corresponds to the script value
|
||||
Value* script_container = get_card_field_container(*game, new_card->data, script_key_name, ignore_field_not_found);
|
||||
if (script_container == nullptr) continue;
|
||||
// set the field value to the script value
|
||||
set_container(script_container, script_value, script_key_name);
|
||||
}
|
||||
}
|
||||
// if the script result is not a collection, simply set the field value to the script value
|
||||
else {
|
||||
set_container(container, script_input, key_name);
|
||||
}
|
||||
// restore old value and card context variables
|
||||
if (ctx_value) ctx.setVariable(SCRIPT_VAR_value, ctx_value);
|
||||
if (ctx_card) ctx.setVariable(SCRIPT_VAR_card, ctx_card);
|
||||
}
|
||||
// if the field has no construction script, simply set the field value to the given value
|
||||
else {
|
||||
set_container(container, value, key_name);
|
||||
}
|
||||
}
|
||||
// if the game has a construction script, set the card context variable to be this card, run script
|
||||
}
|
||||
}
|
||||
// if the game has a construction script, set the card context variable to be this card, run script
|
||||
if (game->import_script) {
|
||||
ScriptValueP ctx_card = ctx.getVariableOpt(SCRIPT_VAR_card);
|
||||
ctx.setVariable(SCRIPT_VAR_card, to_script(new_card));
|
||||
ScriptValueP script_input = game->import_script.invoke(ctx, true);
|
||||
if (script_input->type() == SCRIPT_COLLECTION) {
|
||||
ctx.setVariable(SCRIPT_VAR_card, to_script(new_card));
|
||||
ScriptValueP script_input = game->import_script.invoke(ctx, true);
|
||||
if (script_input->type() == SCRIPT_COLLECTION) {
|
||||
// iterate on the key/value pairs given by the script
|
||||
ScriptValueP script_it = script_input->makeIterator();
|
||||
ScriptValueP script_key;
|
||||
while (ScriptValueP script_value = script_it->next(&script_key)) {
|
||||
assert(script_key);
|
||||
ScriptValueP script_key;
|
||||
while (ScriptValueP script_value = script_it->next(&script_key)) {
|
||||
assert(script_key);
|
||||
if (script_key == script_nil) continue;
|
||||
String script_key_name = script_key->toString();
|
||||
// check if the script value is for a built-in field
|
||||
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, ignore_field_not_found)) continue;
|
||||
// find the field value that corresponds to the script value
|
||||
Value* script_container = get_card_field_container(*game, new_card->data, script_key_name, ignore_field_not_found);
|
||||
if (script_container == nullptr) continue;
|
||||
// set the field value to the script value
|
||||
set_container(script_container, script_value, script_key_name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
queue_message(MESSAGE_ERROR, _ERROR_("game import script not map"));
|
||||
}
|
||||
// restore old context card
|
||||
// find the field value that corresponds to the script value
|
||||
Value* script_container = get_card_field_container(*game, new_card->data, script_key_name, ignore_field_not_found);
|
||||
if (script_container == nullptr) continue;
|
||||
// set the field value to the script value
|
||||
set_container(script_container, script_value, script_key_name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
queue_message(MESSAGE_ERROR, _ERROR_("game import script not map"));
|
||||
}
|
||||
// restore old context card
|
||||
if (ctx_card) ctx.setVariable(SCRIPT_VAR_card, ctx_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) {
|
||||
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;
|
||||
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());
|
||||
}
|
||||
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));
|
||||
_set.actions.addAction(make_unique<AddCardAction>(ADD, _set, _cards));
|
||||
SCRIPT_RETURN(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SCRIPT_RETURN(false);
|
||||
}
|
||||
SCRIPT_RETURN(false);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Init
|
||||
|
||||
@@ -152,7 +152,7 @@ SCRIPT_FUNCTION(english_number_ordinal) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Singular/plural
|
||||
|
||||
String english_singular(const String& str) {
|
||||
String english_singular(const String& str) {
|
||||
if (str.Lower() == _("plains")) return str;
|
||||
if (str.size() > 3 && is_substr(str, str.size()-3, _("ies"))) {
|
||||
return str.substr(0, str.size() - 3) + _("y");
|
||||
|
||||
@@ -54,9 +54,9 @@ String get_export_full_path(String& rel_name) {
|
||||
return fn.GetFullPath();
|
||||
}
|
||||
|
||||
void ensure_dir_valid(String& path) {
|
||||
void ensure_dir_valid(String& path) {
|
||||
if (!wxDirExists(path)) {
|
||||
wxFileName filename = path;
|
||||
wxFileName filename = path;
|
||||
filename.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ String to_html(const String& str_in, const SymbolFontP& symbol_font, double symb
|
||||
String str = remove_tag_contents(str_in,_("<sep-soft"));
|
||||
String ret;
|
||||
Tag bold (_("<b>"), _("</b>")),
|
||||
italic(_("<i>"), _("</i>")),
|
||||
italic(_("<i>"), _("</i>")),
|
||||
underline(_("<u>"), _("</u>")),
|
||||
symbol(_("<span class=\"symbol\">"), _("</span>"));
|
||||
TagStack tags;
|
||||
@@ -232,7 +232,7 @@ String to_html(const String& str_in, const SymbolFontP& symbol_font, double symb
|
||||
} else if (is_substr(str, i, _("i"))) {
|
||||
tags.open (ret, italic);
|
||||
} else if (is_substr(str, i, _("/i"))) {
|
||||
tags.close(ret, italic);
|
||||
tags.close(ret, italic);
|
||||
} else if (is_substr(str, i, _("u"))) {
|
||||
tags.open(ret, underline);
|
||||
} else if (is_substr(str, i, _("/u"))) {
|
||||
@@ -312,7 +312,7 @@ String to_bbcode(const String& str_in) {
|
||||
String str = remove_tag_contents(str_in,_("<sep-soft"));
|
||||
String ret;
|
||||
Tag bold (_("[b]"), _("[/b]")),
|
||||
italic(_("[i]"), _("[/i]")),
|
||||
italic(_("[i]"), _("[/i]")),
|
||||
underline(_("[u]"), _("[/u]"));
|
||||
TagStack tags;
|
||||
String symbols;
|
||||
@@ -332,7 +332,7 @@ String to_bbcode(const String& str_in) {
|
||||
tags.open(ret, underline);
|
||||
} else if (is_substr(str, i, _("/u"))) {
|
||||
tags.close(ret, underline);
|
||||
}
|
||||
}
|
||||
/*else if (is_substr(str, i, _("sym"))) {
|
||||
tags.open (ret, symbol);
|
||||
} else if (is_substr(str, i, _("/sym"))) {
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
#include <data/card.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/symbol.hpp>
|
||||
#include <data/field/symbol.hpp>
|
||||
#include <data/field/symbol.hpp>
|
||||
#include <data/format/formats.hpp>
|
||||
#include <gfx/generated_image.hpp>
|
||||
#include <render/symbol/filter.hpp>
|
||||
#include <cli/text_io_handler.hpp> // for MSE_CLI
|
||||
#include <cli/text_io_handler.hpp> // for MSE_CLI
|
||||
|
||||
void parse_enum(const String&, ImageCombine& out);
|
||||
|
||||
@@ -29,45 +29,55 @@ SCRIPT_FUNCTION(to_image) {
|
||||
SCRIPT_PARAM_C(GeneratedImageP, input);
|
||||
return input;
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(to_card_image) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(CardP, input);
|
||||
SCRIPT_PARAM_DEFAULT(double, zoom, 100);
|
||||
SCRIPT_PARAM_DEFAULT(Degrees, angle, 0);
|
||||
SCRIPT_PARAM_DEFAULT(bool, use_user_settings, false);
|
||||
if (use_user_settings) {
|
||||
// Use the User's Preferences for Export Zoom and Angle settings.
|
||||
return make_intrusive<ArbitraryImage>(export_bitmap(set, input).ConvertToImage());
|
||||
} else {
|
||||
// Use the provided (or defaulted) Zoom and Angle.
|
||||
return make_intrusive<ArbitraryImage>(export_bitmap(set, input, (zoom / 100), deg_to_rad(angle)).ConvertToImage());
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(import_image) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(String, input);
|
||||
auto extImg = make_intrusive<ExternalImage>(input);
|
||||
if (cli.haveConsole()) // makes sure generate() is called, but only once, when using the CLI
|
||||
extImg->generate(GeneratedImage::Options(0, 0, set->stylesheet.get(), set));
|
||||
return extImg;
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(to_card_image) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(CardP, input);
|
||||
SCRIPT_PARAM_DEFAULT(double, zoom, 100);
|
||||
SCRIPT_PARAM_DEFAULT(Degrees, angle, 0);
|
||||
SCRIPT_PARAM_DEFAULT(bool, use_user_settings, false);
|
||||
if (use_user_settings) {
|
||||
// Use the User's Preferences for Export Zoom and Angle settings.
|
||||
return make_intrusive<ArbitraryImage>(export_bitmap(set, input).ConvertToImage());
|
||||
} else {
|
||||
// Use the provided (or defaulted) Zoom and Angle.
|
||||
return make_intrusive<ArbitraryImage>(export_bitmap(set, input, (zoom / 100), deg_to_rad(angle)).ConvertToImage());
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(import_image) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(String, input);
|
||||
auto extImg = make_intrusive<ExternalImage>(input);
|
||||
if (cli.haveConsole()) // makes sure generate() is called, but only once, when using the CLI
|
||||
extImg->generate(GeneratedImage::Options(0, 0, set->stylesheet.get(), set));
|
||||
return extImg;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Image functions
|
||||
|
||||
SCRIPT_FUNCTION(width_of) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, set->stylesheet.get()));
|
||||
SCRIPT_RETURN(image.GetWidth());
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(height_of) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, set->stylesheet.get()));
|
||||
SCRIPT_RETURN(image.GetHeight());
|
||||
|
||||
SCRIPT_FUNCTION(width_of) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, set->stylesheet.get()));
|
||||
SCRIPT_RETURN(image.GetWidth());
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(height_of) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, set->stylesheet.get()));
|
||||
SCRIPT_RETURN(image.GetHeight());
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(dimensions_of) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, set->stylesheet.get()));
|
||||
ScriptCustomCollectionP ret(new ScriptCustomCollection());
|
||||
ret->value.push_back(to_script(image.GetWidth()));
|
||||
ret->value.push_back(to_script(image.GetHeight()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(insert_image) {
|
||||
@@ -77,7 +87,7 @@ SCRIPT_FUNCTION(insert_image) {
|
||||
SCRIPT_PARAM(int, offset_y);
|
||||
SCRIPT_OPTIONAL_PARAM_(Color, background_color);
|
||||
return make_intrusive<InsertedImage>(base_image, inserted_image, offset_x, offset_y, background_color);
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(linear_blend) {
|
||||
SCRIPT_PARAM(GeneratedImageP, image1);
|
||||
@@ -273,10 +283,11 @@ SCRIPT_FUNCTION(built_in_image) {
|
||||
// ----------------------------------------------------------------------------- : Init
|
||||
|
||||
void init_script_image_functions(Context& ctx) {
|
||||
ctx.setVariable(_("to_image"), script_to_image);
|
||||
ctx.setVariable(_("to_card_image"), script_to_card_image);
|
||||
ctx.setVariable(_("width_of"), script_width_of);
|
||||
ctx.setVariable(_("to_image"), script_to_image);
|
||||
ctx.setVariable(_("to_card_image"), script_to_card_image);
|
||||
ctx.setVariable(_("width_of"), script_width_of);
|
||||
ctx.setVariable(_("height_of"), script_height_of);
|
||||
ctx.setVariable(_("dimensions_of"), script_dimensions_of);
|
||||
ctx.setVariable(_("linear_blend"), script_linear_blend);
|
||||
ctx.setVariable(_("masked_blend"), script_masked_blend);
|
||||
ctx.setVariable(_("combine_blend"), script_combine_blend);
|
||||
@@ -298,5 +309,5 @@ void init_script_image_functions(Context& ctx) {
|
||||
ctx.setVariable(_("drop_shadow"), script_drop_shadow);
|
||||
ctx.setVariable(_("symbol_variation"), script_symbol_variation);
|
||||
ctx.setVariable(_("built_in_image"), script_built_in_image);
|
||||
ctx.setVariable(_("import_image"), script_import_image);
|
||||
ctx.setVariable(_("import_image"), script_import_image);
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ void TokenIterator::readToken() {
|
||||
newline = true;
|
||||
} else if (isSpace(c)) {
|
||||
++pos;
|
||||
// ignore
|
||||
// ignore
|
||||
} else if (is_substr(pos, end, "include localized file:")) {
|
||||
pos += 23; // "include localized file:"
|
||||
const char* newlines = "\r\n";
|
||||
|
||||
@@ -73,8 +73,8 @@ void init_script_variables() {
|
||||
Var(stylesheet);
|
||||
Var(card_style);
|
||||
Var(card);
|
||||
Var(styling);
|
||||
Var(extra_card_style);
|
||||
Var(styling);
|
||||
Var(extra_card_style);
|
||||
Var(extra_card);
|
||||
Var(value);
|
||||
Var(condition);
|
||||
|
||||
@@ -142,8 +142,8 @@ enum Variable
|
||||
, SCRIPT_VAR_stylesheet
|
||||
, SCRIPT_VAR_card_style
|
||||
, SCRIPT_VAR_card
|
||||
, SCRIPT_VAR_styling
|
||||
, SCRIPT_VAR_extra_card_style
|
||||
, SCRIPT_VAR_styling
|
||||
, SCRIPT_VAR_extra_card_style
|
||||
, SCRIPT_VAR_extra_card
|
||||
, SCRIPT_VAR_value
|
||||
, SCRIPT_VAR_condition
|
||||
|
||||
@@ -39,14 +39,14 @@ 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));
|
||||
|
||||
// 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.
|
||||
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_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 {
|
||||
@@ -73,13 +73,13 @@ 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_extra_card_style, to_script(&stylesheet->extra_card_style));
|
||||
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_extra_card_style, script_nil);
|
||||
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