Skip to content

Commit 0583ea6

Browse files
committed
feat: 同步 MaaFW v5.1 接口及回调消息
1 parent d307240 commit 0583ea6

14 files changed

Lines changed: 392 additions & 5 deletions

File tree

‎src/MaaFramework.Binding.Extensions/Notification/NotificationDetail.cs‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,44 @@ public record TaskerTaskDetail(
2626
[property: JsonPropertyName("hash")] string Hash
2727
);
2828

29+
/// <inheritdoc cref="MaaMsg.Node.PipelineNode.Prefix"/>
30+
public record NodePipelineNodeDetail(
31+
[property: JsonPropertyName("task_id")] int TaskId,
32+
[property: JsonPropertyName("node_id")] int NodeId,
33+
[property: JsonPropertyName("name")] string Name,
34+
[property: JsonPropertyName("focus")] JsonElement? Focus
35+
);
36+
37+
/// <inheritdoc cref="MaaMsg.Node.RecognitionNode.Prefix"/>
38+
public record NodeRecognitionNodeDetail(
39+
[property: JsonPropertyName("task_id")] int TaskId,
40+
[property: JsonPropertyName("node_id")] int NodeId,
41+
[property: JsonPropertyName("name")] string Name,
42+
[property: JsonPropertyName("focus")] JsonElement? Focus
43+
);
44+
45+
/// <inheritdoc cref="MaaMsg.Node.ActionNode.Prefix"/>
46+
public record NodeActionNodeDetail(
47+
[property: JsonPropertyName("task_id")] int TaskId,
48+
[property: JsonPropertyName("node_id")] int NodeId,
49+
[property: JsonPropertyName("name")] string Name,
50+
[property: JsonPropertyName("focus")] JsonElement? Focus
51+
);
52+
53+
/// <summary>
54+
/// Represents an item in the next list.
55+
/// </summary>
56+
public record NextListItem(
57+
[property: JsonPropertyName("name")] string Name,
58+
[property: JsonPropertyName("jump_back")] bool JumpBack,
59+
[property: JsonPropertyName("anchor")] bool Anchor
60+
);
61+
2962
/// <inheritdoc cref="MaaMsg.Node.NextList.Prefix"/>
3063
public record NodeNextListDetail(
3164
[property: JsonPropertyName("task_id")] int TaskId,
3265
[property: JsonPropertyName("name")] string Name,
33-
[property: JsonPropertyName("list")] IReadOnlyList<string> NextList,
66+
[property: JsonPropertyName("list")] IReadOnlyList<NextListItem> NextList,
3467
[property: JsonPropertyName("focus")] JsonElement? Focus
3568
);
3669

‎src/MaaFramework.Binding.Extensions/Notification/NotificationDetailContext.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ namespace MaaFramework.Binding.Notification;
66
[JsonSerializable(typeof(ResourceLoadingDetail))]
77
[JsonSerializable(typeof(ControllerActionDetail))]
88
[JsonSerializable(typeof(TaskerTaskDetail))]
9+
[JsonSerializable(typeof(NodePipelineNodeDetail))]
10+
[JsonSerializable(typeof(NodeRecognitionNodeDetail))]
11+
[JsonSerializable(typeof(NodeActionNodeDetail))]
12+
[JsonSerializable(typeof(NextListItem))]
913
[JsonSerializable(typeof(NodeNextListDetail))]
1014
[JsonSerializable(typeof(NodeRecognitionDetail))]
1115
[JsonSerializable(typeof(NodeActionDetail))]

‎src/MaaFramework.Binding.Extensions/Notification/NotificationHandler.cs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public static class NotificationHandlerExtensions
2121
{
2222
MaaMsg.Resource.Loading.Starting
2323
or MaaMsg.Controller.Action.Starting
24+
or MaaMsg.Node.PipelineNode.Starting
25+
or MaaMsg.Node.RecognitionNode.Starting
26+
or MaaMsg.Node.ActionNode.Starting
2427
or MaaMsg.Node.Action.Starting
2528
or MaaMsg.Node.NextList.Starting
2629
or MaaMsg.Node.Recognition.Starting
@@ -29,6 +32,9 @@ or MaaMsg.Tasker.Task.Starting
2932

3033
MaaMsg.Resource.Loading.Succeeded
3134
or MaaMsg.Controller.Action.Succeeded
35+
or MaaMsg.Node.PipelineNode.Succeeded
36+
or MaaMsg.Node.RecognitionNode.Succeeded
37+
or MaaMsg.Node.ActionNode.Succeeded
3238
or MaaMsg.Node.Action.Succeeded
3339
or MaaMsg.Node.NextList.Succeeded
3440
or MaaMsg.Node.Recognition.Succeeded
@@ -37,6 +43,9 @@ or MaaMsg.Tasker.Task.Succeeded
3743

3844
MaaMsg.Resource.Loading.Failed
3945
or MaaMsg.Controller.Action.Failed
46+
or MaaMsg.Node.PipelineNode.Failed
47+
or MaaMsg.Node.RecognitionNode.Failed
48+
or MaaMsg.Node.ActionNode.Failed
4049
or MaaMsg.Node.Action.Failed
4150
or MaaMsg.Node.NextList.Failed
4251
or MaaMsg.Node.Recognition.Failed
@@ -102,5 +111,17 @@ public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHan
102111
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
103112
public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHandler<NodeActionDetail, IMaaContext> notify)
104113
=> notify.ToCallback(MaaMsg.Node.Action.Prefix);
114+
115+
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
116+
public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHandler<NodePipelineNodeDetail, IMaaContext> notify)
117+
=> notify.ToCallback(MaaMsg.Node.PipelineNode.Prefix);
118+
119+
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
120+
public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHandler<NodeRecognitionNodeDetail, IMaaContext> notify)
121+
=> notify.ToCallback(MaaMsg.Node.RecognitionNode.Prefix);
122+
123+
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
124+
public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHandler<NodeActionNodeDetail, IMaaContext> notify)
125+
=> notify.ToCallback(MaaMsg.Node.ActionNode.Prefix);
105126
}
106127

‎src/MaaFramework.Binding.Extensions/Notification/NotificationHandlerRegistry.cs‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ public void OnCallback(object? sender, MaaCallbackEventArgs e)
4545
Tasker.Task.OnSucceeded(sender, e.Details); return;
4646
case MaaMsg.Tasker.Task.Failed:
4747
Tasker.Task.OnFailed(sender, e.Details); return;
48+
case MaaMsg.Node.PipelineNode.Starting:
49+
Node.PipelineNode.OnStarting(sender, e.Details); return;
50+
case MaaMsg.Node.PipelineNode.Succeeded:
51+
Node.PipelineNode.OnSucceeded(sender, e.Details); return;
52+
case MaaMsg.Node.PipelineNode.Failed:
53+
Node.PipelineNode.OnFailed(sender, e.Details); return;
54+
case MaaMsg.Node.RecognitionNode.Starting:
55+
Node.RecognitionNode.OnStarting(sender, e.Details); return;
56+
case MaaMsg.Node.RecognitionNode.Succeeded:
57+
Node.RecognitionNode.OnSucceeded(sender, e.Details); return;
58+
case MaaMsg.Node.RecognitionNode.Failed:
59+
Node.RecognitionNode.OnFailed(sender, e.Details); return;
60+
case MaaMsg.Node.ActionNode.Starting:
61+
Node.ActionNode.OnStarting(sender, e.Details); return;
62+
case MaaMsg.Node.ActionNode.Succeeded:
63+
Node.ActionNode.OnSucceeded(sender, e.Details); return;
64+
case MaaMsg.Node.ActionNode.Failed:
65+
Node.ActionNode.OnFailed(sender, e.Details); return;
4866
case MaaMsg.Node.NextList.Starting:
4967
Node.NextList.OnStarting(sender, e.Details); return;
5068
case MaaMsg.Node.NextList.Succeeded:
@@ -130,6 +148,48 @@ internal void OnFailed(object? sender, string details) => Failed?.Invoke(sender,
130148
public NodeRegistry Node { get; } = new();
131149
public sealed class NodeRegistry
132150
{
151+
public PipelineNodeRegistry PipelineNode { get; } = new();
152+
public sealed class PipelineNodeRegistry
153+
{
154+
public event EventHandler<NodePipelineNodeDetail>? Starting;
155+
internal void OnStarting(object? sender, string details) => Starting?.Invoke(sender, JsonSerializer.Deserialize(details,
156+
NotificationDetailContext.Default.NodePipelineNodeDetail) ?? throw new InvalidCastException());
157+
public event EventHandler<NodePipelineNodeDetail>? Succeeded;
158+
internal void OnSucceeded(object? sender, string details) => Succeeded?.Invoke(sender, JsonSerializer.Deserialize(details,
159+
NotificationDetailContext.Default.NodePipelineNodeDetail) ?? throw new InvalidCastException());
160+
public event EventHandler<NodePipelineNodeDetail>? Failed;
161+
internal void OnFailed(object? sender, string details) => Failed?.Invoke(sender, JsonSerializer.Deserialize(details,
162+
NotificationDetailContext.Default.NodePipelineNodeDetail) ?? throw new InvalidCastException());
163+
}
164+
165+
public RecognitionNodeRegistry RecognitionNode { get; } = new();
166+
public sealed class RecognitionNodeRegistry
167+
{
168+
public event EventHandler<NodeRecognitionNodeDetail>? Starting;
169+
internal void OnStarting(object? sender, string details) => Starting?.Invoke(sender, JsonSerializer.Deserialize(details,
170+
NotificationDetailContext.Default.NodeRecognitionNodeDetail) ?? throw new InvalidCastException());
171+
public event EventHandler<NodeRecognitionNodeDetail>? Succeeded;
172+
internal void OnSucceeded(object? sender, string details) => Succeeded?.Invoke(sender, JsonSerializer.Deserialize(details,
173+
NotificationDetailContext.Default.NodeRecognitionNodeDetail) ?? throw new InvalidCastException());
174+
public event EventHandler<NodeRecognitionNodeDetail>? Failed;
175+
internal void OnFailed(object? sender, string details) => Failed?.Invoke(sender, JsonSerializer.Deserialize(details,
176+
NotificationDetailContext.Default.NodeRecognitionNodeDetail) ?? throw new InvalidCastException());
177+
}
178+
179+
public ActionNodeRegistry ActionNode { get; } = new();
180+
public sealed class ActionNodeRegistry
181+
{
182+
public event EventHandler<NodeActionNodeDetail>? Starting;
183+
internal void OnStarting(object? sender, string details) => Starting?.Invoke(sender, JsonSerializer.Deserialize(details,
184+
NotificationDetailContext.Default.NodeActionNodeDetail) ?? throw new InvalidCastException());
185+
public event EventHandler<NodeActionNodeDetail>? Succeeded;
186+
internal void OnSucceeded(object? sender, string details) => Succeeded?.Invoke(sender, JsonSerializer.Deserialize(details,
187+
NotificationDetailContext.Default.NodeActionNodeDetail) ?? throw new InvalidCastException());
188+
public event EventHandler<NodeActionNodeDetail>? Failed;
189+
internal void OnFailed(object? sender, string details) => Failed?.Invoke(sender, JsonSerializer.Deserialize(details,
190+
NotificationDetailContext.Default.NodeActionNodeDetail) ?? throw new InvalidCastException());
191+
}
192+
133193
public NextListRegistry NextList { get; } = new();
134194
public sealed class NextListRegistry
135195
{

‎src/MaaFramework.Binding.Native/Interop/AgentClient/MaaAgentClientAPI.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ public static partial class MaaAgentClient
6363
[return: MarshalAs(UnmanagedType.U1)]
6464
public static partial bool MaaAgentClientSetTimeout(MaaAgentClientHandle client, long milliseconds);
6565

66+
[LibraryImport("MaaAgentClient", StringMarshalling = StringMarshalling.Utf8)]
67+
[return: MarshalAs(UnmanagedType.U1)]
68+
public static partial bool MaaAgentClientGetCustomRecognitionList(MaaAgentClientHandle client, MaaStringListBufferHandle buffer);
69+
70+
[LibraryImport("MaaAgentClient", StringMarshalling = StringMarshalling.Utf8)]
71+
[return: MarshalAs(UnmanagedType.U1)]
72+
public static partial bool MaaAgentClientGetCustomActionList(MaaAgentClientHandle client, MaaStringListBufferHandle buffer);
73+
6674
[Obsolete]
6775
[LibraryImport("MaaAgentClient", StringMarshalling = StringMarshalling.Utf8)]
6876
public static partial MaaAgentClientHandle MaaAgentClientCreate();

‎src/MaaFramework.Binding.Native/Interop/Framework/Instance/MaaContext.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,20 @@ public static partial class MaaContext
5050

5151
[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
5252
public static partial MaaContextHandle MaaContextClone(MaaContextHandle context);
53+
54+
[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
55+
[return: MarshalAs(UnmanagedType.U1)]
56+
public static partial bool MaaContextSetAnchor(MaaContextHandle context, string anchorName, string nodeName);
57+
58+
[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
59+
[return: MarshalAs(UnmanagedType.U1)]
60+
public static partial bool MaaContextGetAnchor(MaaContextHandle context, string anchorName, MaaStringBufferHandle buffer);
61+
62+
[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
63+
[return: MarshalAs(UnmanagedType.U1)]
64+
public static partial bool MaaContextGetHitCount(MaaContextHandle context, string nodeName, out MaaSize count);
65+
66+
[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
67+
[return: MarshalAs(UnmanagedType.U1)]
68+
public static partial bool MaaContextClearHitCount(MaaContextHandle context, string nodeName);
5369
}

‎src/MaaFramework.Binding.Native/Interop/Framework/Instance/MaaResource.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,12 @@ public static partial class MaaResource
100100
[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
101101
[return: MarshalAs(UnmanagedType.U1)]
102102
public static partial bool MaaResourceGetNodeList(MaaResourceHandle res, MaaStringListBufferHandle buffer);
103+
104+
[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
105+
[return: MarshalAs(UnmanagedType.U1)]
106+
public static partial bool MaaResourceGetCustomRecognitionList(MaaResourceHandle res, MaaStringListBufferHandle buffer);
107+
108+
[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
109+
[return: MarshalAs(UnmanagedType.U1)]
110+
public static partial bool MaaResourceGetCustomActionList(MaaResourceHandle res, MaaStringListBufferHandle buffer);
103111
}

‎src/MaaFramework.Binding.Native/MaaAgentClient.cs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,30 @@ private void KillAndDisposeAgentServerProcess(bool disposing)
356356
_agentServerProcess = null;
357357
}
358358
}
359+
360+
/// <inheritdoc/>
361+
/// <remarks>
362+
/// Wrapper of <see cref="MaaAgentClientGetCustomRecognitionList"/>.
363+
/// </remarks>
364+
public IList<string> CustomRecognitionList
365+
{
366+
get
367+
{
368+
_ = MaaStringListBuffer.TryGetList(out var list, h => MaaAgentClientGetCustomRecognitionList(Handle, h)).ThrowIfFalse();
369+
return list!;
370+
}
371+
}
372+
373+
/// <inheritdoc/>
374+
/// <remarks>
375+
/// Wrapper of <see cref="MaaAgentClientGetCustomActionList"/>.
376+
/// </remarks>
377+
public IList<string> CustomActionList
378+
{
379+
get
380+
{
381+
_ = MaaStringListBuffer.TryGetList(out var list, h => MaaAgentClientGetCustomActionList(Handle, h)).ThrowIfFalse();
382+
return list!;
383+
}
384+
}
359385
}

‎src/MaaFramework.Binding.Native/MaaContext.cs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,33 @@ IMaaContext IMaaContext.Clone()
136136
/// </remarks>
137137
public MaaContext Clone()
138138
=> new(MaaContextClone(Handle));
139+
140+
/// <inheritdoc/>
141+
/// <remarks>
142+
/// Wrapper of <see cref="MaaContextSetAnchor"/>.
143+
/// </remarks>
144+
public bool SetAnchor(string anchorName, string nodeName)
145+
=> MaaContextSetAnchor(Handle, anchorName, nodeName);
146+
147+
/// <inheritdoc/>
148+
/// <remarks>
149+
/// Wrapper of <see cref="MaaContextGetAnchor"/>.
150+
/// </remarks>
151+
public bool GetAnchor(string anchorName, [MaybeNullWhen(false)] out string nodeName)
152+
=> MaaStringBuffer.TryGetValue(out nodeName, buffer
153+
=> MaaContextGetAnchor(Handle, anchorName, buffer));
154+
155+
/// <inheritdoc/>
156+
/// <remarks>
157+
/// Wrapper of <see cref="MaaContextGetHitCount"/>.
158+
/// </remarks>
159+
public bool GetHitCount(string nodeName, out ulong count)
160+
=> MaaContextGetHitCount(Handle, nodeName, out count);
161+
162+
/// <inheritdoc/>
163+
/// <remarks>
164+
/// Wrapper of <see cref="MaaContextClearHitCount"/>.
165+
/// </remarks>
166+
public bool ClearHitCount(string nodeName)
167+
=> MaaContextClearHitCount(Handle, nodeName);
139168
}

‎src/MaaFramework.Binding.Native/MaaResource.cs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,30 @@ public IList<string> NodeList
344344
return list!;
345345
}
346346
}
347+
348+
/// <inheritdoc/>
349+
/// <remarks>
350+
/// Wrapper of <see cref="MaaResourceGetCustomRecognitionList"/>.
351+
/// </remarks>
352+
public IList<string> CustomRecognitionList
353+
{
354+
get
355+
{
356+
_ = MaaStringListBuffer.TryGetList(out var list, h => MaaResourceGetCustomRecognitionList(Handle, h)).ThrowIfFalse();
357+
return list!;
358+
}
359+
}
360+
361+
/// <inheritdoc/>
362+
/// <remarks>
363+
/// Wrapper of <see cref="MaaResourceGetCustomActionList"/>.
364+
/// </remarks>
365+
public IList<string> CustomActionList
366+
{
367+
get
368+
{
369+
_ = MaaStringListBuffer.TryGetList(out var list, h => MaaResourceGetCustomActionList(Handle, h)).ThrowIfFalse();
370+
return list!;
371+
}
372+
}
347373
}

0 commit comments

Comments
 (0)