Browse Source

Add block type and color properties

tags/v1.0.0
NorbiPeti NGnius (Graham) <ngniusness@gmail.com> 4 years ago
parent
commit
6f8241554d
16 changed files with 75 additions and 113 deletions
  1. +51
    -11
      GamecraftModdingAPI/Block.cs
  2. +8
    -3
      GamecraftModdingAPI/Blocks/BlockEngine.cs
  3. +1
    -8
      GamecraftModdingAPI/Blocks/BlockIdentifiers.cs
  4. +1
    -16
      GamecraftModdingAPI/Blocks/MovementEngine.cs
  5. +0
    -7
      GamecraftModdingAPI/Blocks/PlacementEngine.cs
  6. +0
    -6
      GamecraftModdingAPI/Blocks/RemovalEngine.cs
  7. +1
    -15
      GamecraftModdingAPI/Blocks/RotationEngine.cs
  8. +1
    -22
      GamecraftModdingAPI/Blocks/SignalEngine.cs
  9. +1
    -7
      GamecraftModdingAPI/Blocks/Signals.cs
  10. +1
    -5
      GamecraftModdingAPI/Blocks/Tweakable.cs
  11. +1
    -5
      GamecraftModdingAPI/Blocks/TweakableEngine.cs
  12. +1
    -2
      GamecraftModdingAPI/Blocks/TweakableStat.cs
  13. +0
    -1
      GamecraftModdingAPI/Main.cs
  14. +0
    -1
      GamecraftModdingAPI/Player.cs
  15. +0
    -3
      GamecraftModdingAPI/Players/PlayerEngine.cs
  16. +8
    -1
      GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs

+ 51
- 11
GamecraftModdingAPI/Block.cs View File

@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Utility;
using RobocraftX.Common;

using Svelto.ECS;
using RobocraftX.Common;
using Unity.Mathematics;

using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Utility;

namespace GamecraftModdingAPI
{
public class Block
@@ -80,11 +81,6 @@ namespace GamecraftModdingAPI
set => MovementEngine.MoveBlock(Id.entityID, value);
}

/// <summary>
/// Returns an array of blocks that are connected to this one.
/// </summary>
public Block[] ConnectedCubes => BlockEngine.GetConnectedBlocks(Id.entityID);

/// <summary>
/// The block's current rotation in degrees.
/// </summary>
@@ -94,13 +90,57 @@ namespace GamecraftModdingAPI
set => RotationEngine.RotateBlock(Id.entityID, value);
}

/// <summary>
/// The block's type (ID). Changing from or to a functional part may crash the game.
/// </summary>
public BlockIDs Type
{
get => (BlockIDs) BlockEngine.GetBlockInfo<DBEntityStruct>(Id).DBID;
set
{
BlockEngine.GetBlockInfo<DBEntityStruct>(Id).DBID = (uint) value;
uint prefabId = PrefabsID.GetPrefabId((uint) value, 0);
BlockEngine.GetBlockInfo<GFXPrefabEntityStructGPUI>(Id).prefabID = prefabId;
BlockEngine.GetBlockInfo<PhysicsPrefabEntityStruct>(Id) = new PhysicsPrefabEntityStruct(prefabId);
}
}

public BlockColors Color
{
get => (BlockColors) (BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(Id).indexInPalette % 10);
set
{
ref var color = ref BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(Id);
color.indexInPalette = (byte) (color.indexInPalette / 10 * 10 + value);
color.needsUpdate = true;
}
}

public byte ColorDarkness
{
get => (byte) (BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(Id).indexInPalette / 10);
set
{
ref var color = ref BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(Id);
color.indexInPalette = (byte) (10 * (byte) value + color.indexInPalette % 10);
color.needsUpdate = true;
}
}

/// <summary>
/// Returns an array of blocks that are connected to this one.
/// </summary>
public Block[] GetConnectedCubes() => BlockEngine.GetConnectedBlocks(Id.entityID);

/// <summary>
/// Removes this block.
/// </summary>
/// <returns>True if the block exists and could be removed.</returns>
public bool Remove()
public bool Remove() => RemovalEngine.RemoveBlock(Id);

public override string ToString()
{
return RemovalEngine.RemoveBlock(Id);
return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Rotation)}: {Rotation}";
}

public static void Init()


+ 8
- 3
GamecraftModdingAPI/Blocks/BlockEngine.cs View File

@@ -1,11 +1,11 @@
using System.Collections.Generic;
using GamecraftModdingAPI.Engines;
using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.DataStructures;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Mathematics;
using GamecraftModdingAPI.Engines;

namespace GamecraftModdingAPI.Blocks
{
@@ -35,5 +35,10 @@ namespace GamecraftModdingAPI.Blocks
ret[i] = new Block(cubesToProcess[i]);
return ret;
}

public ref T GetBlockInfo<T>(EGID blockID) where T : struct, IEntityComponent
{
return ref entitiesDB.QueryEntity<T>(blockID);
}
}
}

+ 1
- 8
GamecraftModdingAPI/Blocks/BlockIdentifiers.cs View File

@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;

using Svelto.ECS;
using Svelto.ECS;
using RobocraftX.Common;

using HarmonyLib;


+ 1
- 16
GamecraftModdingAPI/Blocks/MovementEngine.cs View File

@@ -1,24 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using RobocraftX;
using RobocraftX.Blocks;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Common;
using RobocraftX.Multiplayer;
using RobocraftX.SimulationModeState;
using RobocraftX.Common;
using RobocraftX.UECS;
using Unity.Entities;
using Svelto.Context;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Transforms;
using Unity.Mathematics;
using UnityEngine;
using Svelto.DataStructures;

using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;


+ 0
- 7
GamecraftModdingAPI/Blocks/PlacementEngine.cs View File

@@ -4,21 +4,14 @@ using System.Reflection;
using DataLoader;
using HarmonyLib;
using RobocraftX.Blocks;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Blocks.Scaling;
using RobocraftX.Character;
using RobocraftX.CommandLine.Custom;
using RobocraftX.Common;
using RobocraftX.Common.Input;
using RobocraftX.Common.Utilities;
using RobocraftX.CR.MachineEditing;
using RobocraftX.StateSync;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using uREPL;

using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;


+ 0
- 6
GamecraftModdingAPI/Blocks/RemovalEngine.cs View File

@@ -2,15 +2,9 @@ using System.Reflection;

using HarmonyLib;
using RobocraftX.Blocks;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Character.Camera;
using RobocraftX.Character.Factories;
using RobocraftX.Common;
using RobocraftX.Players;
using Svelto.ECS;
using uREPL;

using GamecraftModdingAPI.Commands;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;



+ 1
- 15
GamecraftModdingAPI/Blocks/RotationEngine.cs View File

@@ -1,21 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using RobocraftX;
using RobocraftX.Blocks;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Common;
using RobocraftX.Multiplayer;
using RobocraftX.SimulationModeState;
using RobocraftX.Common;
using RobocraftX.UECS;
using Unity.Entities;
using Svelto.Context;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Transforms;
using Unity.Mathematics;
using UnityEngine;



+ 1
- 22
GamecraftModdingAPI/Blocks/SignalEngine.cs View File

@@ -1,27 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using RobocraftX;
using RobocraftX.Blocks;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Common;
using RobocraftX.Multiplayer;
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;
using Unity.Mathematics;
using UnityEngine;
using Svelto.ECS;
using Gamecraft.Wires;

using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;

namespace GamecraftModdingAPI.Blocks


+ 1
- 7
GamecraftModdingAPI/Blocks/Signals.cs View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Svelto.ECS;
using Svelto.ECS;

using GamecraftModdingAPI.Utility;



+ 1
- 5
GamecraftModdingAPI/Blocks/Tweakable.cs View File

@@ -1,8 +1,4 @@
using System;

using Svelto.ECS;

namespace GamecraftModdingAPI.Blocks
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// Common tweakable stats operations.


+ 1
- 5
GamecraftModdingAPI/Blocks/TweakableEngine.cs View File

@@ -1,11 +1,7 @@
using System;
using System.Reflection;

using RobocraftX.Blocks;
using RobocraftX.Blocks;
using Gamecraft.Wires;
using Svelto.ECS;

using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;




+ 1
- 2
GamecraftModdingAPI/Blocks/TweakableStat.cs View File

@@ -1,5 +1,4 @@
using System;
namespace GamecraftModdingAPI.Blocks
namespace GamecraftModdingAPI.Blocks
{
public enum TweakableStat
{


+ 0
- 1
GamecraftModdingAPI/Main.cs View File

@@ -72,7 +72,6 @@ namespace GamecraftModdingAPI
// init object-oriented classes
Player.Init();
Block.Init();
RuntimeCommands.Register("getblock", () => new Player(PlayerType.Local).GetBlockLookedAt());
Logging.MetaLog($"{currentAssembly.GetName().Name} v{currentAssembly.GetName().Version} initialized");
}



+ 0
- 1
GamecraftModdingAPI/Player.cs View File

@@ -3,7 +3,6 @@
using Unity.Mathematics;

using GamecraftModdingAPI.Players;
using GamecraftModdingAPI.Utility;

namespace GamecraftModdingAPI
{


+ 0
- 3
GamecraftModdingAPI/Players/PlayerEngine.cs View File

@@ -248,10 +248,7 @@ namespace GamecraftModdingAPI.Players
? GhostBlockUtils.GetBuildInteractionDistance(entitiesDB, rayCast)
: maxDistance;
if (rayCast.hit && rayCast.distance <= distance)
{
Console.WriteLine("Hit block: " + rayCast.hitEgid);
return new Block(rayCast.hitEgid);
}

return null;
}


+ 8
- 1
GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs View File

@@ -12,6 +12,7 @@ using RobocraftX.SimulationModeState;
using GamecraftModdingAPI.Commands;
using GamecraftModdingAPI.Events;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Blocks;

namespace GamecraftModdingAPI.Tests
{
@@ -100,7 +101,7 @@ namespace GamecraftModdingAPI.Tests
.Action((float x, float y, float z) =>
{
if (GameState.IsBuildMode())
foreach (var block in Block.GetLastPlacedBlock().ConnectedCubes)
foreach (var block in Block.GetLastPlacedBlock().GetConnectedCubes())
block.Position += new Unity.Mathematics.float3(x, y, z);
else
GamecraftModdingAPI.Utility.Logging.CommandLogError("Blocks can only be moved in Build mode!");
@@ -141,6 +142,12 @@ namespace GamecraftModdingAPI.Tests
Tasks.Scheduler.Schedule(task);
}).Build();

CommandBuilder.Builder("getBlock")
.Action(() => uREPL.Log.Output(new Player(Players.PlayerType.Local).GetBlockLookedAt()+"")).Build();
CommandBuilder.Builder("changeToAluminium")
.Action(() => new Player(Players.PlayerType.Local).GetBlockLookedAt().Type = BlockIDs.AluminiumCube)
.Build();

/*
CommandManager.AddCommand(new SimpleCustomCommandEngine<float>((float d) => { UnityEngine.Camera.main.fieldOfView = d; },
"SetFOV", "Set the player camera's field of view"));


Loading…
Cancel
Save