From d41053d07357534bdd29848d3919a40819bfb30a Mon Sep 17 00:00:00 2001 From: atampy25 <24306974+atampy25@users.noreply.github.com> Date: Mon, 22 Apr 2024 22:15:19 +1000 Subject: [PATCH 1/2] Change how editor messages define entity source --- Mods/Editor/Src/EditorServer.cpp | 11 ++++------- Mods/Editor/editor.d.ts | 7 ++++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Mods/Editor/Src/EditorServer.cpp b/Mods/Editor/Src/EditorServer.cpp index d35c0dbb..ebef2639 100644 --- a/Mods/Editor/Src/EditorServer.cpp +++ b/Mods/Editor/Src/EditorServer.cpp @@ -551,6 +551,7 @@ void EditorServer::SendEntityList(EditorServer::WebSocket* p_Socket, std::shared s_EventStream << "{"; s_EventStream << write_json("id") << ":" << write_json(std::format("{:016x}", s_Node->EntityId)) << ","; + s_EventStream << write_json("source") << ":" << write_json("game") << ","; s_EventStream << write_json("tblu") << ":" << write_json(std::format("{:016X}", s_Node->TBLU.GetID())) << ","; s_EventStream << write_json("type") << ":" << write_json((*s_Node->Entity->GetType()->m_pInterfaces)[0].m_pTypeId->typeInfo()->m_pTypeName); @@ -625,11 +626,13 @@ void EditorServer::WriteEntityDetails(std::ostream& p_Stream, ZEntityRef p_Entit p_Stream << write_json("name") << ":" << write_json(s_Name) << ","; } + p_Stream << write_json("source") << ":" << write_json("game") << ","; + p_Stream << write_json("tblu") << ":" << write_json(std::format("{:016X}", s_Factory->m_ridResource.GetID())) << ","; } else { // TODO: Name. - p_Stream << write_json("byEditor") << ":" << write_json(true) << ","; + p_Stream << write_json("source") << ":" << write_json("editor") << ","; } // Write type and interfaces. @@ -842,12 +845,6 @@ EntitySelector EditorServer::ReadEntitySelector(simdjson::ondemand::value p_Sele }; } - const bool s_ByEditor = p_Selector["byEditor"]; - - if (!s_ByEditor) { - throw std::runtime_error("Entity selector 'byEditor' field cannot be `false` when 'tblu' is not present."); - } - return { .EntityId = s_Id64, .TbluHash = std::nullopt, diff --git a/Mods/Editor/editor.d.ts b/Mods/Editor/editor.d.ts index 7f2e5efe..808a2f03 100644 --- a/Mods/Editor/editor.d.ts +++ b/Mods/Editor/editor.d.ts @@ -53,19 +53,20 @@ interface PropertyValue { interface GameEntity { id: EntityId; + source: "game"; tblu: ResourceId; } interface EditorEntity { id: EntityId; - byEditor: true; + source: "editor"; } // Rules used to select either an entity spawned by the game or by the editor. -// When `tblu` is defined and set to a blueprint (TBLU) resource id / hash, +// When `source` is set to "game" and `tblu` is defined and set to a blueprint (TBLU) resource id / hash, // the entity will be looked up based on the provided `id` in the collection of entities // spawned by the game based on that blueprint. -// Otherwise, when `byEditor` is defined and set to `true`, the entity will be looked up +// Otherwise, the entity will be looked up // in the collection of entities spawned by the editor at runtime. type EntitySelector = GameEntity | EditorEntity; From 65585326dcccac22818e3578acdb5a8928cfe423 Mon Sep 17 00:00:00 2001 From: atampy25 <24306974+atampy25@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:11:46 +1000 Subject: [PATCH 2/2] Fix msgId being required on every field --- Mods/Editor/Src/EditorServer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Mods/Editor/Src/EditorServer.cpp b/Mods/Editor/Src/EditorServer.cpp index ebef2639..056dbc49 100644 --- a/Mods/Editor/Src/EditorServer.cpp +++ b/Mods/Editor/Src/EditorServer.cpp @@ -106,8 +106,10 @@ void EditorServer::OnMessage(WebSocket* p_Socket, std::string_view p_Message) no std::optional s_MessageId; - if (s_JsonMsg["msgId"].type() == simdjson::ondemand::json_type::number) { - s_MessageId = s_JsonMsg["msgId"]; + if (s_JsonMsg.find_field("msgId").error() == simdjson::SUCCESS) { + if (s_JsonMsg["msgId"].type() == simdjson::ondemand::json_type::number) { + s_MessageId = s_JsonMsg["msgId"]; + } } if (s_Type == "hello") {