beta-1.4/persistence-implementation (#3)

Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
2026-03-19 13:27:37 -06:00
parent bfe4f7d6a9
commit 5fb4a96159
26 changed files with 277 additions and 15 deletions

Binary file not shown.

View File

@@ -0,0 +1,28 @@
extends Node
class_name BaseTestRunner
func _ready() -> void:
var methods := self.get_method_list()
for method in methods:
var method_name: String = method["name"]
if method_name.left(5).to_lower() != "test_":
continue
var return_dict: Dictionary = method["return"]
var return_type: int = return_dict["type"]
if return_type != 1:
print_rich("[color=yellow]Skipping Unit Test Method '%s'. Reason: Return type is not bool[/color]" % method_name)
continue
var args: Array = method["args"]
if not args.is_empty():
print_rich("[color=yellow]Skipping Unit Test Method '%s', Reason: Method requires arguments.[/color]" % method_name)
continue
var result: bool = call(method_name)
if result:
print_rich("[color=green]%s: Success![/color]" % method_name)
else:
print_rich("[color=red]%s: Failure...[/color]" % method_name)

View File

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

View File

@@ -0,0 +1,3 @@
[gd_scene format=3 uid="uid://rl2o7alqg7w4"]
[node name="BaseTestRunner" type="Node" unique_id=1916529975]

View File

@@ -0,0 +1,14 @@
extends BaseTestRunner
func Test_1() -> bool:
var json_string = "{\"Key\": false}"
var json = JSON.new()
var parse_result := json.parse(json_string)
if parse_result != OK:
return false
return true
func Test_2() -> String:
return ''

View File

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

View File

@@ -0,0 +1,6 @@
[gd_scene format=3 uid="uid://c23ct3b1nmih7"]
[ext_resource type="Script" uid="uid://xrexdmk7d1qx" path="res://Debug/Unit Testing/Scripts/json_parsing_tests.gd" id="1_beu12"]
[node name="JsonParsingTests" type="Node" unique_id=2014332517]
script = ExtResource("1_beu12")

View File

@@ -5,6 +5,10 @@ enum States {
PECKING
}
@export var minimum_pecking_schedule_gap := 8.0
@export var maximum_pecking_schedule_gap := 25.0
@export var should_log_pecking_schedule := false
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
var current_state := States.IDLE
@@ -23,11 +27,12 @@ func _process(delta: float) -> void:
animated_sprite_2d.play("pecking")
await animated_sprite_2d.animation_finished
animated_sprite_2d.play("idle")
pecking_sched = randf_range(8.0, 25.0)
pecking_sched = randf_range(minimum_pecking_schedule_gap, maximum_pecking_schedule_gap)
pecking_timer = 0
current_state = States.IDLE
_print_sched()
func _print_sched() -> void:
print("%s Pecking Schedule: %f" % [name, pecking_sched])
if should_log_pecking_schedule:
print("%s Pecking Schedule: %f" % [name, pecking_sched])

View File

@@ -1,6 +1,7 @@
extends StaticBody2D
class_name BaseChest
signal ChestOpened
signal OpeningAnimationStarted
@export var is_open := false
@@ -8,7 +9,12 @@ signal OpeningAnimationStarted
# Public Methods
func Open() -> void:
is_open = true
ChestOpened.emit()
func OpenAlreadyOpened() -> void:
pass
func SetOpenedFromLoad() -> void:
is_open = true

View File

@@ -27,6 +27,11 @@ func OpenAlreadyOpened() -> void:
already_opened_message_dialogue_trigger.Trigger()
func SetOpenedFromLoad() -> void:
super.SetOpenedFromLoad()
chest_01_sprite.play("opened")
# Private Methods
func _ready() -> void:
if is_open:

View File

@@ -1,5 +1,7 @@
extends StaticBody2D
signal Opened
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D
@@ -15,3 +17,5 @@ func OpenGate() -> void:
collision_shape_2d.set_deferred("disabled", true)
sprite.play("open")
Opened.emit()

View File

@@ -395,6 +395,6 @@ shape = SubResource("RectangleShape2D_5ttkm")
y_sort_enabled = true
position = Vector2(0, 15)
sprite_frames = SubResource("SpriteFrames_pki7h")
animation = &"closed"
animation = &"open"
autoplay = "closed"
offset = Vector2(0, -15)

View File

@@ -4,6 +4,9 @@ extends Node2D
@export var spawn_markers: Node2D
@export var destination_markers: Node2D
# Debug
@export var should_log_schedule := false
@export_range(0.0, 60.0) var minimum_schedule_gap := 20.0
@export_range(1.0, 61.0) var maximum_schedule_gap := 60.0
@@ -25,7 +28,8 @@ func _ready() -> void:
# At spawn, we might want to spawn some leaves sooner...
_spawn_schedule -= randf_range(0.0, _spawn_schedule)
_spawn_schedule = max(0, _spawn_schedule)
print("%s - Leaf Spawn Schedule: %f" % [get_parent().name, _spawn_schedule])
_log_schedule()
func _process(delta: float) -> void:
@@ -33,6 +37,7 @@ func _process(delta: float) -> void:
if _spawn_timer >= _spawn_schedule:
_spawn_timer = 0.0
_set_random_spawn_schedule()
_log_schedule()
var spawn := _get_random_spawn_point()
var destination := _get_random_destination_point()
@@ -76,3 +81,8 @@ func _get_random_destination_point() -> Vector2:
var offset := Vector2(randf_range(-5.0, 5.0), randf_range(-5.0, 5.0))
return marker.position + offset
func _log_schedule() -> void:
if should_log_schedule:
print("%s - Leaf Spawn Schedule: %f" % [get_parent().name, _spawn_schedule])

BIN
Game Icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

40
Game Icon.png.import Normal file
View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ckbsqf4p5xu44"
path="res://.godot/imported/Game Icon.png-1ecac6caff9b7691e845293f1a955d2a.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Game Icon.png"
dest_files=["res://.godot/imported/Game Icon.png-1ecac6caff9b7691e845293f1a955d2a.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -11,6 +11,8 @@
[ext_resource type="PackedScene" uid="uid://byp273amg5ji8" path="res://Entities/Map Objects/Chests/Item Chests/item_chest_01 (Wooden).tscn" id="5_bnsbe"]
[ext_resource type="Texture2D" uid="uid://bf6llktwqhs8l" path="res://Assets/Sprites/Door Fade.png" id="5_jett5"]
[ext_resource type="PackedScene" uid="uid://did853bh5xeic" path="res://Maps/Connectors/spawn_marker_connector.tscn" id="5_lphfo"]
[ext_resource type="PackedScene" uid="uid://w4mh31se58f4" path="res://Persistence/Connectors/chest_persistence_connector.tscn" id="6_l5trr"]
[ext_resource type="PackedScene" uid="uid://c5ymu08jotbfp" path="res://Persistence/Connectors/gate_persistence_connector.tscn" id="7_0w1de"]
[ext_resource type="PackedScene" uid="uid://be6xfndyj4ckx" path="res://Entities/Map Objects/Trees/tree_02.tscn" id="7_ycf72"]
[ext_resource type="PackedScene" uid="uid://cc3qat6un2323" path="res://Entities/Map Objects/Trees/tree_01.tscn" id="8_yab5j"]
[ext_resource type="PackedScene" uid="uid://bcx1d8kvp7o0h" path="res://Entities/Map Objects/Trees/tree_03.tscn" id="9_lwurn"]
@@ -25,7 +27,7 @@
[ext_resource type="PackedScene" uid="uid://coaf2ndwb6h61" path="res://Entities/Map Objects/Decorative/Signs/wooden_sign_02.tscn" id="19_jtncl"]
[ext_resource type="PackedScene" uid="uid://cla2d3gii8qda" path="res://Entities/Map Objects/Loading Zone/interactive_loading_zone.tscn" id="20_c5vrl"]
[ext_resource type="PackedScene" uid="uid://b60nr4wfvijpf" path="res://Entities/Map Objects/Dialogue/dialogue_trigger.tscn" id="20_x6da4"]
[ext_resource type="PackedScene" uid="uid://c7rjjlamkqhnw" path="res://Debug/under_construction_block.tscn" id="26_4lnhp"]
[ext_resource type="PackedScene" uid="uid://c7rjjlamkqhnw" path="res://Debug/Utility Objects/under_construction_block.tscn" id="26_4lnhp"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_lwurn"]
size = Vector2(768, 494)
@@ -63,25 +65,33 @@ size = Vector2(10, 7)
[node name="Map 01" type="Node2D" unique_id=411453136]
y_sort_enabled = true
[node name="Connectors" type="Node" parent="." unique_id=1365901208]
[node name="Map Connectors" type="Node" parent="." unique_id=1365901208]
[node name="Chest Interaction Connector" parent="Connectors" unique_id=625804018 node_paths=PackedStringArray("player") instance=ExtResource("1_jtncl")]
[node name="Chest Interaction Connector" parent="Map Connectors" unique_id=625804018 node_paths=PackedStringArray("player") instance=ExtResource("1_jtncl")]
player = NodePath("../../Player")
[node name="Arrow Spawner" parent="Connectors" unique_id=627092886 node_paths=PackedStringArray("player", "arrow_parent") instance=ExtResource("2_jtncl")]
[node name="Arrow Spawner" parent="Map Connectors" unique_id=627092886 node_paths=PackedStringArray("player", "arrow_parent") instance=ExtResource("2_jtncl")]
player = NodePath("../../Player")
arrow_parent = NodePath("../../Objects/Projectiles")
[node name="Bench Interaction Connector" parent="Connectors" unique_id=541204437 node_paths=PackedStringArray("player") instance=ExtResource("3_x6da4")]
[node name="Bench Interaction Connector" parent="Map Connectors" unique_id=541204437 node_paths=PackedStringArray("player") instance=ExtResource("3_x6da4")]
player = NodePath("../../Player")
[node name="Interactive Loading Zone Connector" parent="Connectors" unique_id=833475826 node_paths=PackedStringArray("player") instance=ExtResource("4_4lnhp")]
[node name="Interactive Loading Zone Connector" parent="Map Connectors" unique_id=833475826 node_paths=PackedStringArray("player") instance=ExtResource("4_4lnhp")]
player = NodePath("../../Player")
[node name="Spawn Marker Connector" parent="Connectors" unique_id=807187299 node_paths=PackedStringArray("player", "markers") instance=ExtResource("5_lphfo")]
[node name="Spawn Marker Connector" parent="Map Connectors" unique_id=807187299 node_paths=PackedStringArray("player", "markers") instance=ExtResource("5_lphfo")]
player = NodePath("../../Player")
markers = NodePath("../../Spawn Markers")
[node name="Persistence Connectors" type="Node" parent="." unique_id=1245900932]
[node name="Chest Persistence Connector" parent="Persistence Connectors" unique_id=281805027 instance=ExtResource("6_l5trr")]
chests = Array[NodePath]([NodePath("../../Objects/Chests/Item Chest 01 - 1"), NodePath("../../Objects/Chests/Item Chest 01 - 2"), NodePath("../../Objects/Chests/Item Chest 01 - 3")])
[node name="GatePersistenceConnector" parent="Persistence Connectors" unique_id=1082904286 instance=ExtResource("7_0w1de")]
gates = Array[NodePath]([NodePath("../../Objects/Spike Gate"), NodePath("../../Objects/Spike Gate2")])
[node name="Camera Limit Connector" type="Area2D" parent="." unique_id=1290795384 node_paths=PackedStringArray("camera_to_limit")]
collision_layer = 0
collision_mask = 0
@@ -340,7 +350,7 @@ destination_marker_name = "Entrance"
position = Vector2(278, 474)
[node name="Player" parent="." unique_id=1502234578 instance=ExtResource("4_4igim")]
position = Vector2(89, 450)
position = Vector2(656, 498)
[node name="Camera2D" type="Camera2D" parent="Player" unique_id=1115720225]
position = Vector2(0, 1)
@@ -385,7 +395,7 @@ position = Vector2(760, 312)
[node name="Under Construction Block12" parent="Debug" unique_id=1005752992 instance=ExtResource("26_4lnhp")]
position = Vector2(760, 328)
[connection signal="SitOnBenchTriggered" from="Connectors/Bench Interaction Connector" to="Player" method="OnSitOnFurnitureTriggered"]
[connection signal="SitOnBenchTriggered" from="Map Connectors/Bench Interaction Connector" to="Player" method="OnSitOnFurnitureTriggered"]
[connection signal="TargetHit" from="Objects/ArrowTarget" to="Objects/Spike Gate" method="OpenGate"]
[connection signal="TargetHit" from="Objects/ArrowTarget" to="Objects/Spike Gate2" method="OpenGate"]
[connection signal="PressurePlateTripped" from="Objects/PressurePlate" to="Objects/Spike Gate" method="OpenGate"]

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")

View File

@@ -0,0 +1,51 @@
extends Node
var _save_dictionary: Dictionary[NodePath, Variant] = {}
# Public Methods
func UpdateData(node_path: NodePath, value: Variant) -> void:
_save_dictionary[node_path] = value
func GetData(node_path: NodePath) -> Variant:
if not _save_dictionary.has(node_path):
return null
return _save_dictionary[node_path]
func HasData(node_path: NodePath) -> bool:
return _save_dictionary.has(node_path)
func SaveToDisk() -> void:
var save_file := FileAccess.open("user://savegame.save", FileAccess.WRITE)
var json := JSON.stringify(_save_dictionary)
save_file.store_line(json)
func LoadFromDisk() -> void:
if not FileAccess.file_exists("user://savegame.save"):
return
var save_file = FileAccess.open("user://savegame.save", FileAccess.READ)
print("Loading save file from path: %s" % save_file.get_path_absolute())
var line := save_file.get_line()
var json = JSON.new()
var parse_result := json.parse(line)
if parse_result != OK:
print("Parsing result when loading file: [%s] in %s at line %d" % [json.get_error_message(), line, json.get_error_line()])
return
var data_dict: Dictionary = json.data
var node_dict: Dictionary[NodePath, Variant]
for key in data_dict:
var value: Variant = data_dict[key]
var node_path := NodePath(key)
node_dict[node_path] = value
_save_dictionary = node_dict
# Private Methods
func _ready() -> void:
LoadFromDisk()

View File

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

View File

@@ -11,10 +11,10 @@ config_version=5
[application]
config/name="Archipelago Game"
config/version="beta-1.3"
config/version="beta-1.4"
run/main_scene="uid://dqgxg3i307lvr"
config/features=PackedStringArray("4.6", "Forward Plus")
config/icon="res://icon.svg"
config/icon="uid://ckbsqf4p5xu44"
[autoload]
@@ -23,6 +23,7 @@ GameManager="*uid://cb4tuxriixfqs"
GroupUtils="*uid://bk7o4drbfh24p"
MapLoader="*uid://c4jogxtdi3m13"
InputManager="*uid://dnbg1dpjcq6vk"
PersistenceManager="*uid://dl2kg1qu0ymi7"
[dotnet]
@@ -37,6 +38,7 @@ folder_colors={
"res://Global Managers/": "red",
"res://Main/": "gray",
"res://Maps/": "green",
"res://Persistence/": "blue",
"res://Resources/": "orange",
"res://Scripts/": "red",
"res://UI/": "yellow"