Browse Source

Create set scale command

master
NorbiPeti 5 years ago
parent
commit
72d3f65fb1
Signed by: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG Key ID: DBA4C4549A927E56
2 changed files with 88 additions and 0 deletions
  1. +3
    -0
      extracommands/ExtraCommands.csproj
  2. +85
    -0
      extracommands/SetScaleCommandEngine.cs

+ 3
- 0
extracommands/ExtraCommands.csproj View File

@@ -40,6 +40,9 @@
<Reference Include="RobocraftX.Input">
<HintPath>..\ref\RobocraftX.Input.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.MachineEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\ref\RobocraftX.MachineEditor.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.MainGame">
<HintPath>..\ref\RobocraftX.MainGame.dll</HintPath>
</Reference>


+ 85
- 0
extracommands/SetScaleCommandEngine.cs View File

@@ -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)
{
}*/
}
}

Loading…
Cancel
Save