diff --git a/project.godot b/project.godot index ebe9cec..a9d2043 100644 --- a/project.godot +++ b/project.godot @@ -73,6 +73,11 @@ capture_mash={ , Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(389, 19),"global_position":Vector2(398, 67),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) ] } +battle_attack={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) +] +} [physics] diff --git a/scenes/Main.tscn b/scenes/Main.tscn index 23cfb12..f38a1eb 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -10,6 +10,8 @@ [ext_resource type="Script" uid="uid://boip0mbmeqmhk" path="res://scripts/core/GameRoot.cs" id="8_jlsqs"] [ext_resource type="PackedScene" uid="uid://bffdg1ki45e4e" path="res://ui/CaptureUI.tscn" id="9_lhr70"] [ext_resource type="Script" uid="uid://bl7xagtutg20w" path="res://scripts/core/CaptureController.cs" id="10_wp0k4"] +[ext_resource type="Script" uid="uid://cbqbnpj2451y4" path="res://scripts/core/PartyManager.cs" id="11_wp0k4"] +[ext_resource type="PackedScene" uid="uid://jfswyfq1eswl" path="res://ui/PartyHUD.tscn" id="12_bjd11"] [node name="Main" type="Node2D" unique_id=1194367579] @@ -39,7 +41,15 @@ script = ExtResource("6_c01mt") script = ExtResource("8_jlsqs") [node name="CaptureUi" parent="." unique_id=1650401906 instance=ExtResource("9_lhr70")] +PartyManagerPath = NodePath("../PartyManager") [node name="CaptureController" type="Node" parent="." unique_id=68644702] script = ExtResource("10_wp0k4") CaptureUIPath = NodePath("../CaptureUi") + +[node name="PartyManager" type="Node" parent="." unique_id=1307007773] +script = ExtResource("11_wp0k4") +SaveManagerPath = NodePath("../SaveManager") + +[node name="PartyHud" parent="." unique_id=1636873718 instance=ExtResource("12_bjd11")] +PartyManagerPath = NodePath("../PartyManager") diff --git a/scripts/core/CreatureRegistry.cs b/scripts/core/CreatureRegistry.cs new file mode 100644 index 0000000..84750e6 --- /dev/null +++ b/scripts/core/CreatureRegistry.cs @@ -0,0 +1,65 @@ +using Godot; +using System.Collections.Generic; +using System.Text.Json; + +public partial class CreatureRegistry : Node +{ + public record CreatureDef( + string id, + string name, + List types, + List biomes, + List time_windows, + int base_hp, + int base_atk, + int base_def, + int capture_difficulty + ); + + public record CreatureFile(int schema, List creatures); + + private readonly Dictionary _byId = new(); + + public CreatureDef Get(string id) + { + if (_byId.TryGetValue(id, out var def)) return def; + throw new KeyNotFoundException($"Unknown creature id: {id}"); + } + + public bool TryGet(string id, out CreatureDef def) => _byId.TryGetValue(id, out def!); + + [Export] public NodePath PackManagerPath { get; set; } + private PackManager? _packs; + + public override void _Ready() + { + _packs = GetNodeOrNull(PackManagerPath); + if (_packs == null) + { + GD.PrintErr("CreatureRegistry: PackManagerPath not set."); + return; + } + + var path = _packs.Resolve("data/creatures/creatures.json"); + if (path == null) + { + GD.PrintErr("CreatureRegistry: Could not resolve data/creatures/creatures.json"); + return; + } + + var json = FileAccess.GetFileAsString(path); + var file = JsonSerializer.Deserialize(json); + + if (file?.creatures == null) + { + GD.PrintErr("CreatureRegistry: Failed to parse creatures.json"); + return; + } + + _byId.Clear(); + foreach (var c in file.creatures) + _byId[c.id] = c; + + GD.Print($"CreatureRegistry: loaded {_byId.Count} creatures"); + } +} diff --git a/scripts/core/CreatureRegistry.cs.uid b/scripts/core/CreatureRegistry.cs.uid new file mode 100644 index 0000000..d04870d --- /dev/null +++ b/scripts/core/CreatureRegistry.cs.uid @@ -0,0 +1 @@ +uid://bi2q7xkb1pew3 diff --git a/scripts/core/PartyManager.cs b/scripts/core/PartyManager.cs new file mode 100644 index 0000000..f342687 --- /dev/null +++ b/scripts/core/PartyManager.cs @@ -0,0 +1,38 @@ +using Godot; +using System.Collections.Generic; +using System.Linq; + +public partial class PartyManager : Node +{ + public List PartyCreatureIds { get; private set; } = new(); + + [Export] public NodePath SaveManagerPath { get; set; } + private SaveManager? _save; + + public override void _Ready() + { + _save = GetNodeOrNull(SaveManagerPath); + if (_save == null) + { + GD.PrintErr("PartyManager: SaveManagerPath not set."); + return; + } + + // v0: party is all captured creatures (later: cap to 6 and add boxes) + PartyCreatureIds = _save.State.CapturedCreatures.ToList(); + GD.Print($"Party loaded: {string.Join(", ", PartyCreatureIds)}"); + } + + public void AddToParty(string creatureId) + { + if (_save == null) return; + + _save.State.CapturedCreatures.Add(creatureId); + _save.Save(); + + if (!PartyCreatureIds.Contains(creatureId)) + PartyCreatureIds.Add(creatureId); + + GD.Print($"Party updated: {string.Join(", ", PartyCreatureIds)}"); + } +} diff --git a/scripts/core/PartyManager.cs.uid b/scripts/core/PartyManager.cs.uid new file mode 100644 index 0000000..a1cdf4d --- /dev/null +++ b/scripts/core/PartyManager.cs.uid @@ -0,0 +1 @@ +uid://cbqbnpj2451y4 diff --git a/scripts/ui/CaptureUI.cs b/scripts/ui/CaptureUI.cs index cb111a1..e500a4f 100644 --- a/scripts/ui/CaptureUI.cs +++ b/scripts/ui/CaptureUI.cs @@ -5,6 +5,8 @@ public partial class CaptureUI : CanvasLayer [Export] public float BaseTimeLimit = 3.0f; [Export] public float BaseRequired = 14.0f; // “energy” required [Export] public float EnergyPerPress = 1.0f; + [Export] public NodePath PartyManagerPath { get; set; } + private PartyManager? _party; private Creature? _target; private SaveManager? _save; @@ -32,7 +34,8 @@ public partial class CaptureUI : CanvasLayer _ballOption.AddItem("Basic Soulball (easy)", 0); _ballOption.AddItem("Heavy Soulball (hard)", 1); - _save = GetNodeOrNull("/root/Main/SaveManager"); // or export a path if you prefer + _party = GetNodeOrNull(PartyManagerPath); + if (_party == null) GD.PrintErr("CaptureUI: PartyManagerPath not set."); } public void StartCapture(Creature target) @@ -102,13 +105,7 @@ public partial class CaptureUI : CanvasLayer GD.Print($"Captured {_target.CreatureId}"); - // v0: store captured creature IDs - if (_save != null) - { - _save.State.CapturedCreatures.Add(_target.CreatureId); - _save.Save(); - } - + _party?.AddToParty(_target.CreatureId); _target.Despawn(); EndCapture(); } diff --git a/scripts/ui/PartyHUD.cs b/scripts/ui/PartyHUD.cs new file mode 100644 index 0000000..21773d5 --- /dev/null +++ b/scripts/ui/PartyHUD.cs @@ -0,0 +1,22 @@ +using Godot; +using System.Linq; + +public partial class PartyHUD : CanvasLayer +{ + [Export] public NodePath PartyManagerPath { get; set; } + private PartyManager? _party; + private Label _label = null!; + + public override void _Ready() + { + _label = GetNode