36 lines
945 B
GDScript
36 lines
945 B
GDScript
class_name RoomState
|
|
extends RefCounted
|
|
|
|
var id: StringName
|
|
var bounds: Rect2i
|
|
var kind: StringName
|
|
var metadata: Dictionary = {}
|
|
|
|
func _init(new_id: StringName, new_bounds: Rect2i, new_kind: StringName = &"", new_metadata: Dictionary = {}) -> void:
|
|
id = new_id
|
|
bounds = new_bounds
|
|
kind = new_kind
|
|
metadata = new_metadata.duplicate(true)
|
|
|
|
func to_dict() -> Dictionary:
|
|
return {
|
|
"id": String(id),
|
|
"bounds": [bounds.position.x, bounds.position.y, bounds.size.x, bounds.size.y],
|
|
"kind": String(kind),
|
|
"metadata": metadata.duplicate(true),
|
|
}
|
|
|
|
static func from_dict(data: Dictionary) -> RoomState:
|
|
var serialized_bounds: Array = data.get("bounds", [0, 0, 0, 0])
|
|
return RoomState.new(
|
|
StringName(data.get("id", "")),
|
|
Rect2i(
|
|
int(serialized_bounds[0]),
|
|
int(serialized_bounds[1]),
|
|
int(serialized_bounds[2]),
|
|
int(serialized_bounds[3])
|
|
),
|
|
StringName(data.get("kind", "")),
|
|
data.get("metadata", {}).duplicate(true)
|
|
)
|