Create persistence manager and connectors for chests and gates

This commit is contained in:
2026-03-19 14:26:57 -05:00
parent 31567f53fb
commit 9fcd24f8b5
14 changed files with 163 additions and 9 deletions

View File

@@ -0,0 +1,21 @@
extends Node
@export var chests: Array[NodePath]
# Private Methods
func _ready() -> void:
for relative_node_path in chests:
var chest: BaseChest = get_node(relative_node_path)
var node_path := chest.get_path()
chest.ChestOpened.connect(func(): _on_chest_opened(chest))
if PersistenceManager.HasData(node_path):
var chest_opened: bool = PersistenceManager.GetData(node_path)
if chest_opened:
chest.call_deferred("SetOpenedFromLoad")
func _on_chest_opened(chest: BaseChest) -> void:
var node_path := chest.get_path()
PersistenceManager.UpdateData(node_path, true)
PersistenceManager.SaveToDisk()

View File

@@ -0,0 +1 @@
uid://75g2fysjrqji

View File

@@ -0,0 +1,40 @@
extends Node
@export var gates: Array[NodePath]
# Private Methods
func _ready() -> void:
for node_path in gates:
_handle_spike_gate(node_path)
func _handle_spike_gate(node_path: NodePath) -> bool:
var node := get_node(node_path)
node_path = node.get_path()
if not node.name.begins_with("Spike Gate"):
return false
# Connect Signal
node.connect("Opened", func(): _on_spike_gate_opened(node))
if not PersistenceManager.HasData(node_path):
return true
var is_open: bool = PersistenceManager.GetData(node_path)
if not is_open:
return true
var collision_shape: CollisionShape2D = node.get_node("CollisionShape2D")
var animated_sprite: AnimatedSprite2D = node.get_node("AnimatedSprite2D")
node.set_deferred("is_open", true)
collision_shape.set_deferred("disabled", true)
animated_sprite.call_deferred("play", "open")
return true
func _on_spike_gate_opened(node: Node) -> void:
var path := node.get_path()
PersistenceManager.UpdateData(path, true)
PersistenceManager.SaveToDisk()

View File

@@ -0,0 +1 @@
uid://brsiegtrne15y

View File

@@ -0,0 +1,6 @@
[gd_scene format=3 uid="uid://w4mh31se58f4"]
[ext_resource type="Script" uid="uid://75g2fysjrqji" path="res://Persistence/Connectors/Scripts/chest_persistence_connector.gd" id="1_hytou"]
[node name="Chest Persistence Connector" type="Node" unique_id=281805027]
script = ExtResource("1_hytou")

View File

@@ -0,0 +1,6 @@
[gd_scene format=3 uid="uid://c5ymu08jotbfp"]
[ext_resource type="Script" uid="uid://brsiegtrne15y" path="res://Persistence/Connectors/Scripts/gate_persistence_connector.gd" id="1_0smsr"]
[node name="GatePersistenceConnector" type="Node" unique_id=1082904286]
script = ExtResource("1_0smsr")