beta-1.4/persistence-implementation (#3)
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
@@ -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()
|
||||
@@ -0,0 +1 @@
|
||||
uid://75g2fysjrqji
|
||||
40
Persistence/Connectors/Scripts/gate_persistence_connector.gd
Normal file
40
Persistence/Connectors/Scripts/gate_persistence_connector.gd
Normal 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()
|
||||
@@ -0,0 +1 @@
|
||||
uid://brsiegtrne15y
|
||||
6
Persistence/Connectors/chest_persistence_connector.tscn
Normal file
6
Persistence/Connectors/chest_persistence_connector.tscn
Normal 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")
|
||||
6
Persistence/Connectors/gate_persistence_connector.tscn
Normal file
6
Persistence/Connectors/gate_persistence_connector.tscn
Normal 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")
|
||||
Reference in New Issue
Block a user