using System;
using System.Collections.Generic;
using Godot;
using Godot.Collections;
using Models;
namespace Core;
///
/// 学科定义资源(先落地一个完整示例)
/// 设计说明:
/// 1) 为避免 .tres 过度嵌套,字段保持扁平化。
/// 2) Buff 规则通过 RuleIds 存储,数值效果可后续用 JSON 增补。
/// 注意事项:
/// - Id 与资源路径应稳定且小写下划线。
/// 未来扩展:
/// - 可补充 Modifiers/AllowedRoles 等字段,进一步丰富配置能力。
///
[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 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 BuffRuleIds { get; set; } = new();
// --- Pools ---
[Export] public Array RolePoolIds { get; set; } = new();
[Export] public Array ItemPoolIds { get; set; } = new();
[Export] public Array 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 source, List target)
{
foreach (var value in source)
{
target.Add(value);
}
}
}