-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatchLoadSaveRound.cs
More file actions
69 lines (65 loc) · 2.31 KB
/
PatchLoadSaveRound.cs
File metadata and controls
69 lines (65 loc) · 2.31 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
using System;
using System.Collections.Generic;
using System.Text;
using HarmonyLib;
using Newtonsoft.Json;
using CommonModNS;
using UnityEngine.InputSystem;
using System.Collections;
namespace BookmarksModNS
{
public partial class BookmarksMod : Mod
{
private void WM_OnLoad(WorldManager wm, SaveRound saveRound)
{
try
{
SerializedKeyValuePair pair = SerializedKeyValuePairHelper.GetWithKey(saveRound.ExtraKeyValues, "blueprintmod_runtime");
if (pair != null)
{
Log($"LoadSaveRound Save Data:\r\n{pair.Value}");
boards = JsonConvert.DeserializeObject<SaveMod>(pair.Value)!.ToMod();
Log($"LoadSaveRound Save Data Loaded");
}
}
catch (Exception e)
{
Log($"SaveModData encountered an exception {e.Message}");
Log(e.StackTrace);
}
Log("LoadSaveRound calling SetBoard");
GoToBoard = wm.CurrentBoard.Id;
}
/// <summary>
/// Set in GoToBoard_Patch. Executed here as GoToBoard calls GetSaveRound.
/// Easier to do this than to patch a delegate function
/// </summary>
public string GoToBoard = null;
private void WM_OnSave(WorldManager wm, SaveRound saveRound)
{
try
{
JsonSerializer serializer = new JsonSerializer();
serializer.NullValueHandling = NullValueHandling.Include;
using (TextWriter tw = new StringWriter())
{
using (JsonWriter writer = new JsonTextWriter(tw))
{
serializer.Serialize(writer, new SaveMod(boards));
}
Log($"GetSaveRound Save Data:\r\n{tw}");
SerializedKeyValuePairHelper.SetOrAdd(saveRound.ExtraKeyValues, "blueprintmod_runtime", tw.ToString());
}
}
catch (Exception e)
{
Log($"LoadModData encountered an exception\r\n{e.StackTrace}");
}
}
private void WM_OnNewGame(WorldManager wm)
{
boards = new();
GoToBoard = global::Board.Mainland;
}
}
}