Box models and item drops

This commit is contained in:
Marco 2025-06-17 17:49:40 +02:00
commit 2fe9618942
132 changed files with 9210 additions and 999 deletions

View file

@ -24,24 +24,67 @@ public partial class LootItem : Resource
[Export(PropertyHint.Flags, "Icon,Count,Ammo,Energy")]
public UiItemType UiType { get; set; } = 0;
[Export] public bool Selectable;
[Export] public bool AutoPickup { get; private set; } = false;
[Export] public Texture2D InventorySprite;
//[Export] public SpriteFrames WorldSprite;
//[Export] public PackedScene HudItemScene;
[Export(PropertyHint.File)] public StringName DropScenePath { get; private set; } // Has to be a string path to avoid recursion issues
[Export(PropertyHint.File)]
public StringName DropScenePath { get; private set; } // Has to be a string path to avoid recursion issues
[Export(PropertyHint.File)]
public StringName DropScenePath3D { get; private set; } // Has to be a string path to avoid recursion issues
public ItemPickup Spawn(Node2D sibling, bool dropAsChild = false)
{
if (string.IsNullOrWhiteSpace(DropScenePath)) return null;
var itemScene = GD.Load<PackedScene>(DropScenePath);
var spawnedItem = dropAsChild ? sibling.CreateChild<ItemPickup>(itemScene) : sibling.CreateSibling<ItemPickup>(itemScene);
var spawnedItem = dropAsChild
? sibling.CreateChild<ItemPickup>(itemScene)
: sibling.CreateSibling<ItemPickup>(itemScene);
spawnedItem.Name = this.ItemKey;
spawnedItem.LootTable.Add(this);
spawnedItem.SetSprite(InventorySprite);
return spawnedItem;
}
public ItemPickup3D Spawn3D(Node3D sibling, bool dropAsChild = false)
{
if (string.IsNullOrWhiteSpace(DropScenePath3D)) return null;
var itemScene = GD.Load<PackedScene>(DropScenePath3D);
var spawnedItem = itemScene.Instantiate<ItemPickup3D>();
spawnedItem.Name = this.ItemKey;
if (dropAsChild)
{
CallDeferred(MethodName.DeferredSpawn3D, sibling, spawnedItem, sibling.GlobalPosition);
//sibling.CallDeferred(Node.MethodName.AddChild, spawnedItem);
//sibling.AddChild(spawnedItem);
}
else
{
CallDeferred(MethodName.DeferredSpawn3D, sibling.GetParentNode3D(), spawnedItem, sibling.GlobalPosition);
//sibling.GetParent().CallDeferred(Node.MethodName.AddChild, spawnedItem);
//sibling.GetParent().AddChild(spawnedItem);
}
//spawnedItem.GlobalPosition = sibling.GlobalPosition;
spawnedItem.LootTable.Add(this);
spawnedItem.SetSprite(InventorySprite);
return spawnedItem;
}
private void DeferredSpawn3D(Node3D parent, Node3D instance, Vector3 position)
{
parent.AddChild(instance);
instance.GlobalPosition = position;
}
}