rft: Wpf CustomTask序列化 (#12264)

This commit is contained in:
status102
2025-04-07 22:50:16 +08:00
committed by GitHub
parent 768c0e289a
commit b508d9e306
4 changed files with 52 additions and 26 deletions

View File

@@ -2208,19 +2208,12 @@ namespace MaaWpfGui.Main
public bool AsstStartGacha(bool once = true)
{
var taskParams = new JObject
var task = new AsstCustomTask()
{
["task_names"] = new JArray
{
once ? "GachaOnce" : "GachaTenTimes",
// TEST
// "Block",
},
CustomTasks = [once ? "GachaOnce" : "GachaTenTimes"],
};
AsstTaskId id = AsstAppendTaskWithEncoding(AsstTaskType.Custom, taskParams);
_taskStatus.Add(id, TaskType.Gacha);
return id != 0 && AsstStart();
var (type, param) = task.Serialize();
return AsstAppendTaskWithEncoding(TaskType.Gacha, type, param) && AsstStart();
}
public bool AsstStartVideoRec(string filename)

View File

@@ -0,0 +1,30 @@
// <copyright file="AsstCustomTask.cs" company="MaaAssistantArknights">
// MaaWpfGui - A part of the MaaCoreArknights project
// Copyright (C) 2021 MistEO and Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License v3.0 only as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY
// </copyright>
#nullable enable
using System.Collections.Generic;
using MaaWpfGui.Services;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace MaaWpfGui.Models.AsstTasks;
public class AsstCustomTask : AsstBaseTask
{
public override AsstTaskType TaskType => AsstTaskType.Custom;
[JsonProperty("task_names")]
public List<string> CustomTasks { get; set; } = [];
public override (AsstTaskType TaskType, JObject Params) Serialize() => (AsstTaskType.Custom, JObject.FromObject(this));
}

View File

@@ -1347,8 +1347,11 @@ namespace MaaWpfGui.ViewModels.UI
break;
case "Custom":
taskRet &= AppendCustom();
break;
{
var (type, param) = CustomTask.Serialize();
taskRet &= Instances.AsstProxy.AsstAppendTaskWithEncoding(AsstProxy.TaskType.Reclamation, type, param);
break;
}
default:
--count;
@@ -1757,18 +1760,6 @@ namespace MaaWpfGui.ViewModels.UI
return Instances.AsstProxy.AsstAppendTaskWithEncoding(AsstProxy.TaskType.Reclamation, type, param);
}
private static bool AppendCustom()
{
var taskParams = new JObject
{
["task_names"] = new JArray
{
CustomTask.TaskName,
},
};
return Instances.AsstProxy.AsstAppendTaskWithEncoding(AsstProxy.TaskType.Custom, AsstTaskType.Custom, taskParams);
}
/// <summary>
/// Gets a value indicating whether it is initialized.
/// </summary>

View File

@@ -1,4 +1,4 @@
// <copyright file="ReclamationSettingsUserControlModel.cs" company="MaaAssistantArknights">
// <copyright file="CustomSettingsUserControlModel.cs" company="MaaAssistantArknights">
// MaaWpfGui - A part of the MaaCoreArknights project
// Copyright (C) 2021 MistEO and Contributors
//
@@ -13,6 +13,9 @@
#nullable enable
using MaaWpfGui.Constants;
using MaaWpfGui.Helper;
using MaaWpfGui.Models.AsstTasks;
using MaaWpfGui.Services;
using Newtonsoft.Json.Linq;
namespace MaaWpfGui.ViewModels.UserControl.TaskQueue;
@@ -36,4 +39,13 @@ public class CustomSettingsUserControlModel : TaskViewModel
ConfigurationHelper.SetGlobalValue(ConfigurationKeys.DebugTaskName, value);
}
}
public override (AsstTaskType Type, JObject Params) Serialize()
{
var task = new AsstCustomTask()
{
CustomTasks = { TaskName },
};
return task.Serialize();
}
}