98 lines
No EOL
4.3 KiB
C#
98 lines
No EOL
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using FNAF_Clone.GUI;
|
|
using FNAF_Clone.Map;
|
|
using GlobalClassLib;
|
|
using Microsoft.Xna.Framework.Input;
|
|
using MonoGameLibrary.Input;
|
|
using PacketLib;
|
|
|
|
namespace FNAF_Clone;
|
|
|
|
public class CommandManager {
|
|
private static (string label, Keys key, Action action)[] keybinds = [
|
|
("Toggle camera", Keys.Space, SendToggleCamera),
|
|
("Toggle left door", Keys.A, ToggleDoorLeft),
|
|
("Toggle centre door", Keys.W, ToggleDoorCentre),
|
|
("Toggle right door", Keys.D, ToggleDoorRight),
|
|
("Toggle back door", Keys.S, ToggleDoorBack),
|
|
("Toggle light", Keys.F, ToggleLight)
|
|
];
|
|
|
|
private static InputListenerHook allControlsHook{ get; } = new(true);
|
|
|
|
public static void InitInputListeners() {
|
|
Array.ForEach(keybinds, tuple => InputManager.AddListener(tuple.label, tuple.key, () => tuple.action(), InputTiming.PRESS, allControlsHook));
|
|
}
|
|
|
|
public static void AllowGameControls(bool state) {
|
|
allControlsHook.Enabled = state;
|
|
}
|
|
|
|
private static void SendToggleCamera() {
|
|
Client.Player.state.monitorUp = !Client.Player.state.monitorUp;
|
|
UIManager.ChangeMonitorState(Client.Player.state.monitorUp);
|
|
Client.SendCommands([PlayerCommand.SET_MONITOR(Client.Player.state.monitorUp)]);
|
|
SoundManager.PlayMonitorFlip();
|
|
}
|
|
|
|
private static void ToggleDoorLeft() => SendToggleDoor(Direction.EAST);
|
|
private static void ToggleDoorCentre() => SendToggleDoor(Direction.NORTH);
|
|
private static void ToggleDoorRight() => SendToggleDoor(Direction.WEST);
|
|
private static void ToggleDoorBack() => SendToggleDoor(Direction.SOUTH);
|
|
|
|
private static Dictionary<Direction, TileConnectorProjection> currentDoorBinds = new();
|
|
|
|
private static void ToggleLight() => SendToggleLight(Client.Player.state.camera, !ClientMapManager.Get(Client.Player.state.camera).Lit);
|
|
|
|
private static void SendToggleDoor(Direction direction) {
|
|
if (Screen.CurrentScreen.Label == UIManager.ScreenTypes.CAMERAS){
|
|
SendToggleRemoteDoor(direction);
|
|
return;
|
|
}
|
|
|
|
if (direction == Direction.SOUTH) return;
|
|
Client.Player.state.doorStates[(int)direction] = !Client.Player.state.doorStates[(int)direction];
|
|
UIManager.ChangeDoorState(direction, Client.Player.state.doorStates[(int)direction]);
|
|
SoundManager.PlayDoor(Client.Player.state.doorStates[(int)direction]);
|
|
Client.SendCommands([PlayerCommand.SET_DOOR_OFFICE(direction, Client.Player.state.doorStates[(int)direction])]);
|
|
}
|
|
|
|
private static void SendToggleRemoteDoor(Direction direction) {
|
|
if (!currentDoorBinds.TryGetValue(direction, out var connector)) return;
|
|
if (connector.Owner != Client.Player) return;
|
|
|
|
connector.Blocked = !connector.Blocked;
|
|
Client.SendCommands([PlayerCommand.SET_DOOR_REMOTE(connector.Id, connector.Blocked)]);
|
|
SoundManager.PlayDoorRemote(connector.Blocked);
|
|
UIManager.ChangeRemoteDoorState(connector.Id, connector.Blocked);
|
|
// Console.WriteLine("Changed door state to: " + (connector.Blocked ? "blocked" : "open") + " for door " + connector);
|
|
// add UIManager toggle door
|
|
}
|
|
|
|
public static void SendChangeCamera(int id) {
|
|
if (id == Client.Player.state.officeTileId || id == Client.Opponent.state.officeTileId) return;
|
|
|
|
Client.Player.state.camera = id;
|
|
UIManager.ChangeCamera(id);
|
|
SoundManager.PlayCameraSwitch();
|
|
Client.SendCommands([PlayerCommand.SWITCH_CAM(id)]);
|
|
MapTileProjection tile = ClientMapManager.Get(id);
|
|
// add UIManager switch camera
|
|
currentDoorBinds.Clear();
|
|
foreach (var c in tile.GetAllConnectors().Where(c => c.Type == ConnectorType.DOOR_REMOTE)){
|
|
Direction dir = c.GetDirection(tile);
|
|
if (dir == Direction.NONE) return;
|
|
currentDoorBinds.Add(dir, c);
|
|
}
|
|
}
|
|
|
|
private static void SendToggleLight(int id, bool state) {
|
|
if(!Client.Player.state.monitorUp || ClientMapManager.Get(id).Owner != Client.Player) return;
|
|
ClientMapManager.Get(id).Lit = state;
|
|
UIManager.UpdateCameras([id]);
|
|
SoundManager.PlayLight(state);
|
|
Client.SendCommands([PlayerCommand.SET_LIGHT(id, state)]);
|
|
}
|
|
} |