Browse Source

Remove noGarage and improve mirror mode

- Mirroring relative to where the player enabled the mode
- Removing blocks that are where the mirrored counterpart of the removed block would be
tags/v1.2.0
NorbiPeti 3 years ago
parent
commit
2ec15427d6
3 changed files with 33 additions and 70 deletions
  1. +0
    -6
      BuildingTools/BuildingTools.cs
  2. +33
    -6
      BuildingTools/MirrorModeEngine.cs
  3. +0
    -58
      BuildingTools/NoGarageCommand.cs

+ 0
- 6
BuildingTools/BuildingTools.cs View File

@@ -244,12 +244,6 @@ namespace BuildingTools
ScalingPermission.NonUniform;
Logging.CommandLog("Free scaling enabled for " + blockID + " until the game is restarted.");
}).Build();
var noGarage = new NoGarageCommand();
CommandBuilder.Builder("noGarage", "Disables the environment switching and allows building on the track.")
.Action(() =>
{
noGarage.Toggle();
}).Build();

_mirrorModeEngine.Init();



+ 33
- 6
BuildingTools/MirrorModeEngine.cs View File

@@ -31,6 +31,7 @@ namespace BuildingTools
private bool _enabled;
private Block _lastPlaced;
private Block _ghostBlock;
private float3 _offset;

private void BlockOnPlaced(object sender, BlockPlacedRemovedEventArgs e)
{
@@ -38,25 +39,51 @@ namespace BuildingTools
if (Player.LocalPlayer.BuildingMode != PlayerBuildingMode.BlockMode) return;
if (e.ID == _lastPlaced?.Id) return;
_lastPlaced = e.Block.Copy();
_lastPlaced.Position *= new float3(-1, 1, 1);
//_lastPlaced.Flipped = !_lastPlaced.Flipped;
_lastPlaced.Position = MirrorPos(_lastPlaced.Position);
_lastPlaced.Flipped = !_lastPlaced.Flipped;
if (math.abs(_lastPlaced.Rotation.y - 90) < float.Epsilon ||
math.abs(_lastPlaced.Rotation.y - 270) < float.Epsilon)
_lastPlaced.Rotation += new float3(0, 180, 0);
}

private void BlockOnRemoved(object sender, BlockPlacedRemovedEventArgs e)
{
if (!_enabled) return;
if (Player.LocalPlayer.BuildingMode != PlayerBuildingMode.BlockMode) return;
var newpos = MirrorPos(e.Block.Position);
foreach (var block in Game.CurrentGame().GetBlocksInGame())
{
if (math.all(math.abs(block.Position - newpos) < 0.1f))
block.Remove();
}
}

private float3 MirrorPos(float3 pos)
{
pos -= _offset;
pos *= new float3(-1, 1, 1);
pos += _offset;
return pos;
}

public void Init()
{
/*Block.Placed += BlockOnPlaced; - TODO.
Block.Placed += BlockOnPlaced;
Block.Removed+=BlockOnRemoved;
Game.Enter += OnGameOnEnter;
Game.Exit += (sender, args) => _button = null;*/
Game.Exit += (sender, args) => _button = null;
}

private void OnGameOnEnter(object sender, GameEventArgs args)
{
_button = new Button("Mirror mode");
_button.OnClick += (_, __) => _enabled = !_enabled;
TryCreateGhostBlock().RunOn(Scheduler.leanRunner);
_button.OnClick += (_, __) =>
{
_enabled = !_enabled;
if(_enabled)
_offset = new float3((float)(Math.Round(Player.LocalPlayer.Position.x / 2, 1) * 2), 0, 0);
};
//TryCreateGhostBlock().RunOn(Scheduler.leanRunner);
}

private IEnumerator<TaskContract> TryCreateGhostBlock()


+ 0
- 58
BuildingTools/NoGarageCommand.cs View File

@@ -1,58 +0,0 @@
using System;
using System.Reflection;
using HarmonyLib;
using TechbloxModdingAPI.Utility;
using UnityEngine;

namespace BuildingTools
{
public class NoGarageCommand
{
private static bool _enabled;

public void Toggle()
{
Logging.CommandLog("Toggling no garage");
// ReSharper disable once AssignmentInConditionalExpression
if(_enabled = !_enabled)
Enable();
Logging.CommandLog($"{(_enabled ? "Enabled" : "Disabled")} no garage");
}

private void Enable()
{
var type = AccessTools.TypeByName("Techblox.Environment.Temporary.EnvironmentSwitchEngine");
var simObj = (GameObject)AccessTools.Field(type,
"THIS_IS_TEMPORARY_CODE_IT_IS_GOING_TO_BE_DELETED_ONCE_WE_HAVE_THE_FINAL_WORLD_SWITCHING_sim_go")
.GetValue(null);
var componentType = AccessTools.TypeByName("Techblox.Garage.GarageMachineBoundaryImplementor");
simObj.AddComponent(componentType);
var component = simObj.GetComponent(componentType);
AccessTools.Field(componentType, "_bounds")
.SetValue(component, new Bounds(default, new Vector3(50, 2, 50)));
AccessTools.Field(componentType, "_padding")
.SetValue(component, 1f);
AccessTools.Field(componentType, "_cameraLookPointDistance")
.SetValue(component, 1f);
}
[HarmonyPatch]
private static class EnvironmentPatch
{
public static bool Prefix(object __instance)
{
if (!_enabled) return true;
Logging.MetaDebugLog("Got a time stopped init event");
AccessTools.Method("Techblox.Environment.Temporary.EnvironmentSwitchEngine:OnTimeRunningInitializationComplete")
.Invoke(__instance, Array.Empty<object>());
Logging.MetaDebugLog("Successfully called time running init event");
return false;
}

public static MethodBase TargetMethod()
{
return AccessTools.Method("Techblox.Environment.Temporary.EnvironmentSwitchEngine:OnTimeStoppedInitializationComplete");
}
}
}
}

Loading…
Cancel
Save