FunGame 框架今日更新:
版本:v2.0.0-dev.0108
Inquiry 的动态字典设计导致其无法开箱即用,必须结合客户端才能使用,我们正在改进这一方面。
之前的做法:
通过Inquiry调用底层询问事件。
在OnCharacterInquiry钩子中获取到反应。
然而,客户端必须适配 string topic 和 Dictionary
这导致纯模组无法独立完成事件的处理。
现在,我们修改了方法签名:
// Effect 基类中
public InquiryResponse Inquiry(Character character, InquiryOptions options)
{
return GamingQueue?.Inquiry(character, options) ?? new(options);
}
// 框架的内部实现
public InquiryResponse Inquiry(Character character, InquiryOptions options)
{
if (!_decisionPoints.TryGetValue(character, out DecisionPoints? dp) || dp is null)
{
dp = new();
_decisionPoints[character] = dp;
}
InquiryResponse response = OnCharacterInquiryEvent(character, dp, options);
Effect[] effects = [.. character.Effects.Where(e => e.IsInEffect)];
foreach (Effect effect in effects)
{
effect.OnCharacterInquiry(character, options, response);
}
return response;
}
// 客户端
_gamingQueue.CharacterInquiryEvent += GamingQueue_CharacterInquiryEvent; // 依旧监听事件
// 不同的是,只需要根据options适配UI即可
private InquiryResponse GamingQueue_CharacterInquiryEvent(GamingQueue character, Character actor, DecisionPoints dp, InquiryOptions options)
{
return new(options);
}
添加了两个类予以支持该功能:
using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Model
{
public class InquiryOptions
{
public InquiryType InquiryType { get; } = InquiryType.None;
public string Topic { get; set; } = "";
public string Description { get; set; } = "";
public Dictionary<string, string> Choices { get; set; } = [];
public string DefaultChoice { get; set; } = "";
public double MinNumberValue { get; set; } = 0;
public double MaxNumberValue { get; set; } = 0;
public double DefaultNumberValue { get; set; } = 0;
public Dictionary<string, object> CustomArgs { get; set; } = [];
public InquiryOptions(InquiryType type, string topic)
{
InquiryType = type;
Topic = topic;
if (type == InquiryType.BinaryChoice)
{
Choices.Add("是", "");
Choices.Add("否", "");
DefaultChoice = "否";
}
}
}
}
using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Model
{
public class InquiryResponse
{
public InquiryType InquiryType { get; } = InquiryType.None;
public string Topic { get; set; } = "";
public List<string> Choices { get; set; } = [];
public string TextResult { get; set; } = "";
public double NumberResult { get; set; } = 0;
public Dictionary<string, object> CustomResponse { get; set; } = [];
public InquiryResponse(InquiryType type, string topic)
{
InquiryType = type;
Topic = topic;
}
public InquiryResponse(InquiryOptions options)
{
InquiryType = options.InquiryType;
Topic = options.Topic;
switch (options.InquiryType)
{
case InquiryType.Choice:
case InquiryType.MultipleChoice:
case InquiryType.BinaryChoice:
if (options.DefaultChoice != "")
{
Choices.Add(options.DefaultChoice);
}
else if (options.Choices.Count > 0)
{
Choices.Add(options.Choices.Keys.First());
}
break;
case InquiryType.TextInput:
TextResult = "";
break;
case InquiryType.NumberInput:
NumberResult = options.DefaultNumberValue;
break;
default:
break;
}
}
}
}
如此一来,模组便无需关心客户端的实现,只需要在询问时预设好默认值即可,客户端也只需要实现询问的 UI,完成了解耦。
评论(0)
暂无评论