|
|
@@ -6,10 +6,12 @@ using System.Reflection; |
|
|
|
using HarmonyLib; |
|
|
|
|
|
|
|
using DataLoader; |
|
|
|
using RobocraftX.Blocks; |
|
|
|
using RobocraftX.Rendering; |
|
|
|
using RobocraftX.Schedulers; |
|
|
|
using Svelto.ECS; |
|
|
|
using Svelto.ECS.Experimental; |
|
|
|
using Svelto.Tasks; |
|
|
|
using Svelto.Tasks.ExtraLean; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.AddressableAssets; |
|
|
|
using Material = UnityEngine.Material; |
|
|
@@ -18,13 +20,17 @@ using GamecraftModdingAPI.Utility; |
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Blocks |
|
|
|
{ |
|
|
|
/// <summary> |
|
|
|
/// Experimental support for adding custom blocks to the game. |
|
|
|
/// </summary> |
|
|
|
public class CustomBlock : Block |
|
|
|
{ |
|
|
|
private static ushort nextID = 500; |
|
|
|
/// <summary> |
|
|
|
/// Key: Prefab path |
|
|
|
/// </summary> |
|
|
|
private static Dictionary<string, Type> _customBlocks = new Dictionary<string, Type>(); |
|
|
|
private static readonly Dictionary<string, Type> CustomBlocks = new Dictionary<string, Type>(); |
|
|
|
private static readonly CustomBlockEngine Engine = new CustomBlockEngine(); |
|
|
|
|
|
|
|
private static bool _canRegister = true; |
|
|
|
|
|
|
@@ -48,7 +54,7 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
throw new ArgumentException("The given block type doesn't have a concrete full name."); |
|
|
|
if (!File.Exists(attr.Catalog)) |
|
|
|
throw new FileNotFoundException("The specified catalog cannot be found for " + typeName); |
|
|
|
_customBlocks.Add(attr.AssetPath, type); |
|
|
|
CustomBlocks.Add(attr.AssetPath, type); |
|
|
|
Logging.MetaDebugLog("Registered custom block type " + typeName); |
|
|
|
} |
|
|
|
|
|
|
@@ -79,7 +85,7 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
|
|
|
|
for (var index = 0; index < prefabs.Count; index++) |
|
|
|
{ |
|
|
|
if (_customBlocks.ContainsKey(prefabData[index].prefabName)) //This is a custom block |
|
|
|
if (CustomBlocks.ContainsKey(prefabData[index].prefabName)) //This is a custom block |
|
|
|
prefabs[index].GetComponentsInChildren<MeshRenderer>()[0].sharedMaterials = materials; |
|
|
|
} |
|
|
|
} |
|
|
@@ -96,7 +102,7 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
public static void Prefix(IDataDB dataDB) |
|
|
|
{ |
|
|
|
//var abd = dataDB.GetValue<CubeListData>((int) BlockIDs.AluminiumCube); |
|
|
|
foreach (var (key, type) in _customBlocks) |
|
|
|
foreach (var (key, type) in CustomBlocks) |
|
|
|
{ |
|
|
|
var attr = type.GetCustomAttribute<CustomBlockAttribute>(); |
|
|
|
var cld = new CubeListData |
|
|
@@ -123,6 +129,7 @@ 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); |
|
|
|
} |
|
|
|
|
|
|
|
_canRegister = false; |
|
|
@@ -150,9 +157,9 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
} |
|
|
|
}*/ |
|
|
|
|
|
|
|
internal static IEnumerator Prepare() |
|
|
|
private static IEnumerator Prepare() |
|
|
|
{ //Should be pretty quick |
|
|
|
foreach (var type in _customBlocks.Values) |
|
|
|
foreach (var type in CustomBlocks.Values) |
|
|
|
{ |
|
|
|
var attr = type.GetCustomAttribute<CustomBlockAttribute>(); |
|
|
|
Logging.Log("Loading custom block catalog " + attr.Catalog); |
|
|
@@ -163,11 +170,23 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
internal new static void Init() |
|
|
|
{ |
|
|
|
Prepare().RunOn(ExtraLean.UIScheduler); |
|
|
|
GameEngineManager.AddGameEngine(Engine); |
|
|
|
} |
|
|
|
|
|
|
|
/*internal static void OnBlockFactoryObtained(BlockEntityFactory factory) |
|
|
|
{ |
|
|
|
var builders = (Dictionary<CubeCategory, IBlockBuilder>) |
|
|
|
AccessTools.Field(factory.GetType(), "_blockBuilders").GetValue(factory); |
|
|
|
builders.Add((CubeCategory) 1000, new BlockBuilder<StandardBlockEntityDescriptor>(Group)); |
|
|
|
}*/ |
|
|
|
|
|
|
|
internal struct DataStruct : IEntityComponent |
|
|
|
{ |
|
|
|
public ECSString Name; |
|
|
|
public ushort ID; |
|
|
|
} |
|
|
|
} |
|
|
|
} |