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 /// 显示所有角色模板