Remote dveře se renderují na mapě. Opravena chyba v GlobalMapTile.CoordsToId, která způsobovala desynchronizaci id místností

This commit is contained in:
Perry 2026-02-16 21:48:59 +01:00
parent 7e6b3d724b
commit 70b5debb22
7 changed files with 58 additions and 27 deletions

View file

@ -2,6 +2,7 @@
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=_002Fhome_002Fperry_002FRiderProjects_002FFNAF_005FClone_002FFNAF_005FClone_002Flib_002FMonoGameLibrary_002Edll/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/AddReferences/RecentPaths/=_002Fhome_002Fperry_002FRiderProjects_002FFNAF_005FClone_002FFNAF_005FClone_002Flib_002FMonoGameLibrary_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACore_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4e0fe18725844db38e9480edfd0e34983e00_003Fb5_003F8dc24573_003FCore_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACore_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4e0fe18725844db38e9480edfd0e34983e00_003Fb5_003F8dc24573_003FCore_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F419320464d0849fb89a7e518f7ff8bc978a00_003Fe8_003F1faf66e3_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F419320464d0849fb89a7e518f7ff8bc978a00_003Fe8_003F1faf66e3_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEventChannel_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F384e456bc26f45f5a6a6a20ae50c6e0dd1a400_003Ffb_003Fca10f160_003FEventChannel_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AINetSerializable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F0f_003Fe2eeb2cd_003FINetSerializable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AINetSerializable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F0f_003Fe2eeb2cd_003FINetSerializable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKeyValuePair_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F384e456bc26f45f5a6a6a20ae50c6e0dd1a400_003Fe8_003F7272ae72_003FKeyValuePair_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKeyValuePair_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F384e456bc26f45f5a6a6a20ae50c6e0dd1a400_003Fe8_003F7272ae72_003FKeyValuePair_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetSerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fcc_003F8a34584a_003FNetSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetSerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fcc_003F8a34584a_003FNetSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using FNAF_Clone.GUI; using FNAF_Clone.GUI;
@ -71,11 +72,14 @@ public class Client {
} }
private static void OnMapInit(MapInitPacket packet) { private static void OnMapInit(MapInitPacket packet) {
(int id1, int id2, ConnectorType type)[] connectors = new (int id1, int id2, ConnectorType type)[packet.Connectors.Length / 3]; (int id1, int id2, ConnectorType type)[] connectorsData = new (int id1, int id2, ConnectorType type)[packet.Connectors.Length / 3];
for (int i = 0; i < packet.Connectors.Length / 3; i++){ for (int i = 0; i < packet.Connectors.Length / 3; i++){
connectors[i] = (packet.Connectors[i * 3], packet.Connectors[i * 3 + 1], (ConnectorType)packet.Connectors[i * 3 + 2]); connectorsData[i] = (packet.Connectors[i * 3], packet.Connectors[i * 3 + 1], (ConnectorType)packet.Connectors[i * 3 + 2]);
} }
ClientMapManager.InitMap(connectors); 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);
} }
public static void Update() { public static void Update() {

View file

@ -14,7 +14,7 @@ public class UIElement {
public bool Pressable { get; set; } = false; public bool Pressable { get; set; } = false;
public bool Visible { get; set; } = true; public bool Visible { get; set; } = true;
private (Point, Point) bounds; // TODO: Change this to support non-rectangular hitboxes public (Point, Point) Bounds{ get; private set; } // TODO: Change this to support non-rectangular hitboxes
private (Point, Point) screenSpaceBounds; private (Point, Point) screenSpaceBounds;
private List<TextureRegion> textures = new(); private List<TextureRegion> textures = new();
private int currentTextureId = 0; private int currentTextureId = 0;
@ -32,22 +32,22 @@ public class UIElement {
private int pixelScaleMultiplier = 1; private int pixelScaleMultiplier = 1;
private void LoadPixelScaleMultiplier() { private void LoadPixelScaleMultiplier() {
pixelScaleMultiplier = (int)(UIManager.GlobalPixelMultiplier * _scaleMultiplier); // TODO: move GlobalPixelMultiplier somewhere where it would make sense pixelScaleMultiplier = (int)(UIManager.GlobalPixelMultiplier * _scaleMultiplier); // TODO: move GlobalPixelMultiplier somewhere where it would make sense
screenSpaceBounds = (bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), bounds.Item2.MultiplyByScalar(pixelScaleMultiplier)); screenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
} }
public UIElement(TextureRegion texture, Point position) { public UIElement(TextureRegion texture, Point position) {
textures.Add(texture); textures.Add(texture);
bounds = (position, position + new Point(texture.Width, texture.Height)); Bounds = (position, position + new Point(texture.Width, texture.Height));
LoadPixelScaleMultiplier(); LoadPixelScaleMultiplier();
} }
public UIElement(TextureRegion[] textures, Point position) { public UIElement(TextureRegion[] textures, Point position) {
this.textures.AddRange(textures); this.textures.AddRange(textures);
bounds = (position, position + new Point(textures[0].Width, textures[0].Height)); Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
LoadPixelScaleMultiplier(); LoadPixelScaleMultiplier();
} }
public UIElement(Point corner1, Point corner2) { public UIElement(Point corner1, Point corner2) {
bounds = (corner1, corner2); Bounds = (corner1, corner2);
Visible = false; Visible = false;
LoadPixelScaleMultiplier(); LoadPixelScaleMultiplier();
} }

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using FNAF_Clone.Map;
using GlobalClassLib; using GlobalClassLib;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MonoGameLibrary; using MonoGameLibrary;
@ -22,6 +23,7 @@ public class UIManager {
private static TextureAtlas monitorAtlas; private static TextureAtlas monitorAtlas;
public static int GlobalPixelMultiplier{ get; private set; } public static int GlobalPixelMultiplier{ get; private set; }
private Dictionary<(int, int), UIElement> doorElements = new();
public static void InitUI() { public static void InitUI() {
GlobalPixelMultiplier = Core.graphicsDevice.Viewport.Height / 360; GlobalPixelMultiplier = Core.graphicsDevice.Viewport.Height / 360;
@ -47,10 +49,10 @@ public class UIManager {
monitorScreen.AddElement("map-frame", new UIElement(monitorAtlas[2], new Point(334, 135))); monitorScreen.AddElement("map-frame", new UIElement(monitorAtlas[2], new Point(334, 135)));
monitorScreen.AddElement("map", new UIElement(monitorAtlas[3], new Point(334, 135))); monitorScreen.AddElement("map", new UIElement(monitorAtlas[3], new Point(334, 135)));
Dictionary<(int,int),string> doorPositions = new(){ // 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, 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" } // {(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 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++){ for (int j = 0; j < 5; j++){
@ -58,16 +60,28 @@ public class UIManager {
int j1 = j; int j1 = j;
Point point1 = new Point(336 + (32 * i), 144 + (32 * j)); Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
Point point2 = new Point(367 + (32 * i), 175 + (32 * j)); Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
monitorScreen.AddElement($"room{i}-{4 - j}", new UIElement(point1, point2) 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(i1, 4 - j1))});
if (doorPositions.ContainsKey((i, j))){ //
monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1)); // if (doorPositions.ContainsKey((i, j))){
// monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
// }
} }
} }
} }
public static void SpawnDoors(TileConnectorProjection[] doors) {
foreach (var door in doors){
if(door.Type != ConnectorType.DOOR_REMOTE) continue;
(int x, int y) dpos = (Math.Abs(door.Tiles.tile1.GridPosition.x - door.Tiles.tile2.GridPosition.x), Math.Abs(door.Tiles.tile1.GridPosition.y - door.Tiles.tile2.GridPosition.y));
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));
}
}
} }
public static void ChangeDoorState(Direction dir, bool state) { public static void ChangeDoorState(Direction dir, bool state) {

View file

@ -10,7 +10,7 @@ using MonoGameLibrary.Input;
namespace FNAF_Clone; namespace FNAF_Clone;
public class GameMain() : Core("fnafkooo", 1920, 1080, false) { public class GameMain() : Core("fnafkooo", 1280, 720, false) {
// private GraphicsDeviceManager _graphics; // private GraphicsDeviceManager _graphics;
// private SpriteBatch _spriteBatch; // private SpriteBatch _spriteBatch;

View file

@ -5,7 +5,8 @@ namespace FNAF_Clone.Map;
public class ClientMapManager { public class ClientMapManager {
private static MapTileProjection[,] map = new MapTileProjection[5, 5]; private static MapTileProjection[,] map = new MapTileProjection[5, 5];
private static MapTileProjection Get((int x, int y) coords) => map[coords.x, coords.y]; private static MapTileProjection Get((int x, int y) coords) => map[coords.x, coords.y];
public static void InitMap((int id1, int id2, ConnectorType type)[] connectors) { public static MapTileProjection Get(int tileId) => Get(MapTileProjection.IdToCoords(tileId));
public static void InitMap() {
for (int i = 0; i < 5; i++){ for (int i = 0; i < 5; i++){
for (int j = 0; j < 2; j++){ for (int j = 0; j < 2; j++){
map[i, j] = new MapTileProjection(MapTileProjection.CoordsToId(i, j)); // TODO: implement ownership map[i, j] = new MapTileProjection(MapTileProjection.CoordsToId(i, j)); // TODO: implement ownership
@ -17,12 +18,18 @@ public class ClientMapManager {
} }
} }
}
public static void InitConnectors(TileConnectorProjection[] connectors) {
foreach (var con in connectors){ foreach (var con in connectors){
(int x, int y) coords1 = MapTileProjection.IdToCoords(con.id1); // (int x, int y) coords1 = MapTileProjection.IdToCoords(con.Tiles.tile1.Id);
(int x, int y) coords2 = MapTileProjection.IdToCoords(con.id2); // (int x, int y) coords2 = MapTileProjection.IdToCoords(con.Tiles.tile2.Id);
map[coords1.x, coords1.y].AddConnector(new TileConnectorProjection(map[coords2.x, coords2.y], con.type)); map[con.Tiles.tile1.GridPosition.x, con.Tiles.tile1.GridPosition.y].AddConnector(con);
} }
} }
public static TileConnectorProjection[] GetConnectors(int tileId) => Get(MapTileProjection.IdToCoords(tileId)).GetAllConnectors(); public static TileConnectorProjection[] GetConnectors(int tileId) => Get(MapTileProjection.IdToCoords(tileId)).GetAllConnectors();
} }

View file

@ -3,13 +3,16 @@ namespace GlobalClassLib;
public abstract class GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTile<TCon, TTile> { // TTile should be the inheriting class public abstract class GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTile<TCon, TTile> { // TTile should be the inheriting class
public int Id { get; private set; } public int Id { get; private set; }
public bool Lit { get; set; } = false; public bool Lit { get; set; } = false;
public (int x, int y) GridPosition { get; private set; }
private List<TCon> connectors = new(); private List<TCon> connectors = new();
public GlobalMapTile(int id) { public GlobalMapTile(int id) {
Id = id; Id = id;
GridPosition = IdToCoords(id);
} }
public void AddConnector(TCon connector) { // tile1 is ignored when provided public void AddConnector(TCon connector) { // tile1 is ignored when provided
connector = connector.Clone();
connector.Tiles.tile1 = (TTile)this; connector.Tiles.tile1 = (TTile)this;
connectors.Add(connector); connectors.Add(connector);
connector.Tiles.tile2._AddConnectorNoRepeat(connector.Clone()); connector.Tiles.tile2._AddConnectorNoRepeat(connector.Clone());
@ -38,6 +41,8 @@ public abstract class GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnecto
public TCon[] GetAllConnectors() => connectors.ToArray(); public TCon[] GetAllConnectors() => connectors.ToArray();
public static int CoordsToId(int x, int y) => x * 5 + y;
public static (int, int) IdToCoords(int id) => (id % 5, id / 5); public const int ID_X_OFFSET = 5; // map grid height
public static int CoordsToId(int x, int y) => x * ID_X_OFFSET + y;
public static (int, int) IdToCoords(int id) => (id / ID_X_OFFSET, id % ID_X_OFFSET);
} }