Files
a301_mmo_game_server/MMOTestServer/MMOserver/Game/Channel/Maps/MapLoader.cs
2026-04-03 01:38:36 +09:00

61 lines
1.3 KiB
C#

using System.Text.Json;
using MMOserver.Game.Channel.Maps.InstanceDungeun;
namespace MMOserver.Game.Channel.Maps;
// Zone 데이터 구조
public record ZoneConfigData(
int ZoneId,
int Row,
int Col,
int CenterX,
int CenterZ
);
// Map 데이터 구조
public record MapConfigData(
int MapId,
string MapType,
int Rows,
int Cols,
int ZoneSize,
List<ZoneConfigData> Zones
);
// 한 채널의 Map정보 List
public record MapFileData(
List<MapConfigData> Maps
);
/*
* maps.json 로더
* - JSON 파싱만 담당
* - Program.cs에서 Initialize() 1회 호출
*/
public static class MapLoader
{
private static readonly JsonSerializerOptions Options = new()
{
PropertyNameCaseInsensitive = true
};
public static MapFileData Data { get; private set; } = null!;
public static void Initialize()
{
string json = File.ReadAllText("maps.json");
Data = JsonSerializer.Deserialize<MapFileData>(json, Options) ?? throw new InvalidOperationException("maps.json 파싱 실패");
}
public static EnumMap ParseMapType(string mapType)
{
return mapType.ToUpper() switch
{
"ROBBY" => EnumMap.ROBBY,
"DUNGEON" => EnumMap.DUNGEON,
"INSTANCE" => EnumMap.INSTANCE,
_ => EnumMap.NONE
};
}
}