Added resource weights and layer unlock UI to the game.

This commit is contained in:
2026-05-09 13:53:00 +02:00
parent 677d8595db
commit 9fa1909dcb
7 changed files with 101 additions and 29 deletions
+27 -20
View File
@@ -4,30 +4,37 @@ using Godot;
public class ResourceDistributor
{
public static Dictionary<string, Texture2D> resources = ResourceLoader.LoadResourceSymbols();
public static Dictionary<string, float[]> weights = ResourceLoader.LoadResourceWeights();
public static string GetResource(List<string> current)
public static string GetResource(int layer)
{
List<string> availableResources = GetUnusedResources(current);
if (availableResources.Count <= 0)
{
availableResources = new List<string>(resources.Keys);
}
return availableResources[GameData.rand.Next(availableResources.Count)];
return ChooseWeighted(layer);
}
private static List<string> GetUnusedResources(List<string> current)
{
List<string> result = new List<string>();
private static string ChooseWeighted(int layer)
{
float totalWeight = 0f;
float weightLerp;
foreach (string resource in resources.Keys)
{
if (!current.Contains(resource))
{
result.Add(resource);
}
}
foreach (string resource in resources.Keys)
{
weightLerp = Mathf.Lerp(weights[resource][0], weights[resource][1], layer);
totalWeight += weightLerp;
}
return result;
}
float r = (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;
if (r <= cumulative)
return resource;
}
return "stone";
}
}