diff --git a/DungeonShooting_Godot/resource/map/RoomConfig.json b/DungeonShooting_Godot/resource/map/RoomConfig.json index 12154da..77990f0 100644 --- a/DungeonShooting_Godot/resource/map/RoomConfig.json +++ b/DungeonShooting_Godot/resource/map/RoomConfig.json @@ -11,28 +11,7 @@ "X": 20, "Y": 13 }, - "DoorAreaInfos": [ - { - "Direction": 3, - "Start": 16, - "End": 304 - }, - { - "Direction": 0, - "Start": 16, - "End": 192 - }, - { - "Direction": 2, - "Start": 16, - "End": 304 - }, - { - "Direction": 1, - "Start": 16, - "End": 192 - } - ] + "DoorAreaInfos": [] } }, { @@ -47,28 +26,7 @@ "X": 19, "Y": 12 }, - "DoorAreaInfos": [ - { - "Direction": 1, - "Start": 16, - "End": 176 - }, - { - "Direction": 2, - "Start": 16, - "End": 176 - }, - { - "Direction": 0, - "Start": 16, - "End": 176 - }, - { - "Direction": 3, - "Start": 128, - "End": 288 - } - ] + "DoorAreaInfos": [] } }, { @@ -83,48 +41,7 @@ "X": 21, "Y": 21 }, - "DoorAreaInfos": [ - { - "Direction": 1, - "Start": 208, - "End": 320 - }, - { - "Direction": 3, - "Start": 16, - "End": 128 - }, - { - "Direction": 2, - "Start": 16, - "End": 128 - }, - { - "Direction": 1, - "Start": 16, - "End": 128 - }, - { - "Direction": 2, - "Start": 208, - "End": 320 - }, - { - "Direction": 3, - "Start": 208, - "End": 320 - }, - { - "Direction": 0, - "Start": 16, - "End": 128 - }, - { - "Direction": 0, - "Start": 208, - "End": 320 - } - ] + "DoorAreaInfos": [] } } ] \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tiledata/Room1.json b/DungeonShooting_Godot/resource/map/tiledata/Room1.json index 58e6deb..40ef5e2 100644 --- a/DungeonShooting_Godot/resource/map/tiledata/Room1.json +++ b/DungeonShooting_Godot/resource/map/tiledata/Room1.json @@ -7,26 +7,5 @@ "X": 20, "Y": 13 }, - "DoorAreaInfos": [ - { - "Direction": 3, - "Start": 16, - "End": 304 - }, - { - "Direction": 0, - "Start": 16, - "End": 192 - }, - { - "Direction": 2, - "Start": 16, - "End": 304 - }, - { - "Direction": 1, - "Start": 16, - "End": 192 - } - ] + "DoorAreaInfos": [] } \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tiledata/Room2.json b/DungeonShooting_Godot/resource/map/tiledata/Room2.json index 04450ef..11b1c01 100644 --- a/DungeonShooting_Godot/resource/map/tiledata/Room2.json +++ b/DungeonShooting_Godot/resource/map/tiledata/Room2.json @@ -7,26 +7,5 @@ "X": 19, "Y": 12 }, - "DoorAreaInfos": [ - { - "Direction": 1, - "Start": 16, - "End": 176 - }, - { - "Direction": 2, - "Start": 16, - "End": 176 - }, - { - "Direction": 0, - "Start": 16, - "End": 176 - }, - { - "Direction": 3, - "Start": 128, - "End": 288 - } - ] + "DoorAreaInfos": [] } \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tiledata/Room3.json b/DungeonShooting_Godot/resource/map/tiledata/Room3.json index ed98615..4b39de8 100644 --- a/DungeonShooting_Godot/resource/map/tiledata/Room3.json +++ b/DungeonShooting_Godot/resource/map/tiledata/Room3.json @@ -7,46 +7,5 @@ "X": 21, "Y": 21 }, - "DoorAreaInfos": [ - { - "Direction": 1, - "Start": 208, - "End": 320 - }, - { - "Direction": 3, - "Start": 16, - "End": 128 - }, - { - "Direction": 2, - "Start": 16, - "End": 128 - }, - { - "Direction": 1, - "Start": 16, - "End": 128 - }, - { - "Direction": 2, - "Start": 208, - "End": 320 - }, - { - "Direction": 3, - "Start": 208, - "End": 320 - }, - { - "Direction": 0, - "Start": 16, - "End": 128 - }, - { - "Direction": 0, - "Start": 208, - "End": 320 - } - ] + "DoorAreaInfos": [] } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/map/DoorAreaInfo.cs b/DungeonShooting_Godot/src/framework/map/DoorAreaInfo.cs index 7ed012e..8d2263c 100644 --- a/DungeonShooting_Godot/src/framework/map/DoorAreaInfo.cs +++ b/DungeonShooting_Godot/src/framework/map/DoorAreaInfo.cs @@ -32,6 +32,17 @@ /// public Vector2 EndPosition; + public DoorAreaInfo() + { + } + + public DoorAreaInfo(DoorDirection direction, float start, float end) + { + Direction = direction; + Start = start; + End = end; + } + /// /// 自动计算 startPosition 和 endPosition /// diff --git a/DungeonShooting_Godot/src/game/GameApplication.cs b/DungeonShooting_Godot/src/game/GameApplication.cs index 9b908ac..c3df18e 100644 --- a/DungeonShooting_Godot/src/game/GameApplication.cs +++ b/DungeonShooting_Godot/src/game/GameApplication.cs @@ -59,17 +59,13 @@ /// /// 房间配置 /// - public readonly List RoomConfig; + public List RoomConfig { get; private set; } public GameApplication() { Instance = this; - - //加载房间配置信息 - var file = FileAccess.Open(ResourcePath.resource_map_RoomConfig_json, FileAccess.ModeFlags.Read); - var asText = file.GetAsText(); - RoomConfig = JsonSerializer.Deserialize>(asText); - file.Dispose(); + + InitRoomConfig(); //扫描并注册当前程序集下的武器 WeaponManager.RegisterWeaponFromAssembly(GetType().Assembly); @@ -120,4 +116,27 @@ //return viewPos; return (viewPos - GameCamera.Main.GlobalPosition + (GameConfig.ViewportSize / 2)) * GameConfig.WindowScale - GameCamera.Main.SubPixelPosition; } + + //初始化房间配置 + private void InitRoomConfig() + { + //加载房间配置信息 + var file = FileAccess.Open(ResourcePath.resource_map_RoomConfig_json, FileAccess.ModeFlags.Read); + var asText = file.GetAsText(); + RoomConfig = JsonSerializer.Deserialize>(asText); + file.Dispose(); + + //需要处理 DoorAreaInfos 长度为 0 的房间, 并为其配置默认值 + foreach (var roomSplit in RoomConfig) + { + var areaInfos = roomSplit.RoomInfo.DoorAreaInfos; + if (areaInfos.Count == 0) + { + areaInfos.Add(new DoorAreaInfo(DoorDirection.N, GenerateDungeon.TileCellSize, (roomSplit.RoomInfo.Size.X - 2) * GenerateDungeon.TileCellSize)); + areaInfos.Add(new DoorAreaInfo(DoorDirection.S, GenerateDungeon.TileCellSize, (roomSplit.RoomInfo.Size.X - 2) * GenerateDungeon.TileCellSize)); + areaInfos.Add(new DoorAreaInfo(DoorDirection.W, GenerateDungeon.TileCellSize, (roomSplit.RoomInfo.Size.Y - 2) * GenerateDungeon.TileCellSize)); + areaInfos.Add(new DoorAreaInfo(DoorDirection.E, GenerateDungeon.TileCellSize, (roomSplit.RoomInfo.Size.Y - 2) * GenerateDungeon.TileCellSize)); + } + } + } }