改动说明 - 实现内容加载器并支持 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),便于后续扩展。
110 lines
2.7 KiB
C#
110 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Godot;
|
|
using Godot.Collections;
|
|
using Models;
|
|
|
|
namespace Core;
|
|
|
|
/// <summary>
|
|
/// 学科定义资源(先落地一个完整示例)
|
|
/// 设计说明:
|
|
/// 1) 为避免 .tres 过度嵌套,字段保持扁平化。
|
|
/// 2) Buff 规则通过 RuleIds 存储,数值效果可后续用 JSON 增补。
|
|
/// 注意事项:
|
|
/// - Id 与资源路径应稳定且小写下划线。
|
|
/// 未来扩展:
|
|
/// - 可补充 Modifiers/AllowedRoles 等字段,进一步丰富配置能力。
|
|
/// </summary>
|
|
[GlobalClass]
|
|
public partial class DisciplineDefinitionResource : Resource, IContentResource
|
|
{
|
|
// --- Header ---
|
|
[Export] public string Id { get; set; }
|
|
[Export] public string NameKey { get; set; }
|
|
[Export] public string NameFallback { get; set; }
|
|
[Export] public string DescriptionKey { get; set; }
|
|
[Export] public string DescriptionFallback { get; set; }
|
|
[Export] public string IconPath { get; set; }
|
|
[Export] public Array<string> Tags { get; set; } = new();
|
|
|
|
// --- Buff ---
|
|
[Export] public string BuffNameKey { get; set; }
|
|
[Export] public string BuffNameFallback { get; set; }
|
|
[Export] public string BuffDescriptionKey { get; set; }
|
|
[Export] public string BuffDescriptionFallback { get; set; }
|
|
[Export] public Array<string> BuffRuleIds { get; set; } = new();
|
|
|
|
// --- Pools ---
|
|
[Export] public Array<string> RolePoolIds { get; set; } = new();
|
|
[Export] public Array<string> ItemPoolIds { get; set; } = new();
|
|
[Export] public Array<string> TaskKeywordIds { get; set; } = new();
|
|
|
|
public Type GetDefinitionType() => typeof(DisciplineDefinition);
|
|
|
|
public object ToDefinition()
|
|
{
|
|
var header = new DefinitionHeader
|
|
{
|
|
Id = Id,
|
|
IconPath = IconPath,
|
|
Name = new LocalizedText
|
|
{
|
|
Key = NameKey,
|
|
Fallback = NameFallback
|
|
},
|
|
Description = new LocalizedText
|
|
{
|
|
Key = DescriptionKey,
|
|
Fallback = DescriptionFallback
|
|
}
|
|
};
|
|
|
|
foreach (var tag in Tags)
|
|
{
|
|
header.Tags.Add(tag);
|
|
}
|
|
|
|
var buff = new DisciplineBuff
|
|
{
|
|
Name = new LocalizedText
|
|
{
|
|
Key = BuffNameKey,
|
|
Fallback = BuffNameFallback
|
|
},
|
|
Description = new LocalizedText
|
|
{
|
|
Key = BuffDescriptionKey,
|
|
Fallback = BuffDescriptionFallback
|
|
},
|
|
Modifiers = new ModifierBundle()
|
|
};
|
|
|
|
foreach (var ruleId in BuffRuleIds)
|
|
{
|
|
buff.Modifiers.RuleIds.Add(ruleId);
|
|
}
|
|
|
|
var definition = new DisciplineDefinition
|
|
{
|
|
Header = header,
|
|
Buff = buff
|
|
};
|
|
|
|
AddRange(RolePoolIds, definition.RolePoolIds);
|
|
AddRange(ItemPoolIds, definition.ItemPoolIds);
|
|
AddRange(TaskKeywordIds, definition.TaskKeywordIds);
|
|
|
|
return definition;
|
|
}
|
|
|
|
private static void AddRange(Array<string> source, List<string> target)
|
|
{
|
|
foreach (var value in source)
|
|
{
|
|
target.Add(value);
|
|
}
|
|
}
|
|
}
|
|
|