改动说明 - 实现内容加载器并支持 res:///user:// 路径解析与 JSON 枚举解析:scripts/Core/ContentRegistry.cs - 新增 .tres 资源定义接口与样例资源类(学科定义):scripts/Core/ContentResources.cs - 默认注册资源/JSON 数据源,启动时自动合并进内容库:scripts/Core/GameSession.cs - 样例 .tres 与 JSON 内容定义:resources/definitions/discipline_biology.tres, resources/definitions/disciplines.json, resources/definitions/archetypes.json - 当前 .tres 走“扁平字段 + RuleIds”,数值型 Modifier 更适合先用 JSON 落地,后续可以把更多字段迁入资源类。 - JSON 采用与 Models 定义一致的结构(DefinitionHeader/LocalizedText/ModifierBundle),便于后续扩展。
57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using Models;
|
|
|
|
namespace Core;
|
|
|
|
/// <summary>
|
|
/// 游戏会话(运行时入口)
|
|
/// 设计说明:
|
|
/// 1) 将 State + Content + Systems + Services 组织为一个整体。
|
|
/// 2) 便于在 Godot Node 中持有,避免散落的静态单例。
|
|
/// 注意事项:
|
|
/// - 真实项目中应通过工厂或依赖注入创建。
|
|
/// 未来扩展:
|
|
/// - 可加入“加载存档/保存存档/重置”接口。
|
|
/// </summary>
|
|
public sealed class GameSession
|
|
{
|
|
public GameState State { get; }
|
|
public GameContentDatabase Content { get; }
|
|
public DomainEventBus Events { get; }
|
|
public ILocalizationService Localization { get; }
|
|
public GameSystems Systems { get; }
|
|
|
|
public GameSession(GameState state, GameContentDatabase content, ILocalizationService localization, DomainEventBus events)
|
|
{
|
|
State = state;
|
|
Content = content;
|
|
Localization = localization;
|
|
Events = events;
|
|
Systems = new GameSystems();
|
|
Systems.Initialize(this);
|
|
}
|
|
|
|
public static GameSession CreateDefault()
|
|
{
|
|
var registry = new ContentRegistry();
|
|
var resourceSource = new ResourceContentSource(0);
|
|
resourceSource.ResourcePaths.Add("res://resources/definitions/discipline_biology.tres");
|
|
registry.RegisterSource(resourceSource);
|
|
|
|
var jsonSource = new JsonContentSource(10);
|
|
jsonSource.DataPaths.Add("res://resources/definitions/disciplines.json");
|
|
jsonSource.DataPaths.Add("res://resources/definitions/archetypes.json");
|
|
registry.RegisterSource(jsonSource);
|
|
|
|
var content = registry.BuildDatabase();
|
|
var localization = new GodotLocalizationService();
|
|
var events = new DomainEventBus();
|
|
return new GameSession(new GameState(), content, localization, events);
|
|
}
|
|
|
|
public void Tick(float delta)
|
|
{
|
|
Systems.Tick(delta);
|
|
}
|
|
}
|
|
|