2024-05-19 14:32:34 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ColdMint.scripts.levelGraphEditor;
|
|
|
|
|
using ColdMint.scripts.serialization;
|
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.map.layoutStrategy;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Layout selection strategy to use at test time</para>
|
|
|
|
|
/// <para>测试时使用的布局选择策略</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TestLayoutStrategy : ILayoutStrategy
|
|
|
|
|
{
|
2024-06-16 14:44:50 +00:00
|
|
|
|
private const string Path = "res://data/levelGraphs/test.yaml";
|
2024-05-19 14:32:34 +00:00
|
|
|
|
|
|
|
|
|
public Task<LevelGraphEditorSaveData?> GetLayout()
|
|
|
|
|
{
|
2024-06-05 14:15:23 +00:00
|
|
|
|
var exists = FileAccess.FileExists(Path);
|
2024-05-19 14:32:34 +00:00
|
|
|
|
if (!exists)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult<LevelGraphEditorSaveData?>(null);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 14:15:23 +00:00
|
|
|
|
var json = FileAccess.GetFileAsString(Path);
|
2024-05-19 14:32:34 +00:00
|
|
|
|
if (json == null)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult<LevelGraphEditorSaveData?>(null);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 14:44:50 +00:00
|
|
|
|
return Task.FromResult(YamlSerialization.Deserialize<LevelGraphEditorSaveData?>(json));
|
2024-05-19 14:32:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|