From 94f7c3a3c4c379abaa6b84189321bf50c79ef631 Mon Sep 17 00:00:00 2001 From: 964293341 Date: Wed, 10 Apr 2024 17:14:04 +0800 Subject: [PATCH 1/2] feat: :sparkles: using `.thuai7.map` in `options.mapResource` --- logic/Server/GameServer.cs | 70 +++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 28 deletions(-) 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() }; From dca9dc1cbc2af60d8f4352ee783ba86b2a9ab83e Mon Sep 17 00:00:00 2001 From: 964293341 Date: Wed, 10 Apr 2024 18:30:58 +0800 Subject: [PATCH 2/2] fix(mapgenerator-js): using space for line splitting --- map-generator/JavaScript/assets/js/map.js | 1 + 1 file changed, 1 insertion(+) 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"; }