This commit is contained in:
Rendo 2025-07-03 19:34:09 +05:00
commit b932e82555
39 changed files with 575 additions and 78 deletions

View file

@ -9,7 +9,9 @@ public interface IEntity
{
public int Hp { get; }
public int MaxHp { get; }
public void TakeDamage(int amount,Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL);
public void TakeDamage(int amount, Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL);
public void Heal(int amount, Node origin);
public void DisableBrain();
public void EnableBrain();
}

View file

@ -0,0 +1,36 @@
using Godot;
using Newlon.Components.GUI.Seedpackets;
public partial class AlmanachGrid : GridContainer
{
private PackedScene _plantCard;
[Export]
private bool _zombies;
public override void _Ready()
{
_plantCard = ResourceLoader.Load<PackedScene>("res://scenes/gui/seedpacket.tscn");
if (_zombies)
{
foreach (var resource in GameRegistry.GetZombies())
{
Seedpacket slot = _plantCard.Instantiate<Seedpacket>();
AddChild(slot);
slot.SetResource(resource);
slot.SetHandler(new AlmanachHandler(slot));
}
}
else
{
foreach (var resource in GameRegistry.GetPlants())
{
Seedpacket slot = _plantCard.Instantiate<Seedpacket>();
AddChild(slot);
slot.SetResource(resource);
slot.SetHandler(new AlmanachHandler(slot));
}
}
}
}

View file

@ -0,0 +1 @@
uid://0mvmfvwe1bc7

View file

@ -17,7 +17,7 @@ public partial class GridLoader : GridContainer
Seedpacket slot = _plantCard.Instantiate<Seedpacket>();
AddChild(slot);
slot.SetPlantResource(resource);
slot.SetResource(resource);
slot.SetHandler(new ChoosableHandler(slot));
}
}

View file

@ -1,11 +1,12 @@
using Godot;
using Newlon;
using Newlon.Components;
using Newlon.Components.GUI.Seedpackets;
using Newlon.Components.Plants;
public partial class Previewport : SubViewport
{
private RuntimePlantData current_display;
private Node current_display;
private Texture2D start_Field;
[Export] private Label title;
@ -19,13 +20,14 @@ public partial class Previewport : SubViewport
public void OnFocusChanged(Control node)
{
if (GetParent<Control>().IsVisibleInTree() == false) return;
if (node is Seedpacket packet)
{
ChangeDisplay(packet.GetPlantResource());
ChangeDisplay(packet.GetResource());
}
}
private void ChangeDisplay(PlantResource resource)
private void ChangeDisplay(DisplayResource resource)
{
// Expand with updates
if (current_display != null)
@ -38,11 +40,12 @@ public partial class Previewport : SubViewport
}
else
GetNode<Sprite2D>("FrameField").Texture = start_Field;
current_display = resource.Scene.Instantiate<RuntimePlantData>();
current_display = resource.Scene.Instantiate();
title.Text = resource.display_name;
description.Text = resource.display_description;
AddChild(current_display);
current_display.DisableBrain();
if (current_display is IEntity entity)
entity.DisableBrain();
}
}

View file

@ -0,0 +1,10 @@
using Godot;
namespace Newlon.Components.GUI.Seedpackets;
public class AlmanachHandler : SeedpacketHandler
{
public AlmanachHandler(Seedpacket owner) : base(owner)
{
}
}

View file

@ -0,0 +1 @@
uid://pse018r220mt

View file

@ -13,7 +13,7 @@ public class ChoosableHandler : SeedpacketHandler, ISeedpacketPress
var hotbarSeedpacket = Seedpacket.Prefab.Instantiate<Seedpacket>();
LevelGUIElements.Instance.SeedpacketsHotbar.AddChild(hotbarSeedpacket);
hotbarSeedpacket.SetPlantResource(_owner.GetPlantResource());
hotbarSeedpacket.SetResource(_owner.GetResource());
var pregameHandler = new HotbarPregameHandler(hotbarSeedpacket);
hotbarSeedpacket.SetHandler(pregameHandler);

View file

@ -10,13 +10,13 @@ public class HotbarHandler : SeedpacketHandler, ISeedpacketPress, ISeedpacketPro
public void Pressed()
{
PlantField.Instance.SetPlant(_owner, _owner.GetPlantResource());
PlantField.Instance.SetPlant(_owner, _owner.GetResource());
AudioSequencer.Play("lift_seed", Seedpacket.LiftStream);
}
public void Process()
{
_owner.disablePacket = RuntimeLevelData.Instance.SunCount < _owner.GetPlantResource().Cost;
_owner.disablePacket = RuntimeLevelData.Instance.SunCount < _owner.GetResource().Cost;
}
public void OnUnfocused()
{

View file

@ -8,7 +8,7 @@ public partial class Seedpacket : TextureButton
public static AudioStream UntapStream;
public static AudioStream LiftStream;
private const string PATH_TO_PACKED_SCENE = "res://scenes/gui/seedpacket.tscn";
private PlantResource _resource;
private DisplayResource _resource;
private Label _cost;
private TextureRect _icon;
private Timer _timer;
@ -50,14 +50,14 @@ public partial class Seedpacket : TextureButton
}
if (_handler is ISeedpacketProcess processHandler) processHandler.Process();
}
public void SetPlantResource( PlantResource resource )
public void SetResource(DisplayResource resource )
{
_resource = resource;
UpdateContents();
}
public PlantResource GetPlantResource()
public DisplayResource GetResource()
{
return _resource;
}

View file

@ -7,7 +7,7 @@ namespace Newlon.Components.Level;
public partial class PlantField : Node2D
{
private Node2D _plantSetter;
private PlantResource _resource;
private DisplayResource _resource;
private Seedpacket _slot;
private bool _previousCanPlace;
private ChannelPlayer player;
@ -21,18 +21,18 @@ public partial class PlantField : Node2D
player = GetNode<ChannelPlayer>("PlantPlayer");
}
public void SetPlant(Seedpacket slot, PlantResource plant)
public void SetPlant(Seedpacket slot, DisplayResource resource)
{
_resource = plant;
_resource = resource;
_slot = slot;
if (plant == null)
if (resource == null)
{
foreach(var child in _plantSetter.GetChildren())
child.QueueFree();
}
else
{
var scene = plant.Scene.Instantiate<Node2D>();
var scene = resource.Scene.Instantiate<Node2D>();
_plantSetter.AddChild(scene);
scene.UseParentMaterial = true;
}
@ -93,7 +93,7 @@ public partial class PlantField : Node2D
var plant = _resource.Scene.Instantiate<RuntimePlantData>();
PoolContainer.Instance.Plants.AddChild(plant);
plant.GlobalPosition = (_plantSetter.GlobalPosition / Utility.Tile).Ceil() * Utility.Tile - new Vector2(20, 14);
plant.Resource = _resource;
plant.Resource = (PlantResource)_resource;
PoolContainer.Instance.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant);

View file

@ -15,7 +15,7 @@ public partial class RuntimeLevelData : Node
}
[Export]
public int SunCount { get; private set; } = 0;
public float SunCount { get; private set; } = 0;
public event Action<LevelStates> OnLevelStateChanged;
public static RuntimeLevelData Instance { get; private set; }
@ -29,17 +29,17 @@ public partial class RuntimeLevelData : Node
}
#region Sun
public void AddSun(int amount)
public void AddSun(float amount)
{
SunCount += amount;
}
public void SpendSun(int amount)
public void SpendSun(float amount)
{
SunCount -= amount;
}
public bool CheckSpendSun(int amount)
public bool CheckSpendSun(float amount)
{
if (SunCount - amount < 0) return false;

View file

@ -38,16 +38,16 @@ public partial class SurvivalZombieSpawner : Node
cachedTankPool.Sort((x, y) =>
{
return (int)(x.cost - y.cost);
return (int)(x.Cost - y.Cost);
});
cachedHordePool.Sort((x, y) =>
{
return (int)(x.cost - y.cost);
return (int)(x.Cost - y.Cost);
});
minSupportPoints = cachedSupportPool[0].cost;
minTankPoints = cachedTankPool[0].cost;
minHordePoints = cachedHordePool[0].cost;
minSupportPoints = cachedSupportPool[0].Cost;
minTankPoints = cachedTankPool[0].Cost;
minHordePoints = cachedHordePool[0].Cost;
fin_a = (velocity_curve.Sample(velocity_curve.MaxDomain) - velocity_curve.Sample(velocity_curve.MaxDomain - 0.001f)) / 0.001f;
}
@ -107,10 +107,10 @@ public partial class SurvivalZombieSpawner : Node
while (given_points >= minSupportPoints)
{
var chosen_zombie = cachedSupportPool[rng.RandiRange(0, cachedSupportPool.Count - 1)];
if (given_points - chosen_zombie.cost >= 0)
if (given_points - chosen_zombie.Cost >= 0)
{
wave.Add(chosen_zombie);
given_points -= chosen_zombie.cost;
given_points -= chosen_zombie.Cost;
}
}
return given_points;
@ -124,14 +124,14 @@ public partial class SurvivalZombieSpawner : Node
int zombieIndex = cachedTankPool.Count - 1;
while (given_points >= minSupportPoints && zombieIndex > -1)
{
if (cachedTankPool[zombieIndex].cost > given_points)
if (cachedTankPool[zombieIndex].Cost > given_points)
{
zombieIndex--;
continue;
}
var chosen_zombie = cachedTankPool[zombieIndex];
wave.Add(chosen_zombie);
given_points -= chosen_zombie.cost;
given_points -= chosen_zombie.Cost;
}
return given_points;
}
@ -141,18 +141,18 @@ public partial class SurvivalZombieSpawner : Node
{
return given_points;
}
while (is_big == false && cachedHordePool.Count > 1 && cachedHordePool[1].cost * 15 <= given_points)
while (is_big == false && cachedHordePool.Count > 1 && cachedHordePool[1].Cost * 15 <= given_points)
{
cachedHordePool.RemoveAt(0);
minHordePoints = cachedHordePool[0].cost;
minHordePoints = cachedHordePool[0].Cost;
}
while (given_points >= minHordePoints)
{
var chosen_zombie = cachedHordePool[rng.RandiRange(0, cachedHordePool.Count - 1)];
if (given_points - chosen_zombie.cost >= 0)
if (given_points - chosen_zombie.Cost >= 0)
{
wave.Add(chosen_zombie);
given_points -= chosen_zombie.cost;
given_points -= chosen_zombie.Cost;
}
}
return given_points;

View file

@ -58,7 +58,7 @@ public partial class ZombieSequencer : Node2D
private void Spawn(string id, int lane)
{
RuntimeZombieData zombie = GameRegistry.GetZombieByName(id).scene.Instantiate<RuntimeZombieData>();
RuntimeZombieData zombie = GameRegistry.GetZombieByName(id).Scene.Instantiate<RuntimeZombieData>();
PoolContainer.Instance.Zombies.AddChild(zombie);
zombie.GlobalPosition = new Vector2(GlobalPosition.X, Utility.RightFieldBoundary.Y - (lane - 1) * Utility.TileHeight);

View file

@ -146,5 +146,17 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
_activeEffectSlots[slot].Exit(this);
_activeEffectSlots[slot] = null;
}
#endregion
public void DisableBrain()
{
GetNode<AnimationPlayer>("AnimationPlayer").ProcessMode = ProcessModeEnum.Pausable;
ProcessMode = ProcessModeEnum.Disabled;
}
public void EnableBrain()
{
GetNode<AnimationPlayer>("AnimationPlayer").ProcessMode = ProcessModeEnum.Inherit;
ProcessMode = ProcessModeEnum.Inherit;
}
#endregion
}