Merge branch 'master' of NorbiPeti/GamecraftModdingAPI into master
Thanks for doing the work to get it working with the latest update! In the next week or two I'll try to find some time to do some work on the API to get the last outstanding API bugs fixed (and maybe add some new features)
This commit is contained in:
commit
1366d95c4a
9 changed files with 50 additions and 50 deletions
|
@ -7,8 +7,7 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
{
|
{
|
||||||
AluminiumCube,
|
AluminiumCube,
|
||||||
AxleS,
|
AxleS,
|
||||||
Battery,
|
HingeS = 3,
|
||||||
HingeS,
|
|
||||||
MotorS,
|
MotorS,
|
||||||
HingeM,
|
HingeM,
|
||||||
MotorM,
|
MotorM,
|
||||||
|
@ -68,8 +67,7 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
GlassConeSegment,
|
GlassConeSegment,
|
||||||
GlassCylinder,
|
GlassCylinder,
|
||||||
GlassSphere,
|
GlassSphere,
|
||||||
Lever,
|
Lever, //63 - two IDs skipped
|
||||||
Reactor, //64 - one ID is skipped
|
|
||||||
PlayerSpawn = 66, //Crashes without special handling
|
PlayerSpawn = 66, //Crashes without special handling
|
||||||
SmallSpawn,
|
SmallSpawn,
|
||||||
MediumSpawn,
|
MediumSpawn,
|
||||||
|
@ -154,6 +152,17 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
ConcreteSlicedCube,
|
ConcreteSlicedCube,
|
||||||
ConcreteSlope,
|
ConcreteSlope,
|
||||||
ConcreteCorner,
|
ConcreteCorner,
|
||||||
|
RoadCarTyre,
|
||||||
|
OffRoadCarTyre,
|
||||||
|
RacingCarTyre,
|
||||||
|
BicycleTyre,
|
||||||
|
FrontBikeTyre,
|
||||||
|
RearBikeTyre,
|
||||||
|
ChopperBikeTyre,
|
||||||
|
TractorTyre,
|
||||||
|
MonsterTruckTyre,
|
||||||
|
MotocrossBikeTyre,
|
||||||
|
CartTyre,
|
||||||
BeachTree1 = 200,
|
BeachTree1 = 200,
|
||||||
BeachTree2,
|
BeachTree2,
|
||||||
BeachTree3,
|
BeachTree3,
|
||||||
|
|
|
@ -20,6 +20,7 @@ using Unity.Mathematics;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
using GamecraftModdingAPI.Utility;
|
using GamecraftModdingAPI.Utility;
|
||||||
|
using Svelto.DataStructures;
|
||||||
|
|
||||||
namespace GamecraftModdingAPI.Blocks
|
namespace GamecraftModdingAPI.Blocks
|
||||||
{
|
{
|
||||||
|
@ -69,9 +70,9 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
public float3 MoveConnectedBlocks(uint blockID, float3 vector)
|
public float3 MoveConnectedBlocks(uint blockID, float3 vector)
|
||||||
{
|
{
|
||||||
Stack<uint> cubeStack = new Stack<uint>();
|
Stack<uint> cubeStack = new Stack<uint>();
|
||||||
Gamecraft.DataStructures.FasterList<uint> cubesToMove = new Gamecraft.DataStructures.FasterList<uint>();
|
FasterList<uint> cubesToMove = new FasterList<uint>();
|
||||||
ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubeStack, cubesToMove, (in GridConnectionsEntityStruct g) => { return false; });
|
ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubeStack, cubesToMove, (in GridConnectionsEntityStruct g) => { return false; });
|
||||||
for (int i = 0; i < cubesToMove.Count; i++)
|
for (int i = 0; i < cubesToMove.count; i++)
|
||||||
{
|
{
|
||||||
MoveBlock(cubesToMove[i], vector);
|
MoveBlock(cubesToMove[i], vector);
|
||||||
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(cubesToMove[i], CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false;
|
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(cubesToMove[i], CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false;
|
||||||
|
|
|
@ -21,14 +21,14 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
/// <param name="color">The block's color</param>
|
/// <param name="color">The block's color</param>
|
||||||
/// <param name="darkness">The block color's darkness (0-9) - 0 is default color</param>
|
/// <param name="darkness">The block color's darkness (0-9) - 0 is default color</param>
|
||||||
/// <param name="position">The block's position in the grid - default block size is 0.2</param>
|
/// <param name="position">The block's position in the grid - default block size is 0.2</param>
|
||||||
/// <param name="rotation">The block's rotation</param>
|
/// <param name="rotation">The block's rotation in degrees</param>
|
||||||
/// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
|
/// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
|
||||||
/// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
|
/// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
|
||||||
/// <param name="playerId">The player who placed the block</param>
|
/// <param name="playerId">The player who placed the block</param>
|
||||||
/// <returns>Whether the operation was successful</returns>
|
/// <returns>Whether the operation was successful</returns>
|
||||||
public static bool PlaceBlock(BlockIDs block, float3 position,
|
public static bool PlaceBlock(BlockIDs block, float3 position,
|
||||||
quaternion rotation = new quaternion(), BlockColors color = BlockColors.Default, byte darkness = 0,
|
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
|
||||||
int uscale = 1, float3 scale = new float3(), uint playerId = 0)
|
int uscale = 1, float3 scale = default, uint playerId = 0)
|
||||||
{
|
{
|
||||||
if (placementEngine.IsInGame && GameState.IsBuildMode())
|
if (placementEngine.IsInGame && GameState.IsBuildMode())
|
||||||
{
|
{
|
||||||
|
@ -38,8 +38,9 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
uREPL.Log.Output(e.Message);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Logging.LogException(e);
|
//Logging.LogException(e);
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,19 +44,8 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
public IEntitiesDB entitiesDB { get; set; }
|
public IEntitiesDB entitiesDB { get; set; }
|
||||||
internal static BlockEntityFactory _blockEntityFactory; //Injected from PlaceBlockEngine
|
internal static BlockEntityFactory _blockEntityFactory; //Injected from PlaceBlockEngine
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Places a block at the given position
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="block">The block's type</param>
|
|
||||||
/// <param name="color">The block's color</param>
|
|
||||||
/// <param name="darkness">The block color's darkness - 0 is default color</param>
|
|
||||||
/// <param name="position">The block's position - default block size is 0.2</param>
|
|
||||||
/// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
|
|
||||||
/// <param name="scale">The block's non-uniform scale - less than 1 means <paramref name="uscale"/> is used</param>
|
|
||||||
/// <param name="playerId">The player who placed the block</param>
|
|
||||||
/// <exception cref="Exception"></exception>
|
|
||||||
public void PlaceBlock(BlockIDs block, BlockColors color, byte darkness, float3 position, int uscale,
|
public void PlaceBlock(BlockIDs block, BlockColors color, byte darkness, float3 position, int uscale,
|
||||||
float3 scale, uint playerId, quaternion rotation)
|
float3 scale, uint playerId, float3 rotation)
|
||||||
{ //It appears that only the non-uniform scale has any visible effect, but if that's not given here it will be set to the uniform one
|
{ //It appears that only the non-uniform scale has any visible effect, but if that's not given here it will be set to the uniform one
|
||||||
if (darkness > 9)
|
if (darkness > 9)
|
||||||
throw new Exception("That is too dark. Make sure to use 0-9 as darkness. (0 is default.)");
|
throw new Exception("That is too dark. Make sure to use 0-9 as darkness. (0 is default.)");
|
||||||
|
@ -68,7 +57,7 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private EntityStructInitializer BuildBlock(ushort block, byte color, float3 position, int uscale, float3 scale, quaternion rot)
|
private EntityStructInitializer BuildBlock(ushort block, byte color, float3 position, int uscale, float3 scale, float3 rot)
|
||||||
{
|
{
|
||||||
if (_blockEntityFactory == null)
|
if (_blockEntityFactory == null)
|
||||||
throw new Exception("The factory is null.");
|
throw new Exception("The factory is null.");
|
||||||
|
@ -77,14 +66,17 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
if (scale.x < 4e-5) scale.x = uscale;
|
if (scale.x < 4e-5) scale.x = uscale;
|
||||||
if (scale.y < 4e-5) scale.y = uscale;
|
if (scale.y < 4e-5) scale.y = uscale;
|
||||||
if (scale.z < 4e-5) scale.z = uscale;
|
if (scale.z < 4e-5) scale.z = uscale;
|
||||||
|
uint dbid = block;
|
||||||
|
if (!PrefabsID.DBIDMAP.ContainsKey(dbid))
|
||||||
|
throw new Exception("Block with ID " + dbid + " not found!");
|
||||||
//RobocraftX.CR.MachineEditing.PlaceBlockEngine
|
//RobocraftX.CR.MachineEditing.PlaceBlockEngine
|
||||||
ScalingEntityStruct scaling = new ScalingEntityStruct {scale = scale};
|
ScalingEntityStruct scaling = new ScalingEntityStruct {scale = scale};
|
||||||
RotationEntityStruct rotation = new RotationEntityStruct {rotation = quaternion.identity};
|
Quaternion rotQ = Quaternion.Euler(rot);
|
||||||
|
RotationEntityStruct rotation = new RotationEntityStruct {rotation = rotQ};
|
||||||
GridRotationStruct gridRotation = new GridRotationStruct
|
GridRotationStruct gridRotation = new GridRotationStruct
|
||||||
{position = float3.zero, rotation = quaternion.identity};
|
{position = position, rotation = rotQ};
|
||||||
CubeCategoryStruct category = new CubeCategoryStruct
|
CubeCategoryStruct category = new CubeCategoryStruct
|
||||||
{category = CubeCategory.General, type = CubeType.Block};
|
{category = CubeCategory.General, type = CubeType.Block};
|
||||||
uint dbid = block;
|
|
||||||
DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid};
|
DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid};
|
||||||
uint num = PrefabsID.DBIDMAP[dbid];
|
uint num = PrefabsID.DBIDMAP[dbid];
|
||||||
GFXPrefabEntityStructGO gfx = new GFXPrefabEntityStructGO {prefabID = num};
|
GFXPrefabEntityStructGO gfx = new GFXPrefabEntityStructGO {prefabID = num};
|
||||||
|
|
|
@ -13,6 +13,7 @@ using RobocraftX.SimulationModeState;
|
||||||
using RobocraftX.UECS;
|
using RobocraftX.UECS;
|
||||||
using Unity.Entities;
|
using Unity.Entities;
|
||||||
using Svelto.Context;
|
using Svelto.Context;
|
||||||
|
using Svelto.DataStructures;
|
||||||
using Svelto.ECS;
|
using Svelto.ECS;
|
||||||
using Svelto.ECS.EntityStructs;
|
using Svelto.ECS.EntityStructs;
|
||||||
using Unity.Transforms;
|
using Unity.Transforms;
|
||||||
|
@ -37,7 +38,7 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
private Stack<uint> cubesStack = new Stack<uint>();
|
private Stack<uint> cubesStack = new Stack<uint>();
|
||||||
private bool stackInUse = false;
|
private bool stackInUse = false;
|
||||||
|
|
||||||
private Gamecraft.DataStructures.FasterList<uint> cubesList = new Gamecraft.DataStructures.FasterList<uint>();
|
private FasterList<uint> cubesList = new FasterList<uint>();
|
||||||
private bool listInUse = false;
|
private bool listInUse = false;
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -171,7 +172,7 @@ namespace GamecraftModdingAPI.Blocks
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Stack<uint> cubeStack = new Stack<uint>();
|
Stack<uint> cubeStack = new Stack<uint>();
|
||||||
Gamecraft.DataStructures.FasterList<uint> cubeList = new Gamecraft.DataStructures.FasterList<uint>();
|
FasterList<uint> cubeList = new FasterList<uint>();
|
||||||
ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubesStack, cubesList, (in GridConnectionsEntityStruct g) => { return g.isIsolator; });
|
ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubesStack, cubesList, (in GridConnectionsEntityStruct g) => { return g.isIsolator; });
|
||||||
uint[] res = cubesList.ToArray();
|
uint[] res = cubesList.ToArray();
|
||||||
foreach (var id in res)
|
foreach (var id in res)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -9,24 +10,31 @@ using RobocraftX;
|
||||||
using Svelto.ECS;
|
using Svelto.ECS;
|
||||||
|
|
||||||
using GamecraftModdingAPI.Utility;
|
using GamecraftModdingAPI.Utility;
|
||||||
|
using RobocraftX.CR.MainGame;
|
||||||
|
|
||||||
namespace GamecraftModdingAPI.Events
|
namespace GamecraftModdingAPI.Events
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
|
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HarmonyPatch(typeof(FullGameCompositionRoot), "ActivateGame")]
|
[HarmonyPatch]
|
||||||
class GameActivatedPatch
|
class GameActivatedPatch
|
||||||
{
|
{
|
||||||
public static void Postfix(ref EnginesRoot ____mainGameEnginesRoot)
|
public static void Postfix(ref EnginesRoot enginesRoot)
|
||||||
{
|
{
|
||||||
// register custom game engines
|
// register custom game engines
|
||||||
GameEngineManager.RegisterEngines(____mainGameEnginesRoot);
|
GameEngineManager.RegisterEngines(enginesRoot);
|
||||||
// A new EnginesRoot is always created when ActivateGame is called
|
// A new EnginesRoot is always created when ActivateGame is called
|
||||||
// so all event emitters and handlers must be re-registered.
|
// so all event emitters and handlers must be re-registered.
|
||||||
EventManager.RegisterEngines(____mainGameEnginesRoot);
|
EventManager.RegisterEngines(enginesRoot);
|
||||||
Logging.Log("Dispatching Game Activated event");
|
Logging.Log("Dispatching Game Activated event");
|
||||||
EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
|
EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MethodBase TargetMethod()
|
||||||
|
{
|
||||||
|
return typeof(MainGameCompositionRoot).GetMethods().First(m => m.Name == "Compose")
|
||||||
|
.MakeGenericMethod(typeof(object));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ namespace GamecraftModdingAPI.Events
|
||||||
public static void Postfix()
|
public static void Postfix()
|
||||||
{
|
{
|
||||||
// Event emitters and handlers should already be registered by GameActivated event
|
// Event emitters and handlers should already be registered by GameActivated event
|
||||||
Logging.Log("Dispatching Game Switched To event");
|
Logging.Log("Not dispatching Game Switched To event");
|
||||||
EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
|
//EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,9 +253,6 @@
|
||||||
<Reference Include="Unity.Addressables">
|
<Reference Include="Unity.Addressables">
|
||||||
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Addressables.dll</HintPath>
|
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Addressables.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Unity.Animation.Rigging">
|
|
||||||
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Animation.Rigging.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Unity.Burst">
|
<Reference Include="Unity.Burst">
|
||||||
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Burst.dll</HintPath>
|
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Burst.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -307,9 +304,6 @@
|
||||||
<Reference Include="Unity.Properties">
|
<Reference Include="Unity.Properties">
|
||||||
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Properties.dll</HintPath>
|
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Properties.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Unity.Rendering.Hybrid">
|
|
||||||
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Rendering.Hybrid.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Unity.RenderPipelines.Core.Runtime">
|
<Reference Include="Unity.RenderPipelines.Core.Runtime">
|
||||||
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.RenderPipelines.Core.Runtime.dll</HintPath>
|
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.RenderPipelines.Core.Runtime.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
|
@ -89,15 +89,9 @@ namespace GamecraftModdingAPI.Utility
|
||||||
/// <param name="extraData">The extra data to pass to the ILogger.
|
/// <param name="extraData">The extra data to pass to the ILogger.
|
||||||
/// This is automatically populated with "OuterException#" and "OuterStacktrace#" entries</param>
|
/// This is automatically populated with "OuterException#" and "OuterStacktrace#" entries</param>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void LogException(Exception e, Dictionary<string, string> extraData = null)
|
public static void LogException(Exception e, string msg = null, Dictionary<string, string> extraData = null)
|
||||||
{
|
{
|
||||||
Svelto.Console.LogException(e, extraData);
|
Svelto.Console.LogException(e, msg, extraData);
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static void LogException(string msg, Exception e, Dictionary<string, string> extraData = null)
|
|
||||||
{
|
|
||||||
Svelto.Console.LogException(msg, e, extraData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -108,9 +102,9 @@ namespace GamecraftModdingAPI.Utility
|
||||||
/// <param name="extraData">The extra data to pass to the ILogger.
|
/// <param name="extraData">The extra data to pass to the ILogger.
|
||||||
/// This is implemented similar to LogException(Exception e, Dictionary extraData)'s extraData</param>
|
/// This is implemented similar to LogException(Exception e, Dictionary extraData)'s extraData</param>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void LogException(object obj, Exception e, Dictionary<string, string> extraData = null)
|
public static void LogException(Exception e, object obj, Dictionary<string, string> extraData = null)
|
||||||
{
|
{
|
||||||
Svelto.Console.LogException(obj.ToString(), e, extraData);
|
Svelto.Console.LogException(e, obj.ToString(), extraData);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|
Loading…
Reference in a new issue