Remote dveře lze na mapě otevírat a zavírat. Office dveře hráče lze vidět na mapě (ukazují se ale pouze pro hráče 1). PlayerCommandy, které přepínají mezi dvěma stavy mají přidaný parametr state - client tudíž určuje jejich nový stav. Pokud se neshoduje stav v GameEventu se stavem odeslaným v Commandu, zobrazí se v konzoli varování. Client již nečeká na odpověď serveru při změně UI. Connectory se neklonují, oba tily používají stejnou instanci.
This commit is contained in:
parent
70b5debb22
commit
cea56112ea
14 changed files with 112 additions and 48 deletions
|
|
@ -79,7 +79,7 @@ public class Client {
|
|||
ClientMapManager.InitMap();
|
||||
TileConnectorProjection[] connectors = connectorsData.Select(c => new TileConnectorProjection(ClientMapManager.Get(c.id1), ClientMapManager.Get(c.id2), c.type)).ToArray();
|
||||
ClientMapManager.InitConnectors(connectors);
|
||||
UIManager.SpawnDoors(connectors);
|
||||
UIManager.SpawnDoors(connectors.Where(c => c.Type == ConnectorType.DOOR_REMOTE).ToArray());
|
||||
}
|
||||
|
||||
public static void Update() {
|
||||
|
|
@ -99,21 +99,26 @@ public class Client {
|
|||
Console.WriteLine("E: Player left");
|
||||
break;
|
||||
case 2: // switch cam
|
||||
if (Player.state.pid == e.Args[0]){
|
||||
Player.state.camera = e.Args[1];
|
||||
}
|
||||
Console.WriteLine($"E: player {e.Args[0]} switched to camera {e.Args[1]}-{e.Args[2]}");
|
||||
if (Player.state.pid != e.Args[0]) return;
|
||||
if (Player.state.camera != e.Args[1]) Console.WriteLine("!!! DESYNC: CAMERA STATE");
|
||||
Console.WriteLine($"E: player {e.Args[0]} switched to camera {e.Args[1]}");
|
||||
break;
|
||||
case 3: // toggle cam
|
||||
Player.state.monitorUp = e.Args[1] == 1;
|
||||
if (Player.state.monitorUp != (e.Args[1] == 1)) Console.WriteLine("!!! DESYNC: MONITOR STATE");
|
||||
|
||||
UIManager.ChangeMonitorState(e.Args[1] == 1);
|
||||
Console.WriteLine($"E: Player {e.Args[0]} toggled monitor {(e.Args[1] == 0 ? "off" : "on")}");
|
||||
break;
|
||||
case 4: // toggle door
|
||||
Player.state.doorStates[e.Args[1]] = e.Args[2] == 1;
|
||||
UIManager.ChangeDoorState((Direction)e.Args[1], e.Args[2] == 1);
|
||||
if (Player.state.doorStates[e.Args[1]] != (e.Args[2] == 1)) Console.WriteLine("!!! DESYNC: DOOR STATE");
|
||||
|
||||
// UIManager.ChangeDoorState((Direction)e.Args[1], e.Args[2] == 1);
|
||||
Console.WriteLine($"E: Player {e.Args[0]} {(e.Args[2] == 1 ? "closed" : "opened")} door {e.Args[1]}");
|
||||
break;
|
||||
case 5: // toggle remote door
|
||||
if (ClientMapManager.GetConnector((e.Args[1], e.Args[2])).Blocked != (e.Args[3] == 1)) Console.WriteLine("!!! DESYNC: REMOTE DOOR STATE");
|
||||
Console.WriteLine($"E: Player {e.Args[0]} {(e.Args[3] == 1 ? "closed" : "opened")} door {e.Args[1]}-{e.Args[2]}");
|
||||
break;
|
||||
case -1: // movement
|
||||
throw new NotImplementedException();
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ public class CommandManager {
|
|||
}
|
||||
|
||||
private static void SendToggleCamera() {
|
||||
Client.SendCommands([PlayerCommand.TOGGLE_MONITOR()]);
|
||||
Client.Player.state.monitorUp = !Client.Player.state.monitorUp;
|
||||
Client.SendCommands([PlayerCommand.SET_MONITOR(Client.Player.state.monitorUp)]);
|
||||
}
|
||||
|
||||
private static void ToggleDoorLeft() => SendToggleDoor(Direction.EAST);
|
||||
|
|
@ -34,23 +35,38 @@ public class CommandManager {
|
|||
private static void ToggleDoorRight() => SendToggleDoor(Direction.WEST);
|
||||
private static void ToggleDoorBack() => SendToggleDoor(Direction.SOUTH);
|
||||
|
||||
private static Dictionary<Direction, TileConnectorProjection> currentDoorBinds = new();
|
||||
|
||||
private static void SendToggleDoor(Direction direction) {
|
||||
if (Screen.CurrentScreen.Label == UIManager.ScreenTypes.CAMERAS){
|
||||
SendToggleRemoteDoor(direction);
|
||||
return;
|
||||
}
|
||||
Client.SendCommands([PlayerCommand.TOGGLE_DOOR_OFFICE(direction)]);
|
||||
Client.Player.state.doorStates[(int)direction] = !Client.Player.state.doorStates[(int)direction];
|
||||
UIManager.ChangeDoorState(direction, 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) { // WIP
|
||||
TileConnectorProjection[] connectors = ClientMapManager.GetConnectors(Client.Player.state.camera).Where(c => c.Type == ConnectorType.DOOR_REMOTE).ToArray();
|
||||
|
||||
|
||||
// Client.SendCommands([PlayerCommand.TOGGLE_DOOR_REMOTE()]);
|
||||
private static void SendToggleRemoteDoor(Direction direction) {
|
||||
if (!currentDoorBinds.TryGetValue(direction, out var val)) return;
|
||||
TileConnectorProjection connector = val;
|
||||
connector.Blocked = !connector.Blocked;
|
||||
Client.SendCommands([PlayerCommand.SET_DOOR_REMOTE(connector.Id, 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 idx, int idy) {
|
||||
Client.SendCommands([PlayerCommand.SWITCH_CAM(idx, idy)]);
|
||||
public static void SendChangeCamera(int id) {
|
||||
Client.Player.state.camera = id;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
|
@ -48,11 +48,6 @@ public class UIManager {
|
|||
monitorScreen.AddElement("view-frame", new UIElement(monitorAtlas[1], new Point(62, 55)));
|
||||
monitorScreen.AddElement("map-frame", new UIElement(monitorAtlas[2], new Point(334, 135)));
|
||||
monitorScreen.AddElement("map", new UIElement(monitorAtlas[3], new Point(334, 135)));
|
||||
|
||||
// Dictionary<(int,int),string> doorPositions = new(){
|
||||
// {(0, 0),"2-5"},{ (1, 0), "2-4" }, { (1, 1), "2-3" }, { (3, 0), "2-2" }, { (3, 1), "2-1" }, { (4, 0), "2-0" }, // TODO: generate this dynamically from server map info
|
||||
// {(0, 3),"1-0"},{ (1, 3), "1-1" }, { (1, 2), "1-2" }, { (3, 3), "1-3" }, { (3, 2), "1-4" }, { (4, 3), "1-5" }
|
||||
// };
|
||||
|
||||
for (int i = 0; i < 5; i++){ // NOTE: this loop does y in reverse, y labels are inverted to match server
|
||||
for (int j = 0; j < 5; j++){
|
||||
|
|
@ -61,7 +56,7 @@ public class UIManager {
|
|||
Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
|
||||
Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
|
||||
monitorScreen.AddElement($"room{MapTileProjection.CoordsToId(i, 4 - j)}", new UIElement(point1, point2)
|
||||
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(i1, 4 - j1))});
|
||||
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(MapTileProjection.CoordsToId(i1, 4 - j1)))});
|
||||
//
|
||||
// if (doorPositions.ContainsKey((i, j))){
|
||||
// monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
|
||||
|
|
@ -79,24 +74,42 @@ public class UIManager {
|
|||
if (dpos.y == 1){
|
||||
int targetId = door.Tiles.tile1.GridPosition.y > door.Tiles.tile2.GridPosition.y ? door.Tiles.tile1.Id : door.Tiles.tile2.Id;
|
||||
UIElement tile = monitorScreen["room"+targetId];
|
||||
|
||||
monitorScreen.AddElement("door"+targetId+"-"+(targetId == door.Tiles.tile1.Id ? door.Tiles.tile2.Id : door.Tiles.tile1.Id), new UIElement([monitorAtlas[5], monitorAtlas[6]], tile.Bounds.Item1));
|
||||
}
|
||||
}
|
||||
|
||||
monitorScreen.AddElement("p1-office-door-left", new UIElement([monitorAtlas[7], monitorAtlas[8]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-centre", new UIElement([monitorAtlas[9], monitorAtlas[10]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p1-office-door-right", new UIElement([monitorAtlas[11], monitorAtlas[12]], new Point(400, 272)));
|
||||
monitorScreen.AddElement("p2-office-door-right", new UIElement([monitorAtlas[13], monitorAtlas[14]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-centre", new UIElement([monitorAtlas[15], monitorAtlas[16]], new Point(400, 144)));
|
||||
monitorScreen.AddElement("p2-office-door-left", new UIElement([monitorAtlas[17], monitorAtlas[18]], new Point(400, 144)));
|
||||
|
||||
}
|
||||
|
||||
public static void ChangeDoorState(Direction dir, bool state) {
|
||||
public static void ChangeDoorState(Direction dir, bool state) { // TODO: make this also change for p2
|
||||
int stateInt = state ? 1 : 0;
|
||||
|
||||
switch ((int)dir){
|
||||
case 0:
|
||||
officeScreen["office_left"].SetTexture(state ? 1 : 0);
|
||||
officeScreen["office_left"].SetTexture(stateInt);
|
||||
monitorScreen["p1-office-door-left"].SetTexture(stateInt);
|
||||
break;
|
||||
case 1:
|
||||
officeScreen["office_centre"].SetTexture(state ? 1 : 0);
|
||||
officeScreen["office_centre"].SetTexture(stateInt);
|
||||
monitorScreen["p1-office-door-centre"].SetTexture(stateInt);
|
||||
break;
|
||||
case 2:
|
||||
officeScreen["office_right"].SetTexture(state ? 1 : 0);
|
||||
officeScreen["office_right"].SetTexture(stateInt);
|
||||
monitorScreen["p1-office-door-right"].SetTexture(stateInt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ChangeRemoteDoorState((int, int) id, bool state) {
|
||||
monitorScreen["door"+Math.Max(id.Item1, id.Item2)+"-"+Math.Min(id.Item1, id.Item2)].SetTexture(state ? 1 : 0);
|
||||
}
|
||||
|
||||
public static void ChangeMonitorState(bool state) {
|
||||
Screen.SetScreen(state ? ScreenTypes.CAMERAS : ScreenTypes.OFFICE);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class GameMain() : Core("fnafkooo", 1280, 720, false) {
|
|||
Client.Connect("127.0.0.1", 9012);
|
||||
CommandManager.InitInputListeners();
|
||||
|
||||
InputManager.AddListener(InputManager.MouseButton.LEFT, (() => Console.WriteLine("LMB pressed at: " + InputManager.MouseState.Position)), InputTiming.PRESS, new InputListenerHook(true));
|
||||
// InputManager.AddListener(InputManager.MouseButton.LEFT, (() => Console.WriteLine("LMB pressed at: " + InputManager.MouseState.Position)), InputTiming.PRESS, new InputListenerHook(true));
|
||||
|
||||
base.Initialize();
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace FNAF_Clone.Map;
|
|||
|
||||
public class ClientMapManager {
|
||||
private static MapTileProjection[,] map = new MapTileProjection[5, 5];
|
||||
private static MapTileProjection Get((int x, int y) coords) => map[coords.x, coords.y];
|
||||
public static MapTileProjection Get((int x, int y) coords) => map[coords.x, coords.y];
|
||||
public static MapTileProjection Get(int tileId) => Get(MapTileProjection.IdToCoords(tileId));
|
||||
public static void InitMap() {
|
||||
for (int i = 0; i < 5; i++){
|
||||
|
|
@ -17,8 +17,6 @@ public class ClientMapManager {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void InitConnectors(TileConnectorProjection[] connectors) {
|
||||
|
|
@ -29,7 +27,7 @@ public class ClientMapManager {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static TileConnectorProjection GetConnector((int, int) id) => Get(id.Item1).GetConnector(id.Item2);
|
||||
|
||||
public static TileConnectorProjection[] GetConnectors(int tileId) => Get(MapTileProjection.IdToCoords(tileId)).GetAllConnectors();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue