2024-10-04 12:53:34 +00:00
|
|
|
|
using ColdMint.scripts.debug;
|
|
|
|
|
using ColdMint.scripts.inventory;
|
2024-06-22 15:29:24 +00:00
|
|
|
|
using ColdMint.scripts.map.events;
|
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.map;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>ItemSpawn</para>
|
|
|
|
|
/// <para>物品出生点</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class ItemSpawn : Marker2D
|
|
|
|
|
{
|
|
|
|
|
[Export] public string? ItemId { get; private set; }
|
|
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
|
|
|
|
base._Ready();
|
2024-09-06 15:36:21 +00:00
|
|
|
|
EventBus.MapGenerationCompleteEvent += MapGenerationCompleteEvent;
|
2024-06-22 15:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MapGenerationCompleteEvent(MapGenerationCompleteEvent mapGenerationCompleteEvent)
|
|
|
|
|
{
|
|
|
|
|
//After the map is generated, create the item instance.
|
|
|
|
|
//当地图生成完成后,创建物品实例。
|
|
|
|
|
if (ItemId == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 14:19:12 +00:00
|
|
|
|
var item = ItemTypeManager.CreateItem(ItemId, this);
|
2024-10-04 12:53:34 +00:00
|
|
|
|
LogCat.LogWithFormat("generated_item_is_empty",LogCat.LogLabel.ItemSpawn,true,ItemId,item == null);
|
2024-06-22 15:29:24 +00:00
|
|
|
|
if (item is Node2D node2D)
|
|
|
|
|
{
|
|
|
|
|
node2D.GlobalPosition = GlobalPosition;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void _ExitTree()
|
|
|
|
|
{
|
|
|
|
|
base._ExitTree();
|
2024-09-06 15:36:21 +00:00
|
|
|
|
EventBus.MapGenerationCompleteEvent -= MapGenerationCompleteEvent;
|
2024-06-22 15:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|