Files
2026-10-24 13:02:19 +08:00

42 lines
1.4 KiB
C#

using System.Text.Json;
namespace anjianjingling.Lua
{
/// <summary>任务列表中的一个脚本任务。</summary>
public sealed class LuaTask
{
public string Name { get; set; } = "新任务";
public bool Enabled { get; set; } = true;
/// <summary>true=无限循环(会阻塞后续任务,需手动停止)。</summary>
public bool Infinite { get; set; } = false;
public int LoopCount { get; set; } = 1;
public int IntervalMs { get; set; } = 1000;
public string Script { get; set; } = "";
/// <summary>积木画布 JSON(有内容时优先于脚本)。</summary>
public string Blocks { get; set; } = "";
/// <summary>启动热键(如 F8),空表示不绑定。</summary>
public string Hotkey { get; set; } = "";
public string Source { get; set; } = "";
public string ModeText => Infinite ? "无限循环" : $"{LoopCount} 次";
public override string ToString() => Name;
}
/// <summary>任务列表 JSON 读写(.ajt)。</summary>
public static class LuaTaskFile
{
private static readonly JsonSerializerOptions Opt = new() { WriteIndented = true };
public static string ToJson(IEnumerable<LuaTask> tasks) => JsonSerializer.Serialize(tasks, Opt);
public static List<LuaTask> FromJson(string json)
=> JsonSerializer.Deserialize<List<LuaTask>>(json) ?? new();
}
}