Skip to content

Commit 3cfc08d

Browse files
committed
[Breaking change] refactor(IMaaContext): make pipelineOverride an optional trailing parameter
1 parent ca58930 commit 3cfc08d

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

src/MaaFramework.Binding.Native/MaaContext.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public MaaContext(MaaContextHandle contextHandle)
3131
/// <remarks>
3232
/// Wrapper of <see cref="MaaContextRunTask"/>.
3333
/// </remarks>
34-
public TaskDetail? RunTask(string entry, [StringSyntax("Json")] string pipelineOverride)
34+
public TaskDetail? RunTask(string entry, [StringSyntax("Json")] string pipelineOverride = "{}")
3535
{
3636
var taskId = MaaContextRunTask(Handle, entry, pipelineOverride);
3737
return taskId == Interop.Native.MaaDef.MaaInvalidId
@@ -40,14 +40,14 @@ public MaaContext(MaaContextHandle contextHandle)
4040
}
4141

4242
/// <inheritdoc/>
43-
public RecognitionDetail? RunRecognition(string entry, [StringSyntax("Json")] string pipelineOverride, IMaaImageBuffer image)
44-
=> RunRecognition(entry, pipelineOverride, (MaaImageBuffer)image);
43+
public RecognitionDetail? RunRecognition(string entry, IMaaImageBuffer image, [StringSyntax("Json")] string pipelineOverride = "{}")
44+
=> RunRecognition(entry, (MaaImageBuffer)image, pipelineOverride);
4545

4646
/// <inheritdoc cref="IMaaContext.RunRecognition"/>
4747
/// <remarks>
4848
/// Wrapper of <see cref="MaaContextRunRecognition"/>.
4949
/// </remarks>
50-
public RecognitionDetail? RunRecognition(string entry, [StringSyntax("Json")] string pipelineOverride, MaaImageBuffer image)
50+
public RecognitionDetail? RunRecognition(string entry, MaaImageBuffer image, [StringSyntax("Json")] string pipelineOverride = "{}")
5151
{
5252
ArgumentNullException.ThrowIfNull(image);
5353
var recognitionId = MaaContextRunRecognition(Handle, entry, pipelineOverride, image.Handle);
@@ -57,14 +57,14 @@ public MaaContext(MaaContextHandle contextHandle)
5757
}
5858

5959
/// <inheritdoc/>
60-
public NodeDetail? RunAction(string entry, [StringSyntax("Json")] string pipelineOverride, IMaaRectBuffer recognitionBox, string recognitionDetail)
61-
=> RunAction(entry, pipelineOverride, (MaaRectBuffer)recognitionBox, recognitionDetail);
60+
public NodeDetail? RunAction(string entry, IMaaRectBuffer recognitionBox, string recognitionDetail, [StringSyntax("Json")] string pipelineOverride = "{}")
61+
=> RunAction(entry, (MaaRectBuffer)recognitionBox, recognitionDetail, pipelineOverride);
6262

6363
/// <inheritdoc cref="IMaaContext.RunAction"/>
6464
/// <remarks>
6565
/// Wrapper of <see cref="MaaContextRunAction"/>.
6666
/// </remarks>
67-
public NodeDetail? RunAction(string entry, [StringSyntax("Json")] string pipelineOverride, MaaRectBuffer recognitionBox, string recognitionDetail)
67+
public NodeDetail? RunAction(string entry, MaaRectBuffer recognitionBox, string recognitionDetail, [StringSyntax("Json")] string pipelineOverride = "{}")
6868
{
6969
ArgumentNullException.ThrowIfNull(recognitionBox);
7070
var nodeId = MaaContextRunAction(Handle, entry, pipelineOverride, recognitionBox.Handle, recognitionDetail);

src/MaaFramework.Binding.UnitTests/Test_Custom.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public bool Analyze(in IMaaContext context, in AnalyzeArgs args, in AnalyzeResul
4646
#endif
4747
Assert.IsNotNull(cloneContext);
4848
Assert.IsNull(
49-
cloneContext.RunRecognition(DiffEntry, "{}", (IMaaImageBuffer<nint>)args.Image));
49+
cloneContext.RunRecognition(DiffEntry, args.Image));
5050
if (!context.Tasker.IsStateless)
5151
{
5252
Assert.AreSame(
@@ -57,7 +57,7 @@ public bool Analyze(in IMaaContext context, in AnalyzeArgs args, in AnalyzeResul
5757
context.TaskJob.Id, cloneContext.TaskJob.Id);
5858

5959
var recognitionDetail =
60-
context.RunRecognition(DiffEntry, DiffParam, args.Image);
60+
context.RunRecognition(DiffEntry, args.Image, DiffParam);
6161
Assert.IsNotNull(
6262
recognitionDetail?.HitBox);
6363

@@ -106,7 +106,7 @@ public bool Run(in IMaaContext context, in RunArgs args)
106106
Assert.AreNotEqual(Detail, args.RecognitionDetail.Detail);
107107
Assert.AreEqual(Box, $"{args.RecognitionBox.X}{args.RecognitionBox.Y}{args.RecognitionBox.Width}{args.RecognitionBox.Height}");
108108

109-
var nodeDetail = context.RunAction(DiffEntry, DiffParam, args.RecognitionBox, args.RecognitionDetail.Detail);
109+
var nodeDetail = context.RunAction(DiffEntry, args.RecognitionBox, args.RecognitionDetail.Detail, DiffParam);
110110
Assert.IsNotNull(nodeDetail);
111111
return true;
112112
}

src/MaaFramework.Binding/IMaaContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@ public interface IMaaContext : ICloneable
2626
/// <param name="entry">The entry name of the task.</param>
2727
/// <param name="pipelineOverride">The json used to override the pipeline.</param>
2828
/// <returns><see cref="TaskDetail"/> if the operation was executed successfully; otherwise, <see langword="null"/>.</returns>
29-
TaskDetail? RunTask(string entry, [StringSyntax("Json")] string pipelineOverride);
29+
TaskDetail? RunTask(string entry, [StringSyntax("Json")] string pipelineOverride = "{}");
3030

3131
/// <summary>
3232
/// Run a recognition.
3333
/// </summary>
3434
/// <param name="entry">The recognition entry name.</param>
35-
/// <param name="pipelineOverride">The json used to override the pipeline.</param>
3635
/// <param name="image">The image to be recognized.</param>
36+
/// <param name="pipelineOverride">The json used to override the pipeline.</param>
3737
/// <returns><see cref="RecognitionDetail"/> if the operation was executed successfully; otherwise, <see langword="null"/>.</returns>
3838
/// <exception cref="ArgumentNullException"/>
39-
RecognitionDetail? RunRecognition(string entry, [StringSyntax("Json")] string pipelineOverride, IMaaImageBuffer image);
39+
RecognitionDetail? RunRecognition(string entry, IMaaImageBuffer image, [StringSyntax("Json")] string pipelineOverride = "{}");
4040

4141
/// <summary>
4242
/// Run an action.
4343
/// </summary>
4444
/// <param name="entry">The action entry name.</param>
45-
/// <param name="pipelineOverride">The json used to override the pipeline.</param>
4645
/// <param name="recognitionBox">The rect buffer containing current rect in the recognition result.</param>
4746
/// <param name="recognitionDetail">The rect detail in the recognition result.</param>
47+
/// <param name="pipelineOverride">The json used to override the pipeline.</param>
4848
/// <returns><see cref="NodeDetail"/> if the operation was executed successfully; otherwise, <see langword="null"/>.</returns>
4949
/// <exception cref="ArgumentNullException"/>
50-
NodeDetail? RunAction(string entry, [StringSyntax("Json")] string pipelineOverride, IMaaRectBuffer recognitionBox, string recognitionDetail);
50+
NodeDetail? RunAction(string entry, IMaaRectBuffer recognitionBox, [StringSyntax("Json")] string recognitionDetail, [StringSyntax("Json")] string pipelineOverride = "{}");
5151

5252
/// <summary>
5353
/// Override a pipeline.

0 commit comments

Comments
 (0)