feat: Save objects states in Obj Manager to keep them btwn rooms (#554)
This commit is contained in:
@@ -163,8 +163,12 @@ func register_object(object: ESCObject, room: ESCRoom = null, force: bool = fals
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
# Object exists in room, set it to is last state (if different from
|
||||||
|
# "default")
|
||||||
|
elif _object_exists_in_room(object, room_key):
|
||||||
|
# Object is already known, set its state to last known state
|
||||||
|
object.set_state(get_object(object.global_id).state)
|
||||||
|
|
||||||
# If the object is already connected, disconnect it for the case of
|
# If the object is already connected, disconnect it for the case of
|
||||||
# forcing the registration, since we don't know if this object will be
|
# forcing the registration, since we don't know if this object will be
|
||||||
@@ -206,6 +210,23 @@ func register_object(object: ESCObject, room: ESCRoom = null, force: bool = fals
|
|||||||
var objects: Dictionary = _get_room_objects_objects(room_key)
|
var objects: Dictionary = _get_room_objects_objects(room_key)
|
||||||
objects[object.global_id] = object
|
objects[object.global_id] = object
|
||||||
|
|
||||||
|
# If object state is not STATE_DEFAULT, save it in manager's object states
|
||||||
|
if object.state != ESCObject.STATE_DEFAULT:
|
||||||
|
if get_object(object.global_id) == null:
|
||||||
|
escoria.logger.report_errors(
|
||||||
|
"ESCObjectManager:register_object()",
|
||||||
|
[
|
||||||
|
"Object with global id %s in room (%s, %s) not found in Object Manager" %
|
||||||
|
[
|
||||||
|
object.global_id,
|
||||||
|
room_key.room_global_id,
|
||||||
|
room_key.room_instance_id
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
get_object(object.global_id).state = object.state
|
||||||
|
|
||||||
# If this is the first object for the room, that means we have a brand new
|
# If this is the first object for the room, that means we have a brand new
|
||||||
# room and it needs to be setup and tracked.
|
# room and it needs to be setup and tracked.
|
||||||
if objects.size() == 1:
|
if objects.size() == 1:
|
||||||
@@ -347,6 +368,7 @@ func unregister_object(object: ESCObject, room_key: ESCRoomObjectsKey) -> void:
|
|||||||
object.node = object.node.duplicate()
|
object.node = object.node.duplicate()
|
||||||
register_object(object, null, true)
|
register_object(object, null, true)
|
||||||
|
|
||||||
|
if object.state == ESCObject.STATE_DEFAULT:
|
||||||
room_objects.erase(object.global_id)
|
room_objects.erase(object.global_id)
|
||||||
|
|
||||||
# If this room is truly empty, it's time to do away with it.
|
# If this room is truly empty, it's time to do away with it.
|
||||||
@@ -438,8 +460,7 @@ func _is_current_room(container: ESCRoomObjects) -> bool:
|
|||||||
# **Returns** True iff container represents the the object manager entry specified
|
# **Returns** True iff container represents the the object manager entry specified
|
||||||
# by room_key.
|
# by room_key.
|
||||||
func _compare_container_to_key(container: ESCRoomObjects, room_key: ESCRoomObjectsKey) -> bool:
|
func _compare_container_to_key(container: ESCRoomObjects, room_key: ESCRoomObjectsKey) -> bool:
|
||||||
return container.room_global_id == room_key.room_global_id \
|
return container.room_global_id == room_key.room_global_id
|
||||||
and container.room_instance_id == room_key.room_instance_id
|
|
||||||
|
|
||||||
|
|
||||||
# Checks whether an entry in the object manager array corresponds to the passed in
|
# Checks whether an entry in the object manager array corresponds to the passed in
|
||||||
@@ -478,7 +499,6 @@ func _object_exists_in_room(object: ESCObject, room_key: ESCRoomObjectsKey) -> b
|
|||||||
for room_container in room_objects:
|
for room_container in room_objects:
|
||||||
if _compare_container_to_key(room_container, room_key) \
|
if _compare_container_to_key(room_container, room_key) \
|
||||||
and room_container.objects.has(object.global_id):
|
and room_container.objects.has(object.global_id):
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ extends Node
|
|||||||
class_name ESCObject
|
class_name ESCObject
|
||||||
|
|
||||||
|
|
||||||
|
# Default object state
|
||||||
|
const STATE_DEFAULT: String = "default"
|
||||||
|
|
||||||
|
|
||||||
# The global id of the object
|
# The global id of the object
|
||||||
var global_id: String
|
var global_id: String
|
||||||
|
|
||||||
@@ -14,7 +18,7 @@ var interactive: bool = true setget _set_interactive, _get_interactive
|
|||||||
|
|
||||||
# The state of the object. If the object has a respective animation,
|
# The state of the object. If the object has a respective animation,
|
||||||
# it will be played
|
# it will be played
|
||||||
var state: String = "default"
|
var state: String = STATE_DEFAULT
|
||||||
|
|
||||||
# The events registered with the object
|
# The events registered with the object
|
||||||
var events: Dictionary = {}
|
var events: Dictionary = {}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ func _ready():
|
|||||||
pause_mode = Node.PAUSE_MODE_STOP
|
pause_mode = Node.PAUSE_MODE_STOP
|
||||||
escoria.object_manager.register_object(
|
escoria.object_manager.register_object(
|
||||||
ESCObject.new(global_id, self),
|
ESCObject.new(global_id, self),
|
||||||
|
null,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ func _ready():
|
|||||||
pause_mode = Node.PAUSE_MODE_STOP
|
pause_mode = Node.PAUSE_MODE_STOP
|
||||||
escoria.object_manager.register_object(
|
escoria.object_manager.register_object(
|
||||||
ESCObject.new(global_id, self),
|
ESCObject.new(global_id, self),
|
||||||
|
null,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user