|
1 | 1 | using OWML.Common;
|
2 | 2 | using OWML.Events;
|
| 3 | +using UnityEngine; |
3 | 4 |
|
4 | 5 | namespace OWML.EnableDebugMode
|
5 | 6 | {
|
6 | 7 | public class EnableDebugMode : ModBehaviour
|
7 | 8 | {
|
| 9 | + private int _renderValue; |
| 10 | + private bool _isStarted; |
| 11 | + private PlayerSpawner _playerSpawner; |
| 12 | + |
8 | 13 | private void Start()
|
9 | 14 | {
|
10 | 15 | ModHelper.Console.WriteLine($"In {nameof(EnableDebugMode)}!");
|
11 | 16 | ModHelper.HarmonyHelper.EmptyMethod<DebugInputManager>("Awake");
|
| 17 | + ModHelper.Events.AddEvent<PlayerSpawner>(Common.Events.AfterAwake); |
| 18 | + ModHelper.Events.OnEvent += OnEvent; |
12 | 19 | }
|
13 | 20 |
|
14 |
| - private int _renderValue; |
| 21 | + private void OnEvent(MonoBehaviour behaviour, Common.Events ev) |
| 22 | + { |
| 23 | + if (behaviour.GetType() == typeof(PlayerSpawner) && ev == Common.Events.AfterAwake) |
| 24 | + { |
| 25 | + _playerSpawner = (PlayerSpawner)behaviour; |
| 26 | + _isStarted = true; |
| 27 | + } |
| 28 | + } |
15 | 29 |
|
16 | 30 | private void Update()
|
17 | 31 | {
|
| 32 | + if (!_isStarted) |
| 33 | + { |
| 34 | + return; |
| 35 | + } |
| 36 | + |
18 | 37 | if (Input.GetKeyDown(DebugKeyCode.cycleGUIMode))
|
19 | 38 | {
|
20 |
| - ModHelper.Console.WriteLine("F1 pressed!"); |
21 |
| - _renderValue++; |
22 |
| - if (_renderValue >= 8) |
23 |
| - { |
24 |
| - _renderValue = 0; |
25 |
| - } |
26 |
| - ModHelper.Console.WriteLine("_renderValue: " + _renderValue); |
27 |
| - typeof(GUIMode).GetAnyField("_renderMode").SetValue(null, _renderValue); |
| 39 | + CycleGUIMode(); |
| 40 | + } |
| 41 | + |
| 42 | + if (Input.GetKeyDown(DebugKeyCode.cometWarp)) |
| 43 | + { |
| 44 | + WarpTo(SpawnLocation.Comet); |
| 45 | + } |
| 46 | + if (Input.GetKeyDown(DebugKeyCode.hourglassTwinsWarp)) |
| 47 | + { |
| 48 | + WarpTo(SpawnLocation.HourglassTwin_1); |
| 49 | + } |
| 50 | + if (Input.GetKeyDown(DebugKeyCode.homePlanetWarp)) |
| 51 | + { |
| 52 | + WarpTo(SpawnLocation.TimberHearth); |
| 53 | + } |
| 54 | + if (Input.GetKeyDown(DebugKeyCode.brittleHollowWarp)) |
| 55 | + { |
| 56 | + WarpTo(SpawnLocation.BrittleHollow); |
28 | 57 | }
|
| 58 | + if (Input.GetKeyDown(DebugKeyCode.gasGiantWarp)) |
| 59 | + { |
| 60 | + WarpTo(SpawnLocation.GasGiant); |
| 61 | + } |
| 62 | + if (Input.GetKeyDown(DebugKeyCode.darkBrambleWarp)) |
| 63 | + { |
| 64 | + WarpTo(SpawnLocation.DarkBramble); |
| 65 | + } |
| 66 | + if (Input.GetKeyDown(DebugKeyCode.shipWarp)) |
| 67 | + { |
| 68 | + WarpTo(SpawnLocation.Ship); |
| 69 | + } |
| 70 | + if (Input.GetKeyDown(DebugKeyCode.quantumWarp)) |
| 71 | + { |
| 72 | + WarpTo(SpawnLocation.QuantumMoon); |
| 73 | + } |
| 74 | + if (Input.GetKeyDown(DebugKeyCode.moonWarp)) |
| 75 | + { |
| 76 | + WarpTo(SpawnLocation.LunarLookout); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + private void CycleGUIMode() |
| 81 | + { |
| 82 | + _renderValue++; |
| 83 | + if (_renderValue >= 8) |
| 84 | + { |
| 85 | + _renderValue = 0; |
| 86 | + } |
| 87 | + ModHelper.Console.WriteLine("Render value: " + _renderValue); |
| 88 | + typeof(GUIMode).GetAnyField("_renderMode").SetValue(null, _renderValue); |
| 89 | + } |
| 90 | + |
| 91 | + private void WarpTo(SpawnLocation location) |
| 92 | + { |
| 93 | + ModHelper.Console.WriteLine($"Warping to {location}!"); |
| 94 | + _playerSpawner.DebugWarp(_playerSpawner.GetSpawnPoint(location)); |
29 | 95 | }
|
30 | 96 |
|
31 | 97 | }
|
|
0 commit comments