Add ability to change properties of existing blocks
And not storing custom block data for now
This commit is contained in:
parent
fdc47832f4
commit
d954060a5a
3 changed files with 43 additions and 17 deletions
|
@ -30,7 +30,9 @@ namespace GamecraftModdingAPI.Blocks
|
|||
/// Key: Prefab path
|
||||
/// </summary>
|
||||
private static readonly Dictionary<string, Type> CustomBlocks = new Dictionary<string, Type>();
|
||||
private static readonly CustomBlockEngine Engine = new CustomBlockEngine();
|
||||
//private static readonly CustomBlockEngine Engine = new CustomBlockEngine();
|
||||
private static readonly List<(ushort id, Action<CubeListData> action)> BlockChangeActions =
|
||||
new List<(ushort, Action<CubeListData>)>();
|
||||
|
||||
private static bool _canRegister = true;
|
||||
|
||||
|
@ -58,6 +60,16 @@ namespace GamecraftModdingAPI.Blocks
|
|||
Logging.MetaDebugLog("Registered custom block type " + typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A low-level method for changing any property of an existing block. Use with caution.
|
||||
/// </summary>
|
||||
/// <param name="id">The block ID</param>
|
||||
/// <param name="modifier">An action that modifies a property of the block</param>
|
||||
public static void ChangeExistingBlock(ushort id, Action<CubeListData> modifier)
|
||||
{
|
||||
BlockChangeActions.Add((id, modifier));
|
||||
}
|
||||
|
||||
public CustomBlock(EGID id) : base(id)
|
||||
{
|
||||
/*if (id.groupID != Group)
|
||||
|
@ -129,9 +141,12 @@ namespace GamecraftModdingAPI.Blocks
|
|||
};
|
||||
dataDB.GetValues<CubeListData>().Add(cld.ID.ToString(), cld); //The registration needs to happen after the ID has been set
|
||||
dataDB.GetFasterValues<CubeListData>().Add(cld.ID, cld); //So can't use the builtin method to create a CubeListData
|
||||
Engine.RegisterBlock((ushort) cld.ID, key);
|
||||
//Engine.RegisterBlock((ushort) cld.ID, key); - TODO
|
||||
}
|
||||
|
||||
foreach (var (id, action) in BlockChangeActions)
|
||||
action(dataDB.GetValue<CubeListData>(id));
|
||||
|
||||
_canRegister = false;
|
||||
}
|
||||
|
||||
|
@ -173,7 +188,7 @@ namespace GamecraftModdingAPI.Blocks
|
|||
internal new static void Init()
|
||||
{
|
||||
Prepare().RunOn(ExtraLean.UIScheduler);
|
||||
GameEngineManager.AddGameEngine(Engine);
|
||||
//GameEngineManager.AddGameEngine(Engine); - TODO: Fix serialization and implement block ID update
|
||||
}
|
||||
|
||||
/*internal static void OnBlockFactoryObtained(BlockEntityFactory factory)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
using GamecraftModdingAPI.Persistence;
|
||||
using GamecraftModdingAPI.Utility;
|
||||
|
@ -9,10 +10,9 @@ using Svelto.ECS.Serialization;
|
|||
|
||||
namespace GamecraftModdingAPI.Blocks
|
||||
{
|
||||
public class CustomBlockEngine : IFactoryEngine
|
||||
/*public class CustomBlockEngine : IFactoryEngine
|
||||
{
|
||||
public class CustomBlockEntityDescriptor : SerializableEntityDescriptor<
|
||||
CustomBlockEntityDescriptor._CustomBlockDescriptor>
|
||||
public class CustomBlockEntityDescriptor : SerializableEntityDescriptor<CustomBlockEntityDescriptor._CustomBlockDescriptor>
|
||||
{
|
||||
[HashName("GamecraftModdingAPICustomBlockV0")]
|
||||
public class _CustomBlockDescriptor : IEntityDescriptor
|
||||
|
@ -28,7 +28,8 @@ namespace GamecraftModdingAPI.Blocks
|
|||
|
||||
public void Ready()
|
||||
{
|
||||
SerializerManager.AddSerializer<CustomBlockEntityDescriptor>(new SimpleEntitySerializer<CustomBlockEntityDescriptor>(db =>
|
||||
SerializerManager.AddSerializer<CustomBlockEntityDescriptor>(
|
||||
new SimpleEntitySerializer<CustomBlockEntityDescriptor>(db =>
|
||||
{
|
||||
var (coll, c) = db.QueryEntities<CustomBlock.DataStruct>(ApiExclusiveGroups.customBlockGroup);
|
||||
var egids = new EGID[c];
|
||||
|
@ -37,21 +38,27 @@ namespace GamecraftModdingAPI.Blocks
|
|||
|
||||
return egids;
|
||||
}));
|
||||
foreach (var (id, name) in _registeredBlocks)
|
||||
{
|
||||
Factory.BuildEntity<CustomBlockEntityDescriptor>(id, ApiExclusiveGroups.customBlockGroup)
|
||||
.Init(new CustomBlock.DataStruct {Name = new ECSString(name), ID = id});
|
||||
}
|
||||
}
|
||||
|
||||
public EntitiesDB entitiesDB { get; set; }
|
||||
private List<(ushort id, string name)> _registeredBlocks = new List<(ushort, string)>();
|
||||
|
||||
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});
|
||||
_registeredBlocks.Add((id, name));
|
||||
}
|
||||
|
||||
public string Name { get; } = "GamecraftModdingAPICustomBlockEngine";
|
||||
public bool isRemovable { get; } = false;
|
||||
public IEntityFactory Factory { get; set; }
|
||||
}
|
||||
}*/
|
||||
}
|
|
@ -36,6 +36,7 @@ using UnityEngine.ResourceManagement.ResourceProviders;
|
|||
using Debug = FMOD.Debug;
|
||||
using EventType = GamecraftModdingAPI.Events.EventType;
|
||||
using Label = GamecraftModdingAPI.Interface.IMGUI.Label;
|
||||
using ScalingPermission = DataLoader.ScalingPermission;
|
||||
|
||||
namespace GamecraftModdingAPI.Tests
|
||||
{
|
||||
|
@ -412,6 +413,9 @@ namespace GamecraftModdingAPI.Tests
|
|||
{
|
||||
Logging.MetaDebugLog("Test custom block catalog not found");
|
||||
}
|
||||
|
||||
CustomBlock.ChangeExistingBlock((ushort) BlockIDs.TyreS,
|
||||
cld => cld.scalingPermission = ScalingPermission.NonUniform);
|
||||
#if TEST
|
||||
TestRoot.RunTests();
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue