Spawn markers in editor

This commit is contained in:
Marco 2025-09-22 16:33:10 +02:00
commit 479df3c7c4
8 changed files with 150 additions and 76 deletions

View file

@ -2,6 +2,7 @@
using Cirno.Scripts.Resources;
using Cirno.Scripts.Utils;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Actors;
@ -52,6 +53,26 @@ public partial class EnemyMarker3D : PreviewMarker3D, IActivable
private EnemyProxy3D _spawnedEnemy;
public void _func_godot_apply_properties(Dictionary<string, Variant> props)
{
//GroupName = (string)props["targetname"];
this.AddToGroup("EnemyMarkers");
AutoSpawn = props["autospawn"].AsBool();
var scriptPath = props["resource_path"].AsString();
if (!string.IsNullOrWhiteSpace(scriptPath))
{
Enemy = GD.Load<EnemyResource>(scriptPath);
}
else
{
GD.PushWarning($"Spawner {this.Name} has no enemy assigned");
}
Billboard = true;
//MarkerId = props["id"].AsInt32();
}
public override void _Ready()
{
base._Ready();

View file

@ -1,6 +1,7 @@
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Actors;
@ -28,61 +29,26 @@ public partial class ItemMarker3D : PreviewMarker3D
[Export] public bool AutoSpawn { get; set; } = false;
// [ExportToolButton("Update Icon")] public Callable RedrawButton => Callable.From(Redraw);
// [ExportToolButton("Clear Children")] public Callable ClearChildrenButton => Callable.From(ClearChildren);
public void _func_godot_apply_properties(Dictionary<string, Variant> props)
{
//GroupName = (string)props["targetname"];
this.AddToGroup("ItemMarkers");
AutoSpawn = props["autospawn"].AsBool();
// public override void _Draw()
// {
// if (!Engine.IsEditorHint()) return;
// if (Item is null) return;
// if (Item.InventorySprite is null) return;
//
// DrawTexture(Item.InventorySprite, - new Vector2(Item.InventorySprite.GetWidth() / 2f, Item.InventorySprite.GetHeight() / 2f));
// }
//
// private void Redraw()
// {
// QueueRedraw();
// }
var scriptPath = props["resource_path"].AsString();
if (!string.IsNullOrWhiteSpace(scriptPath))
{
Item = GD.Load<LootItem>(scriptPath);
}
else
{
GD.PushWarning($"Spawner {this.Name} has no item assigned");
}
// private void ClearChildren()
// {
// var children = GetChildren();
// foreach (var child in children)
// {
// if (child is Sprite3D)
// {
// child.QueueFree();
// }
// }
//
// _sprite = null;
// }
Billboard = true;
//MarkerId = props["id"].AsInt32();
}
// private void QueueRedraw()
// {
// if (!Engine.IsEditorHint()) return;
// if (Item?.InventorySprite is null) return;
//
// if (_sprite is null)
// {
// GD.Print("Remaking sprite");
// _sprite = new EditorSprite3D();
// this.AddChild(_sprite);
// //_sprite.Owner = GetTree().EditedSceneRoot;
// }
//
// _sprite.Texture = Item.InventorySprite;
// //_sprite.SetRotationDegrees(new Vector3(-45, 45, 0));
// _sprite.FixedSize = true;
// _sprite.SetBillboardMode(BaseMaterial3D.BillboardModeEnum.Enabled);
// _sprite.TextureFilter = BaseMaterial3D.TextureFilterEnum.Nearest;
//
//
// }
//private Sprite3D _sprite;
public override void _Ready()
{
base._Ready();

View file

@ -21,7 +21,7 @@ public partial class PreviewMarker3D : Marker3D
private bool _fixedSize;
private bool _billboard;
private float _pixelSize = 0.1f;
private float _pixelSize = 0.05f;
[Export]
protected bool FixedSize

View file

@ -17,32 +17,31 @@ public partial class GameController : Node
private Hud _hud;
private IsoPlayerFSMProxy _player;
public IsoPlayerStateMachine Player => _player.PlayerFSM;
[Export] private Marker3D _cameraTarget;
public Vector3? PlayerPosition => _player?.GlobalPosition ?? null;
public Vector3? PlayerVelocity => _player?.Velocity ?? null;
[Export] public bool DebugDraw { get; set; }
[Signal]
public delegate void ManagerReadyEventHandler();
[Export] public MapResource MapResource { get; private set; }
[Export] public PackedScene PlayerTemplate { get; set; }
[Export] public Dictionary<int, NodePath> SpawnMarkers { get; private set; } = new();
[Export]
public int EggStartIndex = 0;
[Export] public int EggStartIndex = 0;
[Export] public Node3D PlayerParentNode { get; set; }
private InventoryManager _inventoryManager { get; set; }
private Vector3 _lastCheckPointPosition;
private GameState GameState => GameStateManager.Instance.GameState;
private GameState GameState => GameStateManager.Instance.GameState;
public Vector3 LastCheckPointPosition
{
get => _lastCheckPointPosition;
@ -57,7 +56,7 @@ public partial class GameController : Node
gsm.ProcessMode = ProcessModeEnum.Always;
this.AddChild(gsm);
gsm.Init(GameState.Playing);
RenderingServer.SetDefaultClearColor(Colors.Black);
if (GlobalState.Instance.SessionSettings.GameMode is GameMode.Roguelite)
{
@ -72,7 +71,7 @@ public partial class GameController : Node
GlobalState.Session.LevelNumber = MapResource.LevelId;
GlobalState.Session.MapId = MapResource.MapId;
}
GlobalState.Instance.ChangeCursor(false);
if (GlobalState.Instance.SessionSettings.AllowSaving)
@ -91,7 +90,7 @@ public partial class GameController : Node
_inventoryManager = GetNodeOrNull<InventoryManager>("InventoryManager");
if (_inventoryManager == null) GD.Print("No inventory manager in scene.");
//SpawnBulletsContainer();
if (_hud != null)
@ -118,7 +117,7 @@ public partial class GameController : Node
{
EmitSignalManagerReady();
}
private void DelayPlayerSpawn()
{
if (SpawnMarkers.Any())
@ -154,7 +153,7 @@ public partial class GameController : Node
// Wait before the player is fully initialized before spawning weapons on it
CallDeferred(MethodName.SpawnWeapons);
}
private void SpawnWeapons()
{
foreach (var startingItem in MapResource.StartData.StartingEquipment)
@ -167,14 +166,14 @@ public partial class GameController : Node
_inventoryManager.RemoveItem(item);
}
}
public void SpawnPlayer()
{
if (_player != null) return;
//_player = this.CreateChild<PlayerMovement>(PlayerTemplate, PlayerSpawnMarker.Position );
_player = PlayerTemplate.Instantiate<IsoPlayerFSMProxy>();
if (PlayerParentNode is not null)
{
PlayerParentNode.AddChild(_player);
@ -186,7 +185,7 @@ public partial class GameController : Node
this.AddChild(_player);
_player.Owner = this;
}
_player.GlobalPosition = GetStartPosition();
LastCheckPointPosition = _player.GlobalPosition;
@ -202,7 +201,7 @@ public partial class GameController : Node
// _cameraTarget.GlobalPosition = _player.Position;
// }
}
public void CameraTargetPlayer()
{
if (_player is null) return;
@ -219,9 +218,8 @@ public partial class GameController : Node
{
_cameraTarget.Position += offset.Value;
}
}
private Vector3 GetStartPosition()
{
var spawners = GetTree().GetNodesInGroup("SpawnMarkers").Cast<PlayerStartMarker3D>().ToList();