From b287f978e3af21a5d4a43ef7debbc621063f78fa Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Mon, 27 May 2024 12:14:38 -0700 Subject: [PATCH] Add WIP vendors --- Characters/SnusDealer.tscn | 74 ++++++++++++++++++++++++++++ Characters/Vendor.cs | 27 ++++++++++ Debug/DebugConsole.cs | 50 ++++++++++++++++++- Dialogue/snus-dealer.dialogue | 23 +++++++++ Dialogue/snus-dealer.dialogue.import | 15 ++++++ Entities/DynamicDoor.cs | 2 +- Entities/TorchLamp.tscn | 6 +-- Items/Weapons/ProjectileSpawner.cs | 9 ++++ Scenes/Maps/ForestNew.tscn | 2 +- State/Global/GlobalState.cs | 9 ++++ Utils/CharacterStats.cs | 4 +- addons/panku_console | 2 +- project.godot | 6 +-- 13 files changed, 217 insertions(+), 12 deletions(-) create mode 100644 Characters/SnusDealer.tscn create mode 100644 Characters/Vendor.cs create mode 100644 Dialogue/snus-dealer.dialogue create mode 100644 Dialogue/snus-dealer.dialogue.import diff --git a/Characters/SnusDealer.tscn b/Characters/SnusDealer.tscn new file mode 100644 index 0000000..625e8ea --- /dev/null +++ b/Characters/SnusDealer.tscn @@ -0,0 +1,74 @@ +[gd_scene load_steps=11 format=3 uid="uid://rd08pot25h00"] + +[ext_resource type="Script" path="res://Characters/NPC.cs" id="1_04gcf"] +[ext_resource type="Script" path="res://State/Character/CharacterStateMachine.cs" id="2_kynkg"] +[ext_resource type="Texture2D" uid="uid://bej8thq7ruyty" path="res://Assets/Sprites/Characters/forsen2.png" id="2_s5nik"] +[ext_resource type="Script" path="res://State/Character/NPCIdleState.cs" id="3_pcrll"] +[ext_resource type="Script" path="res://State/Thinker/IdleState.cs" id="3_rgc42"] +[ext_resource type="Script" path="res://State/Thinker/ThinkerStateMachine.cs" id="4_mo4wj"] +[ext_resource type="PackedScene" uid="uid://dldnp8eunxj3q" path="res://BoundingBoxes/InteractionTrigger.tscn" id="5_sjs24"] +[ext_resource type="Script" path="res://Utils/InteractionTriggerDialogue.cs" id="5_yknpw"] +[ext_resource type="Resource" uid="uid://c4n7vhoxybu70" path="res://Dialogue/snus-dealer.dialogue" id="6_isvnq"] +[ext_resource type="Script" path="res://Items/Inventory.cs" id="7_vip6b"] + +[node name="Character" type="CharacterBody2D" node_paths=PackedStringArray("ThinkerStateMachine", "Sprite", "Inventory", "StateMachine")] +script = ExtResource("1_04gcf") +ThinkerStateMachine = NodePath("Thinker") +Sprite = NodePath("Sprites/Sprite") +Inventory = NodePath("Inventory") +StateMachine = NodePath("StateMachine") + +[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState", "Character")] +script = ExtResource("2_kynkg") +InitialState = NodePath("Idle") +Character = NodePath("..") + +[node name="Idle" type="Node" parent="StateMachine" node_paths=PackedStringArray("Character")] +script = ExtResource("3_pcrll") +Character = NodePath("../..") + +[node name="Thinker" type="Node" parent="." node_paths=PackedStringArray("InitialState")] +script = ExtResource("4_mo4wj") +InitialState = NodePath("Idle") + +[node name="Idle" type="Node" parent="Thinker" node_paths=PackedStringArray("NPC")] +script = ExtResource("3_rgc42") +NPC = NodePath("../..") + +[node name="Animations" type="Node" parent="."] + +[node name="Movement" type="AnimationPlayer" parent="Animations"] + +[node name="Hurt" type="AnimationPlayer" parent="Animations"] + +[node name="Stun" type="AnimationPlayer" parent="Animations"] + +[node name="Attack" type="AnimationPlayer" parent="Animations"] + +[node name="Stats" type="Node" parent="."] + +[node name="Sprites" type="Node2D" parent="."] + +[node name="Sprite" type="Sprite2D" parent="Sprites"] +texture = ExtResource("2_s5nik") +centered = false +offset = Vector2(-12, -20) +hframes = 46 + +[node name="Inventory" type="Node2D" parent="." node_paths=PackedStringArray("Hotbar")] +script = ExtResource("7_vip6b") +Hotbar = [] + +[node name="Interaction" type="Node2D" parent="." node_paths=PackedStringArray("InteractionTrigger")] +position = Vector2(0, -4) +script = ExtResource("5_yknpw") +InteractionTrigger = NodePath("InteractionTrigger") +DialogueResource = ExtResource("6_isvnq") +DialogueTitle = "shop" + +[node name="InteractionTrigger" parent="Interaction" instance=ExtResource("5_sjs24")] + +[node name="Label" parent="Interaction/InteractionTrigger/Popup" index="0"] +text = "Listen" + +[editable path="Interaction/InteractionTrigger"] diff --git a/Characters/Vendor.cs b/Characters/Vendor.cs new file mode 100644 index 0000000..8487415 --- /dev/null +++ b/Characters/Vendor.cs @@ -0,0 +1,27 @@ +//using Godot; +//using SupaLidlGame.BoundingBoxes; +//using SupaLidlGame.Extensions; +// +//namespace SupaLidlGame.Characters; +// +//public partial class Vendor : NPC +//{ +// [Export] +// public InteractionTrigger InteractionTrigger { get; set; } +// +// [Export(PropertyHint.File, "*.dialogue")] +// public Resource DialogueResource { get; set; } +// +// [Export] +// public string DialogueTitle { get; set; } +// +// public override void _Ready() +// { +// InteractionTrigger.Interaction += OnInteraction; +// } +// +// private void OnInteraction() +// { +// this.GetWorld().DialogueBalloon.Start(DialogueResource, DialogueTitle); +// } +//} diff --git a/Debug/DebugConsole.cs b/Debug/DebugConsole.cs index 580f6b0..659c988 100644 --- a/Debug/DebugConsole.cs +++ b/Debug/DebugConsole.cs @@ -34,6 +34,8 @@ public sealed partial class DebugConsole : Control private Node ctx => Context; + public const double DEBUG_REFRESH_INTERVAL = 0.25; + public override void _Ready() { _entry = GetNode("%Entry"); @@ -61,6 +63,39 @@ public sealed partial class DebugConsole : Control } } }; + + GD.Print("DebugConsole init"); + // TODO: put this in a separate class + // watch godot.log + bool isFileLoggingEnabled = ProjectSettings + .GetSetting("debug/file_logging/enable_file_logging.pc") + .AsBool(); + + if (isFileLoggingEnabled) + { + GD.Print("File logging is enabled."); + string logPath = ProjectSettings + .GetSetting("debug/file_logging/log_path") + .AsString(); + var fs = FileAccess.Open(logPath, FileAccess.ModeFlags.Read); + + var timer = new Timer(); + AddChild(timer); + timer.Timeout += () => + { + // push + while (fs.GetPosition() < fs.GetLength()) + { + string line = fs.GetLine(); + _output.Text += line; + } + }; + timer.Start(DEBUG_REFRESH_INTERVAL); + } + else + { + GD.PushWarning("File logging is not enabled."); + } } public IEnumerable SplitPath(NodePath path) @@ -209,13 +244,21 @@ public sealed partial class DebugConsole : Control Godot.Expression exp = new(); - string[] reserved = { "from", "set_context", "context", "set_prop", "to_node_path" }; + string[] reserved = { + "from", + "set_context", + "context", + "set_prop", + "to_node_path", + "load", + }; Godot.Collections.Array reservedMap = new(); reservedMap.Add(new Callable(this, MethodName.From)); reservedMap.Add(new Callable(this, MethodName.SetContext)); reservedMap.Add(Context); reservedMap.Add(new Callable(this, MethodName.SetProp)); reservedMap.Add(new Callable(this, MethodName.ToNodePath)); + reservedMap.Add(new Callable(this, MethodName.Load)); var err = exp.Parse(str, reserved); if (err != Error.Ok) @@ -246,4 +289,9 @@ public sealed partial class DebugConsole : Control { Context = node; } + + private Resource Load(string path) + { + return ResourceLoader.Load(path); + } } diff --git a/Dialogue/snus-dealer.dialogue b/Dialogue/snus-dealer.dialogue new file mode 100644 index 0000000..d70cfe4 --- /dev/null +++ b/Dialogue/snus-dealer.dialogue @@ -0,0 +1,23 @@ +~ start + +Snus Dealer: d + +% => test +% => dont_snus + +=> END + +~ test + +Snus Dealer: asdadsadasd + +=> END + +~ dont_snus + +Snus Dealer: If you don't snus... +Snus Dealer: you lose. + +=> END + +~ shop \ No newline at end of file diff --git a/Dialogue/snus-dealer.dialogue.import b/Dialogue/snus-dealer.dialogue.import new file mode 100644 index 0000000..df1ddd2 --- /dev/null +++ b/Dialogue/snus-dealer.dialogue.import @@ -0,0 +1,15 @@ +[remap] + +importer="dialogue_manager_compiler_11" +type="Resource" +uid="uid://c4n7vhoxybu70" +path="res://.godot/imported/snus-dealer.dialogue-69dbddee28632f18888364bae03f393d.tres" + +[deps] + +source_file="res://Dialogue/snus-dealer.dialogue" +dest_files=["res://.godot/imported/snus-dealer.dialogue-69dbddee28632f18888364bae03f393d.tres"] + +[params] + +defaults=true diff --git a/Entities/DynamicDoor.cs b/Entities/DynamicDoor.cs index 7670eb8..38661e7 100644 --- a/Entities/DynamicDoor.cs +++ b/Entities/DynamicDoor.cs @@ -58,7 +58,7 @@ public partial class DynamicDoor : StaticBody2D foreach (var navmesh in Rebake) { // rebake navmesh so NPCs can correctly travel conditionally - GD.Print("rebaking"); + GD.Print("Dynamic door updated; rebaking navmeshes..."); navmesh.BakeNavigationPolygon(); } } diff --git a/Entities/TorchLamp.tscn b/Entities/TorchLamp.tscn index 11df0f7..d858e18 100644 --- a/Entities/TorchLamp.tscn +++ b/Entities/TorchLamp.tscn @@ -102,12 +102,12 @@ y_sort_enabled = true texture_filter = 1 sprite_frames = SubResource("SpriteFrames_gf7ku") autoplay = "default" -frame = 6 -frame_progress = 0.743234 +frame = 9 +frame_progress = 0.966501 offset = Vector2(0, -12) [node name="PointLight2D" type="PointLight2D" parent="."] -color = Color(1, 0.9525, 0.85, 1) +color = Color(1, 0.811765, 0.537255, 1) energy = 1.2 blend_mode = 2 shadow_filter_smooth = 3.0 diff --git a/Items/Weapons/ProjectileSpawner.cs b/Items/Weapons/ProjectileSpawner.cs index 6362899..33d5ad2 100644 --- a/Items/Weapons/ProjectileSpawner.cs +++ b/Items/Weapons/ProjectileSpawner.cs @@ -24,6 +24,15 @@ public partial class ProjectileSpawner : Ranged [Export] public float ProjectileAngleDeviation { get; set; } + public string ProjectilePath + { + get => Projectile?.ResourcePath; + set + { + Projectile = GD.Load(value); + } + } + protected virtual void SpawnProjectile(Scenes.Map map, Vector2 direction, float velocityModifier = 1) { diff --git a/Scenes/Maps/ForestNew.tscn b/Scenes/Maps/ForestNew.tscn index 369dba3..102854a 100644 --- a/Scenes/Maps/ForestNew.tscn +++ b/Scenes/Maps/ForestNew.tscn @@ -843,7 +843,7 @@ position = Vector2(1272, 0) [node name="Campfire" parent="Entities" index="0" instance=ExtResource("3_ve4i2")] position = Vector2(-24, -8) -[node name="Areas" parent="." index="3"] +[node name="Areas" parent="." index="10"] visible = false [node name="Main" type="NavigationRegion2D" parent="Areas" index="0"] diff --git a/State/Global/GlobalState.cs b/State/Global/GlobalState.cs index a4fe117..8c56b17 100644 --- a/State/Global/GlobalState.cs +++ b/State/Global/GlobalState.cs @@ -14,6 +14,8 @@ public partial class GlobalState : Node [Export] public Stats Stats { get; set; } + public static GlobalState Instance { get; private set; } + [Export] public GameSettings Settings { get; set; } @@ -30,6 +32,13 @@ public partial class GlobalState : Node public override void _Ready() { + if (Instance != null) + { + throw new MultipleSingletonsException(); + } + + Instance = this; + ProcessMode = ProcessModeEnum.Always; LoadSettings(); } diff --git a/Utils/CharacterStats.cs b/Utils/CharacterStats.cs index 3cc30e0..61d5946 100644 --- a/Utils/CharacterStats.cs +++ b/Utils/CharacterStats.cs @@ -1,4 +1,5 @@ using Godot; +using SupaLidlGame.Extensions; namespace SupaLidlGame.Utils; @@ -52,8 +53,7 @@ public partial class CharacterStats : Node else { _shouldDecayStagger = false; - _staggerDecayTimer.Stop(); - _staggerDecayTimer.Start(1); + _staggerDecayTimer.Restart(1); } } diff --git a/addons/panku_console b/addons/panku_console index 3662539..b265f5c 160000 --- a/addons/panku_console +++ b/addons/panku_console @@ -1 +1 @@ -Subproject commit 36625398e3ad45306521926c5190141a7ac925b0 +Subproject commit b265f5cebab07f3af55c92f642b458db9c973a7c diff --git a/project.godot b/project.godot index ab181a7..9c20780 100644 --- a/project.godot +++ b/project.godot @@ -17,17 +17,17 @@ config/icon="res://icon.svg" [autoload] -DialogueManager="*res://addons/dialogue_manager/dialogue_manager.gd" GlobalState="*res://State/Global/GlobalState.cs" EventBus="*res://Events/EventBus.cs" BaseUI="*res://UI/Base.tscn" World="*res://Scenes/Level.tscn" AudioManager="*res://Audio/AudioManager.cs" DebugUi="*res://UI/Debug/DebugUI.tscn" +DialogueManager="*res://addons/dialogue_manager/dialogue_manager.gd" [dialogue_manager] -general/states=["GlobalState"] +general/states=["GlobalState", "World"] general/wrap_lines=true [display] @@ -201,7 +201,7 @@ cast={ [internationalization] -locale/translations_pot_files=PackedStringArray("res://Assets/Dialog/doc.dialogue", "res://Assets/Dialogue/doc.dialogue", "res://Assets/Dialogue/spellbook.dialogue", "res://Assets/Dialogue/books.dialogue", "res://Assets/Dialogue/clone-machine.dialogue") +locale/translations_pot_files=PackedStringArray("res://Assets/Dialogue/doc.dialogue", "res://Assets/Dialogue/books.dialogue", "res://Assets/Dialogue/clone-machine.dialogue", "res://Dialogue/snus-dealer.dialogue") [layer_names]