Recovered orphaned WIP before switching to a new task
This commit is contained in:
+61
-19
@@ -1,15 +1,15 @@
|
|||||||
class_name WorldObject
|
class_name WorldObject
|
||||||
extends RefCounted
|
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
|
## This is the runtime representation of a WorldObject from the chunk data
|
||||||
## metadata. It mirrors [ChunkDataDecoder.WorldObjectData] but is a standalone
|
## format (see docs/architecture/world.md §3.3). It holds the object's
|
||||||
## class so it can be referenced by scene nodes.
|
## identity, transform, properties, and moderation flags.
|
||||||
|
|
||||||
## Stable object ID, unique within the chunk.
|
## Stable object ID, unique within the chunk.
|
||||||
var id: String = ""
|
var id: String = ""
|
||||||
|
|
||||||
## Object type: "prop", "interactable", "spawn_point", "door", etc.
|
## Object type (e.g. "prop", "interactable", "spawn_point", "door").
|
||||||
var type: String = ""
|
var type: String = ""
|
||||||
|
|
||||||
## Reference to the object's mesh/glTF asset.
|
## Reference to the object's mesh/glTF asset.
|
||||||
@@ -27,7 +27,7 @@ var scale: Vector3 = Vector3.ONE
|
|||||||
## Type-specific key/value properties.
|
## Type-specific key/value properties.
|
||||||
var properties: Dictionary = {}
|
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
|
var is_dynamic: bool = false
|
||||||
|
|
||||||
## Per-object content moderation flags.
|
## Per-object content moderation flags.
|
||||||
@@ -60,34 +60,76 @@ func _init(
|
|||||||
flags = p_flags
|
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:
|
func to_dict() -> Dictionary:
|
||||||
return {
|
return {
|
||||||
"id": id,
|
"id": id,
|
||||||
"type": type,
|
"type": type,
|
||||||
"asset_id": asset_id,
|
"asset_id": asset_id,
|
||||||
"position": position,
|
"position": [position.x, position.y, position.z],
|
||||||
"rotation": rotation,
|
"rotation": [rotation.x, rotation.y, rotation.z, rotation.w],
|
||||||
"scale": scale,
|
"scale": [scale.x, scale.y, scale.z],
|
||||||
"properties": properties,
|
"properties": properties,
|
||||||
"dynamic": is_dynamic,
|
"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:
|
static func from_dict(d: Dictionary) -> WorldObject:
|
||||||
var flags := ChunkDataDecoder.ContentFlags.new()
|
var pos := Vector3(
|
||||||
if d.has("flags"):
|
d.get("position", [0, 0, 0])[0],
|
||||||
flags.from_dict(d["flags"])
|
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(
|
return WorldObject.new(
|
||||||
d.get("id", ""),
|
d.get("id", ""),
|
||||||
d.get("type", ""),
|
d.get("type", ""),
|
||||||
d.get("asset_id", ""),
|
d.get("asset_id", ""),
|
||||||
d.get("position", Vector3.ZERO),
|
pos,
|
||||||
d.get("rotation", Vector4(0, 0, 0, 1)),
|
rot,
|
||||||
d.get("scale", Vector3.ONE),
|
scl,
|
||||||
d.get("properties", {}),
|
d.get("properties", {}),
|
||||||
d.get("dynamic", false),
|
d.get("dynamic", false),
|
||||||
flags,
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user