cirnogodot/Scripts/Actors/ItemMarker3D.cs

98 lines
2.2 KiB
C#
Raw Permalink Normal View History

2025-06-17 17:49:40 +02:00
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Godot;
2025-09-22 16:33:10 +02:00
using Godot.Collections;
2025-06-17 17:49:40 +02:00
namespace Cirno.Scripts.Actors;
[Tool]
2025-06-21 16:44:44 +02:00
public partial class ItemMarker3D : PreviewMarker3D
2025-06-17 17:49:40 +02:00
{
2025-07-02 10:34:14 +02:00
private readonly Vector3 _boxSize = new Vector3(0.5f, 0.8f, 0.5f);
2025-06-17 17:49:40 +02:00
private LootItem _item;
[Export]
public LootItem Item
{
get => _item;
set
{
_item = value;
if (Engine.IsEditorHint())
{
2025-06-21 16:44:44 +02:00
//QueueRedraw();
this.Texture = _item.InventorySprite;
2025-06-17 17:49:40 +02:00
}
}
}
[Export] public bool AutoSpawn { get; set; } = false;
2025-09-22 16:33:10 +02:00
public void _func_godot_apply_properties(Dictionary<string, Variant> props)
{
//GroupName = (string)props["targetname"];
this.AddToGroup("ItemMarkers");
AutoSpawn = props["autospawn"].AsBool();
2025-06-17 17:49:40 +02:00
2025-09-22 16:33:10 +02:00
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");
}
2025-06-17 17:49:40 +02:00
2025-09-22 16:33:10 +02:00
Billboard = true;
//MarkerId = props["id"].AsInt32();
}
2025-06-17 17:49:40 +02:00
public override void _Ready()
{
2025-06-21 16:44:44 +02:00
base._Ready();
// _sprite = GetNodeOrNull<Sprite3D>("Sprite3D");
// if (Engine.IsEditorHint())
// {
// QueueRedraw();
//
// return;
// }
//
// ClearChildren();
2025-06-17 17:49:40 +02:00
if (AutoSpawn)
{
Spawn(false);
}
}
// public override void _Process(double delta)
// {
//
// }
public ItemPickup3D Spawn(bool deleteMarker)
{
if (Engine.IsEditorHint()) return null;
if (Item is null) return null;
if (deleteMarker)
{
this.QueueFree();
}
return Item.Spawn3D(this);
}
2025-07-02 10:34:14 +02:00
public override void _Process(double delta)
{
if (!Engine.IsEditorHint()) return;
2025-08-12 14:37:48 +02:00
#if !DISABLE_DD3D
2025-07-02 10:34:14 +02:00
DebugDraw3D.DrawBox(this.GlobalPosition - _boxSize / 2, Quaternion.Identity, _boxSize, Colors.Blue);
2025-08-12 14:37:48 +02:00
#endif
2025-07-02 10:34:14 +02:00
//DebugDraw3D.DrawSphere(this.GlobalPosition, 0.1f, Colors.Green);
}
2025-06-17 17:49:40 +02:00
}