2021-01-07 05:35:15 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2021-01-19 09:22:23 +00:00
|
|
|
using System;
|
2023-10-12 12:06:39 +00:00
|
|
|
using System.Linq;
|
2022-01-20 08:18:53 +00:00
|
|
|
using JetBrains.Annotations;
|
2021-01-07 05:35:15 +00:00
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Game.Database;
|
2023-10-12 12:06:39 +00:00
|
|
|
using osu.Game.Rulesets;
|
2021-01-07 05:35:15 +00:00
|
|
|
using Realms;
|
|
|
|
|
|
|
|
namespace osu.Game.Input.Bindings
|
|
|
|
{
|
2021-01-13 09:07:35 +00:00
|
|
|
[MapTo(nameof(KeyBinding))]
|
2021-01-08 06:49:01 +00:00
|
|
|
public class RealmKeyBinding : RealmObject, IHasGuidPrimaryKey, IKeyBinding
|
2021-01-07 05:35:15 +00:00
|
|
|
{
|
2021-01-08 06:49:01 +00:00
|
|
|
[PrimaryKey]
|
2022-01-20 08:18:53 +00:00
|
|
|
public Guid ID { get; set; }
|
2021-01-07 05:35:15 +00:00
|
|
|
|
2021-11-22 09:34:04 +00:00
|
|
|
public string? RulesetName { get; set; }
|
2021-01-07 05:35:15 +00:00
|
|
|
|
|
|
|
public int? Variant { get; set; }
|
|
|
|
|
2022-01-19 00:46:45 +00:00
|
|
|
[Ignored]
|
2021-01-13 09:07:35 +00:00
|
|
|
public KeyCombination KeyCombination
|
2021-01-08 06:49:01 +00:00
|
|
|
{
|
2021-01-13 09:07:35 +00:00
|
|
|
get => KeyCombinationString;
|
|
|
|
set => KeyCombinationString = value.ToString();
|
2021-01-08 06:49:01 +00:00
|
|
|
}
|
|
|
|
|
2023-10-12 12:06:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The resultant action which is triggered by this binding.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// This implementation always returns an integer.
|
|
|
|
/// If wanting to get the actual enum-typed value, use <see cref="GetAction"/>.
|
|
|
|
/// </remarks>
|
2022-01-19 00:46:45 +00:00
|
|
|
[Ignored]
|
2021-01-13 09:07:35 +00:00
|
|
|
public object Action
|
2021-01-08 06:49:01 +00:00
|
|
|
{
|
2021-01-13 09:07:35 +00:00
|
|
|
get => ActionInt;
|
|
|
|
set => ActionInt = (int)value;
|
2021-01-08 06:49:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 09:07:35 +00:00
|
|
|
[MapTo(nameof(Action))]
|
|
|
|
public int ActionInt { get; set; }
|
2021-01-07 07:53:36 +00:00
|
|
|
|
2021-01-13 09:07:35 +00:00
|
|
|
[MapTo(nameof(KeyCombination))]
|
2022-01-20 08:18:53 +00:00
|
|
|
public string KeyCombinationString { get; set; } = null!;
|
|
|
|
|
|
|
|
public RealmKeyBinding(object action, KeyCombination keyCombination, string? rulesetName = null, int? variant = null)
|
|
|
|
{
|
|
|
|
Action = action;
|
|
|
|
KeyCombination = keyCombination;
|
|
|
|
|
|
|
|
RulesetName = rulesetName;
|
|
|
|
Variant = variant;
|
|
|
|
ID = Guid.NewGuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
[UsedImplicitly] // Realm
|
|
|
|
private RealmKeyBinding()
|
|
|
|
{
|
|
|
|
}
|
2023-10-12 12:06:39 +00:00
|
|
|
|
|
|
|
public object GetAction(RulesetStore rulesets)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(RulesetName))
|
|
|
|
return (GlobalAction)ActionInt;
|
|
|
|
|
|
|
|
var ruleset = rulesets.GetRuleset(RulesetName);
|
|
|
|
var actionType = ruleset!.CreateInstance()
|
|
|
|
.GetDefaultKeyBindings(Variant ?? 0)
|
|
|
|
.First() // let's just assume nobody does something stupid like mix multiple types...
|
|
|
|
.Action
|
|
|
|
.GetType();
|
|
|
|
|
|
|
|
return Enum.ToObject(actionType, ActionInt);
|
|
|
|
}
|
2021-01-07 05:35:15 +00:00
|
|
|
}
|
|
|
|
}
|