Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ jobs:
# 恢复.NET本地工具
- name: Restore .NET tools
run: dotnet tool restore

- name: Setup Node.js 20
uses: actions/setup-node@v5
with:
node-version: 20

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.2.15

- name: Install config tool dependencies
working-directory: tools/gframework-config-tool
run: bun install

- name: Run config tool tests
working-directory: tools/gframework-config-tool
run: bun run test

# 构建项目,使用Release配置且跳过恢复步骤
- name: Build
Expand Down
46 changes: 30 additions & 16 deletions GFramework.Game.Tests/Config/ArchitectureConfigIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
using System.Linq;
using System.Threading.Tasks;
using GFramework.Core.Architectures;
using GFramework.Game.Abstractions.Config;
using GFramework.Game.Config;
using GFramework.Game.Config.Generated;
using NUnit.Framework;

namespace GFramework.Game.Tests.Config;

/// <summary>
/// 验证在 <see cref="Architecture" /> 初始化流程中可以通过聚合注册入口加载生成配置表,并通过表访问器读取数据。
/// 验证在 <see cref="Architecture" /> 初始化流程中可以通过官方配置启动帮助器加载生成配置表,并通过表访问器读取数据。
/// </summary>
[TestFixture]
public class ArchitectureConfigIntegrationTests
{
/// <summary>
/// 架构初始化期间,通过 <see cref="YamlConfigLoader" /> 的聚合注册入口注册生成表
/// 并将 <see cref="ConfigRegistry" /> 作为 utility 暴露给架构上下文读取。
/// 架构初始化期间,通过 <see cref="GameConfigBootstrap" /> 收敛生成表注册、加载与注册表暴露
/// 并将 <see cref="IConfigRegistry" /> 作为 utility 暴露给架构上下文读取。
/// </summary>
[Test]
public async Task ConfigLoaderCanRunDuringArchitectureInitialization()
Expand All @@ -43,7 +44,7 @@ public async Task ConfigLoaderCanRunDuringArchitectureInitialization()
Assert.That(retrieved, Is.Not.Null);
Assert.That(retrieved!.Get(1).Name, Is.EqualTo("Slime"));
Assert.That(architecture.Registry.TryGetItemTable(out _), Is.False);
Assert.That(architecture.Context.GetUtility<ConfigRegistry>(), Is.SameAs(architecture.Registry));
Assert.That(architecture.Context.GetUtility<IConfigRegistry>(), Is.SameAs(architecture.Registry));
});
}
finally
Expand Down Expand Up @@ -131,30 +132,43 @@ private static void DeleteDirectoryIfExists(string path)

private sealed class ConsumerArchitecture : Architecture
{
private readonly string _configRoot;
private readonly GameConfigBootstrap _bootstrap;

public ConfigRegistry Registry { get; }
public IConfigRegistry Registry => _bootstrap.Registry;

public MonsterTable MonsterTable { get; private set; } = null!;

public ConsumerArchitecture(string configRoot)
{
_configRoot = configRoot ?? throw new ArgumentNullException(nameof(configRoot));
Registry = new ConfigRegistry();
if (configRoot == null)
{
throw new ArgumentNullException(nameof(configRoot));
}

_bootstrap = new GameConfigBootstrap(
new GameConfigBootstrapOptions
{
RootPath = configRoot,
ConfigureLoader = static loader =>
loader.RegisterAllGeneratedConfigTables(
new GeneratedConfigRegistrationOptions
{
IncludedConfigDomains = new[] { MonsterConfigBindings.ConfigDomain }
})
});
}

protected override void OnInitialize()
{
RegisterUtility(Registry);

var loader = new YamlConfigLoader(_configRoot)
.RegisterAllGeneratedConfigTables(
new GeneratedConfigRegistrationOptions
{
IncludedConfigDomains = new[] { MonsterConfigBindings.ConfigDomain }
});
loader.LoadAsync(Registry).GetAwaiter().GetResult();
_bootstrap.InitializeAsync().GetAwaiter().GetResult();
MonsterTable = Registry.GetMonsterTable();
}

public override async ValueTask DestroyAsync()
{
_bootstrap.Dispose();
await base.DestroyAsync();
}
}
}
Loading
Loading