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
{
/// <summary>
/// Preset block colours
/// </summary>
public enum BlockColors
{
Default = byte.MaxValue,

View file

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

View file

@ -20,7 +20,7 @@ namespace GamecraftModdingAPI.Blocks
/// </summary>
/// <param name="id">The block's id</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)
{
if (movementEngine.IsInGame && movementEngine.IsBuildMode())
@ -36,7 +36,7 @@ namespace GamecraftModdingAPI.Blocks
/// </summary>
/// <param name="id">The starting block's id</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)
{
if (movementEngine.IsInGame && movementEngine.IsBuildMode())

View file

@ -1,12 +1,13 @@
using System;
using GamecraftModdingAPI.Utility;
using GCMC;
using Unity.Mathematics;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// Common block movement operations
/// Common block placement operations
/// </summary>
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="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>
/// <exception cref="Exception"></exception>
/// <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)
{
if (placementEngine.IsInGame && GameState.IsBuildMode())
{
try
{
placementEngine.PlaceBlock(block, color, darkness, position, uscale, scale, playerId, rotation);
}
catch (Exception e)
{
#if DEBUG
Logging.LogException(e);
#endif
return false;
}
return true;
}
return false;
}

View file

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

View file

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

View file

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