From 5371d31d99746de4298a1819d09562bd24b1b9a1 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Tue, 8 Oct 2024 10:52:42 +0800 Subject: [PATCH] =?UTF-8?q?Split=20the=20function=20that=20places=20the=20?= =?UTF-8?q?barrier.=20=E6=8B=86=E5=88=86=E6=94=BE=E7=BD=AE=E5=B1=8F?= =?UTF-8?q?=E9=9A=9C=E7=9A=84=E5=87=BD=E6=95=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/map/MapGenerator.cs | 49 +++-------------- scripts/map/room/Room.cs | 105 ++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 43 deletions(-) diff --git a/scripts/map/MapGenerator.cs b/scripts/map/MapGenerator.cs index 098a7fd..116a8bb 100644 --- a/scripts/map/MapGenerator.cs +++ b/scripts/map/MapGenerator.cs @@ -60,7 +60,11 @@ public static class MapGenerator if (_roomInjectionProcessorsDictionary == null) { _roomInjectionProcessorsDictionary = new Dictionary - { { key, roomInjectionProcessor } }; + { + { + key, roomInjectionProcessor + } + }; return true; } @@ -327,48 +331,7 @@ public static class MapGenerator { return; } - - var ground = room.GetTileMapLayer(Config.TileMapLayerName.Ground); - var barrier = room.GetTileMapLayer(Config.TileMapLayerName.Barrier); - if (ground == null || barrier == null) - { - return; - } - - var roomSlots = room.RoomSlots; - if (roomSlots == null || roomSlots.Length == 0) - { - return; - } - - foreach (var roomSlot in roomSlots) - { - if (roomSlot == null) - { - continue; - } - - if (roomSlot.Matched) - { - continue; - } - - //Place the corresponding coordinate tiles of the barrier layer on the ground level. - //将屏障层的对应坐标瓦片放到地面层。 - CoordinateUtils.ForEachCell(roomSlot.StartPosition, roomSlot.EndPosition, - i => - { - var cellSourceId = barrier.GetCellSourceId(i); - if (cellSourceId == -1) - { - return; - } - - ground.SetCell(i, cellSourceId, barrier.GetCellAtlasCoords(i), barrier.GetCellAlternativeTile(i)); - }); - } - - barrier.QueueFree(); + room.PlaceBarrierInUnmatchedSlots(); } /// diff --git a/scripts/map/room/Room.cs b/scripts/map/room/Room.cs index e0e1098..a9f97a4 100644 --- a/scripts/map/room/Room.cs +++ b/scripts/map/room/Room.cs @@ -50,6 +50,111 @@ public class Room return _tileMapLayers?.FirstOrDefault(tileMapLayer => tileMapLayer.Name == layerName); } + /// + /// Places a barrier in a slot where a match has been found. + /// 在找到匹配的槽位放置屏障。 + /// + private void PlaceBarrierInMatchedSlot() + { + ProcessRoomSlots(action: (roomSlot, ground, barrier, i) => + { + if (!roomSlot.Matched) + { + return; + } + var cellSourceId = barrier.GetCellSourceId(i); + if (cellSourceId == -1) + { + return; + } + + ground.SetCell(i, cellSourceId, barrier.GetCellAtlasCoords(i), barrier.GetCellAlternativeTile(i)); + }); + } + + /// + /// Clear the barrier that finds a matching slot + /// 清空找到匹配的槽位的屏障。 + /// + private void ClearBarriersInMatchedSlots() + { + ProcessRoomSlots(action: (roomSlot, ground, barrier, i) => + { + if (!roomSlot.Matched) + { + return; + } + var cellSourceId = barrier.GetCellSourceId(i); + if (cellSourceId == -1) + { + return; + } + + ground.SetCell(i, cellSourceId, barrier.GetCellAtlasCoords(i), barrier.GetCellAlternativeTile(i)); + }); + } + + /// + /// Places barriers in slots that do not have a match. + /// 在未匹配的槽位放置屏障。 + /// + public void PlaceBarrierInUnmatchedSlots() + { + ProcessRoomSlots(action: (roomSlot, ground, barrier, i) => + { + if (roomSlot.Matched) + { + return; + } + var cellSourceId = barrier.GetCellSourceId(i); + if (cellSourceId == -1) + { + return; + } + + ground.SetCell(i, cellSourceId, barrier.GetCellAtlasCoords(i), barrier.GetCellAlternativeTile(i)); + }); + } + + /// + /// Executes a callback for each room slot, providing the corresponding coordinates in the barrier and ground layers. + /// 对每个房间槽位执行回调,提供barrier层和ground层对应的坐标。 + /// + /// + ///The callback action to be executed, which takes the barrier layer, ground layer, and coordinates as parameters. + ///要执行的回调操作,它以屏障层、底层和坐标作为参数。 + /// + private void ProcessRoomSlots(Action action) + { + var ground = GetTileMapLayer(Config.TileMapLayerName.Ground); + var barrier = GetTileMapLayer(Config.TileMapLayerName.Barrier); + if (ground == null || barrier == null) + { + return; + } + + if (RoomSlots == null || RoomSlots.Length == 0) + { + return; + } + + foreach (var roomSlot in RoomSlots) + { + if (roomSlot == null) + { + continue; + } + + //Place the corresponding coordinate tiles of the barrier layer on the ground level. + //将屏障层的对应坐标瓦片放到地面层。 + CoordinateUtils.ForEachCell(roomSlot.StartPosition, roomSlot.EndPosition, i => + { + action.Invoke(roomSlot, ground, barrier, i); + }); + } + barrier.QueueFree(); + } + /// /// ShowAllCharacterTemplate /// 显示所有角色模板