Displaying blueprint before placing, enums, ToString()s

Added support for getting the player's current building mode (build, color, config, blueprint)
Added support for getting the current game's mode (building, playing, prefab etc.)
This commit is contained in:
Norbi Peti 2020-11-14 02:52:16 +01:00
parent 680721256c
commit f30dcd251f
7 changed files with 109 additions and 2 deletions

View file

@ -0,0 +1,23 @@
namespace GamecraftModdingAPI.App
{
public enum CurrentGameMode
{
None,
/// <summary>
/// Building a game
/// </summary>
Build,
/// <summary>
/// Playing a game
/// </summary>
Play,
/// <summary>
/// Viewing a prefab
/// </summary>
View,
/// <summary>
/// Viewing a tutorial
/// </summary>
Tutorial
}
}

View file

@ -335,6 +335,18 @@ namespace GamecraftModdingAPI.App
gameEngine.ToggleTimeMode(); gameEngine.ToggleTimeMode();
} }
/// <summary>
/// The mode of the game.
/// </summary>
public CurrentGameMode Mode
{
get
{
if (menuMode || !VerifyMode()) return CurrentGameMode.None;
return (CurrentGameMode) GameMode.CurrentMode;
}
}
/// <summary> /// <summary>
/// Load the game save. /// Load the game save.
/// This happens asynchronously, so when this method returns the game not loaded yet. /// This happens asynchronously, so when this method returns the game not loaded yet.

View file

@ -203,5 +203,10 @@ namespace GamecraftModdingAPI
public bool IsReadOnly { get; } = false; public bool IsReadOnly { get; } = false;
public Block this[int index] => blocks[index]; //Setting is not supported, since the order doesn't matter public Block this[int index] => blocks[index]; //Setting is not supported, since the order doesn't matter
public override string ToString()
{
return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Rotation)}: {Rotation}, {nameof(Count)}: {Count}";
}
} }
} }

View file

@ -36,6 +36,10 @@ namespace GamecraftModdingAPI.Blocks
AccessTools.DeclaredField(PlaceBlueprintUtilityType, "_localBlockMap"); AccessTools.DeclaredField(PlaceBlueprintUtilityType, "_localBlockMap");
private static readonly MethodInfo BuildBlock = AccessTools.Method(PlaceBlueprintUtilityType, "BuildBlock"); private static readonly MethodInfo BuildBlock = AccessTools.Method(PlaceBlueprintUtilityType, "BuildBlock");
private static readonly MethodInfo BuildWires = AccessTools.Method(PlaceBlueprintUtilityType, "BuildWires"); private static readonly MethodInfo BuildWires = AccessTools.Method(PlaceBlueprintUtilityType, "BuildWires");
private static readonly Type SerializeGhostBlueprintType =
AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BoxSelect.SerializeGhostChildrenOnAddEngine");
private static readonly MethodInfo SerializeGhostBlueprint =
AccessTools.Method(SerializeGhostBlueprintType, "SerializeClipboardGhostEntities");
private static NativeEntityRemove nativeRemove; private static NativeEntityRemove nativeRemove;
private static MachineGraphConnectionEntityFactory connectionFactory; private static MachineGraphConnectionEntityFactory connectionFactory;
@ -44,6 +48,8 @@ namespace GamecraftModdingAPI.Blocks
private static IEntitySerialization entitySerialization; private static IEntitySerialization entitySerialization;
private static IEntityFactory entityFactory; private static IEntityFactory entityFactory;
private static FasterList<EGID> globalBlockMap; private static FasterList<EGID> globalBlockMap;
private static object SerializeGhostBlueprintInstance;
private static GhostChildEntityFactory BuildGhostBlueprintFactory;
public void Ready() public void Ready()
{ {
@ -130,6 +136,19 @@ namespace GamecraftModdingAPI.Blocks
SelectionSerializationUtility.CopySelectionToClipboard(playerID, entitiesDB, SelectionSerializationUtility.CopySelectionToClipboard(playerID, entitiesDB,
serializationData.blueprintData, entitySerialization, entityFactory, blockIDs, serializationData.blueprintData, entitySerialization, entityFactory, blockIDs,
(uint) blockIDs.Length, pos, rot, -1); (uint) blockIDs.Length, pos, rot, -1);
BuildGhostBlueprint(selected, pos, rot, playerID);
SerializeGhostBlueprint.Invoke(SerializeGhostBlueprintInstance, new object[] {playerID, blueprintID});
}
private void BuildGhostBlueprint(ICollection<Block> blocks, float3 pos, quaternion rot, uint playerID)
{
GhostChildUtility.ClearGhostChildren(playerID, entitiesDB, entityFunctions);
foreach (var block in blocks)
{
GhostChildUtility.BuildGhostChild(in playerID, block.Id, in pos, in rot, entitiesDB,
BuildGhostBlueprintFactory, false);
}
} }
public Block[] PlaceBlueprintBlocks(uint blueprintID, uint playerID, float3 pos, float3 rot) public Block[] PlaceBlueprintBlocks(uint blueprintID, uint playerID, float3 pos, float3 rot)
@ -238,6 +257,34 @@ namespace GamecraftModdingAPI.Blocks
} }
} }
[HarmonyPatch]
private static class SerializeGhostBlueprintPatch
{
public static void Postfix(object __instance)
{
SerializeGhostBlueprintInstance = __instance;
}
public static MethodBase TargetMethod()
{
return AccessTools.GetDeclaredConstructors(SerializeGhostBlueprintType)[0];
}
}
[HarmonyPatch]
private static class BuildGhostBlueprintPatch
{
public static void Postfix(GhostChildEntityFactory ghostChildEntityFactory)
{
BuildGhostBlueprintFactory = ghostChildEntityFactory;
}
public static MethodBase TargetMethod()
{
return AccessTools.GetDeclaredConstructors(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine"))[0];
}
}
public IEntityFactory Factory { get; set; } public IEntityFactory Factory { get; set; }
} }
} }

View file

@ -72,5 +72,10 @@ namespace GamecraftModdingAPI
{ {
BlockGroup._engine.DisposeBlueprint(Id); BlockGroup._engine.DisposeBlueprint(Id);
} }
public override string ToString()
{
return $"{nameof(Id)}: {Id}";
}
} }
} }

View file

@ -1,5 +1,4 @@
using System; using System;
using Gamecraft.GUI.Blueprints;
using Unity.Mathematics; using Unity.Mathematics;
using RobocraftX.Common; using RobocraftX.Common;
using RobocraftX.Common.Players; using RobocraftX.Common.Players;
@ -354,7 +353,13 @@ namespace GamecraftModdingAPI
set => BlockGroup._engine.SelectBlueprint(value?.Id ?? uint.MaxValue); set => BlockGroup._engine.SelectBlueprint(value?.Id ?? uint.MaxValue);
} }
// object methods /// <summary>
/// The player's mode in time stopped mode, determining what they place.
/// </summary>
public PlayerBuildingMode BuildingMode => (PlayerBuildingMode) playerEngine
.GetCharacterStruct<PlayerInputTimeStoppedContextStruct>(Id, out _).timeStoppedContext;
// object methods
/// <summary> /// <summary>
/// Teleport the player to the specified coordinates. /// Teleport the player to the specified coordinates.

View file

@ -0,0 +1,10 @@
namespace GamecraftModdingAPI.Players
{
public enum PlayerBuildingMode
{
BlockMode,
ColourMode,
ConfigMode,
BlueprintMode
}
}