From 72d3f65fb1ec7d5be761fe4a2cd159f660462fec Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 15 Jan 2020 23:26:52 +0100 Subject: [PATCH] Create set scale command --- extracommands/ExtraCommands.csproj | 3 + extracommands/SetScaleCommandEngine.cs | 85 ++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 extracommands/SetScaleCommandEngine.cs diff --git a/extracommands/ExtraCommands.csproj b/extracommands/ExtraCommands.csproj index f07799a..6991e54 100644 --- a/extracommands/ExtraCommands.csproj +++ b/extracommands/ExtraCommands.csproj @@ -40,6 +40,9 @@ ..\ref\RobocraftX.Input.dll + + ..\ref\RobocraftX.MachineEditor.dll + ..\ref\RobocraftX.MainGame.dll diff --git a/extracommands/SetScaleCommandEngine.cs b/extracommands/SetScaleCommandEngine.cs new file mode 100644 index 0000000..62fefdb --- /dev/null +++ b/extracommands/SetScaleCommandEngine.cs @@ -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 ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) + { + } + + public override void Ready() + { + CustomCommandUtility.Register("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( + (ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup.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( + (ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup.Group, out _)[index]; + Console.WriteLine("Scaling " + index + ": " + scaling); + ref var scale = ref entitiesDB.QueryEntities( + (ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup.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(egid); + ref var scaling = ref entitiesDB.QueryEntity(egid); + UpdateScale(ref scale, ref scaling, ref entityView); + entitiesDB.PublishEntityChange(egid); + entitiesDB.PublishEntityChange(egid); + entitiesDB.PublishEntityChange(egid); + } + + public void Remove(ref GhostScalingEntityStruct entityView, EGID egid) + { + }*/ + } +} \ No newline at end of file