Big project cleanup with overhaul of file responsibilities (KISS) and code (DRY, YAGNI)

This commit is contained in:
2026-05-14 11:17:02 +02:00
parent bd6cdeb97b
commit 300c8f5a42
54 changed files with 2030 additions and 1745 deletions
+17 -17
View File
@@ -1,40 +1,40 @@
using System.Collections.Generic;
using Godot;
public class ResourceDistributor
public static class ResourceDistributor
{
public static Dictionary<string, Texture2D> resources = ResourceLoader.LoadResourceSymbols();
public static Dictionary<string, float[]> weights = ResourceLoader.LoadResourceWeights();
public static Dictionary<string, Texture2D> resources = ResourceLoader.LoadResourceSymbols();
public static Dictionary<string, float[]> weights = ResourceLoader.LoadResourceWeights();
public static string GetResource(int layer)
{
return ChooseWeighted(layer);
}
public static string GetResource(int layer)
{
return ChooseWeighted(layer);
}
private static string ChooseWeighted(int layer)
private static string ChooseWeighted(int layer)
{
float totalWeight = 0f;
float weightLerp;
foreach (string resource in resources.Keys)
{
weightLerp = Mathf.Lerp(weights[resource][0], weights[resource][1], layer);
totalWeight += weightLerp;
totalWeight += GetWeight(resource, layer);
}
float r = (float)(GameData.rand.NextDouble() * totalWeight);
float randomWeight = (float)(GameData.rand.NextDouble() * totalWeight);
float cumulative = 0f;
foreach (string resource in resources.Keys)
{
weightLerp = Mathf.Lerp(weights[resource][0], weights[resource][1], layer);
cumulative += weightLerp;
cumulative += GetWeight(resource, layer);
if (r <= cumulative)
return resource;
if (randomWeight <= cumulative) return resource;
}
return "stone";
}
private static float GetWeight(string resource, int layer)
{
return Mathf.Lerp(weights[resource][0], weights[resource][1], layer);
}
}