Add the Generate map button used in the test to adjust the room selection algorithm.
加入测试使用的生成地图按钮,调整房间的选取算法。
This commit is contained in:
parent
4023d1d870
commit
c73bc185a5
|
@ -5,6 +5,36 @@
|
||||||
"ToId": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
|
"ToId": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
|
||||||
"FromPort": 0,
|
"FromPort": 0,
|
||||||
"ToPort": 0
|
"ToPort": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"FromId": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
|
||||||
|
"ToId": "9d764cca-5057-470a-976d-ba472a21e2cc",
|
||||||
|
"FromPort": 0,
|
||||||
|
"ToPort": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"FromId": "9d764cca-5057-470a-976d-ba472a21e2cc",
|
||||||
|
"ToId": "08c9d2be-6174-4efe-91fc-e1b205c4dd53",
|
||||||
|
"FromPort": 0,
|
||||||
|
"ToPort": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"FromId": "08c9d2be-6174-4efe-91fc-e1b205c4dd53",
|
||||||
|
"ToId": "55d2ef86-49d0-4f8c-9f06-286673a5e1da",
|
||||||
|
"FromPort": 0,
|
||||||
|
"ToPort": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"FromId": "55d2ef86-49d0-4f8c-9f06-286673a5e1da",
|
||||||
|
"ToId": "07cc5f19-df5c-44aa-9997-81e48f4e2c4e",
|
||||||
|
"FromPort": 0,
|
||||||
|
"ToPort": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"FromId": "07cc5f19-df5c-44aa-9997-81e48f4e2c4e",
|
||||||
|
"ToId": "ea62a8ef-5575-4259-814a-b3454ff688f5",
|
||||||
|
"FromPort": 0,
|
||||||
|
"ToPort": 0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"RoomNodeDataList": [
|
"RoomNodeDataList": [
|
||||||
|
@ -19,6 +49,51 @@
|
||||||
"StartingRoom"
|
"StartingRoom"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"Id": "9d764cca-5057-470a-976d-ba472a21e2cc",
|
||||||
|
"Title": "房间3",
|
||||||
|
"Description": "",
|
||||||
|
"RoomTemplateSet": [
|
||||||
|
"res://prefab/roomTemplates/dungeon"
|
||||||
|
],
|
||||||
|
"Tags": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Id": "08c9d2be-6174-4efe-91fc-e1b205c4dd53",
|
||||||
|
"Title": "房间4",
|
||||||
|
"Description": "",
|
||||||
|
"RoomTemplateSet": [
|
||||||
|
"res://prefab/roomTemplates/dungeon"
|
||||||
|
],
|
||||||
|
"Tags": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Id": "55d2ef86-49d0-4f8c-9f06-286673a5e1da",
|
||||||
|
"Title": "房间5",
|
||||||
|
"Description": "",
|
||||||
|
"RoomTemplateSet": [
|
||||||
|
"res://prefab/roomTemplates/dungeon"
|
||||||
|
],
|
||||||
|
"Tags": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Id": "ea62a8ef-5575-4259-814a-b3454ff688f5",
|
||||||
|
"Title": "房间7",
|
||||||
|
"Description": "",
|
||||||
|
"RoomTemplateSet": [
|
||||||
|
"res://prefab/roomTemplates/dungeon"
|
||||||
|
],
|
||||||
|
"Tags": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Id": "07cc5f19-df5c-44aa-9997-81e48f4e2c4e",
|
||||||
|
"Title": "房间6",
|
||||||
|
"Description": "",
|
||||||
|
"RoomTemplateSet": [
|
||||||
|
"res://prefab/roomTemplates/dungeon"
|
||||||
|
],
|
||||||
|
"Tags": null
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"Id": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
|
"Id": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
|
||||||
"Title": "大厅",
|
"Title": "大厅",
|
||||||
|
|
|
@ -28,3 +28,4 @@ filename,文件名,File name,ファイル名
|
||||||
cancel,取消,Cancel,キャンセル
|
cancel,取消,Cancel,キャンセル
|
||||||
load,加载,Load,ろーど
|
load,加载,Load,ろーど
|
||||||
delete_selected_node,删除选中的节点,Delete selected node,選択されたノードを削除します
|
delete_selected_node,删除选中的节点,Delete selected node,選択されたノードを削除します
|
||||||
|
re_create_map,重新创建地图,Re-create map,地図を再作成します
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -67,6 +67,22 @@ grow_horizontal = 0
|
||||||
horizontal_alignment = 2
|
horizontal_alignment = 2
|
||||||
script = ExtResource("5_dis4v")
|
script = ExtResource("5_dis4v")
|
||||||
|
|
||||||
|
[node name="RecreateMapButton" type="Button" parent="CanvasLayer/Control"]
|
||||||
|
layout_mode = 0
|
||||||
|
offset_right = 8.0
|
||||||
|
offset_bottom = 8.0
|
||||||
|
text = "re_create_map"
|
||||||
|
|
||||||
|
[node name="SeedLabel" type="Label" parent="CanvasLayer/Control"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 5
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
offset_left = -20.0
|
||||||
|
offset_right = 20.0
|
||||||
|
offset_bottom = 25.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
|
||||||
[node name="ProjectileContainer" type="Node2D" parent="."]
|
[node name="ProjectileContainer" type="Node2D" parent="."]
|
||||||
|
|
||||||
[node name="DamageNumberContainer" type="Node2D" parent="."]
|
[node name="DamageNumberContainer" type="Node2D" parent="."]
|
||||||
|
|
|
@ -11,6 +11,8 @@ namespace ColdMint.scripts.loader.sceneLoader;
|
||||||
|
|
||||||
public partial class GameSceneLoader : SceneLoaderTemplate
|
public partial class GameSceneLoader : SceneLoaderTemplate
|
||||||
{
|
{
|
||||||
|
private Label? _seedLabel;
|
||||||
|
|
||||||
public override Task InitializeData()
|
public override Task InitializeData()
|
||||||
{
|
{
|
||||||
//加载血条场景
|
//加载血条场景
|
||||||
|
@ -30,14 +32,41 @@ public partial class GameSceneLoader : SceneLoaderTemplate
|
||||||
|
|
||||||
public override async Task LoadScene()
|
public override async Task LoadScene()
|
||||||
{
|
{
|
||||||
|
var debugMode = Config.IsDebug();
|
||||||
|
var recreateMapButton = GetNodeOrNull<Button>("CanvasLayer/Control/RecreateMapButton");
|
||||||
|
if (recreateMapButton != null)
|
||||||
|
{
|
||||||
|
recreateMapButton.Visible = debugMode;
|
||||||
|
recreateMapButton.Pressed += () => { _ = GenerateMap(); };
|
||||||
|
}
|
||||||
|
|
||||||
|
_seedLabel = GetNodeOrNull<Label>("CanvasLayer/Control/SeedLabel");
|
||||||
|
if (_seedLabel != null)
|
||||||
|
{
|
||||||
|
_seedLabel.Visible = Config.IsDebug();
|
||||||
|
}
|
||||||
|
|
||||||
MapGenerator.MapRoot = GetNode<Node>("MapRoot");
|
MapGenerator.MapRoot = GetNode<Node>("MapRoot");
|
||||||
MapGenerator.LayoutStrategy = new TestLayoutStrategy();
|
MapGenerator.LayoutStrategy = new TestLayoutStrategy();
|
||||||
MapGenerator.LayoutParsingStrategy = new SequenceLayoutParsingStrategy();
|
MapGenerator.LayoutParsingStrategy = new SequenceLayoutParsingStrategy();
|
||||||
MapGenerator.RoomPlacementStrategy = new PatchworkRoomPlacementStrategy();
|
MapGenerator.RoomPlacementStrategy = new PatchworkRoomPlacementStrategy();
|
||||||
//Test the seeds used
|
await GenerateMap();
|
||||||
//2531276826 Right-Down和Left-Down匹配成功
|
}
|
||||||
//4208831693 Left-Down和Right-Up匹配成功
|
|
||||||
MapGenerator.Seed = "2531276826";
|
/// <summary>
|
||||||
|
/// <para>Generate map</para>
|
||||||
|
/// <para>生成地图</para>
|
||||||
|
/// </summary>
|
||||||
|
private async Task GenerateMap()
|
||||||
|
{
|
||||||
|
MapGenerator.Seed = GuidUtils.GetGuid();
|
||||||
|
if (_seedLabel != null)
|
||||||
|
{
|
||||||
|
//If you have a seedLabel, then set the seed to it.
|
||||||
|
//如果有seedLabel,那么将种子设置上去。
|
||||||
|
_seedLabel.Text = "Seed:" + MapGenerator.Seed;
|
||||||
|
}
|
||||||
|
|
||||||
await MapGenerator.GenerateMap();
|
await MapGenerator.GenerateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ColdMint.scripts.debug;
|
using ColdMint.scripts.debug;
|
||||||
using ColdMint.scripts.levelGraphEditor;
|
|
||||||
using ColdMint.scripts.map.dateBean;
|
using ColdMint.scripts.map.dateBean;
|
||||||
using ColdMint.scripts.map.interfaces;
|
using ColdMint.scripts.map.interfaces;
|
||||||
using ColdMint.scripts.map.LayoutParsingStrategy;
|
using ColdMint.scripts.map.LayoutParsingStrategy;
|
||||||
|
@ -97,6 +96,7 @@ public static class MapGenerator
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NodeUtils.DeleteAllChild(_mapRoot);
|
||||||
//Get the layout data
|
//Get the layout data
|
||||||
//拿到布局图数据
|
//拿到布局图数据
|
||||||
var levelGraphEditorSaveData = await _layoutStrategy.GetLayout();
|
var levelGraphEditorSaveData = await _layoutStrategy.GetLayout();
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
using System.Threading.Tasks;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using ColdMint.scripts.debug;
|
using ColdMint.scripts.debug;
|
||||||
using ColdMint.scripts.levelGraphEditor;
|
using ColdMint.scripts.levelGraphEditor;
|
||||||
using ColdMint.scripts.map.dateBean;
|
using ColdMint.scripts.map.dateBean;
|
||||||
using ColdMint.scripts.map.interfaces;
|
using ColdMint.scripts.map.interfaces;
|
||||||
using ColdMint.scripts.map.room;
|
using ColdMint.scripts.map.room;
|
||||||
using ColdMint.scripts.utils;
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts.map.RoomPlacer;
|
namespace ColdMint.scripts.map.RoomPlacer;
|
||||||
|
@ -19,8 +19,6 @@ namespace ColdMint.scripts.map.RoomPlacer;
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy
|
public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy
|
||||||
{
|
{
|
||||||
private readonly Vector2 _halfCell = new Vector2(Config.CellSize / 2f, Config.CellSize / 2f);
|
|
||||||
|
|
||||||
public Task<bool> PlaceRoom(Node mapRoot, RoomPlacementData roomPlacementData)
|
public Task<bool> PlaceRoom(Node mapRoot, RoomPlacementData roomPlacementData)
|
||||||
{
|
{
|
||||||
if (roomPlacementData.Room == null || roomPlacementData.Position == null)
|
if (roomPlacementData.Room == null || roomPlacementData.Position == null)
|
||||||
|
@ -65,8 +63,9 @@ public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy
|
||||||
return Task.FromResult<RoomPlacementData?>(null);
|
return Task.FromResult<RoomPlacementData?>(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Matches unmatched slots.
|
//Saves all data in the room template that matches the parent room.
|
||||||
//对未匹配的插槽进行匹配。
|
//保存房间模板内所有与父房间匹配的数据。
|
||||||
|
var useableRoomPlacementData = new List<RoomPlacementData>();
|
||||||
foreach (var roomRes in roomResArray)
|
foreach (var roomRes in roomResArray)
|
||||||
{
|
{
|
||||||
var newRoom = RoomFactory.CreateRoom(roomRes);
|
var newRoom = RoomFactory.CreateRoom(roomRes);
|
||||||
|
@ -77,7 +76,10 @@ public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy
|
||||||
|
|
||||||
//Create a room, try to use the room slot to match the existing room slot.
|
//Create a room, try to use the room slot to match the existing room slot.
|
||||||
//创建了一个房间,尝试使用房间的槽与现有的房间槽匹配。
|
//创建了一个房间,尝试使用房间的槽与现有的房间槽匹配。
|
||||||
if (!IsMatch(parentRoomNode, newRoom, out var mainRoomSlot, out var newRoomSlot).Result) continue;
|
if (!IsMatch(parentRoomNode, newRoom, out var mainRoomSlot, out var newRoomSlot).Result)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (mainRoomSlot == null || newRoomSlot == null)
|
if (mainRoomSlot == null || newRoomSlot == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -91,11 +93,19 @@ public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy
|
||||||
Room = newRoom,
|
Room = newRoom,
|
||||||
Position = position
|
Position = position
|
||||||
};
|
};
|
||||||
return Task.FromResult<RoomPlacementData?>(roomPlacementData);
|
useableRoomPlacementData.Add(roomPlacementData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (useableRoomPlacementData.Count == 0)
|
||||||
|
{
|
||||||
return Task.FromResult<RoomPlacementData?>(null);
|
return Task.FromResult<RoomPlacementData?>(null);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var index = randomNumberGenerator.Randi() % useableRoomPlacementData.Count;
|
||||||
|
return Task.FromResult<RoomPlacementData?>(useableRoomPlacementData[(int)index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Task<RoomPlacementData?> CalculatePlacementDataForStartingRoom(RandomNumberGenerator randomNumberGenerator,
|
public Task<RoomPlacementData?> CalculatePlacementDataForStartingRoom(RandomNumberGenerator randomNumberGenerator,
|
||||||
RoomNodeData startRoomNodeData)
|
RoomNodeData startRoomNodeData)
|
||||||
|
@ -127,6 +137,8 @@ public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mainRoom"></param>
|
/// <param name="mainRoom"></param>
|
||||||
/// <param name="newRoom"></param>
|
/// <param name="newRoom"></param>
|
||||||
|
/// <param name="outMainRoomSlot"></param>
|
||||||
|
/// <param name="outNewRoomSlot"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<bool> IsMatch(Room? mainRoom, Room newRoom, out RoomSlot? outMainRoomSlot, out RoomSlot? outNewRoomSlot)
|
public Task<bool> IsMatch(Room? mainRoom, Room newRoom, out RoomSlot? outMainRoomSlot, out RoomSlot? outNewRoomSlot)
|
||||||
{
|
{
|
||||||
|
@ -253,7 +265,8 @@ public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy
|
||||||
if (result.Y < 0)
|
if (result.Y < 0)
|
||||||
{
|
{
|
||||||
result.Y += Config.CellSize;
|
result.Y += Config.CellSize;
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
result.Y -= Config.CellSize;
|
result.Y -= Config.CellSize;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user