From 1824cb94cf061742c87d387aa3dbdde7c8fe63f4 Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Tue, 15 Aug 2023 11:27:03 -0700 Subject: [PATCH] fix crashing when respawning with no save --- Assets/default-save.tres | 25 +++++++++++++++++++++++++ Characters/Boss.cs | 8 +++++++- Characters/Character.cs | 2 +- Characters/DocCenturion.tscn | 1 - Events/EventBus.cs | 6 ++++++ UI/BossBar.cs | 16 ++++++++++++++++ Utils/CacheStore.cs | 2 +- Utils/World.cs | 11 ++++++----- 8 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 Assets/default-save.tres diff --git a/Assets/default-save.tres b/Assets/default-save.tres new file mode 100644 index 0000000..30d36a3 --- /dev/null +++ b/Assets/default-save.tres @@ -0,0 +1,25 @@ +[gd_resource type="Resource" load_steps=8 format=3 uid="uid://betjy08c65fp1"] + +[ext_resource type="Script" path="res://State/Global/MapState.cs" id="1_aydul"] +[ext_resource type="Script" path="res://State/Global/Progression.cs" id="2_y82md"] +[ext_resource type="Script" path="res://State/Global/Stats.cs" id="3_rktrk"] +[ext_resource type="Script" path="res://Utils/Save.cs" id="4_n4440"] + +[sub_resource type="Resource" id="Resource_nf41v"] +script = ExtResource("1_aydul") +_state = {} + +[sub_resource type="Resource" id="Resource_7l14i"] +script = ExtResource("2_y82md") + +[sub_resource type="Resource" id="Resource_e5qnf"] +script = ExtResource("3_rktrk") +SaveLocation = Vector2(252, 0) +SaveMapKey = "res://Scenes/Maps/ArenaExterior.tscn" +DeathCount = 0 + +[resource] +script = ExtResource("4_n4440") +Progression = SubResource("Resource_7l14i") +MapState = SubResource("Resource_nf41v") +Stats = SubResource("Resource_e5qnf") diff --git a/Characters/Boss.cs b/Characters/Boss.cs index 6810b4a..258fe67 100644 --- a/Characters/Boss.cs +++ b/Characters/Boss.cs @@ -20,6 +20,7 @@ public abstract partial class Boss : Enemy public abstract int Intensity { get; } private bool _isActive; + private Events.EventBus _eventBus; [Export] public virtual bool IsActive @@ -30,7 +31,10 @@ public abstract partial class Boss : Enemy _isActive = value; // register or deregister ourselves when we are active/inactive - this.GetWorld().RegisterBoss(_isActive ? this : null); + _eventBus.EmitSignal( + Events.EventBus.SignalName.RegisteredBoss, + _isActive ? this : null + ); } } @@ -47,6 +51,8 @@ public abstract partial class Boss : Enemy { Reset(); }; + + _eventBus = this.GetEventBus(); } protected void UpdateBossStatus(bool status) diff --git a/Characters/Character.cs b/Characters/Character.cs index 9c02342..eb82f37 100644 --- a/Characters/Character.cs +++ b/Characters/Character.cs @@ -331,7 +331,7 @@ public partial class Character : CharacterBody2D, IFaction if (Health <= 0) { EmitSignal(SignalName.Death, args); - GetNode("DeathParticles") + GetNode("DeathParticles")? .CloneOnWorld() .EmitOneShot(); } diff --git a/Characters/DocCenturion.tscn b/Characters/DocCenturion.tscn index 0284afa..56f7b2a 100644 --- a/Characters/DocCenturion.tscn +++ b/Characters/DocCenturion.tscn @@ -315,7 +315,6 @@ MaxDistanceToTarget = 128.0 UseItemDistance = 48.0 PassiveState = NodePath("../Idle") PursueState = NodePath("../Idle") -PursueOnLineOfSight = false NPC = NodePath("../..") [node name="Idle" type="Node" parent="ThinkerStateMachine" node_paths=PackedStringArray("PursueState", "NavigationAgent", "NPC")] diff --git a/Events/EventBus.cs b/Events/EventBus.cs index 2f93bbc..50c2ad4 100644 --- a/Events/EventBus.cs +++ b/Events/EventBus.cs @@ -18,4 +18,10 @@ public partial class EventBus : Node [Signal] public delegate void PlayerHealthChangedEventHandler(HealthChangedArgs args); + + [Signal] + public delegate void RegisteredBossEventHandler(Characters.Boss boss); + + [Signal] + public delegate void DeregisteredBossEventHandler(Characters.Boss boss); } diff --git a/UI/BossBar.cs b/UI/BossBar.cs index 391ee76..74e0618 100644 --- a/UI/BossBar.cs +++ b/UI/BossBar.cs @@ -1,13 +1,16 @@ using Godot; using SupaLidlGame.Characters; +using SupaLidlGame.Extensions; namespace SupaLidlGame.UI; public partial class BossBar : VBoxContainer { public TextureProgressBar ProgressBar { get; set; } + public Label BossNameLabel { get; set; } + private Events.EventBus _eventBus; private Boss _boss; public Boss Boss @@ -24,6 +27,19 @@ public partial class BossBar : VBoxContainer { ProgressBar = GetNode("BarMargin/BossBar"); BossNameLabel = GetNode