Add forest visualization and update miracle requirements

This commit is contained in:
2025-08-23 03:16:28 +02:00
parent 18312671d7
commit d198aed01f
9 changed files with 5381 additions and 4 deletions

File diff suppressed because it is too large Load Diff

7
Scenes/tree.tscn Normal file
View File

@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://8w7tvsgkev1y"]
[ext_resource type="Texture2D" uid="uid://cemch3556ibiy" path="res://Sprites/Tree.png" id="1_0vwjc"]
[node name="Tree" type="Sprite2D"]
scale = Vector2(0.01, 0.01)
texture = ExtResource("1_0vwjc")

View File

@@ -30,12 +30,15 @@ public class GameLogic
public bool TryToPerformMiracle(GameState state, MiracleDefinition miracle)
{
if (state.Get(Stat.Faith) < miracle.FaithCost || state.Get(Stat.Followers) < miracle.FollowersRequired)
if (state.Get(Stat.Faith) < miracle.FaithCost ||
state.Get(Stat.Followers) < miracle.FollowersRequired ||
state.Get(Stat.Production) < miracle.ProductionRequired)
{
return false;
}
state.Modify(Stat.Faith, -miracle.FaithCost);
state.Modify(Stat.Production, -miracle.ProductionRequired);
if (miracle.Effects != null)
{

View File

@@ -21,8 +21,8 @@ public class GameState
Set(Stat.Faith, 50);
Set(Stat.Followers, 40);
Set(Stat.FaithPerFollower, 0.5);
Set(Stat.ProductionPerSecond, 1.0);
Set(Stat.CorruptionPerSecond, 0.1);
Set(Stat.ProductionPerSecond, 0.0);
Set(Stat.CorruptionPerSecond, 0.01);
}
public double Get(Stat stat) => _stats[stat].Value;

View File

@@ -13,6 +13,7 @@ public partial class MiracleDefinition : Resource
[Export] public string Name { get; set; }
[Export] public double FaithCost { get; set; }
[Export] public long FollowersRequired { get; set; }
[Export] public double ProductionRequired { get; set; }
[Export] public Array<Effect> Effects { get; set; }
}

View File

@@ -32,6 +32,7 @@ public class MiracleDto
public string Name { get; set; }
public double FaithCost { get; set; }
public long FollowersRequired { get; set; }
public double ProductionRequired { get; set; }
public bool UnlockedByDefault { get; set; }
public List<EffectDto> Effects { get; set; }
}

View File

@@ -69,6 +69,7 @@ public static class MiracleLoader
Name = miracleDto.Name,
FaithCost = miracleDto.FaithCost,
FollowersRequired = miracleDto.FollowersRequired,
ProductionRequired = miracleDto.ProductionRequired,
Effects = []
};

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Godot;
using ParasiticGod.Scripts.Core;
using ParasiticGod.Scripts.Singletons;
namespace ParasiticGod.Scripts;
[GlobalClass]
public partial class ForestVisualizer : Node
{
[Export] private Node2D _treesContainer;
private List<Node2D> _trees = [];
private int _lastKnownTreesToShow = -1;
private bool _isUpdating = false;
public override void _Ready()
{
foreach (var child in _treesContainer.GetChildren())
{
if (child is Node2D tree)
{
_trees.Add(tree);
}
}
var rng = new RandomNumberGenerator();
rng.Randomize();
_trees = _trees.OrderBy(_ => Guid.NewGuid()).ToList();
GameBus.Instance.StateChanged += OnStateChanged;
}
public override void _ExitTree()
{
GameBus.Instance.StateChanged -= OnStateChanged;
}
private void OnStateChanged(GameState newState)
{
if (_isUpdating) return;
var corruptionRatio = newState.Get(Stat.Corruption) / 100.0;
var treesToShow = (int)(_trees.Count * (1.0 - corruptionRatio));
if (treesToShow != _lastKnownTreesToShow)
{
UpdateForestProgressively(treesToShow);
}
}
private async void UpdateForestProgressively(int treesToShow)
{
_isUpdating = true;
for (var i = 0; i < _trees.Count; i++)
{
var tree = _trees[i];
var shouldBeVisible = i < treesToShow;
var needsChange = tree.Visible != shouldBeVisible;
if (needsChange)
{
tree.Visible = shouldBeVisible;
await ToSignal(GetTree().CreateTimer(0.01f), SceneTreeTimer.SignalName.Timeout);
}
}
_lastKnownTreesToShow = treesToShow;
_isUpdating = false;
}
}

View File

@@ -0,0 +1 @@
uid://furbvcmw31bx