Fix styling and docs

This commit is contained in:
NGnius (Graham) 2020-01-03 19:54:35 -05:00
parent 79a2f7c09c
commit cd6862bb29
7 changed files with 46 additions and 36 deletions

View file

@ -1,5 +1,8 @@
namespace GamecraftModdingAPI.Blocks namespace GamecraftModdingAPI.Blocks
{ {
/// <summary>
/// Preset block colours
/// </summary>
public enum BlockColors public enum BlockColors
{ {
Default = byte.MaxValue, Default = byte.MaxValue,

View file

@ -1,5 +1,8 @@
namespace GamecraftModdingAPI.Blocks namespace GamecraftModdingAPI.Blocks
{ {
/// <summary>
/// Possible block types
/// </summary>
public enum BlockIDs public enum BlockIDs
{ {
AluminiumCube, AluminiumCube,

View file

@ -20,7 +20,7 @@ namespace GamecraftModdingAPI.Blocks
/// </summary> /// </summary>
/// <param name="id">The block's id</param> /// <param name="id">The block's id</param>
/// <param name="vector">The movement amount (x,y,z)</param> /// <param name="vector">The movement amount (x,y,z)</param>
/// <returns></returns> /// <returns>Whether the operation was successful</returns>
public static bool MoveBlock(uint id, float3 vector) public static bool MoveBlock(uint id, float3 vector)
{ {
if (movementEngine.IsInGame && movementEngine.IsBuildMode()) if (movementEngine.IsInGame && movementEngine.IsBuildMode())
@ -36,7 +36,7 @@ namespace GamecraftModdingAPI.Blocks
/// </summary> /// </summary>
/// <param name="id">The starting block's id</param> /// <param name="id">The starting block's id</param>
/// <param name="vector">The movement amount (x,y,z)</param> /// <param name="vector">The movement amount (x,y,z)</param>
/// <returns></returns> /// <returns>Whether the operation was successful</returns>
public static bool MoveConnectedBlocks(uint id, float3 vector) public static bool MoveConnectedBlocks(uint id, float3 vector)
{ {
if (movementEngine.IsInGame && movementEngine.IsBuildMode()) if (movementEngine.IsInGame && movementEngine.IsBuildMode())

View file

@ -1,12 +1,13 @@
using System; using System;
using GamecraftModdingAPI.Utility;
using GCMC;
using Unity.Mathematics; using Unity.Mathematics;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks namespace GamecraftModdingAPI.Blocks
{ {
/// <summary> /// <summary>
/// Common block movement operations /// Common block placement operations
/// </summary> /// </summary>
public static class Placement public static class Placement
{ {
@ -24,17 +25,26 @@ namespace GamecraftModdingAPI.Blocks
/// <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>
/// <exception cref="Exception"></exception> /// <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, quaternion rotation = new quaternion(), BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = new float3(), uint playerId = 0) int uscale = 1, float3 scale = new float3(), uint playerId = 0)
{ {
if (placementEngine.IsInGame && GameState.IsBuildMode()) if (placementEngine.IsInGame && GameState.IsBuildMode())
{
try
{ {
placementEngine.PlaceBlock(block, color, darkness, position, uscale, scale, playerId, rotation); placementEngine.PlaceBlock(block, color, darkness, position, uscale, scale, playerId, rotation);
}
catch (Exception e)
{
#if DEBUG
Logging.LogException(e);
#endif
return false;
}
return true; return true;
} }
return false; return false;
} }

View file

@ -1,10 +1,8 @@
using System; using System;
using System.Reflection; using System.Reflection;
using DataLoader; using DataLoader;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Utility;
using Harmony; using Harmony;
using JetBrains.Annotations;
using RobocraftX.Blocks; using RobocraftX.Blocks;
using RobocraftX.Blocks.Ghost; using RobocraftX.Blocks.Ghost;
using RobocraftX.Blocks.Scaling; using RobocraftX.Blocks.Scaling;
@ -22,8 +20,13 @@ using Unity.Mathematics;
using UnityEngine; using UnityEngine;
using uREPL; using uREPL;
namespace GCMC using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{ {
/// <summary>
/// Engine which executes block placement actions
/// </summary>
public class PlacementEngine : IApiEngine public class PlacementEngine : IApiEngine
{ {
public bool IsInGame = false; public bool IsInGame = false;
@ -55,8 +58,6 @@ namespace GCMC
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, quaternion 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
try
{
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.)");
BuildBlock((ushort) block, (byte) (color + darkness * 10), position, uscale, scale, rotation).Init( BuildBlock((ushort) block, (byte) (color + darkness * 10), position, uscale, scale, rotation).Init(
@ -66,12 +67,6 @@ namespace GCMC
placedBy = playerId placedBy = playerId
}); });
} }
catch (Exception e)
{
Console.WriteLine(e);
Log.Error(e.Message);
}
}
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, quaternion rot)
{ {
@ -135,16 +130,15 @@ namespace GCMC
return structInitializer; return structInitializer;
} }
public string Name { get; } = nameof(PlacementEngine); public string Name { get; } = "GamecraftModdingAPIPlacementGameEngine";
[HarmonyPatch] [HarmonyPatch]
[UsedImplicitly]
public class FactoryObtainerPatch public class FactoryObtainerPatch
{ {
static void Postfix(BlockEntityFactory blockEntityFactory) static void Postfix(BlockEntityFactory blockEntityFactory)
{ {
_blockEntityFactory = blockEntityFactory; _blockEntityFactory = blockEntityFactory;
Debug.Log("Block entity factory injected."); Logging.MetaDebugLog("Block entity factory injected.");
} }
static MethodBase TargetMethod(HarmonyInstance instance) static MethodBase TargetMethod(HarmonyInstance instance)

View file

@ -19,8 +19,8 @@ namespace GamecraftModdingAPI.Blocks
/// Rotate a single block by a specific amount in degrees /// Rotate a single block by a specific amount in degrees
/// </summary> /// </summary>
/// <param name="id">The block's id</param> /// <param name="id">The block's id</param>
/// <param name="vector">The rotation amount around the x,y,z-planes</param> /// <param name="vector">The rotation amount around the x,y,z-axis</param>
/// <returns></returns> /// <returns>Whether the operation was successful</returns>
public static bool RotateBlock(uint id, float3 vector) public static bool RotateBlock(uint id, float3 vector)
{ {
if (rotationEngine.IsInGame && rotationEngine.IsBuildMode()) if (rotationEngine.IsInGame && rotationEngine.IsBuildMode())
@ -35,8 +35,8 @@ namespace GamecraftModdingAPI.Blocks
/// Rotate all connected blocks by a specific amount in degrees /// Rotate all connected blocks by a specific amount in degrees
/// </summary> /// </summary>
/// <param name="id">The starting block's id</param> /// <param name="id">The starting block's id</param>
/// <param name="vector">The rotation around the x,y,z-planes</param> /// <param name="vector">The rotation around the x,y,z-axis</param>
/// <returns></returns> /// <returns>Whether the operation was successful</returns>
public static bool RotateConnectedBlocks(uint id, float3 vector) public static bool RotateConnectedBlocks(uint id, float3 vector)
{ {
if (rotationEngine.IsInGame && rotationEngine.IsBuildMode()) if (rotationEngine.IsInGame && rotationEngine.IsBuildMode())

View file

@ -24,7 +24,7 @@ using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks namespace GamecraftModdingAPI.Blocks
{ {
/// <summary> /// <summary>
/// Engine which executes block movement actions /// Engine which executes signal actions
/// </summary> /// </summary>
public class SignalEngine : IApiEngine public class SignalEngine : IApiEngine
{ {