Enemy spawning

This commit is contained in:
Marco 2025-06-21 16:44:44 +02:00
commit 29dc9bebe0
20 changed files with 564 additions and 105 deletions

View file

@ -5,7 +5,7 @@ using Godot;
namespace Cirno.Scripts.Actors;
[Tool]
public partial class ItemMarker3D : Marker3D
public partial class ItemMarker3D : PreviewMarker3D
{
private LootItem _item;
@ -18,15 +18,16 @@ public partial class ItemMarker3D : Marker3D
_item = value;
if (Engine.IsEditorHint())
{
QueueRedraw();
//QueueRedraw();
this.Texture = _item.InventorySprite;
}
}
}
[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);
// [ExportToolButton("Update Icon")] public Callable RedrawButton => Callable.From(Redraw);
// [ExportToolButton("Clear Children")] public Callable ClearChildrenButton => Callable.From(ClearChildren);
// public override void _Draw()
// {
@ -37,60 +38,61 @@ public partial class ItemMarker3D : Marker3D
// DrawTexture(Item.InventorySprite, - new Vector2(Item.InventorySprite.GetWidth() / 2f, Item.InventorySprite.GetHeight() / 2f));
// }
//
private void Redraw()
{
QueueRedraw();
}
// private void Redraw()
// {
// QueueRedraw();
// }
private void ClearChildren()
{
var children = GetChildren();
foreach (var child in children)
{
if (child is Sprite3D)
{
child.QueueFree();
}
}
_sprite = null;
}
// private void ClearChildren()
// {
// var children = GetChildren();
// foreach (var child in children)
// {
// if (child is Sprite3D)
// {
// child.QueueFree();
// }
// }
//
// _sprite = null;
// }
private void QueueRedraw()
{
if (!Engine.IsEditorHint()) return;
if (Item?.InventorySprite is null) return;
// 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;
//
//
// }
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;
//private Sprite3D _sprite;
public override void _Ready()
{
_sprite = GetNodeOrNull<Sprite3D>("Sprite3D");
if (Engine.IsEditorHint())
{
QueueRedraw();
return;
}
ClearChildren();
base._Ready();
// _sprite = GetNodeOrNull<Sprite3D>("Sprite3D");
// if (Engine.IsEditorHint())
// {
// QueueRedraw();
//
// return;
// }
//
// ClearChildren();
if (AutoSpawn)
{