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:
NGnius 2020-02-09 04:00:22 +00:00 committed by Gitea
commit 1366d95c4a
9 changed files with 50 additions and 50 deletions

View file

@ -7,8 +7,7 @@ namespace GamecraftModdingAPI.Blocks
{
AluminiumCube,
AxleS,
Battery,
HingeS,
HingeS = 3,
MotorS,
HingeM,
MotorM,
@ -68,8 +67,7 @@ namespace GamecraftModdingAPI.Blocks
GlassConeSegment,
GlassCylinder,
GlassSphere,
Lever,
Reactor, //64 - one ID is skipped
Lever, //63 - two IDs skipped
PlayerSpawn = 66, //Crashes without special handling
SmallSpawn,
MediumSpawn,
@ -154,6 +152,17 @@ namespace GamecraftModdingAPI.Blocks
ConcreteSlicedCube,
ConcreteSlope,
ConcreteCorner,
RoadCarTyre,
OffRoadCarTyre,
RacingCarTyre,
BicycleTyre,
FrontBikeTyre,
RearBikeTyre,
ChopperBikeTyre,
TractorTyre,
MonsterTruckTyre,
MotocrossBikeTyre,
CartTyre,
BeachTree1 = 200,
BeachTree2,
BeachTree3,

View file

@ -20,6 +20,7 @@ using Unity.Mathematics;
using UnityEngine;
using GamecraftModdingAPI.Utility;
using Svelto.DataStructures;
namespace GamecraftModdingAPI.Blocks
{
@ -69,9 +70,9 @@ namespace GamecraftModdingAPI.Blocks
public float3 MoveConnectedBlocks(uint blockID, float3 vector)
{
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; });
for (int i = 0; i < cubesToMove.Count; i++)
for (int i = 0; i < cubesToMove.count; i++)
{
MoveBlock(cubesToMove[i], vector);
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(cubesToMove[i], CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false;

View file

@ -21,14 +21,14 @@ namespace GamecraftModdingAPI.Blocks
/// <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="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="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>
/// <returns>Whether the operation was successful</returns>
public static bool PlaceBlock(BlockIDs block, float3 position,
quaternion rotation = new quaternion(), BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = new float3(), uint playerId = 0)
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, uint playerId = 0)
{
if (placementEngine.IsInGame && GameState.IsBuildMode())
{
@ -38,8 +38,9 @@ namespace GamecraftModdingAPI.Blocks
}
catch (Exception e)
{
uREPL.Log.Output(e.Message);
#if DEBUG
Logging.LogException(e);
//Logging.LogException(e);
#endif
return false;
}

View file

@ -44,19 +44,8 @@ namespace GamecraftModdingAPI.Blocks
public IEntitiesDB entitiesDB { get; set; }
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,
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
if (darkness > 9)
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)
throw new Exception("The factory is null.");
@ -77,14 +66,17 @@ namespace GamecraftModdingAPI.Blocks
if (scale.x < 4e-5) scale.x = uscale;
if (scale.y < 4e-5) scale.y = 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
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
{position = float3.zero, rotation = quaternion.identity};
{position = position, rotation = rotQ};
CubeCategoryStruct category = new CubeCategoryStruct
{category = CubeCategory.General, type = CubeType.Block};
uint dbid = block;
DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid};
uint num = PrefabsID.DBIDMAP[dbid];
GFXPrefabEntityStructGO gfx = new GFXPrefabEntityStructGO {prefabID = num};

View file

@ -13,6 +13,7 @@ using RobocraftX.SimulationModeState;
using RobocraftX.UECS;
using Unity.Entities;
using Svelto.Context;
using Svelto.DataStructures;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Transforms;
@ -37,7 +38,7 @@ namespace GamecraftModdingAPI.Blocks
private Stack<uint> cubesStack = new Stack<uint>();
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;
public void Dispose()
@ -171,7 +172,7 @@ namespace GamecraftModdingAPI.Blocks
else
{
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; });
uint[] res = cubesList.ToArray();
foreach (var id in res)

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -9,24 +10,31 @@ using RobocraftX;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
using RobocraftX.CR.MainGame;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
/// </summary>
[HarmonyPatch(typeof(FullGameCompositionRoot), "ActivateGame")]
[HarmonyPatch]
class GameActivatedPatch
{
public static void Postfix(ref EnginesRoot ____mainGameEnginesRoot)
public static void Postfix(ref EnginesRoot enginesRoot)
{
// register custom game engines
GameEngineManager.RegisterEngines(____mainGameEnginesRoot);
GameEngineManager.RegisterEngines(enginesRoot);
// A new EnginesRoot is always created when ActivateGame is called
// so all event emitters and handlers must be re-registered.
EventManager.RegisterEngines(____mainGameEnginesRoot);
EventManager.RegisterEngines(enginesRoot);
Logging.Log("Dispatching Game Activated event");
EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
}
public static MethodBase TargetMethod()
{
return typeof(MainGameCompositionRoot).GetMethods().First(m => m.Name == "Compose")
.MakeGenericMethod(typeof(object));
}
}
}

View file

@ -20,8 +20,8 @@ namespace GamecraftModdingAPI.Events
public static void Postfix()
{
// Event emitters and handlers should already be registered by GameActivated event
Logging.Log("Dispatching Game Switched To event");
EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
Logging.Log("Not dispatching Game Switched To event");
//EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
}
}
}

View file

@ -253,9 +253,6 @@
<Reference Include="Unity.Addressables">
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Addressables.dll</HintPath>
</Reference>
<Reference Include="Unity.Animation.Rigging">
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Animation.Rigging.dll</HintPath>
</Reference>
<Reference Include="Unity.Burst">
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Burst.dll</HintPath>
</Reference>
@ -307,9 +304,6 @@
<Reference Include="Unity.Properties">
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Properties.dll</HintPath>
</Reference>
<Reference Include="Unity.Rendering.Hybrid">
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.Rendering.Hybrid.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.Core.Runtime">
<HintPath>..\ref\Gamecraft_Data\Managed\Unity.RenderPipelines.Core.Runtime.dll</HintPath>
</Reference>

View file

@ -89,15 +89,9 @@ namespace GamecraftModdingAPI.Utility
/// <param name="extraData">The extra data to pass to the ILogger.
/// This is automatically populated with "OuterException#" and "OuterStacktrace#" entries</param>
[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);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogException(string msg, Exception e, Dictionary<string, string> extraData = null)
{
Svelto.Console.LogException(msg, e, extraData);
Svelto.Console.LogException(e, msg, extraData);
}
/// <summary>
@ -108,9 +102,9 @@ namespace GamecraftModdingAPI.Utility
/// <param name="extraData">The extra data to pass to the ILogger.
/// This is implemented similar to LogException(Exception e, Dictionary extraData)'s extraData</param>
[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)]