Forbidden plants

This commit is contained in:
Rendo 2025-07-29 04:41:38 +05:00
commit 3fe903f2b8
9 changed files with 92 additions and 36 deletions

View file

@ -1,5 +1,7 @@
using System.Collections.Generic;
using Godot;
using Godot.Collections;
using Newlon.Components.GUI;
using Newlon.Resources;
[Tool]
@ -9,15 +11,17 @@ public partial class SeedpacketEditor : BaseEditor
public override void SetEditedData(AdventureLevelResource data)
{
base.SetEditedData(data);
SetPrepickedPlants();
SetupPrepickedPlants();
SetupForbiddablePlants();
}
public override void Save()
{
CalculatePrepickedPlants();
CalculateForbiddenPlants();
base.Save();
}
private void SetPrepickedPlants()
private void SetupPrepickedPlants()
{
for (int i = 0; i < editedResource.prepickedPlants.Count; i++)
{
@ -28,6 +32,21 @@ public partial class SeedpacketEditor : BaseEditor
}
}
}
private void SetupForbiddablePlants()
{
var plants = GetPlants();
var packed = ResourceLoader.Load<PackedScene>("uid://dymyownbt688c");
for (int i = 0; i < plants.Count; i++)
{
var seedpacket = packed.Instantiate<ForbiddableSeedpacket>();
seedpacket.HeldResource = plants[i];
seedpacket.forbidden = editedResource.forbiddenPlants.Contains(plants[i].GetInternalID());
seedpacket.RefreshTexture();
seedpacket.SaveCallback += Save;
GetNode("%FPlantsContainer").AddChild(seedpacket);
}
}
private void CalculatePrepickedPlants()
{
Array<string> prepicked = new();
@ -40,6 +59,20 @@ public partial class SeedpacketEditor : BaseEditor
}
editedResource.prepickedPlants = prepicked;
}
private void CalculateForbiddenPlants()
{
Array<string> forbidden = new();
foreach (var child in GetNode("%FPlantsContainer").GetChildren())
{
if (child is ForbiddableSeedpacket packet && packet.forbidden)
{
forbidden.Add(packet.HeldResource.GetInternalID());
}
}
editedResource.forbiddenPlants = forbidden;
}
private PlantResource TryGetPlant(string plantName)
{
foreach (var file in ResourceLoader.ListDirectory(PLANTS_DIRECTORY))
@ -49,5 +82,20 @@ public partial class SeedpacketEditor : BaseEditor
}
return null;
}
private List<PlantResource> GetPlants()
{
var result = new List<PlantResource>();
foreach (var file in ResourceLoader.ListDirectory(PLANTS_DIRECTORY))
{
result.Add(ResourceLoader.Load<PlantResource>(PLANTS_DIRECTORY + file));
}
result.Sort((a, b) =>
{
return a.Order - b.Order;
});
return result;
}
}