2020-06-02 03:12:40 +02:00
|
|
|
using System;
|
2020-07-15 21:58:24 +02:00
|
|
|
|
2020-06-02 03:12:40 +02:00
|
|
|
using RobocraftX.Common;
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
2020-07-15 21:58:24 +02:00
|
|
|
using GamecraftModdingAPI.Engines;
|
|
|
|
using GamecraftModdingAPI.Utility;
|
2020-11-12 02:39:58 +01:00
|
|
|
using RobocraftX.Blocks;
|
2020-07-15 21:58:24 +02:00
|
|
|
|
2020-06-02 03:12:40 +02:00
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
|
|
{
|
2020-11-12 02:39:58 +01:00
|
|
|
public class BlockEventsEngine : IReactionaryEngine<BlockTagEntityStruct>
|
2020-06-02 03:12:40 +02:00
|
|
|
{
|
|
|
|
public event EventHandler<BlockPlacedRemovedEventArgs> Placed;
|
|
|
|
public event EventHandler<BlockPlacedRemovedEventArgs> Removed;
|
|
|
|
|
|
|
|
public void Ready()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntitiesDB entitiesDB { get; set; }
|
2020-07-15 21:58:24 +02:00
|
|
|
|
2020-06-02 03:12:40 +02:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Name { get; } = "GamecraftModdingAPIBlockEventsEngine";
|
|
|
|
public bool isRemovable { get; } = false;
|
|
|
|
|
2020-07-15 21:58:24 +02:00
|
|
|
private bool shouldAddRemove;
|
2020-11-12 02:39:58 +01:00
|
|
|
public void Add(ref BlockTagEntityStruct entityComponent, EGID egid)
|
2020-06-02 03:12:40 +02:00
|
|
|
{
|
2020-07-15 21:58:24 +02:00
|
|
|
if (!(shouldAddRemove = !shouldAddRemove))
|
|
|
|
return;
|
|
|
|
ExceptionUtil.InvokeEvent(Placed, this,
|
2020-11-12 02:39:58 +01:00
|
|
|
new BlockPlacedRemovedEventArgs {ID = egid});
|
2020-06-02 03:12:40 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 02:39:58 +01:00
|
|
|
public void Remove(ref BlockTagEntityStruct entityComponent, EGID egid)
|
2020-06-02 03:12:40 +02:00
|
|
|
{
|
2020-07-15 21:58:24 +02:00
|
|
|
if (!(shouldAddRemove = !shouldAddRemove))
|
|
|
|
return;
|
|
|
|
ExceptionUtil.InvokeEvent(Removed, this,
|
2020-11-12 02:39:58 +01:00
|
|
|
new BlockPlacedRemovedEventArgs {ID = egid});
|
2020-06-02 03:12:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public struct BlockPlacedRemovedEventArgs
|
|
|
|
{
|
|
|
|
public EGID ID;
|
|
|
|
public BlockIDs Type;
|
2020-07-19 01:13:39 +02:00
|
|
|
private Block block;
|
|
|
|
|
|
|
|
public Block Block => block ?? (block = new Block(ID));
|
2020-06-02 03:12:40 +02:00
|
|
|
}
|
|
|
|
}
|