From 0026a9f9d250a05d6e85ba97c9c5b228e5f3c040 Mon Sep 17 00:00:00 2001 From: Ada Date: Fri, 28 Feb 2025 03:34:39 +1000 Subject: [PATCH] CanvasCommand serialisation fix, metatype still broken --- libraries/script-engine/src/CanvasCommand.cpp | 13 +++++++------ libraries/script-engine/src/CanvasCommand.h | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/script-engine/src/CanvasCommand.cpp b/libraries/script-engine/src/CanvasCommand.cpp index d8a8d33319..ca837acc10 100644 --- a/libraries/script-engine/src/CanvasCommand.cpp +++ b/libraries/script-engine/src/CanvasCommand.cpp @@ -19,11 +19,12 @@ #include "ScriptValue.h" #include "ScriptManager.h" #include "ScriptValueUtils.h" +#include "v8/FastScriptValueUtils.h" STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){ auto scriptEngine = manager->engine().get(); - scriptRegisterMetaType(scriptEngine); + scriptRegisterMetaType(scriptEngine, "CanvasCommand"); scriptRegisterMetaType(scriptEngine, "CanvasImage"); scriptRegisterMetaType(scriptEngine, "CanvasPath"); scriptRegisterMetaType, qVectorCanvasCommandToScriptValue, qVectorCanvasCommandFromScriptValue>(scriptEngine); @@ -51,7 +52,7 @@ ScriptValue canvasCommandToScriptValue(ScriptEngine* engine, const CanvasCommand case Variant::SetColor: { auto props = cmd._setColor; - obj.setProperty("color", props.color); + obj.setProperty("color", u8vec3ColorToScriptValue(engine, glm::u8vec3(props.color.red(), props.color.green(), props.color.blue()))); return obj; } @@ -78,7 +79,7 @@ ScriptValue canvasCommandToScriptValue(ScriptEngine* engine, const CanvasCommand case Variant::FillPath: { auto props = cmd._fillPath; - obj.setProperty("path", props.path); + obj.setProperty("path", qPainterPathToScriptValue(engine, props.path)); return obj; } @@ -113,7 +114,7 @@ ScriptValue canvasCommandToScriptValue(ScriptEngine* engine, const CanvasCommand case Variant::StrokePath: { auto props = cmd._strokePath; - obj.setProperty("path", props.path); + obj.setProperty("path", qPainterPathToScriptValue(engine, props.path)); return obj; } @@ -172,7 +173,7 @@ ScriptValue canvasCommandToScriptValue(ScriptEngine* engine, const CanvasCommand obj.setProperty("destY", props.dst.y()); obj.setProperty("destW", props.dst.width()); obj.setProperty("destH", props.dst.height()); - obj.setProperty("image", props.image); + obj.setProperty("image", canvasImageToScriptValue(engine, props.image)); return obj; } @@ -350,7 +351,7 @@ ScriptValue canvasImageToScriptValue(ScriptEngine* engine, const CanvasImage& im ScriptValue obj = engine->newObject(); obj.setProperty(IMG_WIDTH_PROP_NAME, img.width); obj.setProperty(IMG_HEIGHT_PROP_NAME, img.height); - obj.setProperty(IMG_BUFFER_PROP_NAME, img.buffer); + obj.setProperty(IMG_BUFFER_PROP_NAME, qBytearrayToScriptValue(engine, img.buffer)); return obj; } diff --git a/libraries/script-engine/src/CanvasCommand.h b/libraries/script-engine/src/CanvasCommand.h index 08c0c2f313..e2c63acb8d 100644 --- a/libraries/script-engine/src/CanvasCommand.h +++ b/libraries/script-engine/src/CanvasCommand.h @@ -216,6 +216,7 @@ private: void registerCanvasMetaTypes(ScriptEngine *engine); +Q_DECLARE_METATYPE(CanvasCommand) ScriptValue canvasCommandToScriptValue(ScriptEngine* engine, const CanvasCommand& cmd); bool canvasCommandFromScriptValue(const ScriptValue& object, CanvasCommand& cmd); CanvasCommand canvasCommandFromScriptValue(const ScriptValue& object);