Refactor hut tier definitions to use images and scales instead of scene paths; add moddable visual component
This commit is contained in:
28
Scripts/Components/ModdableVisual.cs
Normal file
28
Scripts/Components/ModdableVisual.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Godot;
|
||||
|
||||
namespace ParasiticGod.Scripts.Components;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ModdableVisual : Node2D
|
||||
{
|
||||
[Export] private Sprite2D _sprite;
|
||||
public Follower.FollowerTier Tier { get; private set; }
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (_sprite != null)
|
||||
{
|
||||
_sprite.Texture = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize(Follower.FollowerTier tier, Texture2D texture, Vector2 scale)
|
||||
{
|
||||
Tier = tier;
|
||||
if (_sprite != null && texture != null)
|
||||
{
|
||||
_sprite.Texture = texture;
|
||||
_sprite.Scale = scale;
|
||||
}
|
||||
}
|
||||
}
|
1
Scripts/Components/ModdableVisual.cs.uid
Normal file
1
Scripts/Components/ModdableVisual.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dpfcbaqgq3l6d
|
@@ -14,6 +14,7 @@ public partial class PopulationVisualizer : Node
|
||||
[Export] private Node2D _markersContainer;
|
||||
[Export] private int _unitsPerMarker = 5;
|
||||
[Export] public VisualCategory Category { get; private set; }
|
||||
[Export] private PackedScene _moddableVisualScene;
|
||||
|
||||
private List<TierDefinition> _tiers;
|
||||
private readonly List<FollowerMarker> _markers = [];
|
||||
@@ -105,11 +106,15 @@ public partial class PopulationVisualizer : Node
|
||||
|
||||
if (i < followersToShow)
|
||||
{
|
||||
if (!marker.IsOccupied || _lastKnownTierIndex != newTierIndex)
|
||||
var currentVisual = marker.GetChildOrNull<ModdableVisual>(0);
|
||||
if (currentVisual == null || currentVisual.Tier != currentTier.TierEnum)
|
||||
{
|
||||
if (marker.IsOccupied) marker.RemoveFollower();
|
||||
var followerInstance = currentTier.Scene.Instantiate<Follower>();
|
||||
marker.PlaceFollower(followerInstance);
|
||||
if (marker.GetChildCount() > 0) marker.GetChild(0).QueueFree();
|
||||
|
||||
var visualInstance = _moddableVisualScene.Instantiate<ModdableVisual>();
|
||||
visualInstance.Initialize(currentTier.TierEnum, currentTier.Texture, currentTier.Scale);
|
||||
|
||||
marker.AddChild(visualInstance);
|
||||
needsChange = true;
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,8 @@ namespace ParasiticGod.Scripts.Core;
|
||||
[GlobalClass]
|
||||
public partial class TierDefinition : Resource
|
||||
{
|
||||
[Export] public PackedScene Scene { get; set; }
|
||||
[Export] public Texture2D Texture { get; set; }
|
||||
[Export] public long Threshold { get; set; }
|
||||
[Export] public Follower.FollowerTier TierEnum { get; set; }
|
||||
[Export] public Vector2 Scale { get; set; } = Vector2.One;
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace ParasiticGod.Scripts.Core;
|
||||
|
||||
@@ -6,7 +7,8 @@ public class TierDto
|
||||
{
|
||||
public Follower.FollowerTier TierEnum { get; set; }
|
||||
public long Threshold { get; set; }
|
||||
public string ScenePath { get; set; }
|
||||
public string ImagePath { get; set; }
|
||||
public Vector2 Scale { get; set; } = Vector2.One;
|
||||
}
|
||||
|
||||
public class TierListDto
|
||||
|
@@ -27,11 +27,18 @@ public static class TierLoader
|
||||
|
||||
foreach (var dto in tierListDto.Tiers)
|
||||
{
|
||||
var image = Image.LoadFromFile(dto.ImagePath);
|
||||
if (image == null)
|
||||
{
|
||||
GD.PushError($"Failed to load image at path: {dto.ImagePath}");
|
||||
continue;
|
||||
}
|
||||
var tierDef = new TierDefinition
|
||||
{
|
||||
Threshold = dto.Threshold,
|
||||
TierEnum = dto.TierEnum,
|
||||
Scene = GD.Load<PackedScene>(dto.ScenePath)
|
||||
Texture = ImageTexture.CreateFromImage(image),
|
||||
Scale = new Vector2(dto.Scale.X, dto.Scale.Y)
|
||||
};
|
||||
loadedTiers.Add(tierDef);
|
||||
}
|
||||
|
Reference in New Issue
Block a user