Add block type and color properties

This commit is contained in:
Norbi Peti 2020-05-13 16:52:21 +02:00 committed by NGnius (Graham)
parent ff57a16565
commit 6f8241554d
16 changed files with 75 additions and 113 deletions

View file

@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using Svelto.ECS;
using RobocraftX.Common;
using Unity.Mathematics;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Utility;
using RobocraftX.Common;
using Svelto.ECS;
using Unity.Mathematics;
namespace GamecraftModdingAPI
{
@ -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()

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);
}
}
}

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;

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;

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;

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;

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;

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

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;

View file

@ -1,8 +1,4 @@
using System;
using Svelto.ECS;
namespace GamecraftModdingAPI.Blocks
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// Common tweakable stats operations.

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;

View file

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

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");
}

View file

@ -3,7 +3,6 @@
using Unity.Mathematics;
using GamecraftModdingAPI.Players;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI
{

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;
}

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"));