Prepicked plants editor
This commit is contained in:
parent
9eba7d3069
commit
56f75a5d06
43 changed files with 532 additions and 50 deletions
|
|
@ -42,7 +42,7 @@ public partial class SaveSerializer : Node
|
|||
|
||||
foreach (var plant in playerProgress.PlayerPlants)
|
||||
{
|
||||
save.PlayerPlants.Add(plant.internal_id);
|
||||
save.PlayerPlants.Add(plant.GetInternalID());
|
||||
}
|
||||
|
||||
access.StoreString(JsonSerializer.Serialize<SaveData>(save));
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ namespace Newlon.Components.Plants;
|
|||
|
||||
public partial class RuntimePlantData : Entity
|
||||
{
|
||||
[Export]
|
||||
public string internal_id;
|
||||
public int Line { get; set; }
|
||||
public PlantResource Resource;
|
||||
private AudioStream eatenSound = ResourceLoader.Load<AudioStream>("res://assets/audio/sfx/gulp.mp3");
|
||||
|
|
|
|||
|
|
@ -15,4 +15,5 @@ public partial class LevelGUIElements : Control
|
|||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace Newlon.Components.GUI;
|
|||
public partial class GridLoader : GridContainer
|
||||
{
|
||||
private PackedScene _plantCard;
|
||||
const string SEEDPACKED_UID = "uid://e7vutg71l6f2";
|
||||
public const string SEEDPACKED_UID = "uid://e7vutg71l6f2";
|
||||
public override void _Ready()
|
||||
{
|
||||
_plantCard = ResourceLoader.Load<PackedScene>(SEEDPACKED_UID);
|
||||
|
|
@ -24,11 +24,21 @@ public partial class GridLoader : GridContainer
|
|||
|
||||
|
||||
slot.SetResource(resource);
|
||||
slot.SetForbidden(RuntimeLevelData.LevelResource.forbiddenPlants.Contains(resource.internal_id));
|
||||
slot.SetForbidden(RuntimeLevelData.LevelResource.forbiddenPlants.Contains(resource.GetInternalID()));
|
||||
slot.SetLocked(PlayerProgress.Instance.PlayerPlants.Contains(resource) == false);
|
||||
if (GetChildCount() == 1) slot.GrabFocus();
|
||||
var handler = new ChoosableHandler(slot);
|
||||
slot.SetHandler(handler);
|
||||
|
||||
if (RuntimeLevelData.LevelResource.prepickedPlants.Contains(resource.GetInternalID()))
|
||||
{
|
||||
slot.SetHandler(new PrepickedDummyHandler(slot));
|
||||
slot.disablePacket = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.SetHandler(new ChoosableHandler(slot));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
scripts/gui/seedpackets/PrepickedDummyHandler.cs
Normal file
15
scripts/gui/seedpackets/PrepickedDummyHandler.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
namespace Newlon.Components.GUI.Seedpackets;
|
||||
public class PrepickedDummyHandler : SeedpacketHandler
|
||||
{
|
||||
public PrepickedDummyHandler(Seedpacket owner) : base(owner)
|
||||
{
|
||||
if (LevelGUIElements.Instance.SeedpacketsHotbar.GetChildCount() >= PlayerProgress.Instance.MaxSeedpackets) return;
|
||||
_owner.disablePacket = true;
|
||||
|
||||
var hotbarSeedpacket = Seedpacket.Prefab.Instantiate<Seedpacket>();
|
||||
LevelGUIElements.Instance.SeedpacketsHotbar.AddChild(hotbarSeedpacket);
|
||||
hotbarSeedpacket.SetResource(_owner.GetResource());
|
||||
|
||||
hotbarSeedpacket.SetHandler(new PrepickedHandler(_owner));
|
||||
}
|
||||
}
|
||||
1
scripts/gui/seedpackets/PrepickedDummyHandler.cs.uid
Normal file
1
scripts/gui/seedpackets/PrepickedDummyHandler.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c7uf1ygofsurs
|
||||
23
scripts/gui/seedpackets/PrepickedHandler.cs
Normal file
23
scripts/gui/seedpackets/PrepickedHandler.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using Newlon.Components.Level;
|
||||
|
||||
namespace Newlon.Components.GUI.Seedpackets;
|
||||
|
||||
public class PrepickedHandler : SeedpacketHandler
|
||||
{
|
||||
public PrepickedHandler(Seedpacket owner) : base(owner)
|
||||
{
|
||||
RuntimeLevelData.Instance.OnLevelStateChanged += OnLevelStateChanged;
|
||||
}
|
||||
|
||||
public void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
|
||||
{
|
||||
if (state == RuntimeLevelData.LevelStates.Game)
|
||||
{
|
||||
_owner.SetHandler(new HotbarHandler(_owner));
|
||||
}
|
||||
else if (state != RuntimeLevelData.LevelStates.ChooseYourSeeds)
|
||||
{
|
||||
_owner.disablePacket = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scripts/gui/seedpackets/PrepickedHandler.cs.uid
Normal file
1
scripts/gui/seedpackets/PrepickedHandler.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d3da4b6e4qwtm
|
||||
|
|
@ -39,7 +39,7 @@ public partial class InitialPackedSceneSpawner : Node
|
|||
{
|
||||
PoolContainer.Instance.Plants.AddChild(plant);
|
||||
node.GlobalPosition = position;
|
||||
plant.Resource = GameRegistry.GetEntityByName(plant.internal_id) as PlantResource;
|
||||
plant.Resource = GameRegistry.GetEntityByName(plant.Resource.GetInternalID()) as PlantResource;
|
||||
PoolContainer.Instance.EntityField[plant.Resource.Layer].Add(plant.GlobalPosition, plant);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public partial class SurvivalZombieSpawner : Node
|
|||
|
||||
foreach (var zom in wave)
|
||||
{
|
||||
ZombieSequencer.Instance.Add(zom.internal_id);
|
||||
ZombieSequencer.Instance.Add(zom.GetInternalID());
|
||||
}
|
||||
|
||||
big_wave = false;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,17 @@ public partial class EntityResource : Resource
|
|||
[Export] public Texture2D Preview;
|
||||
[Export] public CustomSeedpacketFrame CustomFrame;
|
||||
[Export] public int Order = 0;
|
||||
public string internal_id;
|
||||
public string parsedDescription;
|
||||
public bool isDescriptionParsed;
|
||||
private string internal_id = "";
|
||||
public string GetInternalID()
|
||||
{
|
||||
if (internal_id == "")
|
||||
{
|
||||
string[] splitstr = ResourcePath.Split('/');
|
||||
string file = splitstr[splitstr.Length - 1].ToLower();
|
||||
internal_id = file.TrimSuffix(".tres");
|
||||
}
|
||||
return internal_id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,7 @@ public partial class GameRegistry : Node
|
|||
if (ResourceLoader.Exists(PLANT_RESOURCE_PATH + file))
|
||||
{
|
||||
var plant = ResourceLoader.Load<PlantResource>(PLANT_RESOURCE_PATH + file);
|
||||
plant.internal_id = file.ToLower().Split('.')[0];
|
||||
EntityDictionary.Add(file.ToLower().Split('.')[0], plant);
|
||||
EntityDictionary.Add(plant.GetInternalID(), plant);
|
||||
}
|
||||
}
|
||||
//Zombie init
|
||||
|
|
@ -33,8 +32,7 @@ public partial class GameRegistry : Node
|
|||
if (ResourceLoader.Exists(ZOMBIE_RESOURCE_PATH + file))
|
||||
{
|
||||
var zombie = ResourceLoader.Load<ZombieResource>(ZOMBIE_RESOURCE_PATH + file);
|
||||
zombie.internal_id = file.ToLower().Split('.')[0];
|
||||
EntityDictionary.Add(file.ToLower().Split('.')[0], zombie);
|
||||
EntityDictionary.Add(zombie.GetInternalID(), zombie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue