mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
feat(architecture): 添加架构阶段感知能力支持
- 在AbstractModel和AbstractSystem中添加OnArchitecturePhase虚方法实现 - 修改Architecture类移除IArchitectureLifecycle接口和OnPhase方法 - 更新IModel和ISystem接口继承IArchitecturePhaseAware接口 - 修改AbstractResourceFactorySystem实现IArchitecturePhaseAware接口 - 在测试类TestModel和TestSystem中添加OnArchitecturePhase方法实现 - 在项目文件中添加对生成器相关目录的排除配置 - 将ArchitecturePhase枚举引入到相关文件中
This commit is contained in:
parent
4e035295ca
commit
2cfa78b91d
@ -1,11 +1,12 @@
|
|||||||
using GFramework.Core.Abstractions.rule;
|
using GFramework.Core.Abstractions.architecture;
|
||||||
|
using GFramework.Core.Abstractions.rule;
|
||||||
|
|
||||||
namespace GFramework.Core.Abstractions.model;
|
namespace GFramework.Core.Abstractions.model;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模型接口,定义了模型的基本行为和功能
|
/// 模型接口,定义了模型的基本行为和功能
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IModel : IContextAware
|
public interface IModel : IContextAware, IArchitecturePhaseAware
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化模型
|
/// 初始化模型
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using GFramework.Core.Abstractions.architecture;
|
||||||
using GFramework.Core.Abstractions.rule;
|
using GFramework.Core.Abstractions.rule;
|
||||||
|
|
||||||
namespace GFramework.Core.Abstractions.system;
|
namespace GFramework.Core.Abstractions.system;
|
||||||
@ -6,7 +7,7 @@ namespace GFramework.Core.Abstractions.system;
|
|||||||
/// 系统接口,定义了系统的基本行为和功能
|
/// 系统接口,定义了系统的基本行为和功能
|
||||||
/// 该接口继承了多个框架相关的接口,提供了系统初始化和销毁能力
|
/// 该接口继承了多个框架相关的接口,提供了系统初始化和销毁能力
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ISystem : IContextAware
|
public interface ISystem : IContextAware, IArchitecturePhaseAware
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化系统
|
/// 初始化系统
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using GFramework.Core.Abstractions.architecture;
|
using GFramework.Core.Abstractions.architecture;
|
||||||
|
using GFramework.Core.Abstractions.enums;
|
||||||
using GFramework.Core.Abstractions.model;
|
using GFramework.Core.Abstractions.model;
|
||||||
|
|
||||||
namespace GFramework.Core.Tests.model;
|
namespace GFramework.Core.Tests.model;
|
||||||
@ -32,4 +33,8 @@ public sealed class TestModel : IModel
|
|||||||
{
|
{
|
||||||
return _context;
|
return _context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnArchitecturePhase(ArchitecturePhase phase)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using GFramework.Core.Abstractions.architecture;
|
using GFramework.Core.Abstractions.architecture;
|
||||||
|
using GFramework.Core.Abstractions.enums;
|
||||||
using GFramework.Core.Abstractions.system;
|
using GFramework.Core.Abstractions.system;
|
||||||
|
|
||||||
namespace GFramework.Core.Tests.system;
|
namespace GFramework.Core.Tests.system;
|
||||||
@ -56,4 +57,8 @@ public sealed class TestSystem : ISystem
|
|||||||
{
|
{
|
||||||
Destroyed = true;
|
Destroyed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnArchitecturePhase(ArchitecturePhase phase)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ public abstract class Architecture(
|
|||||||
IArchitectureServices? services = null,
|
IArchitectureServices? services = null,
|
||||||
IArchitectureContext? context = null
|
IArchitectureContext? context = null
|
||||||
)
|
)
|
||||||
: IArchitecture, IArchitectureLifecycle
|
: IArchitecture
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取架构配置对象
|
/// 获取架构配置对象
|
||||||
@ -80,19 +80,6 @@ public abstract class Architecture(
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IArchitectureLifecycle Implementation
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 处理架构阶段变更通知
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="phase">当前架构阶段</param>
|
|
||||||
/// <param name="architecture">架构实例</param>
|
|
||||||
public virtual void OnPhase(ArchitecturePhase phase, IArchitecture architecture)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Fields and Properties
|
#region Fields and Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -362,7 +349,7 @@ public abstract class Architecture(
|
|||||||
{
|
{
|
||||||
if (CurrentPhase >= ArchitecturePhase.Ready && !Configuration.Options.AllowLateRegistration)
|
if (CurrentPhase >= ArchitecturePhase.Ready && !Configuration.Options.AllowLateRegistration)
|
||||||
{
|
{
|
||||||
var errorMsg = "Cannot register system after Architecture is Ready";
|
const string errorMsg = "Cannot register system after Architecture is Ready";
|
||||||
_logger.Error(errorMsg);
|
_logger.Error(errorMsg);
|
||||||
throw new InvalidOperationException(errorMsg);
|
throw new InvalidOperationException(errorMsg);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using GFramework.Core.Abstractions.architecture;
|
using GFramework.Core.Abstractions.architecture;
|
||||||
|
using GFramework.Core.Abstractions.enums;
|
||||||
using GFramework.Core.Abstractions.model;
|
using GFramework.Core.Abstractions.model;
|
||||||
|
|
||||||
namespace GFramework.Core.model;
|
namespace GFramework.Core.model;
|
||||||
@ -31,6 +32,14 @@ public abstract class AbstractModel : IModel
|
|||||||
return _context;
|
return _context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 处理架构阶段事件的虚拟方法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="phase">当前的架构阶段</param>
|
||||||
|
public virtual void OnArchitecturePhase(ArchitecturePhase phase)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 抽象初始化方法,由子类实现具体的初始化逻辑
|
/// 抽象初始化方法,由子类实现具体的初始化逻辑
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using GFramework.Core.Abstractions.enums;
|
||||||
using GFramework.Core.Abstractions.logging;
|
using GFramework.Core.Abstractions.logging;
|
||||||
using GFramework.Core.Abstractions.system;
|
using GFramework.Core.Abstractions.system;
|
||||||
using GFramework.Core.rule;
|
using GFramework.Core.rule;
|
||||||
@ -37,6 +38,14 @@ public abstract class AbstractSystem : ContextAwareBase, ISystem
|
|||||||
_logger.Info($"System destroyed: {GetType().Name}");
|
_logger.Info($"System destroyed: {GetType().Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 处理架构阶段事件的虚拟方法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="phase">当前的架构阶段</param>
|
||||||
|
public virtual void OnArchitecturePhase(ArchitecturePhase phase)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 抽象初始化方法,由子类实现具体的初始化逻辑
|
/// 抽象初始化方法,由子类实现具体的初始化逻辑
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -11,24 +11,23 @@ namespace GFramework.Godot.assets;
|
|||||||
/// 资源工厂系统抽象基类,用于统一管理各类资源的创建与预加载逻辑。
|
/// 资源工厂系统抽象基类,用于统一管理各类资源的创建与预加载逻辑。
|
||||||
/// 提供注册场景和资源的方法,并通过依赖的资源加载系统和资产目录系统完成实际资源的获取与构造。
|
/// 提供注册场景和资源的方法,并通过依赖的资源加载系统和资产目录系统完成实际资源的获取与构造。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceFactorySystem, IArchitectureLifecycle
|
public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceFactorySystem, IArchitecturePhaseAware
|
||||||
{
|
{
|
||||||
private IAssetCatalogSystem? _assetCatalogSystem;
|
private IAssetCatalogSystem? _assetCatalogSystem;
|
||||||
private ResourceFactory.Registry? _registry;
|
private ResourceFactory.Registry? _registry;
|
||||||
private IResourceLoadSystem? _resourceLoadSystem;
|
private IResourceLoadSystem? _resourceLoadSystem;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 架构阶段回调,在架构就绪时注册和预加载资源
|
/// 在架构阶段发生变化时执行相应的处理逻辑。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="phase">当前架构阶段</param>
|
/// <param name="phase">当前的架构阶段</param>
|
||||||
/// <param name="architecture">架构实例</param>
|
public void OnArchitecturePhase(ArchitecturePhase phase)
|
||||||
public void OnPhase(ArchitecturePhase phase, IArchitecture architecture)
|
|
||||||
{
|
{
|
||||||
if (phase == ArchitecturePhase.Ready)
|
if (phase == ArchitecturePhase.Ready)
|
||||||
{
|
{
|
||||||
// 注册资源
|
// 在架构准备就绪阶段注册资源并预加载所有资源
|
||||||
RegisterResources();
|
RegisterResources();
|
||||||
// 预加载所有资源
|
|
||||||
_registry!.PreloadAll();
|
_registry!.PreloadAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,6 +44,7 @@ public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceF
|
|||||||
return _registry!.ResolveFactory<T>(key);
|
return _registry!.ResolveFactory<T>(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据资产目录映射信息获取资源工厂函数。
|
/// 根据资产目录映射信息获取资源工厂函数。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -47,6 +47,10 @@
|
|||||||
<None Remove="GFramework.Godot.Abstractions\**"/>
|
<None Remove="GFramework.Godot.Abstractions\**"/>
|
||||||
<None Remove="GFramework.Game.Abstractions\**"/>
|
<None Remove="GFramework.Game.Abstractions\**"/>
|
||||||
<None Remove="GFramework.Core.Tests\**"/>
|
<None Remove="GFramework.Core.Tests\**"/>
|
||||||
|
<None Remove="GFramework.Generator\**"/>
|
||||||
|
<None Remove="GFramework.Generator.Attributes\**"/>
|
||||||
|
<None Remove="GFramework.Godot.SourceGenerators.Attributes\**"/>
|
||||||
|
<None Remove="GFramework.SourceGenerators.Attributes\**"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<!-- 聚合核心模块 -->
|
<!-- 聚合核心模块 -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -77,6 +81,10 @@
|
|||||||
<Compile Remove="GFramework.Godot.Abstractions\**"/>
|
<Compile Remove="GFramework.Godot.Abstractions\**"/>
|
||||||
<Compile Remove="GFramework.Game.Abstractions\**"/>
|
<Compile Remove="GFramework.Game.Abstractions\**"/>
|
||||||
<Compile Remove="GFramework.Core.Tests\**"/>
|
<Compile Remove="GFramework.Core.Tests\**"/>
|
||||||
|
<Compile Remove="GFramework.Generator\**"/>
|
||||||
|
<Compile Remove="GFramework.Generator.Attributes\**"/>
|
||||||
|
<Compile Remove="GFramework.Godot.SourceGenerators.Attributes\**"/>
|
||||||
|
<Compile Remove="GFramework.SourceGenerators.Attributes\**"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Remove="GFramework.Core\**"/>
|
<EmbeddedResource Remove="GFramework.Core\**"/>
|
||||||
@ -93,6 +101,10 @@
|
|||||||
<EmbeddedResource Remove="GFramework.Godot.Abstractions\**"/>
|
<EmbeddedResource Remove="GFramework.Godot.Abstractions\**"/>
|
||||||
<EmbeddedResource Remove="GFramework.Game.Abstractions\**"/>
|
<EmbeddedResource Remove="GFramework.Game.Abstractions\**"/>
|
||||||
<EmbeddedResource Remove="GFramework.Core.Tests\**"/>
|
<EmbeddedResource Remove="GFramework.Core.Tests\**"/>
|
||||||
|
<EmbeddedResource Remove="GFramework.Generator\**"/>
|
||||||
|
<EmbeddedResource Remove="GFramework.Generator.Attributes\**"/>
|
||||||
|
<EmbeddedResource Remove="GFramework.Godot.SourceGenerators.Attributes\**"/>
|
||||||
|
<EmbeddedResource Remove="GFramework.SourceGenerators.Attributes\**"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AdditionalFiles Remove="AnalyzerReleases.Shipped.md"/>
|
<AdditionalFiles Remove="AnalyzerReleases.Shipped.md"/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user