Supports spawning players at birth points.

支持将玩家生成在出生点。
This commit is contained in:
Cold-Mint 2024-05-31 22:26:38 +08:00
parent 91cffd4866
commit db402ab7b2
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
10 changed files with 161 additions and 54 deletions

View File

@ -1,52 +1,88 @@
{
"ConnectionDataList": [
{
"FromId": "c0255eb6-2c75-44f7-9058-0921fe8fb0d8",
"ToId": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
"FromPort": 0,
"ToPort": 0
},
{
"FromId": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
"ToId": "ba32e05c-0c80-4a79-b5ce-5b8150400e05",
"FromPort": 0,
"ToPort": 0
}
{
"FromId": "c0255eb6-2c75-44f7-9058-0921fe8fb0d8",
"ToId": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
"FromPort": 0,
"ToPort": 0
},
{
"FromId": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
"ToId": "ba32e05c-0c80-4a79-b5ce-5b8150400e05",
"FromPort": 0,
"ToPort": 0
},
{
"FromId": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
"ToId": "8b3d645a-96c0-407e-871d-6f4a0b69557b",
"FromPort": 0,
"ToPort": 0
},
{
"FromId": "8b3d645a-96c0-407e-871d-6f4a0b69557b",
"ToId": "7e3ae680-3d7e-4ae9-b82f-5bfbe1c2f613",
"FromPort": 0,
"ToPort": 0
},
{
"FromId": "ba32e05c-0c80-4a79-b5ce-5b8150400e05",
"ToId": "7e3ae680-3d7e-4ae9-b82f-5bfbe1c2f613",
"FromPort": 0,
"ToPort": 0
}
],
"RoomNodeDataList": [
{
"Id": "c0255eb6-2c75-44f7-9058-0921fe8fb0d8",
"Title": "起点房间",
"Description": "测试的起点房间。",
"RoomTemplateSet": [
"res://prefab/roomTemplates/dungeon"
],
"Tags": [
"StartingRoom"
],
"RoomInjectionProcessorId": null,
"RoomInjectionProcessorConfig": null
},
{
"Id": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
"Title": "大厅",
"Description": "比普通房间要大一些的房间,有多个门,用于连接到其他房间。",
"RoomTemplateSet": [
"res://prefab/roomTemplates/dungeon/utilityRoom.tscn"
],
"Tags": null,
"RoomInjectionProcessorId": null,
"RoomInjectionProcessorConfig": null
},
{
"Id": "ba32e05c-0c80-4a79-b5ce-5b8150400e05",
"Title": "房间3",
"Description": "",
"RoomTemplateSet": [
"res://prefab/roomTemplates/dungeon/"
],
"Tags": null,
"RoomInjectionProcessorData": "[\n {\n \"Id\": \"TimeInterval\",\n \"Config\": \"{\\\"DateSpecifiesLevel\\\":0,\\\"StartTime\\\":\\\"2024/1/1 20:34:23\\\",\\\"EndTime\\\":\\\"2025/1/1 20:34:23\\\"}\"\n }\n]"
}
{
"Id": "c0255eb6-2c75-44f7-9058-0921fe8fb0d8",
"Title": "起点房间",
"Description": "测试的起点房间。",
"RoomTemplateSet": [
"res://prefab/roomTemplates/dungeon/initialRoom.tscn"
],
"Tags": [
"StartingRoom"
],
"RoomInjectionProcessorData": null
},
{
"Id": "ba32e05c-0c80-4a79-b5ce-5b8150400e05",
"Title": "房间3",
"Description": "",
"RoomTemplateSet": [
"res://prefab/roomTemplates/dungeon/"
],
"Tags": null,
"RoomInjectionProcessorData": "[\n {\n \"Id\": \"TimeInterval\",\n \"Config\": \"{\\\"DateSpecifiesLevel\\\":0,\\\"StartTime\\\":\\\"2024/1/1 20:34:23\\\",\\\"EndTime\\\":\\\"2025/1/1 20:34:23\\\"}\"\n }\n]"
},
{
"Id": "4ae948ea-82b7-4b2d-bec2-19ed8a9d4c03",
"Title": "大厅",
"Description": "比普通房间要大一些的房间,有多个门,用于连接到其他房间。",
"RoomTemplateSet": [
"res://prefab/roomTemplates/dungeon/utilityRoom.tscn"
],
"Tags": null,
"RoomInjectionProcessorData": null
},
{
"Id": "8b3d645a-96c0-407e-871d-6f4a0b69557b",
"Title": "房间4",
"Description": "",
"RoomTemplateSet": [
"res://prefab/roomTemplates/dungeon/"
],
"Tags": null,
"RoomInjectionProcessorData": ""
},
{
"Id": "7e3ae680-3d7e-4ae9-b82f-5bfbe1c2f613",
"Title": "房间5",
"Description": "",
"RoomTemplateSet": [
"res://prefab/roomTemplates/dungeon/"
],
"Tags": null,
"RoomInjectionProcessorData": ""
}
]
}
}

View File

@ -17,4 +17,6 @@ place_existing_rooms,放置已存在的房间{0}。,Place existing rooms {0}.,
room_placement_failed,房间{0}放置失败。,Room {0} placement failed.,部屋{0}の放置に失敗します。
room_placement_information,房间{0}已被成功放置在{1}。,Room {0} has been successfully placed in {1}.,部屋{0}を{1}に配置しました。
room_injection_processor_does_not_exist,找不到房间注入处理器{0}请检测是否在MapGenerator内注册。,"Room injection processor {0} not found, check to see if it is registered in MapGenerator.",部屋注入プロセッサ{0}が見つかりません、MapGenerator内に登録されているかどうか検出してください。
time_range_debug,当前时间:{0}起始时间:{1},结束时间{2},是否在范围内{3},"Current time: {0} Start time: {1}, end time {2}, whether in range {3}",現在時間:{0}開始時間:{1}終了時間{2}範囲内かどうか{3}です
time_range_debug,当前时间:{0}起始时间:{1},结束时间{2},是否在范围内{3},"Current time: {0} Start time: {1}, end time {2}, whether in range {3}",現在時間:{0}開始時間:{1}終了時間{2}範囲内かどうか{3}です
player_spawn_debug,玩家{0}生成在{1}。,"Player {0} spawned at {1}.",プレイヤー{0}が{1}に生成されました。
player_packed_scene_not_exist,玩家预制场景不存在。,Player packed scene does not exist.,プレイヤーのパックされたシーンが存在しません。
1 id zh en jp
17 room_placement_failed 房间{0}放置失败。 Room {0} placement failed. 部屋{0}の放置に失敗します。
18 room_placement_information 房间{0}已被成功放置在{1}。 Room {0} has been successfully placed in {1}. 部屋{0}を{1}に配置しました。
19 room_injection_processor_does_not_exist 找不到房间注入处理器{0},请检测是否在MapGenerator内注册。 Room injection processor {0} not found, check to see if it is registered in MapGenerator. 部屋注入プロセッサ{0}が見つかりません、MapGenerator内に登録されているかどうか検出してください。
20 time_range_debug 当前时间:{0}起始时间:{1},结束时间{2},是否在范围内{3} Current time: {0} Start time: {1}, end time {2}, whether in range {3} 現在時間:{0}開始時間:{1}終了時間{2}範囲内かどうか{3}です
21 player_spawn_debug 玩家{0}生成在{1}。 Player {0} spawned at {1}. プレイヤー{0}が{1}に生成されました。
22 player_packed_scene_not_exist 玩家预制场景不存在。 Player packed scene does not exist. プレイヤーのパックされたシーンが存在しません。

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://du5ldsp613fei"]
[gd_scene load_steps=5 format=3 uid="uid://du5ldsp613fei"]
[ext_resource type="TileSet" uid="uid://c4wpp12rr44hi" path="res://tileSets/dungeon.tres" id="1_rn2om"]
[ext_resource type="Script" path="res://scripts/map/PlayerSpawn.cs" id="2_6p8mv"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kiih8"]
size = Vector2(508.75, 254)
@ -36,3 +37,7 @@ position = Vector2(491, 193)
position = Vector2(5, 0)
shape = SubResource("RectangleShape2D_jxmys")
debug_color = Color(0.854902, 0.14902, 0.823529, 0.419608)
[node name="Marker2D" type="Marker2D" parent="."]
position = Vector2(216, 113)
script = ExtResource("2_6p8mv")

View File

@ -89,5 +89,4 @@ grow_horizontal = 2
[node name="WeaponContainer" type="Node2D" parent="."]
[node name="Camera2D" type="Camera2D" parent="."]
zoom = Vector2(0.5, 0.5)
[node name="PlayerContainer" type="Node2D" parent="."]

View File

@ -22,6 +22,8 @@ public static class GameSceneNodeHolder
/// </summary>
public static Node2D? WeaponContainer { get; set; }
public static Node2D? PlayerContainer { get; set; }
public static HotBar? HotBar { get; set; }

View File

@ -15,18 +15,26 @@ public partial class GameSceneLoader : SceneLoaderTemplate
public override Task InitializeData()
{
//Loading the blood bar scene
//加载血条场景
var healthBarUi = GetNode<HealthBarUi>("CanvasLayer/Control/VBoxContainer/HealthBarUi");
GameSceneNodeHolder.HealthBarUi = healthBarUi;
//Load HotBar
//加载HotBar
var hotBar = GetNode<HotBar>("CanvasLayer/Control/VBoxContainer/HotBar");
GameSceneNodeHolder.HotBar = hotBar;
//Load operation prompt
//加载操作提示
var operationTip = GetNode<RichTextLabel>("CanvasLayer/Control/VBoxContainer/OperationTip");
GameSceneNodeHolder.OperationTipLabel = operationTip;
//Loaded weapon container
//加载武器容器
var weaponContainer = GetNode<Node2D>("WeaponContainer");
GameSceneNodeHolder.WeaponContainer = weaponContainer;
//Load player container
//加载玩家容器
var playerContainer = GetNode<Node2D>("PlayerContainer");
GameSceneNodeHolder.PlayerContainer = playerContainer;
return Task.CompletedTask;
}
@ -66,9 +74,6 @@ public partial class GameSceneLoader : SceneLoaderTemplate
/// </summary>
private async Task GenerateMap()
{
//2757235769 房间边框重叠!
//4175259928 房间内容重叠!
//212782913 起始房间重叠!
MapGenerator.Seed = GuidUtils.GetGuid();
if (_seedLabel != null)
{

View File

@ -0,0 +1,58 @@
using ColdMint.scripts.character;
using ColdMint.scripts.debug;
using ColdMint.scripts.loader.sceneLoader;
using ColdMint.scripts.map.events;
using Godot;
namespace ColdMint.scripts.map;
/// <summary>
/// <para>PlayerSpawn</para>
/// <para>玩家出生点</para>
/// </summary>
public partial class PlayerSpawn : Marker2D
{
private PackedScene? _playerPackedScene;
public override void _Ready()
{
base._Ready();
_playerPackedScene = GD.Load<PackedScene>("res://prefab/entitys/Character.tscn");
MapGenerator.MapGenerationCompleteEvent += MapGenerationCompleteEvent;
}
private void MapGenerationCompleteEvent(MapGenerationCompleteEvent mapGenerationCompleteEvent)
{
MapGenerator.MapGenerationCompleteEvent -= MapGenerationCompleteEvent;
//After the map is generated, create the player instance.
//当地图生成完成后,创建玩家实例。
if (GameSceneNodeHolder.Player != null)
{
//An existing player instance will not be created.
//已经存在玩家实例,不再创建。
GameSceneNodeHolder.Player.Position = GlobalPosition;
return;
}
if (GameSceneNodeHolder.PlayerContainer == null)
{
return;
}
if (_playerPackedScene == null)
{
LogCat.LogError("player_packed_scene_not_exist");
return;
}
var playerNode = _playerPackedScene.Instantiate();
if (playerNode is not Player player)
{
return;
}
GameSceneNodeHolder.PlayerContainer.AddChild(player);
GameSceneNodeHolder.Player = player;
player.Position = GlobalPosition;
LogCat.LogWithFormat("player_spawn_debug", player.ReadOnlyCharacterName, player.Position);
}
}