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