diff --git a/Mods/Editor/Src/EditorServer.cpp b/Mods/Editor/Src/EditorServer.cpp index d35c0dbb..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") { @@ -551,6 +553,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 +628,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 +847,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;