Implement unique IDs and card linking

This commit is contained in:
GenevensiS
2025-08-11 16:17:13 +02:00
committed by GitHub
parent 13406b946c
commit 3bf9de18b1
100 changed files with 2432 additions and 1219 deletions
+72 -26
View File
@@ -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));