mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
98 lines
No EOL
2.2 KiB
C#
98 lines
No EOL
2.2 KiB
C#
using Cirno.Scripts.Interactables;
|
|
using Cirno.Scripts.Resources;
|
|
using Godot;
|
|
using Godot.Collections;
|
|
|
|
namespace Cirno.Scripts.Actors;
|
|
|
|
[Tool]
|
|
public partial class ItemMarker3D : PreviewMarker3D
|
|
{
|
|
private readonly Vector3 _boxSize = new Vector3(0.5f, 0.8f, 0.5f);
|
|
|
|
private LootItem _item;
|
|
|
|
[Export]
|
|
public LootItem Item
|
|
{
|
|
get => _item;
|
|
set
|
|
{
|
|
_item = value;
|
|
if (Engine.IsEditorHint())
|
|
{
|
|
//QueueRedraw();
|
|
this.Texture = _item.InventorySprite;
|
|
}
|
|
}
|
|
}
|
|
|
|
[Export] public bool AutoSpawn { get; set; } = false;
|
|
|
|
public void _func_godot_apply_properties(Dictionary<string, Variant> props)
|
|
{
|
|
//GroupName = (string)props["targetname"];
|
|
this.AddToGroup("ItemMarkers");
|
|
AutoSpawn = props["autospawn"].AsBool();
|
|
|
|
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");
|
|
}
|
|
|
|
Billboard = true;
|
|
//MarkerId = props["id"].AsInt32();
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
// _sprite = GetNodeOrNull<Sprite3D>("Sprite3D");
|
|
// if (Engine.IsEditorHint())
|
|
// {
|
|
// QueueRedraw();
|
|
//
|
|
// return;
|
|
// }
|
|
//
|
|
// ClearChildren();
|
|
|
|
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);
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (!Engine.IsEditorHint()) return;
|
|
|
|
#if !DISABLE_DD3D
|
|
DebugDraw3D.DrawBox(this.GlobalPosition - _boxSize / 2, Quaternion.Identity, _boxSize, Colors.Blue);
|
|
#endif
|
|
//DebugDraw3D.DrawSphere(this.GlobalPosition, 0.1f, Colors.Green);
|
|
}
|
|
} |