From 2e680146125081256209121c2dca073f1b5105f6 Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Thu, 15 Jan 2026 18:08:34 +0100 Subject: [PATCH] make to_json work on StyleP and IndexMap --- src/gui/card_link_window.cpp | 1 + src/script/functions/basic.cpp | 5 ++-- src/script/functions/json.cpp | 42 ++++++++++++++++++++++++++++------ src/script/functions/json.hpp | 4 ++++ src/script/to_value.hpp | 1 - 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/gui/card_link_window.cpp b/src/gui/card_link_window.cpp index f710dae6..486bd924 100644 --- a/src/gui/card_link_window.cpp +++ b/src/gui/card_link_window.cpp @@ -67,6 +67,7 @@ void CardLinkWindow::getSelection(vector& out) const { void CardLinkWindow::setSelection(const vector& cards) { list->setSelection(cards); + queue_message(MESSAGE_WARNING, String("") << cards.size()); } void CardLinkWindow::setRelationType() { int index = relation_type->GetSelection(); diff --git a/src/script/functions/basic.cpp b/src/script/functions/basic.cpp index bad8f3a5..5bd850fa 100644 --- a/src/script/functions/basic.cpp +++ b/src/script/functions/basic.cpp @@ -271,10 +271,9 @@ SCRIPT_FUNCTION(to_json) { SCRIPT_PARAM_C(ScriptValueP, input); SCRIPT_PARAM_C(Set*, set); SCRIPT_PARAM_DEFAULT(bool, pretty_print, true); + SCRIPT_PARAM_DEFAULT(bool, console_print, false); boost::json::value jv = mse_to_json(input, set); - - queue_message(MESSAGE_ERROR, json_pretty_print(jv)); - + if (console_print) queue_message(MESSAGE_INFO, json_pretty_print(jv)); if (pretty_print) return to_script(json_pretty_print(jv)); else return to_script(json_ugly_print(jv)); } diff --git a/src/script/functions/json.cpp b/src/script/functions/json.cpp index 2ca44b8e..843ac9d0 100644 --- a/src/script/functions/json.cpp +++ b/src/script/functions/json.cpp @@ -502,6 +502,23 @@ boost::json::object mse_to_json(const CardP& card, const Set* set) { return cardv; } +boost::json::object mse_to_json(const StyleP& style) { + //style->update(set->getContext()); + boost::json::object stylev; + stylev.emplace("mse_object_type", "style"); + stylev.emplace("z_index", wxString::Format(wxT("%i"), style->z_index)); + stylev.emplace("tab_index", wxString::Format(wxT("%i"), style->tab_index)); + stylev.emplace("left", wxString::Format(wxT("%.2f"), style->left())); + stylev.emplace("top", wxString::Format(wxT("%.2f"), style->top())); + stylev.emplace("right", wxString::Format(wxT("%.2f"), style->right())); + stylev.emplace("bottom", wxString::Format(wxT("%.2f"), style->bottom())); + stylev.emplace("width", wxString::Format(wxT("%.2f"), style->width())); + stylev.emplace("height", wxString::Format(wxT("%.2f"), style->height())); + stylev.emplace("angle", wxString::Format(wxT("%.2f"), style->angle())); + stylev.emplace("visible", style->visible()); + return stylev; +} + boost::json::object mse_to_json(const Set* set) { boost::json::object setv; setv.emplace("mse_object_type", "set"); @@ -537,17 +554,28 @@ boost::json::object mse_to_json(const Set* set) { return setv; } +boost::json::object mse_to_json(const IndexMap& map) { + boost::json::object indexmapv; + indexmapv.emplace("mse_object_type", "index_map"); + for (auto it = map.begin(); it != map.end(); ++it) { + write(indexmapv, (*it)->fieldP->name, *it); + } + return indexmapv; +} + boost::json::value mse_to_json(const ScriptValueP& sv, Set* set) { - ScriptType type = sv->type(); // special types - if (ScriptObject* i = dynamic_cast*>(sv.get())) return mse_to_json(i->getValue()); - if (ScriptObject* t = dynamic_cast*>(sv.get())) return mse_to_json(t->getValue()); - if (ScriptObject* k = dynamic_cast*> (sv.get())) return mse_to_json(k->getValue()); - if (ScriptObject* c = dynamic_cast*> (sv.get())) return mse_to_json(c->getValue(), set); - if (ScriptObject* z = dynamic_cast*> (sv.get())) return mse_to_json(z->getValue().get()); - if (ScriptObject* s = dynamic_cast*> (sv.get())) return mse_to_json(s->getValue()); + if (ScriptObject* o = dynamic_cast*> (sv.get())) return mse_to_json( o->getValue()); + if (ScriptObject* o = dynamic_cast*> (sv.get())) return mse_to_json( o->getValue()); + if (ScriptObject* o = dynamic_cast*> (sv.get())) return mse_to_json( o->getValue()); + if (ScriptObject* o = dynamic_cast*> (sv.get())) return mse_to_json( o->getValue()); + if (ScriptObject* o = dynamic_cast*> (sv.get())) return mse_to_json( o->getValue(), set); + if (ScriptObject* o = dynamic_cast*> (sv.get())) return mse_to_json( o->getValue().get()); + if (ScriptObject* o = dynamic_cast*> (sv.get())) return mse_to_json( o->getValue()); + if (ScriptMap>* o = dynamic_cast>*>(sv.get())) return mse_to_json(*o->value); // primitive types + ScriptType type = sv->type(); if (type == SCRIPT_NIL) return boost::json::value(nullptr); if (type == SCRIPT_INT) return boost::json::value(sv->toInt()); if (type == SCRIPT_DOUBLE) return boost::json::value(sv->toDouble()); diff --git a/src/script/functions/json.hpp b/src/script/functions/json.hpp index c9b1a128..40f0a32e 100644 --- a/src/script/functions/json.hpp +++ b/src/script/functions/json.hpp @@ -66,6 +66,10 @@ boost::json::object mse_to_json(const KeywordP& keyword); boost::json::object mse_to_json(const CardP& card, const Set* set); +boost::json::object mse_to_json(const StyleP& style); + boost::json::object mse_to_json(const Set* set); +boost::json::object mse_to_json(const IndexMap& map); + boost::json::value mse_to_json(const ScriptValueP& sv, Set* set); diff --git a/src/script/to_value.hpp b/src/script/to_value.hpp index eea710f3..6df826d0 100644 --- a/src/script/to_value.hpp +++ b/src/script/to_value.hpp @@ -185,7 +185,6 @@ public: compare_ptr = value; return COMPARE_AS_POINTER; } -private: /// Store a pointer to a collection, collections are only ever used for structures owned outside the script const Collection* value; };