After the map is generated, tiles will be copied from the Barrier layer when unused slots appear. Plug the slot.
生成地图后,当出现尚未使用的插槽,将会从Barrier层拷贝瓦片。堵上插槽。
This commit is contained in:
parent
ce8f9121a5
commit
1e019339d8
|
@ -29,8 +29,12 @@ collision_mask = 162
|
|||
platform_floor_layers = 4294967042
|
||||
platform_wall_layers = 128
|
||||
script = ExtResource("1_1dlls")
|
||||
CharacterName = null
|
||||
CanMutateAfterDeath = null
|
||||
InitialHp = null
|
||||
MaxHp = 32
|
||||
CampId = "Default"
|
||||
LootListId = null
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CapsuleShape2D_bb8wt")
|
||||
|
|
|
@ -76,6 +76,10 @@ use_parent_material = true
|
|||
tile_map_data = PackedByteArray("AAAAAAAAAQAAAAMAAAAAAAEAAQACAAEAAAAAAAIAAQACAAEAAAABAAAAAQABAAIAAAACAAAAAQABAAIAAAADAAAAAQABAAIAAAAEAAAAAQABAAIAAAAHAAAAAQABAAIAAAAIAAAAAQABAAIAAAAJAAAAAQABAAIAAAAKAAAAAQABAAIAAAALAAAAAQABAAIAAAAMAAAAAQABAAIAAAANAAAAAQABAAIAAAAOAAAAAQABAAMAAAAPAAAAAQACAAMAAAAPAAEAAQACAAQAAAAPAAIAAQACAAQAAAABAAUAAQABAAAAAAACAAUAAQABAAAAAAADAAUAAQABAAAAAAAEAAUAAQABAAAAAAAFAAUAAQABAAAAAAAGAAUAAQABAAAAAAAHAAUAAQABAAAAAAAIAAUAAQABAAAAAAAJAAUAAQABAAAAAAAKAAUAAQABAAAAAAALAAUAAQABAAAAAAAMAAUAAQABAAAAAAANAAUAAQABAAAAAAAOAAUAAQABAAAAAAAAAAUAAQAAAAUAAAAPAAUAAQACAAUAAAAFAAAAAQAEAAQAAAAGAAAAAQAEAAQAAAA=")
|
||||
tile_set = ExtResource("1_a15hy")
|
||||
|
||||
[node name="Barrier" type="TileMapLayer" parent="TileMap"]
|
||||
tile_map_data = PackedByteArray("AAAPAAMAAQAAAAEAAAAPAAQAAQAAAAEAAAAAAAMAAQACAAEAAAAAAAQAAQACAAEAAAAFAAAAAQABAAIAAAAGAAAAAQABAAIAAAA=")
|
||||
tile_set = ExtResource("1_a15hy")
|
||||
|
||||
[node name="PointLight2D" type="PointLight2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2(256, 96.5)
|
||||
|
|
|
@ -55,6 +55,7 @@ shape = SubResource("RectangleShape2D_131jn")
|
|||
[node name="Marker2D" type="Marker2D" parent="."]
|
||||
position = Vector2(237, 69)
|
||||
script = ExtResource("2_7q101")
|
||||
ResPath = null
|
||||
metadata/ResPath = "res://prefab/entitys/DelivererOfDarkMagic.tscn"
|
||||
|
||||
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
|
||||
|
@ -77,6 +78,11 @@ use_parent_material = true
|
|||
tile_map_data = PackedByteArray("AAAAAAAAAQAAAAMAAAAAAAEAAQACAAEAAAAAAAIAAQACAAEAAAABAAAAAQABAAIAAAACAAAAAQABAAIAAAADAAAAAQABAAIAAAAEAAAAAQABAAIAAAAFAAAAAQABAAIAAAAGAAAAAQABAAIAAAAHAAAAAQABAAIAAAAIAAAAAQABAAIAAAAJAAAAAQABAAIAAAAKAAAAAQABAAIAAAALAAAAAQABAAIAAAAMAAAAAQABAAIAAAANAAAAAQABAAIAAAAOAAAAAQABAAMAAAAPAAAAAQACAAMAAAAPAAEAAQACAAQAAAAPAAIAAQACAAQAAAABAAUAAQABAAAAAAACAAUAAQABAAAAAAADAAUAAQABAAAAAAAEAAUAAQABAAAAAAAFAAUAAQABAAAAAAAIAAUAAQABAAAAAAAJAAUAAQABAAAAAAAKAAUAAQABAAAAAAALAAUAAQABAAAAAAAMAAUAAQABAAAAAAANAAUAAQABAAAAAAAOAAUAAQABAAAAAAAAAAUAAQAAAAUAAAAPAAUAAQACAAUAAAAGAAUAAQAEAAQAAAAHAAUAAQAEAAQAAAA=")
|
||||
tile_set = ExtResource("1_rn2om")
|
||||
|
||||
[node name="Barrier" type="TileMapLayer" parent="TileMap"]
|
||||
use_parent_material = true
|
||||
tile_map_data = PackedByteArray("AAAAAAMAAQACAAEAAAAAAAQAAQACAAEAAAAPAAMAAQAAAAEAAAAPAAQAAQAAAAEAAAAGAAUAAQABAAAAAAAHAAUAAQABAAAAAAA=")
|
||||
tile_set = ExtResource("1_rn2om")
|
||||
|
||||
[node name="PointLight2D" type="PointLight2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2(256.5, 94)
|
||||
|
|
|
@ -65,6 +65,11 @@ use_parent_material = true
|
|||
tile_map_data = PackedByteArray("AAAAAAAAAQAAAAMAAAAAAAEAAQACAAEAAAAAAAIAAQACAAEAAAAAAAMAAQACAAEAAAAAAAQAAQACAAEAAAAAAAcAAQAAAAUAAAAPAAAAAQACAAMAAAAPAAEAAQACAAQAAAAPAAIAAQACAAQAAAAPAAMAAQACAAQAAAAPAAQAAQACAAQAAAAPAAcAAQACAAUAAAAAAAUAAQACAAEAAAAAAAYAAQACAAEAAAABAAAAAQABAAIAAAACAAAAAQABAAIAAAADAAAAAQABAAIAAAAEAAAAAQABAAIAAAAFAAAAAQABAAIAAAAGAAAAAQABAAIAAAAHAAAAAQABAAIAAAAIAAAAAQABAAIAAAAJAAAAAQABAAIAAAAKAAAAAQABAAIAAAALAAAAAQABAAIAAAAMAAAAAQABAAIAAAANAAAAAQABAAIAAAAOAAAAAQABAAMAAAABAAcAAQABAAAAAAACAAcAAQABAAAAAAADAAcAAQABAAAAAAAEAAcAAQABAAAAAAAFAAcAAQABAAAAAAAGAAcAAQABAAAAAAAHAAcAAQABAAAAAAAIAAcAAQABAAAAAAAJAAcAAQABAAAAAAAKAAcAAQABAAAAAAALAAcAAQABAAAAAAAMAAcAAQABAAAAAAANAAcAAQABAAAAAAAOAAcAAQABAAAAAAA=")
|
||||
tile_set = ExtResource("1_rn2om")
|
||||
|
||||
[node name="Barrier" type="TileMapLayer" parent="TileMap"]
|
||||
use_parent_material = true
|
||||
tile_map_data = PackedByteArray("AAAPAAUAAQAAAAEAAAAPAAYAAQAAAAEAAAA=")
|
||||
tile_set = ExtResource("1_rn2om")
|
||||
|
||||
[node name="PointLight2D" type="PointLight2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2(259.5, 128.5)
|
||||
|
|
|
@ -45,10 +45,9 @@ position = Vector2(720, 61)
|
|||
shape = SubResource("RectangleShape2D_30r3c")
|
||||
|
||||
[node name="Area2D3" type="Area2D" parent="RoomSlotList"]
|
||||
position = Vector2(138, 11)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RoomSlotList/Area2D3"]
|
||||
position = Vector2(584, 437)
|
||||
position = Vector2(722, 447)
|
||||
shape = SubResource("RectangleShape2D_6qg1t")
|
||||
|
||||
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
|
||||
|
@ -72,6 +71,12 @@ use_parent_material = true
|
|||
tile_map_data = PackedByteArray("AAAAAAAAAQAAAAMAAAAAAAEAAQACAAEAAAAAAAIAAQACAAEAAAAAAAMAAQACAAEAAAAAAAQAAQACAAEAAAAAAAUAAQACAAEAAAAAAAYAAQACAAEAAAABAAAAAQABAAIAAAACAAAAAQABAAIAAAADAAAAAQABAAIAAAAEAAAAAQABAAIAAAAFAAAAAQABAAIAAAAGAAAAAQABAAIAAAAHAAAAAQABAAIAAAAIAAAAAQABAAIAAAAJAAAAAQABAAIAAAAKAAAAAQABAAIAAAALAAAAAQABAAIAAAAMAAAAAQABAAIAAAANAAAAAQABAAIAAAAOAAAAAQABAAIAAAAPAAAAAQABAAIAAAAQAAAAAQABAAIAAAARAAAAAQABAAIAAAASAAAAAQABAAIAAAATAAAAAQABAAIAAAAUAAAAAQABAAIAAAAVAAAAAQABAAIAAAAWAAAAAQACAAMAAAAWAAMAAQAAAAEAAAAWAAQAAQAAAAEAAAAWAAUAAQAAAAEAAAAWAAYAAQAAAAEAAAAWAAcAAQAAAAEAAAAWAAgAAQAAAAEAAAAWAAkAAQAAAAEAAAAWAAoAAQAAAAEAAAAWAAsAAQAAAAEAAAAWAAwAAQAAAAEAAAAAAAcAAQACAAEAAAAAAAgAAQACAAEAAAAAAAkAAQACAAEAAAAAAAoAAQACAAEAAAAAAAsAAQACAAEAAAAAAAwAAQACAAEAAAAVAA8AAQABAAAAAAAUAA8AAQABAAAAAAATAA8AAQABAAAAAAASAA8AAQABAAAAAAARAA8AAQABAAAAAAAQAA8AAQABAAAAAAAPAA8AAQABAAAAAAAOAA8AAQABAAAAAAANAA8AAQABAAAAAAAMAA8AAQABAAAAAAALAA8AAQABAAAAAAAKAA8AAQABAAAAAAAJAA8AAQABAAAAAAAIAA8AAQABAAAAAAAHAA8AAQABAAAAAAAGAA8AAQABAAAAAAAFAA8AAQABAAAAAAAEAA8AAQABAAAAAAADAA8AAQABAAAAAAACAA8AAQABAAAAAAABAA8AAQABAAAAAAAAAA8AAQAAAAUAAAAWAA8AAQACAAUAAAASAAsAAQAEAAQAAAATAAsAAQAEAAQAAAAUAAsAAQAEAAQAAAAVAAsAAQAFAAQAAAABAAsAAQADAAQAAAACAAsAAQAEAAQAAAADAAsAAQAEAAQAAAAEAAsAAQAEAAQAAAAFAAsAAQAEAAQAAAAGAAsAAQAEAAQAAAAHAAsAAQAEAAQAAAAIAAsAAQAEAAQAAAAOAAsAAQAEAAQAAAAPAAsAAQAEAAQAAAAQAAsAAQAEAAQAAAARAAsAAQAEAAQAAAABAAoAAQAEAAMAAAAVAAoAAQAEAAMAAAACAAoAAQAEAAIAAAAUAAoAAQAEAAIAAAANAAQAAQAEAAQAAAANAAwAAQAEAAQAAAAMAA0AAQAEAAQAAAALAA4AAQAEAAQAAAAJAAsAAQAEAAQAAAAGAAoAAQAEAAQAAAAHAAkAAQAEAAQAAAAIAAgAAQAEAAQAAAAJAAcAAQAEAAQAAAAKAAcAAQAEAAQAAAALAAcAAQAEAAQAAAAMAAcAAQAEAAQAAAANAAcAAQAEAAQAAAAOAAcAAQAEAAQAAAAPAAcAAQAEAAQAAAAQAAcAAQAEAAQAAAARAAcAAQAEAAQAAAASAAcAAQAEAAQAAAATAAcAAQAEAAQAAAAUAAcAAQAEAAQAAAAVAAcAAQAEAAQAAAABAAcAAQAEAAQAAAACAAcAAQAEAAQAAAADAAcAAQAEAAQAAAAEAAcAAQAEAAQAAAAFAAcAAQAEAAQAAAALAAYAAQAEAAQAAAAMAAUAAQAEAAQAAAAPAAMAAQAEAAQAAAAQAAMAAQAEAAQAAAARAAMAAQAEAAQAAAASAAMAAQAEAAQAAAATAAMAAQAEAAQAAAAUAAMAAQAEAAQAAAAVAAMAAQAEAAQAAAABAAMAAQAEAAQAAAACAAMAAQAEAAQAAAADAAMAAQAEAAQAAAAEAAMAAQAEAAQAAAAFAAMAAQAEAAQAAAAGAAMAAQAEAAQAAAAHAAMAAQAEAAQAAAAIAAMAAQAEAAQAAAAJAAMAAQAEAAQAAAA=")
|
||||
tile_set = ExtResource("1_rn2om")
|
||||
|
||||
[node name="Barrier" type="TileMapLayer" parent="TileMap"]
|
||||
visible = false
|
||||
use_parent_material = true
|
||||
tile_map_data = PackedByteArray("AAAWAA0AAQAAAAEAAAAWAA4AAQAAAAEAAAAWAAEAAQAAAAEAAAAWAAIAAQAAAAEAAAAAAA0AAQACAAEAAAAAAA4AAQACAAEAAAA=")
|
||||
tile_set = ExtResource("1_rn2om")
|
||||
|
||||
[node name="PointLight2D" type="PointLight2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2(367.5, 258)
|
||||
|
|
|
@ -20,7 +20,7 @@ public static class Config
|
|||
/// </summary>
|
||||
public const string Test = "test";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>Difficulty</para>
|
||||
/// <para>游戏难度</para>
|
||||
|
@ -32,11 +32,13 @@ public static class Config
|
|||
/// <para>简单模式</para>
|
||||
/// </summary>
|
||||
public const int Easy = 0;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Normal mode</para>
|
||||
/// <para>正常模式</para>
|
||||
/// </summary>
|
||||
public const int Normal = 1;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Hard mode</para>
|
||||
/// <para>困难模式</para>
|
||||
|
@ -136,7 +138,7 @@ public static class Config
|
|||
/// <para>快捷栏上有多少个物品槽</para>
|
||||
/// </summary>
|
||||
public const int HotBarSize = 9;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>Whether version isolation is enabled</para>
|
||||
|
@ -420,28 +422,25 @@ public static class Config
|
|||
|
||||
public static class OffsetAngleMode
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// <para>Random(Default)</para>
|
||||
/// <para>随机的(默认)</para>
|
||||
/// </summary>
|
||||
public const int Random = 0;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>AlwaysSame</para>
|
||||
/// <para>永远不变的偏移角度</para>
|
||||
/// </summary>
|
||||
public const int AlwaysSame = 1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>Cross</para>
|
||||
/// <para>交叉变换</para>
|
||||
/// </summary>
|
||||
public const int Cross = 2;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>Physical collision layer number</para>
|
||||
/// <para>物理碰撞层 序号</para>
|
||||
|
@ -474,6 +473,12 @@ public static class Config
|
|||
/// </remarks>
|
||||
public const string Ground = "Ground";
|
||||
|
||||
/// <summary>
|
||||
/// <para>Barrier</para>
|
||||
/// <para>屏障</para>
|
||||
/// </summary>
|
||||
public const string Barrier = "Barrier";
|
||||
|
||||
/// <summary>
|
||||
/// <para>Background decorative layer</para>
|
||||
/// <para>背景装饰层</para>
|
||||
|
|
|
@ -33,12 +33,6 @@ public static class EventBus
|
|||
/// </summary>
|
||||
public static Action<MapGenerationStartEvent>? MapGenerationStartEvent;
|
||||
|
||||
/// <summary>
|
||||
/// <para>New rooms are placed within the map to perform events</para>
|
||||
/// <para>新的房间被放置在地图内执行的事件</para>
|
||||
/// </summary>
|
||||
public static Action<MapGenerationPlaceRoomFinishEvent>? MapGenerationPlaceRoomFinishEvent;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Map generation completion event</para>
|
||||
/// <para>地图生成完成事件</para>
|
||||
|
|
|
@ -148,11 +148,6 @@ public static class MapGenerator
|
|||
return;
|
||||
}
|
||||
|
||||
if (GameSceneDepend.MiniMap != null)
|
||||
{
|
||||
GameSceneDepend.MiniMap.Clear();
|
||||
}
|
||||
|
||||
if (GameSceneDepend.AiCharacterContainer != null)
|
||||
{
|
||||
NodeUtils.DeleteAllChild(GameSceneDepend.AiCharacterContainer);
|
||||
|
@ -290,6 +285,13 @@ public static class MapGenerator
|
|||
await PlaceRoomAndAddRecord(roomNodeData.Id, roomPlacementData, roomDictionary);
|
||||
}
|
||||
|
||||
//Place barriers
|
||||
//放置屏障
|
||||
foreach (var roomDictionaryValue in roomDictionary.Values)
|
||||
{
|
||||
PlaceBarrier(roomDictionaryValue);
|
||||
}
|
||||
|
||||
//All rooms have been placed.
|
||||
//所有房间已放置完毕。
|
||||
await _roomPlacementStrategy.GeneratedComplete(_mapRoot);
|
||||
|
@ -298,7 +300,8 @@ public static class MapGenerator
|
|||
//调用地图生成完成事件
|
||||
var eventObj = new MapGenerationCompleteEvent
|
||||
{
|
||||
RandomNumberGenerator = randomNumberGenerator
|
||||
RandomNumberGenerator = randomNumberGenerator,
|
||||
RoomDictionary = roomDictionary
|
||||
};
|
||||
EventBus.MapGenerationCompleteEvent?.Invoke(eventObj);
|
||||
var aiCharacterGenerateEvent = new AiCharacterGenerateEvent
|
||||
|
@ -308,6 +311,63 @@ public static class MapGenerator
|
|||
EventBus.AiCharacterGenerateEvent?.Invoke(aiCharacterGenerateEvent);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>Place barriers</para>
|
||||
/// <para>放置屏障</para>
|
||||
/// </summary>
|
||||
/// <param name="room"></param>
|
||||
/// <returns></returns>
|
||||
private static void PlaceBarrier(Room? room)
|
||||
{
|
||||
if (room == null)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Place rooms and add mappings</para>
|
||||
/// <para>放置房间,并增加映射</para>
|
||||
|
@ -343,12 +403,6 @@ public static class MapGenerator
|
|||
dictionary.Add(roomNodeDataId, roomPlacementData.NewRoom);
|
||||
LogCat.LogWithFormat("room_placement_information", LogCat.LogLabel.Default, LogCat.UploadFormat, roomNodeDataId,
|
||||
roomPlacementData.Position.ToString());
|
||||
var mapGenerationPlaceRoomFinishEvent = new MapGenerationPlaceRoomFinishEvent
|
||||
{
|
||||
RoomNodeDataId = roomNodeDataId,
|
||||
RoomPlacementData = roomPlacementData
|
||||
};
|
||||
EventBus.MapGenerationPlaceRoomFinishEvent?.Invoke(mapGenerationPlaceRoomFinishEvent);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using ColdMint.scripts.map.room;
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.map.events;
|
||||
|
@ -16,4 +18,10 @@ public class MapGenerationCompleteEvent
|
|||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
public RandomNumberGenerator? RandomNumberGenerator { get; set; }
|
||||
// ReSharper restore UnusedAutoPropertyAccessor.Global
|
||||
|
||||
/// <summary>
|
||||
/// <para>All placed rooms</para>
|
||||
/// <para>所有已放置的房间</para>
|
||||
/// </summary>
|
||||
public Dictionary<string, Room>? RoomDictionary { get; set; }
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
using ColdMint.scripts.map.dateBean;
|
||||
|
||||
namespace ColdMint.scripts.map.events;
|
||||
|
||||
/// <summary>
|
||||
/// <para>MapGenerationPlaceRoomFinishEvent</para>
|
||||
/// <para>地图生成器放置房间完成后执行的事件</para>
|
||||
/// </summary>
|
||||
public class MapGenerationPlaceRoomFinishEvent
|
||||
{
|
||||
public string? RoomNodeDataId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>RoomPlacementData</para>
|
||||
/// <para>房间的放置数据</para>
|
||||
/// </summary>
|
||||
public RoomPlacementData? RoomPlacementData { get; set; }
|
||||
}
|
|
@ -39,14 +39,15 @@ public partial class MiniMap : NinePatchRect
|
|||
{
|
||||
_roomPreviewContainer = GetNode<Node2D>("RoomPreviewContainer");
|
||||
_miniMapMidpointCoordinate = Size / 2;
|
||||
EventBus.MapGenerationPlaceRoomFinishEvent += MapGenerationPlaceRoomFinishEvent;
|
||||
EventBus.MapGenerationCompleteEvent += MapGenerationCompleteEvent;
|
||||
EventBus.MapGenerationStartEvent += MapGenerationStartEvent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Clean up all room preview images in the mini map</para>
|
||||
/// <para>清理迷你地图内的所有房间预览图</para>
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
private void Clear()
|
||||
{
|
||||
_roomToRoomPreviews.Clear();
|
||||
if (_roomPreviewContainer != null)
|
||||
|
@ -55,6 +56,11 @@ public partial class MiniMap : NinePatchRect
|
|||
}
|
||||
}
|
||||
|
||||
private void MapGenerationStartEvent(MapGenerationStartEvent mapGenerationStartEvent)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Display room preview image</para>
|
||||
/// <para>显示房间预览图</para>
|
||||
|
@ -72,26 +78,29 @@ public partial class MiniMap : NinePatchRect
|
|||
/// <para>After the map generator completes placing the room</para>
|
||||
/// <para>地图生成器放置房间完成后</para>
|
||||
/// </summary>
|
||||
/// <param name="mapGenerationPlaceRoomFinishEvent"></param>
|
||||
private void MapGenerationPlaceRoomFinishEvent(MapGenerationPlaceRoomFinishEvent mapGenerationPlaceRoomFinishEvent)
|
||||
/// <param name="mapGenerationCompleteEvent"></param>
|
||||
private void MapGenerationCompleteEvent(MapGenerationCompleteEvent mapGenerationCompleteEvent)
|
||||
{
|
||||
var roomPlacementData = mapGenerationPlaceRoomFinishEvent.RoomPlacementData;
|
||||
if (roomPlacementData?.NewRoom == null || mapGenerationPlaceRoomFinishEvent.RoomNodeDataId == null)
|
||||
if (mapGenerationCompleteEvent.RoomDictionary == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var tileMapLayer = roomPlacementData.NewRoom.GetTileMapLayer(Config.TileMapLayerName.Ground);
|
||||
var textureRect = CreateRoomPreview(tileMapLayer,
|
||||
CalculateRelativePositionOnTheMinimap(tileMapLayer, roomPlacementData));
|
||||
if (textureRect == null)
|
||||
foreach (var dictionaryKey in mapGenerationCompleteEvent.RoomDictionary.Keys)
|
||||
{
|
||||
LogCat.LogWithFormat("failed_to_create_room_preview", LogCat.LogLabel.Default, LogCat.UploadFormat,
|
||||
mapGenerationPlaceRoomFinishEvent.RoomNodeDataId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_roomToRoomPreviews[roomPlacementData.NewRoom] = textureRect;
|
||||
var roomDictionaryValue = mapGenerationCompleteEvent.RoomDictionary[dictionaryKey];
|
||||
var tileMapLayer = roomDictionaryValue.GetTileMapLayer(Config.TileMapLayerName.Ground);
|
||||
var textureRect = CreateRoomPreview(tileMapLayer,
|
||||
CalculateRelativePositionOnTheMinimap(roomDictionaryValue));
|
||||
if (textureRect == null)
|
||||
{
|
||||
LogCat.LogErrorWithFormat("failed_to_create_room_preview", LogCat.LogLabel.Default, LogCat.UploadFormat,
|
||||
dictionaryKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
_roomToRoomPreviews[roomDictionaryValue] = textureRect;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,15 +113,14 @@ public partial class MiniMap : NinePatchRect
|
|||
///<para>Returns the position relative to the point in the minimap container</para>
|
||||
///<para>返回相对对于迷你地图容器中点的位置</para>
|
||||
/// </returns>
|
||||
private Vector2? CalculateRelativePositionOnTheMinimap(TileMapLayer? groundTileMapLayer,
|
||||
RoomPlacementData roomPlacementData)
|
||||
private Vector2? CalculateRelativePositionOnTheMinimap(Room room)
|
||||
{
|
||||
if (groundTileMapLayer == null || roomPlacementData.Position == null)
|
||||
if (room.RootNode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return roomPlacementData.Position.Value / Config.CellSize * Config.RoomPreviewScale;
|
||||
return room.RootNode.Position / Config.CellSize * Config.RoomPreviewScale;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -165,6 +173,7 @@ public partial class MiniMap : NinePatchRect
|
|||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
EventBus.MapGenerationPlaceRoomFinishEvent -= MapGenerationPlaceRoomFinishEvent;
|
||||
EventBus.MapGenerationCompleteEvent -= MapGenerationCompleteEvent;
|
||||
EventBus.MapGenerationStartEvent -= MapGenerationStartEvent;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.utils;
|
||||
|
||||
|
@ -74,4 +75,21 @@ public static class CoordinateUtils
|
|||
|
||||
return orientationDescribes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>传入矩形起点和终点,遍历瓦片地图上的每一个坐标</para>
|
||||
/// </summary>
|
||||
/// <param name="startPoint"></param>
|
||||
/// <param name="endPosition"></param>
|
||||
/// <param name="action"></param>
|
||||
public static void ForEachCell(Vector2I startPoint,Vector2I endPosition,Action<Vector2I> action)
|
||||
{
|
||||
for (var x = startPoint.X; x <= endPosition.X; x++)
|
||||
{
|
||||
for (var y = startPoint.Y; y <= endPosition.Y; y++)
|
||||
{
|
||||
action.Invoke(new Vector2I(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user