-
Notifications
You must be signed in to change notification settings - Fork 0
/
Save.cs
60 lines (48 loc) · 1.4 KB
/
Save.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Collections.Generic;
using System.IO;
using Tomlet;
using Tomlet.Attributes;
using UnityEngine;
namespace QuickSwitchCombination;
public class Data
{
[TomlPrecedingComment("The character index")]
internal int Character;
[TomlPrecedingComment("The elfin index")]
internal int Elfin;
[TomlPrecedingComment("The shortcut key for switching character")]
internal KeyCode Key;
// For toml deserialization
public Data()
{
}
public Data(int character, int elfin, KeyCode key)
{
Character = character;
Elfin = elfin;
Key = key;
}
}
public struct Config
{
[TomlPrecedingComment("Menu for adding settings")]
internal KeyCode MenuKey { get; set; } = KeyCode.F11;
internal List<Data> Data { get; set; } = new() { new Data(11, 7, KeyCode.F12) };
public Config()
{
}
}
public static class Save
{
internal static Config Settings { get; private set; }
internal static void Load()
{
if (!File.Exists(Path.Combine("UserData", "QuickSwitchCombination.cfg")))
{
var defaultConfig = TomletMain.TomlStringFrom(new Config());
File.WriteAllText(Path.Combine("UserData", "QuickSwitchCombination.cfg"), defaultConfig);
}
var configs = File.ReadAllText(Path.Combine("UserData", "QuickSwitchCombination.cfg"));
Settings = TomletMain.To<Config>(configs);
}
}