diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index 466a6faa..f00391ce 100755 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -262,47 +262,61 @@ public GameServer(ArgumentOptions options) game = new(MapInfo.defaultMapStruct, options.TeamCount); else { - uint[,] map = new uint[GameData.MapRows, GameData.MapCols]; - try + // txt文本方案 + if (options.MapResource.EndsWith(".txt")) { - string? line; - int i = 0, j = 0; - using StreamReader sr = new(options.MapResource); - while (!sr.EndOfStream && i < GameData.MapRows) + try { - if ((line = sr.ReadLine()) != null) + uint[,] map = new uint[GameData.MapRows, GameData.MapCols]; + string? line; + int i = 0, j = 0; + using StreamReader sr = new(options.MapResource); + #region 读取txt地图 + while (!sr.EndOfStream && i < GameData.MapRows) { - string[] nums = line.Split(' '); - foreach (string item in nums) + if ((line = sr.ReadLine()) != null) { - if (item.Length > 1)//以兼容原方案 - { - map[i, j] = (uint)int.Parse(item); - } - else + string[] nums = line.Split(' '); + foreach (string item in nums) { - //2022-04-22 by LHR 十六进制编码地图方案(防止地图编辑员瞎眼x - map[i, j] = (uint)MapEncoder.Hex2Dec(char.Parse(item)); - } - j++; - if (j >= GameData.MapCols) - { - j = 0; - break; + if (item.Length > 1)//以兼容原方案 + map[i, j] = (uint)int.Parse(item); + else + //2022-04-22 by LHR 十六进制编码地图方案(防止地图编辑员瞎眼x + map[i, j] = (uint)MapEncoder.Hex2Dec(char.Parse(item)); + j++; + if (j >= GameData.MapCols) + { + j = 0; + break; + } } + i++; } - i++; } + #endregion + game = new(new(GameData.MapRows, GameData.MapCols, map), options.TeamCount); + } + catch + { + game = new(MapInfo.defaultMapStruct, options.TeamCount); } } - catch + // MapStruct二进制方案 + else if (options.MapResource.EndsWith(".map")) { - map = MapInfo.defaultMap; + try + { + game = new(MapStruct.FromFile(options.MapResource), options.TeamCount); + } + catch + { + game = new(MapInfo.defaultMapStruct, options.TeamCount); + } } - finally + else { - MapStruct mapResource = new(GameData.MapRows, GameData.MapCols, map); - game = new(mapResource, options.TeamCount); + game = new(MapInfo.defaultMapStruct, options.TeamCount); } } currentMapMsg = new() { MapMessage = MapMsg() }; diff --git a/map-generator/JavaScript/assets/js/map.js b/map-generator/JavaScript/assets/js/map.js index 50ce0c7d..3f360ed2 100644 --- a/map-generator/JavaScript/assets/js/map.js +++ b/map-generator/JavaScript/assets/js/map.js @@ -85,6 +85,7 @@ function saveAsTxt() { for (var i = 0; i < 50; i++) { for (var j = 0; j < 50; j++) { str += map[j][i]; + str += " "; } str += "\n"; }