mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-11 20:38:58 +08:00
- 新增输入绑定 DTO、设备上下文和 UI 语义桥接契约。 - 实现 Game 默认输入绑定存储、动作映射和 UI 分发桥接。 - 落地 Godot InputMap 适配、测试覆盖与配套文档。 - 更新 ai-plan 恢复点、worktree 映射与采用入口。
40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
// Copyright (c) 2025-2026 GeWuYou
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
using GFramework.Game.Abstractions.Input;
|
|
using GFramework.Game.Abstractions.UI;
|
|
|
|
namespace GFramework.Game.Input;
|
|
|
|
/// <summary>
|
|
/// 提供动作名称到 UI 语义动作的默认映射实现。
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// 默认映射只负责桥接现有 `UiInputAction` 语义,并通过字符串别名兼容 Godot 常见 `ui_*` 动作命名。
|
|
/// 更复杂的项目级 action map 可以通过自定义实现覆盖该行为。
|
|
/// </remarks>
|
|
public sealed class UiInputActionMap : IUiInputActionMap
|
|
{
|
|
private static readonly IReadOnlyDictionary<string, UiInputAction> DefaultMappings =
|
|
new Dictionary<string, UiInputAction>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["cancel"] = UiInputAction.Cancel,
|
|
["ui_cancel"] = UiInputAction.Cancel,
|
|
["confirm"] = UiInputAction.Confirm,
|
|
["ui_accept"] = UiInputAction.Confirm,
|
|
["submit"] = UiInputAction.Confirm
|
|
};
|
|
|
|
/// <inheritdoc />
|
|
public bool TryMap(string actionName, out UiInputAction action)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(actionName))
|
|
{
|
|
action = UiInputAction.None;
|
|
return false;
|
|
}
|
|
|
|
return DefaultMappings.TryGetValue(actionName, out action);
|
|
}
|
|
}
|