Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复:自动广播初始配置文件的问题 #508

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions src/AutoBroadcast/ABConfig.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Newtonsoft.Json;
using System.IO;

namespace AutoBroadcast;

public class ABConfig
{
[JsonProperty("广播列表")]
public Broadcast[] Broadcasts = new Broadcast[0];
public Broadcast[] Broadcasts { get; set; } = new Broadcast[0];

public ABConfig Write(string file)
{
Expand All @@ -17,47 +18,51 @@ public static ABConfig Read(string file)
{
if (!File.Exists(file))
{
ABConfig.WriteExample(file);
WriteExample(file);
}
return JsonConvert.DeserializeObject<ABConfig>(File.ReadAllText(file)) ?? new();
return JsonConvert.DeserializeObject<ABConfig>(File.ReadAllText(file)) ?? new ABConfig();
}

public static void WriteExample(string file)
{

File.WriteAllText(file, JsonConvert.SerializeObject(new Broadcast[]
var exampleConfig = new ABConfig
{
new Broadcast()
Broadcasts = new[]
{
Name = "示例广播",
Enabled = true,
Messages = new string[] { "/time 4:30", "设置时间为4:30" },
ColorRGB = new float[] { 255, 234, 115 },
Interval = 600,
new Broadcast
{
Name = "示例广播",
Enabled = true,
Messages = new string[] { "/time 4:30", "设置时间为4:30" },
ColorRGB = new float[] { 255, 234, 115 },
Interval = 600,
}
}
}, Formatting.Indented));
};

File.WriteAllText(file, JsonConvert.SerializeObject(exampleConfig, Formatting.Indented));
ACaiCat marked this conversation as resolved.
Show resolved Hide resolved
}
}

public class Broadcast
{
[JsonProperty("广播名称")]
public string Name = string.Empty;
public string Name { get; set; } = string.Empty;

[JsonProperty("启用")]
public bool Enabled = false;
public bool Enabled { get; set; } = false;

[JsonProperty("广播消息")]
public string[] Messages = new string[0];
public string[] Messages { get; set; } = new string[0];

[JsonProperty("RGB颜色")]
public float[] ColorRGB = new float[3];
public float[] ColorRGB { get; set; } = new float[3];

[JsonProperty("时间间隔")]
public int Interval = 0;
public int Interval { get; set; } = 0;

[JsonProperty("延迟执行")]
public int StartDelay = 0;
public int StartDelay { get; set; } = 0;

[JsonProperty("广播组")]
public string[] Groups { get; set; } = new string[0];
Expand Down
2 changes: 1 addition & 1 deletion src/AutoBroadcast/AutoBroadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class AutoBroadcast : TerrariaPlugin
public override string Name => "AutoBroadcast";
public override string Author => "Scavenger";
public override string Description => "自动广播插件";
public override Version Version => new Version(1, 0, 5);
public override Version Version => new Version(1, 0, 6);
public string ConfigPath => Path.Combine(TShock.SavePath, "AutoBroadcastConfig.json");
public ABConfig Config = new ABConfig();
public DateTime LastCheck = DateTime.UtcNow;
Expand Down
2 changes: 2 additions & 0 deletions src/AutoBroadcast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
## 更新日志

```
v1.0.6
修复了初始配置文件的问题
v1.0.5
i18n 和 README_EN.md
v1.0.4
Expand Down
Loading