Fix issues with new update, waypoint fixes

Waypoints can be created from pilot seats now and it won't try to teleport to a waypoint if in a pilot seat
This commit is contained in:
Norbi Peti 2020-02-08 17:52:41 +01:00
parent f9c034693f
commit dce3045989
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 43 additions and 29 deletions

View file

@ -44,7 +44,7 @@
<HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Input.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Input.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.MachineEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> <Reference Include="RobocraftX.MachineEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\ref\RobocraftX.MachineEditor.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.MachineEditor.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.MainGame"> <Reference Include="RobocraftX.MainGame">
<HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.MainGame.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.MainGame.dll</HintPath>
@ -62,7 +62,7 @@
<HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Physics.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Physics.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.Services, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> <Reference Include="RobocraftX.Services, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\ref\RobocraftX.Services.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Services.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.StateSync"> <Reference Include="RobocraftX.StateSync">
<HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.StateSync.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.StateSync.dll</HintPath>

View file

@ -9,7 +9,6 @@ using UnityEngine;
using uREPL; using uREPL;
using Svelto.Context; using Svelto.Context;
using RobocraftX; using RobocraftX;
using Svelto.ECS.EntityStructs;
using Unity.Mathematics; using Unity.Mathematics;
using RobocraftX.Character.Camera; using RobocraftX.Character.Camera;
using RobocraftX.Character.Factories; using RobocraftX.Character.Factories;
@ -36,10 +35,9 @@ namespace ExtraCommands.Basics
private void RotateAbsoluteCommand(float vertical, float horizontal) private void RotateAbsoluteCommand(float vertical, float horizontal)
{ {
uint count; EntityCollection<CharacterCameraEntityStruct> cameras = entitiesDB.QueryEntities<CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup);
CharacterCameraEntityStruct[] cameras = entitiesDB.QueryEntities<CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup, out count);
int num2 = 0; int num2 = 0;
while ((long)num2 < (long)((ulong)count)) while (num2 < cameras.length)
{ {
cameras[num2].eulerRotation.x = vertical; cameras[num2].eulerRotation.x = vertical;
cameras[num2].eulerRotation.y = horizontal; cameras[num2].eulerRotation.y = horizontal;
@ -60,12 +58,11 @@ namespace ExtraCommands.Basics
private void RotateRelativeCommand(float vertical, float horizontal) private void RotateRelativeCommand(float vertical, float horizontal)
{ {
float2 angleDelta = new float2(vertical, horizontal); float2 angleDelta = new float2(vertical, horizontal);
uint count; EntityCollection<CharacterCameraSettingsEntityStruct, CharacterCameraEntityStruct> tuple = this.entitiesDB.QueryEntities<CharacterCameraSettingsEntityStruct, CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup);
ValueTuple<CharacterCameraSettingsEntityStruct[], CharacterCameraEntityStruct[]> tuple = this.entitiesDB.QueryEntities<CharacterCameraSettingsEntityStruct, CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup, out count); EntityCollection<CharacterCameraSettingsEntityStruct> settings = tuple.Item1;
CharacterCameraSettingsEntityStruct[] settings = tuple.Item1; EntityCollection<CharacterCameraEntityStruct> cameras = tuple.Item2;
CharacterCameraEntityStruct[] cameras = tuple.Item2;
int num2 = 0; int num2 = 0;
while ((long)num2 < (long)((ulong)count)) while (num2 < cameras.length)
{ {
CharacterCameraMovementUtility.UpdateCameraRotationFromDelta(ref cameras[num2], in settings[num2], angleDelta); CharacterCameraMovementUtility.UpdateCameraRotationFromDelta(ref cameras[num2], in settings[num2], angleDelta);
// TODO: Multiplayer compatibility // TODO: Multiplayer compatibility

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using GamecraftModdingAPI.Commands;
using Harmony; using Harmony;
using RobocraftX.GUI.CommandLine; using RobocraftX.GUI.CommandLine;
using RobocraftX.Multiplayer; using RobocraftX.Multiplayer;
@ -22,16 +23,15 @@ using Unity.Mathematics;
namespace ExtraCommands.Basics namespace ExtraCommands.Basics
{ {
[CustomCommand("SetScale")] [CustomCommand("SetScale")]
class SetScaleCommandEngine : CustomCommandEngine class SetScaleCommandEngine : ICustomCommandEngine
{ {
public SetScaleCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
public void Ready()
{ {
CommandRegistrationHelper.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.");
} }
public override void Ready() public IEntitiesDB entitiesDB { get; set; }
{
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 static float3 _scale; private static float3 _scale;
//private HarmonyInstance harmony; //private HarmonyInstance harmony;
@ -49,19 +49,17 @@ namespace ExtraCommands.Basics
}*/ }*/
_scale = new float3(x, y, z); _scale = new float3(x, y, z);
GhostScalingEntityStruct[] scalings = EntityCollection<GhostScalingEntityStruct> scalings =
entitiesDB.QueryEntities<GhostScalingEntityStruct>( entitiesDB.QueryEntities<GhostScalingEntityStruct>(
(ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out uint count); (ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group);
Console.WriteLine("Found " + count + "/" + scalings.Length + " scalings."); Console.WriteLine("Found " + scalings.length + " scalings.");
var egid = new EGID(0, NamedExclusiveGroup<GHOST_BLOCKS>.Group); var egid = new EGID(0, NamedExclusiveGroup<GHOST_BLOCKS>.Group);
for (int index = 0; index < count; index++) for (int index = 0; index < scalings.length; index++)
{ {
Console.WriteLine("G scaling " + index + ": " + scalings[index].ghostScale); Console.WriteLine("G scaling " + index + ": " + scalings[index].ghostScale);
ref var scaling = ref entitiesDB.QueryEntities<ScalingEntityStruct>( ref var scaling = ref entitiesDB.QueryEntity<ScalingEntityStruct>(egid);
(ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out _)[index];
Console.WriteLine("Scaling " + index + ": " + scaling); Console.WriteLine("Scaling " + index + ": " + scaling);
ref var scale = ref entitiesDB.QueryEntities<BlockPlacementScaleEntityStruct>( ref var scale = ref entitiesDB.QueryEntity<BlockPlacementScaleEntityStruct>(egid);
(ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out _)[index];
Console.WriteLine("Scale " + index + ": " + scale.snapGridScale); Console.WriteLine("Scale " + index + ": " + scale.snapGridScale);
UpdateScale(ref scale, ref scaling, ref scalings[index], egid); UpdateScale(ref scale, ref scaling, ref scalings[index], egid);
} }
@ -87,9 +85,9 @@ namespace ExtraCommands.Basics
Console.WriteLine("Scale updated (" + scaling.scale + ")"); Console.WriteLine("Scale updated (" + scaling.scale + ")");
} }
public override void Dispose() public void Dispose()
{ {
CustomCommandUtility.Unregister("SetScale"); CommandRegistrationHelper.Unregister("SetScale");
} }
/*public void Add(ref GhostScalingEntityStruct entityView, EGID egid) /*public void Add(ref GhostScalingEntityStruct entityView, EGID egid)
@ -153,5 +151,8 @@ namespace ExtraCommands.Basics
.First(m => m.Name.Contains("UpdatePlacementCursorScales")); .First(m => m.Name.Contains("UpdatePlacementCursorScales"));
} }
} }
public string Name { get; } = "SetScale";
public string Description { get; } = "Set the scale for the next block to be placed.";
} }
} }

View file

@ -34,7 +34,17 @@ namespace ExtraCommands.Waypoints
private void CreateWaypointCommand(object name) private void CreateWaypointCommand(object name)
{ {
ref RigidBodyEntityStruct reference = ref entitiesDB.QueryEntity<RigidBodyEntityStruct>(0u, CharacterExclusiveGroups.CharacterGroup); RigidBodyEntityStruct reference;
if (entitiesDB.TryQueryEntitiesAndIndex(0u, CharacterExclusiveGroups.OnFootGroup, out uint index,
out RigidBodyEntityStruct[] array)
|| entitiesDB.TryQueryEntitiesAndIndex(0u, CharacterExclusiveGroups.InPilotSeatGroup, out index,
out array))
reference = array[index];
else
{
Log.Output("Player not found!");
return;
}
_waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z }; _waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z };
uREPL.Log.Output("Saved " + name.ToString()); uREPL.Log.Output("Saved " + name.ToString());
} }
@ -46,7 +56,13 @@ namespace ExtraCommands.Waypoints
uREPL.Log.Error("Waypoint not found"); uREPL.Log.Error("Waypoint not found");
return; return;
} }
float[] loc = _waypoints[name];
if (entitiesDB.Exists<RigidBodyEntityStruct>(0u, CharacterExclusiveGroups.InPilotSeatGroup))
{
Log.Error("Cannot teleport from a pilot seat");
return;
}
float[] loc = _waypoints[name];
uREPL.RuntimeCommands.Call<float, float, float>("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]); uREPL.RuntimeCommands.Call<float, float, float>("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]);
} }