|
|
@@ -0,0 +1,85 @@ |
|
|
|
using System; |
|
|
|
using RobocraftX.GUI.CommandLine; |
|
|
|
using RobocraftX.Multiplayer; |
|
|
|
using RobocraftX.StateSync; |
|
|
|
using RobocraftX.Character; |
|
|
|
using Svelto.ECS; |
|
|
|
using Unity.Entities; |
|
|
|
using UnityEngine; |
|
|
|
using uREPL; |
|
|
|
using Svelto.Context; |
|
|
|
using RobocraftX; |
|
|
|
using RobocraftX.Blocks.Ghost; |
|
|
|
using RobocraftX.Blocks.Scaling; |
|
|
|
using RobocraftX.Common; |
|
|
|
using RobocraftX.CR.MachineEditing; |
|
|
|
using Svelto.ECS.EntityStructs; |
|
|
|
using Unity.Mathematics; |
|
|
|
|
|
|
|
namespace ExtraCommands.Basics |
|
|
|
{ |
|
|
|
[CustomCommand("SetScale")] |
|
|
|
class SetScaleCommandEngine : CustomCommandEngine |
|
|
|
{ |
|
|
|
public SetScaleCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
public override void Ready() |
|
|
|
{ |
|
|
|
CustomCommandUtility.Register<float, float, float>("SetScale", SetScaleCommand, "Set the scale for the next block. Use 0 0 0 to reset. The displayed cube is uniformly scaled until placed."); |
|
|
|
} |
|
|
|
|
|
|
|
private float3 _scale; |
|
|
|
|
|
|
|
private void SetScaleCommand(float x, float y, float z) |
|
|
|
{ |
|
|
|
_scale = new float3(x, y, z); |
|
|
|
GhostScalingEntityStruct[] scalings = |
|
|
|
entitiesDB.QueryEntities<GhostScalingEntityStruct>( |
|
|
|
(ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out uint count); |
|
|
|
Console.WriteLine("Found " + count + "/" + scalings.Length + " scalings."); |
|
|
|
for (int index = 0; index < count; index++) |
|
|
|
{ |
|
|
|
Console.WriteLine("G scaling " + index + ": " + scalings[index].ghostScale); |
|
|
|
ref var scaling = ref entitiesDB.QueryEntities<ScalingEntityStruct>( |
|
|
|
(ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out _)[index]; |
|
|
|
Console.WriteLine("Scaling " + index + ": " + scaling); |
|
|
|
ref var scale = ref entitiesDB.QueryEntities<BlockPlacementScaleEntityStruct>( |
|
|
|
(ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out _)[index]; |
|
|
|
Console.WriteLine("Scale " + index + ": " + scale.snapGridScale); |
|
|
|
UpdateScale(ref scale, ref scaling, ref scalings[index]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void UpdateScale(ref BlockPlacementScaleEntityStruct scale, ref ScalingEntityStruct scaling, |
|
|
|
ref GhostScalingEntityStruct gscaling) |
|
|
|
{ |
|
|
|
if (_scale.x < 4e5 || _scale.y < 4e5 || _scale.z < 4e5) return; |
|
|
|
scale.snapGridScale = (int) _scale.x; |
|
|
|
scale.blockPlacementHeight = (int) _scale.y; |
|
|
|
scaling.scale = _scale; |
|
|
|
gscaling.ghostScale = _scale; |
|
|
|
} |
|
|
|
|
|
|
|
public override void Dispose() |
|
|
|
{ |
|
|
|
CustomCommandUtility.Unregister("SetScale"); |
|
|
|
} |
|
|
|
|
|
|
|
/*public void Add(ref GhostScalingEntityStruct entityView, EGID egid) |
|
|
|
{ //If the cursor is near a block, it recreates the entity - nope |
|
|
|
Console.WriteLine("Entity " + egid + " added: " + entityView.ghostScale); |
|
|
|
ref var scale = ref entitiesDB.QueryEntity<BlockPlacementScaleEntityStruct>(egid); |
|
|
|
ref var scaling = ref entitiesDB.QueryEntity<ScalingEntityStruct>(egid); |
|
|
|
UpdateScale(ref scale, ref scaling, ref entityView); |
|
|
|
entitiesDB.PublishEntityChange<ScalingEntityStruct>(egid); |
|
|
|
entitiesDB.PublishEntityChange<BlockPlacementScaleEntityStruct>(egid); |
|
|
|
entitiesDB.PublishEntityChange<GhostScalingEntityStruct>(egid); |
|
|
|
} |
|
|
|
|
|
|
|
public void Remove(ref GhostScalingEntityStruct entityView, EGID egid) |
|
|
|
{ |
|
|
|
}*/ |
|
|
|
} |
|
|
|
} |