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