From d752cf528037ae668154c7ddccbbf2de90a95c89 Mon Sep 17 00:00:00 2001 From: coder-bot Date: Mon, 17 Aug 2026 21:57:57 +0000 Subject: [PATCH] Recovered orphaned WIP before switching to a new task --- scripts/world_object.gd | 80 +++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/scripts/world_object.gd b/scripts/world_object.gd index 4e7dd8e..8895fff 100644 --- a/scripts/world_object.gd +++ b/scripts/world_object.gd @@ -1,15 +1,15 @@ class_name WorldObject extends RefCounted -## A world object (prop, interactable, spawn point, etc.) within a chunk. +## A world object (static or dynamic) within a chunk. ## -## This is the runtime representation used by [ChunkScene] to hold object -## metadata. It mirrors [ChunkDataDecoder.WorldObjectData] but is a standalone -## class so it can be referenced by scene nodes. +## This is the runtime representation of a WorldObject from the chunk data +## format (see docs/architecture/world.md ยง3.3). It holds the object's +## identity, transform, properties, and moderation flags. ## Stable object ID, unique within the chunk. var id: String = "" -## Object type: "prop", "interactable", "spawn_point", "door", etc. +## Object type (e.g. "prop", "interactable", "spawn_point", "door"). var type: String = "" ## Reference to the object's mesh/glTF asset. @@ -27,7 +27,7 @@ var scale: Vector3 = Vector3.ONE ## Type-specific key/value properties. var properties: Dictionary = {} -## Whether this is a spawnable dynamic entity template. +## Whether this is a spawnable dynamic entity (true) or static (false). var is_dynamic: bool = false ## Per-object content moderation flags. @@ -60,34 +60,76 @@ func _init( flags = p_flags -## Convert to a dictionary representation. +## Get a property value by key. +func get_property(key: String) -> Variant: + return properties.get(key) + + +## Set a property value. +func set_property(key: String, value: Variant) -> void: + properties[key] = value + is_dirty = true + + +## Check if this object is walkable (based on properties). +func is_walkable() -> bool: + return properties.get("walkable", true) + + +## Check if this object is climbable (based on properties). +func is_climbable() -> bool: + return properties.get("climbable", false) + + +## Check if this object is interactable. +func is_interactable() -> bool: + return type == "interactable" or properties.get("interactable", false) + + +## Get the object's display name. +func get_display_name() -> String: + return properties.get("display_name", id) + + +## Serialize this object to a dictionary (for networking). func to_dict() -> Dictionary: return { "id": id, "type": type, "asset_id": asset_id, - "position": position, - "rotation": rotation, - "scale": scale, + "position": [position.x, position.y, position.z], + "rotation": [rotation.x, rotation.y, rotation.z, rotation.w], + "scale": [scale.x, scale.y, scale.z], "properties": properties, "dynamic": is_dynamic, - "flags": flags.to_dict(), } -## Create a WorldObject from a dictionary. +## Create a WorldObject from a dictionary (for networking). static func from_dict(d: Dictionary) -> WorldObject: - var flags := ChunkDataDecoder.ContentFlags.new() - if d.has("flags"): - flags.from_dict(d["flags"]) + var pos := Vector3( + d.get("position", [0, 0, 0])[0], + d.get("position", [0, 0, 0])[1], + d.get("position", [0, 0, 0])[2] + ) + var rot := Vector4( + d.get("rotation", [0, 0, 0, 1])[0], + d.get("rotation", [0, 0, 0, 1])[1], + d.get("rotation", [0, 0, 0, 1])[2], + d.get("rotation", [0, 0, 0, 1])[3] + ) + var scl := Vector3( + d.get("scale", [1, 1, 1])[0], + d.get("scale", [1, 1, 1])[1], + d.get("scale", [1, 1, 1])[2] + ) return WorldObject.new( d.get("id", ""), d.get("type", ""), d.get("asset_id", ""), - d.get("position", Vector3.ZERO), - d.get("rotation", Vector4(0, 0, 0, 1)), - d.get("scale", Vector3.ONE), + pos, + rot, + scl, d.get("properties", {}), d.get("dynamic", false), - flags, )