|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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; }
- }
- }
|