Skip to content

Commit

Permalink
Merge pull request #103 from atampy25/source-changes
Browse files Browse the repository at this point in the history
Change how editor messages define entity source and fix msgId being required on every message
  • Loading branch information
OrfeasZ authored Apr 22, 2024
2 parents 1c20fff + 6558532 commit 8240d58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 8 additions & 9 deletions Mods/Editor/Src/EditorServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ void EditorServer::OnMessage(WebSocket* p_Socket, std::string_view p_Message) no

std::optional<int64_t> 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") {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions Mods/Editor/editor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 8240d58

Please sign in to comment.