From dfaaf07e24997479af7b65069a0ae5647b545d86 Mon Sep 17 00:00:00 2001 From: Mootfrost777 Date: Sun, 18 Aug 2024 17:17:46 +0300 Subject: [PATCH] Fix paths to run game without sources --- ZoFo/GameCore/GameManagers/MapManager/MapManager.cs | 11 ++++++----- ZoFo/GameCore/GameManagers/SoundManager.cs | 12 ++---------- ZoFo/GameCore/Graphics/AnimationBuilder.cs | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/ZoFo/GameCore/GameManagers/MapManager/MapManager.cs b/ZoFo/GameCore/GameManagers/MapManager/MapManager.cs index 94bf9e3..72dcdea 100644 --- a/ZoFo/GameCore/GameManagers/MapManager/MapManager.cs +++ b/ZoFo/GameCore/GameManagers/MapManager/MapManager.cs @@ -33,13 +33,13 @@ namespace ZoFo.GameCore.GameManagers.MapManager PropertyNameCaseInsensitive = true }; TileMap tileMap = - JsonSerializer.Deserialize(File.ReadAllText(string.Format(_templatePath, mapName)), options); + JsonSerializer.Deserialize(File.ReadAllText(Path.Combine(AppContext.BaseDirectory, string.Format(_templatePath, mapName))), options); // Загрузка TileSet-ов по TileSetInfo List tileSets = new List(); foreach (TileSetInfo tileSetInfo in tileMap.TileSets) { - TileSet tileSet = LoadTileSet(Path.Combine("Content", "MapData", "TileMaps", tileSetInfo.Source)); + TileSet tileSet = LoadTileSet(Path.Combine(AppContext.BaseDirectory, "Content", "MapData", "TileMaps", tileSetInfo.Source)); tileSet.FirstGid = tileSetInfo.FirstGid; tileSets.Add(tileSet); } @@ -75,14 +75,15 @@ namespace ZoFo.GameCore.GameManagers.MapManager (i / chunk.Height) * tileMap.TileHeight + chunk.Y * tileMap.TileHeight); Tile tile = tileSet.Tiles[number]; // По факту может быть StopObjectom, но на уровне Tiled это все в первую очередь Tile - + string textureName = Path.Combine(AppContext.BaseDirectory, "Content", "Textures", "TileSetImages", + Path.GetFileName(tileSet.Image).Replace(".png", "")); switch (tile.Type) { case "Tile": AppManager.Instance.server.RegisterGameObject(new MapObject(position, new Vector2(tileSet.TileWidth, tileSet.TileHeight), sourceRectangle, - "Textures/TileSetImages/" + Path.GetFileName(tileSet.Image).Replace(".png", ""))); + textureName)); break; case "StopObject": @@ -91,7 +92,7 @@ namespace ZoFo.GameCore.GameManagers.MapManager AppManager.Instance.server.RegisterGameObject(new StopObject(position, new Vector2(tileSet.TileWidth, tileSet.TileHeight), sourceRectangle, - "Textures/TileSetImages/" + Path.GetFileName(tileSet.Image).Replace(".png", ""), + textureName, collisionRectangles.ToArray())); break; diff --git a/ZoFo/GameCore/GameManagers/SoundManager.cs b/ZoFo/GameCore/GameManagers/SoundManager.cs index 97a5922..90db282 100644 --- a/ZoFo/GameCore/GameManagers/SoundManager.cs +++ b/ZoFo/GameCore/GameManagers/SoundManager.cs @@ -24,19 +24,11 @@ namespace ZoFo.GameCore.GameManagers { //List sounds = AppManager.Instance.Content.Load>("sounds/"); - string a = Path.Combine("Content", "sounds"); - string[] k; - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - k = Directory.GetFiles(Path.Combine("bin", "Debug", "net8.0", "Content", "sounds")).Where(x => x.EndsWith("xnb")).ToArray(); - } - else{ - k = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Content", "sounds")).Where(x => x.EndsWith("xnb")).ToArray(); - } + string[] k = Directory.GetFiles(Path.Combine(AppContext.BaseDirectory, "Content", "sounds")).Where(x => x.EndsWith("xnb")).ToArray(); if (k.Length > 0) { - string[] soundFiles = k.Select(x => x.Split("\\").Last().Split("/").Last().Replace(".xnb", "")).ToArray();// папка со звуками там где exe + string[] soundFiles = k.Select(x => x.Split("/").Last().Replace(".xnb", "")).ToArray();// папка со звуками там где exe foreach (var soundFile in soundFiles) { Sounds.Add(soundFile, AppManager.Instance.Content.Load(Path.Combine("sounds", soundFile))); diff --git a/ZoFo/GameCore/Graphics/AnimationBuilder.cs b/ZoFo/GameCore/Graphics/AnimationBuilder.cs index e85ec28..50f9162 100644 --- a/ZoFo/GameCore/Graphics/AnimationBuilder.cs +++ b/ZoFo/GameCore/Graphics/AnimationBuilder.cs @@ -12,7 +12,7 @@ namespace ZoFo.GameCore.Graphics public void LoadAnimations() { Animations = new List(); - string[] animationFilesNames = Directory.GetFiles("Content/Textures/Animations"); + string[] animationFilesNames = Directory.GetFiles(Path.Combine(AppContext.BaseDirectory, "Content", "Textures", "Animations")); StreamReader reader; foreach (var fileName in animationFilesNames)