2024-05-07 09:38:50 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
using ColdMint.scripts.inventory;
|
|
|
|
|
using ColdMint.scripts.map;
|
2024-05-19 14:32:34 +00:00
|
|
|
|
using ColdMint.scripts.map.LayoutParsingStrategy;
|
|
|
|
|
using ColdMint.scripts.map.layoutStrategy;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
using ColdMint.scripts.map.RoomPlacer;
|
2024-05-21 14:50:33 +00:00
|
|
|
|
using ColdMint.scripts.utils;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.loader.sceneLoader;
|
|
|
|
|
|
2024-06-05 14:15:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Game scene loader</para>
|
|
|
|
|
/// <para>游戏场景加载器</para>
|
|
|
|
|
/// </summary>
|
2024-04-28 13:55:19 +00:00
|
|
|
|
public partial class GameSceneLoader : SceneLoaderTemplate
|
|
|
|
|
{
|
2024-07-19 13:12:53 +00:00
|
|
|
|
private Label? _seedLabel;
|
2024-05-23 13:58:49 +00:00
|
|
|
|
|
2024-07-19 13:12:53 +00:00
|
|
|
|
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;
|
|
|
|
|
//Backpack Ui container
|
|
|
|
|
//背包Ui容器
|
|
|
|
|
var backpackUiContainer = GetNode<Control>("CanvasLayer/BackpackUIContainer");
|
|
|
|
|
GameSceneNodeHolder.BackpackUiContainer = backpackUiContainer;
|
|
|
|
|
//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 Packsack container
|
|
|
|
|
//加载背包容器
|
|
|
|
|
var packsackContainer = GetNode<Node2D>("PacksackContainer");
|
|
|
|
|
GameSceneNodeHolder.PacksackContainer = packsackContainer;
|
|
|
|
|
//Load AICharacter container
|
|
|
|
|
//加载AICharacter容器
|
|
|
|
|
var aiCharacterContainer = GetNode<Node2D>("AICharacterContainer");
|
|
|
|
|
GameSceneNodeHolder.AiCharacterContainer = aiCharacterContainer;
|
|
|
|
|
//Load player container
|
|
|
|
|
//加载玩家容器
|
|
|
|
|
var playerContainer = GetNode<Node2D>("PlayerContainer");
|
|
|
|
|
GameSceneNodeHolder.PlayerContainer = playerContainer;
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
2024-07-19 13:12:53 +00:00
|
|
|
|
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(); };
|
|
|
|
|
}
|
2024-05-23 13:58:49 +00:00
|
|
|
|
|
2024-07-19 13:12:53 +00:00
|
|
|
|
_seedLabel = GetNodeOrNull<Label>("CanvasLayer/Control/SeedLabel");
|
|
|
|
|
if (_seedLabel != null)
|
|
|
|
|
{
|
|
|
|
|
_seedLabel.Visible = debugMode;
|
|
|
|
|
}
|
2024-05-23 13:58:49 +00:00
|
|
|
|
|
2024-07-19 13:12:53 +00:00
|
|
|
|
MapGenerator.MapRoot = GetNode<Node>("MapRoot");
|
|
|
|
|
MapGenerator.LayoutStrategy = new TestLayoutStrategy();
|
|
|
|
|
MapGenerator.LayoutParsingStrategy = new SequenceLayoutParsingStrategy();
|
|
|
|
|
MapGenerator.RoomPlacementStrategy = new PatchworkRoomPlacementStrategy();
|
|
|
|
|
await GenerateMap();
|
|
|
|
|
}
|
2024-05-23 13:58:49 +00:00
|
|
|
|
|
2024-07-19 13:12:53 +00:00
|
|
|
|
/// <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,那么将种子设置上去。
|
|
|
|
|
var seedInfo = TranslationServerUtils.TranslateWithFormat("ui_seed_info", MapGenerator.Seed);
|
|
|
|
|
_seedLabel.Text = seedInfo ?? $"Seed: {MapGenerator.Seed}";
|
|
|
|
|
}
|
|
|
|
|
await MapGenerator.GenerateMap();
|
|
|
|
|
}
|
|
|
|
|
}
|