basic Party Manager
This commit is contained in:
parent
c141e6a169
commit
6f1d5ea681
10 changed files with 158 additions and 8 deletions
65
scripts/core/CreatureRegistry.cs
Normal file
65
scripts/core/CreatureRegistry.cs
Normal file
|
|
@ -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<string> types,
|
||||
List<string> biomes,
|
||||
List<string> time_windows,
|
||||
int base_hp,
|
||||
int base_atk,
|
||||
int base_def,
|
||||
int capture_difficulty
|
||||
);
|
||||
|
||||
public record CreatureFile(int schema, List<CreatureDef> creatures);
|
||||
|
||||
private readonly Dictionary<string, CreatureDef> _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<PackManager>(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<CreatureFile>(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");
|
||||
}
|
||||
}
|
||||
1
scripts/core/CreatureRegistry.cs.uid
Normal file
1
scripts/core/CreatureRegistry.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bi2q7xkb1pew3
|
||||
38
scripts/core/PartyManager.cs
Normal file
38
scripts/core/PartyManager.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class PartyManager : Node
|
||||
{
|
||||
public List<string> PartyCreatureIds { get; private set; } = new();
|
||||
|
||||
[Export] public NodePath SaveManagerPath { get; set; }
|
||||
private SaveManager? _save;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_save = GetNodeOrNull<SaveManager>(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)}");
|
||||
}
|
||||
}
|
||||
1
scripts/core/PartyManager.cs.uid
Normal file
1
scripts/core/PartyManager.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cbqbnpj2451y4
|
||||
|
|
@ -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<SaveManager>("/root/Main/SaveManager"); // or export a path if you prefer
|
||||
_party = GetNodeOrNull<PartyManager>(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();
|
||||
}
|
||||
|
|
|
|||
22
scripts/ui/PartyHUD.cs
Normal file
22
scripts/ui/PartyHUD.cs
Normal file
|
|
@ -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<Label>("PartyLabel");
|
||||
_party = GetNodeOrNull<PartyManager>(PartyManagerPath);
|
||||
if (_party == null) GD.PrintErr("PartyHUD: PartyManagerPath not set.");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_party == null) return;
|
||||
_label.Text = "Party: " + string.Join(", ", _party.PartyCreatureIds.Take(6));
|
||||
}
|
||||
}
|
||||
1
scripts/ui/PartyHUD.cs.uid
Normal file
1
scripts/ui/PartyHUD.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://lonokky58akh
|
||||
Loading…
Add table
Add a link
Reference in a new issue