Skip to content

Commit 5bcbcfb

Browse files
committed
[Breaking change] feat: controller features
MaaXYZ/MaaFramework#815
1 parent 9bc9b2f commit 5bcbcfb

7 files changed

Lines changed: 45 additions & 13 deletions

File tree

src/MaaFramework.Binding.Native/Extensions/DesktopWindowInfoExtensions.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@ public static class DesktopWindowInfoExtensions
1010
/// </summary>
1111
/// <param name="info">The DesktopWindowInfo.</param>
1212
/// <param name="screencapMethod">The screencap method.</param>
13-
/// <param name="inputMethod">The input method.</param>
13+
/// <param name="mouseMethod">The mouse method.</param>
14+
/// <param name="keyboardMethod">The keyboard method.</param>
1415
/// <param name="hWnd">The new handle to a win32 window.</param>
1516
/// <param name="link">Executes <see cref="MaaController.LinkStart"/> if <see cref="LinkOption.Start"/>; otherwise, not link.</param>
1617
/// <param name="check">Checks LinkStart().Wait() status if <see cref="CheckStatusOption.ThrowIfNotSucceeded"/>; otherwise, not check.</param>
1718
/// <returns>A MaaWin32Controller.</returns>
1819
/// <exception cref="ArgumentNullException"/>
1920
public static MaaWin32Controller ToWin32Controller(this DesktopWindowInfo info,
2021
Win32ScreencapMethod screencapMethod,
21-
Win32InputMethod inputMethod,
22+
Win32InputMethod mouseMethod,
23+
Win32InputMethod keyboardMethod,
2224
nint? hWnd = null,
2325
LinkOption link = LinkOption.Start,
2426
CheckStatusOption check = CheckStatusOption.ThrowIfNotSucceeded)
2527
{
2628
ArgumentNullException.ThrowIfNull(info);
2729

2830
return hWnd.HasValue
29-
? new MaaWin32Controller(hWnd.Value, screencapMethod, inputMethod, link, check)
30-
: new MaaWin32Controller(info, screencapMethod, inputMethod, link, check);
31+
? new MaaWin32Controller(hWnd.Value, screencapMethod, mouseMethod, keyboardMethod, link, check)
32+
: new MaaWin32Controller(info, screencapMethod, mouseMethod, keyboardMethod, link, check);
3133
}
3234
}

src/MaaFramework.Binding.UnitTests/Test_Custom.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public bool Analyze(in IMaaContext context, in AnalyzeArgs args, in AnalyzeResul
7171

7272
var recognitionDetail =
7373
context.RunRecognition(DiffEntry, args.Image, DiffParam);
74+
Assert.IsFalse(
75+
context.GetNodeData(DiffEntry, out data));
7476
Assert.IsNotNull(
7577
recognitionDetail?.HitBox);
7678

@@ -81,16 +83,14 @@ public bool Analyze(in IMaaContext context, in AnalyzeArgs args, in AnalyzeResul
8183
Assert.IsTrue(
8284
cloneContext.OverrideNext(DiffEntry, [DiffEntry]));
8385

86+
Assert.IsFalse(
87+
context.GetNodeData(DiffEntry, out data));
8488
Assert.IsTrue(
8589
cloneContext.GetNodeData(DiffEntry, out data));
8690
Assert.IsNotNull(data);
8791
Assert.IsTrue(
8892
data.Contains($"\"next\":[\"{DiffEntry}\"]"));
8993

90-
Assert.IsTrue(
91-
context.GetNodeData(DiffEntry, out data));
92-
Assert.IsFalse(
93-
data.Contains($"\"next\":[\"{DiffEntry}\"]"));
9494

9595
Assert.IsTrue(
9696
recognitionDetail.HitBox.TryCopyTo(results.Box));
@@ -212,6 +212,8 @@ public bool RequestUuid(in IMaaStringBuffer buffer)
212212
return uuid is not null && buffer.TrySetValue(uuid);
213213
}
214214

215+
public ControllerFeatures GetFeatures() => ControllerFeatures.None;
216+
215217
public bool Screencap(in IMaaImageBuffer buffer)
216218
=> c.Screencap().Wait().IsSucceeded() && c.GetCachedImage(buffer);
217219

src/MaaFramework.Binding.UnitTests/Test_IMaaAgentClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void Case_RunTask(MaaTypes type, IMaaAgentClient maaAgentClient)
152152
using (var cts = new CancellationTokenSource(10 * 1000))
153153
{
154154
Assert.IsTrue(
155-
// agent.LinkStart());
155+
// agent.LinkStart());
156156
agent.LinkStart(StartupAgentServer, cts.Token));
157157
}
158158
var status = maa

src/MaaFramework.Binding.UnitTests/Test_IMaaController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,19 @@ public void CreateInstances()
119119
using var win32Native1 = new MaaWin32Controller(
120120
windowInfo.Handle,
121121
Win32ScreencapMethod.GDI,
122+
Win32InputMethod.SendMessage,
122123
Win32InputMethod.SendMessage);
123124
using var win32Native2 = new MaaWin32Controller(
124125
windowInfo.Handle,
125126
Win32ScreencapMethod.GDI,
126127
Win32InputMethod.SendMessage,
128+
Win32InputMethod.SendMessage,
127129
LinkOption.None);
128130
using var win32Native3 = new MaaWin32Controller(
129131
windowInfo.Handle,
130132
Win32ScreencapMethod.GDI,
131133
Win32InputMethod.SendMessage,
134+
Win32InputMethod.SendMessage,
132135
LinkOption.Start,
133136
CheckStatusOption.None);
134137
#endregion
@@ -387,8 +390,8 @@ public void CreateInvalidInstances()
387390

388391
#if !GITHUB_ACTIONS
389392
#region MaaWin32Controller
390-
Assert.ThrowsExactly<ArgumentException>(static () => new MaaWin32Controller(1, Win32ScreencapMethod.None, Win32InputMethod.Seize));
391-
Assert.ThrowsExactly<ArgumentException>(static () => new MaaWin32Controller(1, Win32ScreencapMethod.GDI, Win32InputMethod.None));
393+
Assert.ThrowsExactly<ArgumentException>(static () => new MaaWin32Controller(1, Win32ScreencapMethod.None, Win32InputMethod.Seize, Win32InputMethod.Seize));
394+
Assert.ThrowsExactly<ArgumentException>(static () => new MaaWin32Controller(1, Win32ScreencapMethod.GDI, Win32InputMethod.None, Win32InputMethod.None));
392395
#endregion
393396
#endif
394397
#endif

src/MaaFramework.Binding.UnitTests/Test_IMaaToolkit.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ private static void Test_Win32_WindowInfos(MaaTypes type, IList<DesktopWindowInf
104104
{
105105
MaaTypes.Native => windows[0].ToWin32Controller(
106106
screencapMethod: Win32ScreencapMethod.GDI,
107-
inputMethod: Win32InputMethod.SendMessage,
107+
mouseMethod: Win32InputMethod.SendMessage,
108+
keyboardMethod: Win32InputMethod.SendMessage,
108109
link: LinkOption.None),
109110
_ => throw new NotImplementedException(),
110111
};
@@ -118,7 +119,8 @@ private static void Test_Win32_WindowInfos(MaaTypes type, IList<DesktopWindowInf
118119
{
119120
MaaTypes.Native => windows[0].ToWin32Controller(
120121
screencapMethod: Win32ScreencapMethod.GDI,
121-
inputMethod: Win32InputMethod.SendMessage),
122+
mouseMethod: Win32InputMethod.SendMessage,
123+
keyboardMethod: Win32InputMethod.SendMessage),
122124
_ => throw new NotImplementedException(),
123125
};
124126
#endif

src/MaaFramework.Binding/Custom/IMaaCustomController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface IMaaCustomController : IMaaCustomResource, IDisposable
1515
/// Write result to buffer.
1616
/// </remarks>
1717
bool RequestUuid(in IMaaStringBuffer buffer);
18+
ControllerFeatures GetFeatures();
1819

1920
/// <remarks>
2021
/// Write result to width and height.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
#pragma warning disable CS1573 // 参数在 XML 注释中没有匹配的 param 标记
11+
#pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
12+
13+
namespace MaaFramework.Binding;
14+
15+
[Flags]
16+
public enum ControllerFeatures : System.UInt64
17+
{
18+
None = 0,
19+
UseMouseDownAndUpInsteadOfClick = 1,
20+
UseKeyboardDownAndUpInsteadOfClick = (1 << 1),
21+
}
22+

0 commit comments

Comments
 (0)