TechbloxModdingAPI/GamecraftModdingAPI/Blocks/CustomBlockEntityDescriptor.cs

57 lines
2.1 KiB
C#
Raw Normal View History

2020-12-26 00:59:06 +00:00
using System;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Persistence;
using GamecraftModdingAPI.Utility;
using RobocraftX.Common;
using Svelto.ECS;
using Svelto.ECS.Experimental;
using Svelto.ECS.Serialization;
namespace GamecraftModdingAPI.Blocks
{
public class CustomBlockEngine : IFactoryEngine
{
public class CustomBlockEntityDescriptor : SerializableEntityDescriptor<
CustomBlockEntityDescriptor._CustomBlockDescriptor>
{
[HashName("GamecraftModdingAPICustomBlockV0")]
public class _CustomBlockDescriptor : IEntityDescriptor
{
public IComponentBuilder[] componentsToBuild { get; } =
{
new SerializableComponentBuilder<SerializationType, CustomBlock.DataStruct>(
((int) SerializationType.Network, new DefaultSerializer<CustomBlock.DataStruct>()),
((int) SerializationType.Storage, new DefaultSerializer<CustomBlock.DataStruct>()))
};
}
}
public void Ready()
{
SerializerManager.AddSerializer<CustomBlockEntityDescriptor>(new SimpleEntitySerializer<CustomBlockEntityDescriptor>(db =>
{
var (coll, c) = db.QueryEntities<CustomBlock.DataStruct>(ApiExclusiveGroups.customBlockGroup);
var egids = new EGID[c];
for (int i = 0; i < c; i++)
egids[i] = new EGID(coll[i].ID, ApiExclusiveGroups.customBlockGroup);
return egids;
}));
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
}
public void RegisterBlock(ushort id, string name)
{
Factory.BuildEntity<CustomBlockEntityDescriptor>(id, ApiExclusiveGroups.customBlockGroup)
.Init(new CustomBlock.DataStruct {Name = new ECSString(name), ID = id});
}
public string Name { get; } = "GamecraftModdingAPICustomBlockEngine";
public bool isRemovable { get; } = false;
public IEntityFactory Factory { get; set; }
}
}