Prepicked plants editor
This commit is contained in:
parent
9eba7d3069
commit
56f75a5d06
43 changed files with 532 additions and 50 deletions
|
|
@ -0,0 +1,53 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Newlon.Resources;
|
||||
|
||||
[Tool]
|
||||
public partial class SeedpacketEditor : BaseEditor
|
||||
{
|
||||
private const string PLANTS_DIRECTORY = "res://assets/plants/";
|
||||
public override void SetEditedData(AdventureLevelResource data)
|
||||
{
|
||||
base.SetEditedData(data);
|
||||
SetPrepickedPlants();
|
||||
}
|
||||
|
||||
public override void Save()
|
||||
{
|
||||
CalculatePrepickedPlants();
|
||||
base.Save();
|
||||
}
|
||||
private void SetPrepickedPlants()
|
||||
{
|
||||
for (int i = 0; i < editedResource.prepickedPlants.Count; i++)
|
||||
{
|
||||
if (GetNode("%PrepickedContainer").GetChild(i).GetNode("Seedpacket") is DnDSeedpacket packet)
|
||||
{
|
||||
packet.HeldResource = TryGetPlant(editedResource.prepickedPlants[i]);
|
||||
packet.RefreshTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void CalculatePrepickedPlants()
|
||||
{
|
||||
Array<string> prepicked = new();
|
||||
foreach (var child in GetNode("%PrepickedContainer").GetChildren())
|
||||
{
|
||||
if (child.GetNode("Seedpacket") is DnDSeedpacket packet && packet.HeldResource != null)
|
||||
{
|
||||
prepicked.Add(packet.HeldResource.GetInternalID());
|
||||
}
|
||||
}
|
||||
editedResource.prepickedPlants = prepicked;
|
||||
}
|
||||
private PlantResource TryGetPlant(string plantName)
|
||||
{
|
||||
foreach (var file in ResourceLoader.ListDirectory(PLANTS_DIRECTORY))
|
||||
{
|
||||
if (plantName != file.TrimSuffix(".tres").ToLower()) continue;
|
||||
return ResourceLoader.Load<PlantResource>(PLANTS_DIRECTORY + file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue