-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookmarksMod.cs
More file actions
190 lines (173 loc) · 5.87 KB
/
BookmarksMod.cs
File metadata and controls
190 lines (173 loc) · 5.87 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using HarmonyLib;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.InputSystem;
using CommonModNS;
namespace BookmarksModNS
{
public enum ModifierKey { SHIFT, CONTROL, ALT }
public partial class BookmarksMod : Mod
{
public static BookmarksMod instance;
public static void Log(string msg) => instance.Logger.Log(msg);
public Board CurrentBoard { get; private set; }
public Dictionary<string, Board> boards = new();
// CONFIG Helpers
public static ModifierKey ModifierKey
{
get => instance?.modifierKey.Value ?? ModifierKey.SHIFT;
private set
{
if (instance?.modifierKey != null)
instance.modifierKey.Value = value;
}
}
public static bool JumpToZero
{
get => instance?.jumpToZero.Value ?? false;
private set
{
if (instance?.jumpToZero != null)
instance.jumpToZero.Value = value;
}
}
private ConfigToggledEnum<ModifierKey> modifierKey;
private ConfigEntryBool jumpToZero;
private void SetupConfiguration()
{
RuntimePlatform platform = Application.platform;
modifierKey = new("bookmarksmod_modifierkey", Config, ModifierKey.SHIFT, new ConfigUI()
{
NameTerm = "bookmarksmod_modifierkey",
TooltipTerm = "bookmarksmod_modifierkey_tooltip",
OnUI = delegate (ConfigEntryBase b)
{
if (Config.Data.TryGetValue("bookmarksmod_config_cntrl", out JToken oldValue))
{
if (oldValue.HasValues && oldValue.Value<bool>())
{
modifierKey.Value = ModifierKey.CONTROL;
Config.Data.Remove("bookmarksmod_config_cntrl");
}
}
}
})
{
currentValueColor = Color.blue,
onDisplayEnumText = delegate (ModifierKey value)
{
string plat = platform == RuntimePlatform.OSXPlayer ? "mac" : "win";
return I.Xlat($"bookmarksmod_modifier_{value}_{plat}");
}
};
jumpToZero = new("bookmarksmod_jumptozero", Config, false, new()
{
NameTerm = "bookmarksmod_jumptozero",
TooltipTerm = "bookmarksmod_jumptozero_tooltip"
})
{
currentValueColor = Color.blue
};
Config.OnSave = ApplyConfig;
}
private void ApplyConfig()
{
ShiftKeys.Reset();
ShiftKeys.defaultMode = modifierKey.Value;
}
public PlayList playList = new PlayList();
//private Task<int> audioCount;
private void LoadAudio()
{
int audioCount = playList.Start(Path + "\\Sounds");
}
private void Awake()
{
instance = this;
Log($"Path = {Path}");
LoadAudio();
SetupConfiguration();
WorldManagerPatches.GetSaveRound += WM_OnSave;
WorldManagerPatches.LoadSaveRound += WM_OnLoad;
WorldManagerPatches.StartNewRound += WM_OnNewGame;
WorldManagerPatches.Update += WM_Update;
WorldManagerPatches.ApplyPatches(Harmony);
Log("Calling Harmony.PatchAll()");
Harmony.PatchAll();
}
public override void Ready()
{
instance = this;
ApplyConfig();
Log($"Set mark using {ShiftKeys.defaultMode}");
// audioCount.Wait();
// Log($"Count = {audioCount.Result}");
Log($"Ready!");
}
public void SetBoard(string id)
{
Log($"SetBoard({id})");
if (boards.TryGetValue(id, out Board board))
{
CurrentBoard = board;
if (JumpToZero)
{
CurrentBoard.UpdateKeys();
PanAndZoom paz = board.marks.FirstOrDefault(x => x.key == Key.Digit0);
//Log($"SetBoard {(paz != null ? paz.zoom.ToString() : "null")}");
paz?.Jump();
}
}
else
{
boards[id] = CurrentBoard = new Board() { Id = id };
}
}
private readonly static List<string> traces = new List<string>();
private void WM_Update(WorldManager _)
{
foreach (string s in traces)
Log(s);
traces.Clear();
if (!String.IsNullOrEmpty(GoToBoard) && !TransitionScreen.InTransition && !I.WM.InAnimation)
{
SetBoard(GoToBoard);
GoToBoard = null;
}
}
public void Trace(string msg)
{
traces.Add(msg);
}
}
[JsonObject(MemberSerialization.OptIn)]
public class SaveMod
{
[JsonProperty]
#pragma warning disable 414
private int version = 1;
#pragma warning restore 414
[JsonProperty]
public List<SaveBoard> boards = new();
public SaveMod(Dictionary<string, Board> realBoards)
{
if (realBoards == null) return;
foreach (string key in realBoards.Keys)
{
boards.Add(new SaveBoard(realBoards[key]));
}
}
public Dictionary<string, Board> ToMod()
{
Dictionary<string, Board> realBoards = new();
foreach (SaveBoard sb in boards)
{
realBoards[sb.id] = sb.ToBoard();
}
return realBoards;
}
}
}