complete refactor
This commit is contained in:
parent
65fe0e5c5d
commit
de2e8b1e50
71 changed files with 212 additions and 137 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace Newlon;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Newlon;
|
||||
|
||||
using Newlon.Resources;
|
||||
using System.Text.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Newlon;
|
||||
|
||||
public partial class SaveSerializer : Node
|
||||
{
|
||||
const string SAVE_PATH = "user://save.json";
|
||||
|
|
@ -24,21 +26,21 @@ public partial class SaveSerializer : Node
|
|||
public static void SaveGame()
|
||||
{
|
||||
var access = FileAccess.Open(SAVE_PATH, FileAccess.ModeFlags.Write);
|
||||
var playerProgress = PlayerProgress.Instance;
|
||||
var save = new SaveData
|
||||
{
|
||||
var playerProgress = PlayerProgress.Instance;
|
||||
var save = new SaveData
|
||||
{
|
||||
|
||||
SFXVolume = (float)Settings.SFX,
|
||||
MusicVolume = (float)Settings.Music,
|
||||
SplashSeen = Settings.Splash,
|
||||
Money = playerProgress.Money,
|
||||
SeedpacketSlots = playerProgress.MaxSeedpackets,
|
||||
PlayerPlants = [],
|
||||
SFXVolume = (float)Settings.SFX,
|
||||
MusicVolume = (float)Settings.Music,
|
||||
SplashSeen = Settings.Splash,
|
||||
Money = playerProgress.Money,
|
||||
SeedpacketSlots = playerProgress.MaxSeedpackets,
|
||||
PlayerPlants = [],
|
||||
|
||||
SaveGameVersion = (string)ProjectSettings.GetSetting("application/config/version")
|
||||
};
|
||||
SaveGameVersion = (string)ProjectSettings.GetSetting("application/config/version")
|
||||
};
|
||||
|
||||
foreach (var plant in playerProgress.PlayerPlants)
|
||||
foreach (var plant in playerProgress.PlayerPlants)
|
||||
{
|
||||
save.PlayerPlants.Add(plant.internal_id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Droppables;
|
||||
|
||||
public partial class DropMover : Node
|
||||
{
|
||||
public float ySpeed = -200.0f;
|
||||
|
|
@ -16,7 +18,7 @@ public partial class DropMover : Node
|
|||
stop_y = ((parent.GlobalPosition / FieldParams.Tile).Ceil() * FieldParams.Tile).Y;
|
||||
gravity = (float)ProjectSettings.GetSetting("physics/2d/default_gravity");
|
||||
|
||||
velocity = new Vector2((GD.Randf()-0.5f)*xSpeed,ySpeed);
|
||||
velocity = new Vector2((GD.Randf() - 0.5f) * xSpeed, ySpeed);
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
|
@ -25,6 +27,6 @@ public partial class DropMover : Node
|
|||
velocity += Vector2.Down * gravity * (float)delta;
|
||||
|
||||
parent.GlobalPosition += velocity * (float)delta;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Droppables;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class DroppableItem : Area2D
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using Godot;
|
||||
using Newlon;
|
||||
using Newlon.Resources;
|
||||
|
||||
namespace Newlon.Components.Droppables;
|
||||
|
||||
public partial class DroppableSeedpacket : DroppableItem
|
||||
{
|
||||
|
|
@ -11,10 +13,10 @@ public partial class DroppableSeedpacket : DroppableItem
|
|||
{
|
||||
_cost.Text = plant.Cost.ToString();
|
||||
_icon.Texture = plant.Preview;
|
||||
if (plant.customFrame != null)
|
||||
if (plant.CustomFrame != null)
|
||||
{
|
||||
_packet.Texture = plant.customFrame.frame;
|
||||
_cost.LabelSettings = plant.customFrame.font;
|
||||
_packet.Texture = plant.CustomFrame.frame;
|
||||
_cost.LabelSettings = plant.CustomFrame.font;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using Godot;
|
||||
using Newlon.Projectiles;
|
||||
using Newlon.Components.Level;
|
||||
using Newlon.Components.Droppables;
|
||||
|
||||
namespace Newlon.Components.Plants;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using Newlon.Components.Level;
|
||||
using Newlon.Resources;
|
||||
|
||||
namespace Newlon.Components.Plants;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using Godot;
|
||||
using Newlon.Components.Level;
|
||||
using System;
|
||||
using Newlon;
|
||||
|
||||
public partial class PlantHotbarSize : PanelContainer
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using Godot;
|
||||
using Newlon;
|
||||
using Newlon.Components;
|
||||
using Newlon.Components.Plants;
|
||||
using Newlon.Resources;
|
||||
|
||||
public partial class RewardScene : Node
|
||||
{
|
||||
|
|
@ -18,9 +18,9 @@ public partial class RewardScene : Node
|
|||
descriptionLabel.Text = Tr(reward.Description);
|
||||
continueButton.Pressed += LevelController.Instance.ReturnToInitiator;
|
||||
|
||||
if (reward is PlantReward plantReward && plantReward.Plant.customFrame != null)
|
||||
if (reward is PlantReward plantReward && plantReward.Plant.CustomFrame != null)
|
||||
{
|
||||
field.Texture = plantReward.Plant.customFrame.almanachField;
|
||||
field.Texture = plantReward.Plant.CustomFrame.almanachField;
|
||||
}
|
||||
|
||||
var rewardedObject = reward.GetPreview().Instantiate();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using Godot;
|
||||
using Newlon.Components.Zombies;
|
||||
using System.Collections.Generic;
|
||||
using Newlon.Resources;
|
||||
|
||||
namespace Newlon.Components.Level;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Newlon;
|
||||
using Newlon.Components.GUI.Seedpackets;
|
||||
|
||||
public partial class AlmanachGrid : GridContainer
|
||||
|
|
@ -20,7 +21,7 @@ public partial class AlmanachGrid : GridContainer
|
|||
Seedpacket slot = _plantCard.Instantiate<Seedpacket>();
|
||||
AddChild(slot);
|
||||
|
||||
slot.SetResource(resource);
|
||||
slot.SetResource(resource.ToGridEntity());
|
||||
slot.SetHandler(new AlmanachHandler(slot));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,15 +33,15 @@ public partial class Previewport : SubViewport
|
|||
{
|
||||
current_display.QueueFree();
|
||||
}
|
||||
if (resource.customFrame != null && resource.customFrame.almanachField != null)
|
||||
if (resource.CustomFrame != null && resource.CustomFrame.almanachField != null)
|
||||
{
|
||||
_frameField.Texture = resource.customFrame.almanachField;
|
||||
_frameField.Texture = resource.CustomFrame.almanachField;
|
||||
}
|
||||
else
|
||||
_frameField.Texture = start_Field;
|
||||
current_display = resource.Scene.Instantiate();
|
||||
title.Text = Tr(resource.name_key);
|
||||
description.Text = Tr("rwd_"+resource.name_key)+"\n"+ Tr(resource.description_key);
|
||||
title.Text = Tr(resource.NameKey);
|
||||
description.Text = Tr("rwd_"+resource.NameKey)+"\n"+ Tr(resource.DescriptionKey);
|
||||
AddChild(current_display);
|
||||
if (current_display is Entity entity)
|
||||
entity.DisableBrain();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Newlon.Resources;
|
||||
|
||||
namespace Newlon.Components.GUI.Seedpackets;
|
||||
|
||||
|
|
@ -8,7 +9,7 @@ public partial class Seedpacket : TextureButton
|
|||
public static AudioStream UntapStream = ResourceLoader.Load<AudioStream>("res://assets/audio/gui/tap2.mp3");
|
||||
public static AudioStream LiftStream = ResourceLoader.Load<AudioStream>("res://assets/audio/gui/seedlift.mp3");
|
||||
private const string PATH_TO_PACKED_SCENE = "res://scenes/gui/seedpacket.tscn";
|
||||
private EntityResource _resource;
|
||||
private GridEntityResource _resource;
|
||||
private Label _cost;
|
||||
private TextureRect _icon;
|
||||
private Timer _timer;
|
||||
|
|
@ -46,14 +47,14 @@ public partial class Seedpacket : TextureButton
|
|||
}
|
||||
if (_handler is ISeedpacketProcess processHandler) processHandler.Process();
|
||||
}
|
||||
public void SetResource(EntityResource resource)
|
||||
public void SetResource(GridEntityResource resource)
|
||||
{
|
||||
_resource = resource;
|
||||
|
||||
UpdateContents();
|
||||
}
|
||||
|
||||
public EntityResource GetResource()
|
||||
public GridEntityResource GetResource()
|
||||
{
|
||||
return _resource;
|
||||
}
|
||||
|
|
@ -69,10 +70,10 @@ public partial class Seedpacket : TextureButton
|
|||
_cost.Text = _resource.Cost.ToString();
|
||||
_icon.Texture = _resource.Preview;
|
||||
_timer.WaitTime = _resource.ReloadTime;
|
||||
if (_resource.customFrame != null)
|
||||
if (_resource.CustomFrame != null)
|
||||
{
|
||||
TextureNormal = _resource.customFrame.frame;
|
||||
_cost.LabelSettings = _resource.customFrame.font;
|
||||
TextureNormal = _resource.CustomFrame.frame;
|
||||
_cost.LabelSettings = _resource.CustomFrame.font;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using Newlon;
|
||||
using Newlon.Resources;
|
||||
using Newlon.Components;
|
||||
using Newlon.Components.Level;
|
||||
using Newlon.Components.Plants;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using Newlon.Components.Level;
|
||||
using Newlon.Resources;
|
||||
|
||||
namespace Newlon;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using Godot;
|
||||
using Newlon.Components.Zombies;
|
||||
using System.Collections.Generic;
|
||||
using Newlon.Resources;
|
||||
using Newlon.Components.Droppables;
|
||||
|
||||
namespace Newlon.Components.Level;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
using Godot;
|
||||
using Newlon.Components.GUI.Seedpackets;
|
||||
using Newlon.Components.Plants;
|
||||
using Newlon.Resources;
|
||||
|
||||
namespace Newlon.Components.Level;
|
||||
|
||||
public partial class PlantField : Node2D
|
||||
{
|
||||
private Node2D _plantSetter;
|
||||
private EntityResource _resource;
|
||||
private GridEntityResource _resource;
|
||||
private Seedpacket _slot;
|
||||
private bool _previousCanPlace;
|
||||
private ChannelPlayer player;
|
||||
[Export] private PackedScene particles;
|
||||
public static PlantField Instance {get; private set;}
|
||||
public static PlantField Instance { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -21,13 +22,13 @@ public partial class PlantField : Node2D
|
|||
player = GetNode<ChannelPlayer>("PlantPlayer");
|
||||
}
|
||||
|
||||
public void SetPlant(Seedpacket slot, EntityResource resource)
|
||||
public void SetPlant(Seedpacket slot, GridEntityResource resource)
|
||||
{
|
||||
_resource = resource;
|
||||
_slot = slot;
|
||||
if (resource == null)
|
||||
{
|
||||
foreach(var child in _plantSetter.GetChildren())
|
||||
foreach (var child in _plantSetter.GetChildren())
|
||||
child.QueueFree();
|
||||
}
|
||||
else
|
||||
|
|
@ -40,7 +41,7 @@ public partial class PlantField : Node2D
|
|||
|
||||
public void ResetPlant()
|
||||
{
|
||||
SetPlant(null,null);
|
||||
SetPlant(null, null);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
|
|
@ -99,7 +100,7 @@ public partial class PlantField : Node2D
|
|||
|
||||
RuntimeLevelData.Instance.SpendSun((int)_resource.Cost);
|
||||
|
||||
PoolContainer.Instance.SpawnParticles(particles, plant.GlobalPosition + Vector2.Down * FieldParams.TileHeight/2.0f);
|
||||
PoolContainer.Instance.SpawnParticles(particles, plant.GlobalPosition + Vector2.Down * FieldParams.TileHeight / 2.0f);
|
||||
|
||||
player.Play();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using Newlon.Particles;
|
||||
|
||||
namespace Newlon.Components.Level;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Newlon.Projectiles;
|
||||
|
||||
namespace Newlon.Components.Level;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using Godot;
|
|||
using System.Collections.Generic;
|
||||
using Newlon.Components.Zombies;
|
||||
using Godot.Collections;
|
||||
using Newlon.Resources;
|
||||
|
||||
namespace Newlon.Components.Level;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Newlon;
|
||||
using Newlon.Resources;
|
||||
|
||||
public partial class SurvivalZombieSpawner : Node
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ using System;
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Newlon.Particles;
|
||||
|
||||
public partial class FallFloor : Node2D
|
||||
{
|
||||
private static FallFloor Instance;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ using Godot;
|
|||
using Newlon.Components.Level;
|
||||
using Newlon.Components.Zombies;
|
||||
|
||||
namespace Newlon.Components;
|
||||
namespace Newlon.Particles;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FallParticle : RigidBody2D
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Particles;
|
||||
|
||||
public partial class StandardParticles : Node2D
|
||||
{
|
||||
private int counter = 0;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Newlon.Components;
|
||||
namespace Newlon.Projectiles;
|
||||
|
||||
//
|
||||
// Base interface for entities
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
using Godot;
|
||||
using Newlon.Components.Level;
|
||||
using Newlon.Systems.Effects;
|
||||
using Newlon.Components;
|
||||
|
||||
namespace Newlon.Components;
|
||||
namespace Newlon.Projectiles;
|
||||
|
||||
//
|
||||
// Projectile that travels from left to right
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using Newlon.Components.GUI;
|
|||
using Newlon.Components.Level;
|
||||
|
||||
|
||||
namespace Newlon;
|
||||
namespace Newlon.Projectiles;
|
||||
|
||||
public partial class Sun : Area2D
|
||||
{
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class EntityResource : Resource
|
||||
{
|
||||
[Export] public string name_key;
|
||||
[Export] public string description_key;
|
||||
[Export]
|
||||
public float Cost;
|
||||
[Export]
|
||||
public PackedScene Scene;
|
||||
[Export]
|
||||
public float ReloadTime;
|
||||
[Export(PropertyHint.Range, "0,1,0.01")]
|
||||
public float ReloadProgress;
|
||||
[Export]
|
||||
public Texture2D Preview;
|
||||
[Export] public CustomSeedpacketFrame customFrame;
|
||||
[Export] public int Layer = 1;
|
||||
[Export] public int Order = 0;
|
||||
public string internal_id;
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class MoneyReward : RewardResource
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon;
|
||||
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class PlantResource : EntityResource
|
||||
{
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using Newlon;
|
||||
|
||||
namespace Newlon.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public abstract partial class RewardResource : Resource
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
using Godot;
|
||||
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class ZombieResource : EntityResource
|
||||
{
|
||||
}
|
||||
16
scripts/resources/entities/EntityResource.cs
Normal file
16
scripts/resources/entities/EntityResource.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class EntityResource : Resource
|
||||
{
|
||||
[Export] public string NameKey;
|
||||
[Export] public string DescriptionKey;
|
||||
[Export] public float Cost;
|
||||
[Export] public PackedScene Scene;
|
||||
[Export] public float ReloadTime;
|
||||
[Export(PropertyHint.Range, "0,1,0.01")] public float ReloadProgress;
|
||||
[Export] public Texture2D Preview;
|
||||
[Export] public CustomSeedpacketFrame CustomFrame;
|
||||
[Export] public int Order = 0;
|
||||
public string internal_id;
|
||||
}
|
||||
11
scripts/resources/entities/GridEntityResource.cs
Normal file
11
scripts/resources/entities/GridEntityResource.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class GridEntityResource : EntityResource
|
||||
{
|
||||
[Export] public int Layer = 1;
|
||||
[Export] public bool DontRegister = false;
|
||||
}
|
||||
1
scripts/resources/entities/GridEntityResource.cs.uid
Normal file
1
scripts/resources/entities/GridEntityResource.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bwjyra0xvhde5
|
||||
9
scripts/resources/entities/PlantResource.cs
Normal file
9
scripts/resources/entities/PlantResource.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class PlantResource : GridEntityResource
|
||||
{
|
||||
}
|
||||
28
scripts/resources/entities/ZombieResource.cs
Normal file
28
scripts/resources/entities/ZombieResource.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class ZombieResource : EntityResource
|
||||
{
|
||||
public GridEntityResource ToGridEntity()
|
||||
{
|
||||
GridEntityResource result = new();
|
||||
|
||||
result.NameKey = NameKey;
|
||||
result.DescriptionKey = DescriptionKey;
|
||||
result.Cost = Cost;
|
||||
result.Scene = Scene;
|
||||
result.ReloadTime = ReloadTime;
|
||||
result.ReloadProgress = ReloadProgress;
|
||||
result.Preview = Preview;
|
||||
result.CustomFrame = CustomFrame;
|
||||
result.Order = Order;
|
||||
|
||||
result.Layer = 1;
|
||||
result.DontRegister = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
using Godot;
|
||||
using Newlon;
|
||||
using Newlon.Resources;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Newlon;
|
||||
|
||||
public partial class GameRegistry : Node
|
||||
{
|
||||
private const string PLANT_RESOURCE_PATH = "res://assets/plants/";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon;
|
||||
|
||||
public class FieldParams
|
||||
{
|
||||
public const int TileWidth = 50;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using Newlon;
|
||||
using Newlon.Resources;
|
||||
|
||||
namespace Newlon;
|
||||
|
||||
public partial class PlayerProgress : Node
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace Newlon;
|
||||
|
||||
public partial class Settings : Node
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue