Repository navigation
Expand file tree
/
Copy pathMod.cs
More file actions
92 lines (73 loc) · 3.28 KB
/
Copy pathMod.cs
File metadata and controls
92 lines (73 loc) · 3.28 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
using Colossal.IO.AssetDatabase;
using Colossal.Logging;
using Game;
using Game.Input;
using Game.Modding;
using Game.SceneFlow;
using HarmonyLib;
using System;
using System.Linq;
using SkylinesMaps.Systems;
namespace SkylinesMaps
{
public class Mod : IMod
{
public static ILog log = LogManager.GetLogger($"{nameof(SkylinesMaps)}").SetShowsErrorsInUI(false);
public const string kToggleInfoviewActionName = "ToggleTrafficInfoview";
public const string kHarmonyId = "Azsaidi." + nameof(SkylinesMaps);
public static ModSettings Settings { get; private set; }
public static ProxyAction ToggleInfoviewAction { get; private set; }
private Harmony m_Harmony;
public void OnLoad(UpdateSystem updateSystem)
{
log.Info(nameof(OnLoad));
if (GameManager.instance.modManager.TryGetExecutableAsset(this, out var asset))
log.Info($"Current mod asset at {asset.path}");
Settings = new ModSettings(this);
Settings.RegisterInOptionsUI();
GameManager.instance.localizationManager.AddSource("en-US", new LocaleEN(Settings));
Settings.RegisterKeyBindings();
ToggleInfoviewAction = Settings.GetAction(kToggleInfoviewActionName);
ToggleInfoviewAction.shouldBeEnabled = true;
AssetDatabase.global.LoadSettings(nameof(SkylinesMaps), Settings, new ModSettings(this));
PatchTrafficFlowChart();
updateSystem.UpdateAt<CongestionInfomodeSystem>(SystemUpdatePhase.UIUpdate);
// Must run after NetColorSystem, which rewrites every EdgeColor each rendering frame.
updateSystem.UpdateAfter<LiveCongestionSystem, Game.Rendering.NetColorSystem>(SystemUpdatePhase.Rendering);
updateSystem.UpdateAt<CityFlowUISystem>(SystemUpdatePhase.UIUpdate);
updateSystem.UpdateAt<TrafficInfoviewToggleSystem>(SystemUpdatePhase.UIUpdate);
updateSystem.UpdateAt<JourneyPlannerSystem>(SystemUpdatePhase.Modification2);
updateSystem.UpdateAt<JourneyPlannerUISystem>(SystemUpdatePhase.UIUpdate);
updateSystem.UpdateAt<JourneyLabelSystem>(SystemUpdatePhase.UIUpdate);
updateSystem.UpdateBefore<JourneyMarkerSystem, Game.Rendering.OverlayRenderSystem>(SystemUpdatePhase.Rendering);
updateSystem.UpdateAt<JourneyTooltipSystem>(SystemUpdatePhase.UITooltip);
}
private void PatchTrafficFlowChart()
{
try
{
m_Harmony = new Harmony(kHarmonyId);
m_Harmony.PatchAll(typeof(Mod).Assembly);
log.Info($"Patched traffic flow chart ({m_Harmony.GetPatchedMethods().Count()} method(s))");
}
catch (Exception e)
{
log.Warn($"Could not patch the traffic flow chart, it will keep the vanilla data: {e.Message}");
}
}
public void OnDispose()
{
log.Info(nameof(OnDispose));
if (m_Harmony != null)
{
m_Harmony.UnpatchAll(kHarmonyId);
m_Harmony = null;
}
if (Settings != null)
{
Settings.UnregisterInOptionsUI();
Settings = null;
}
}
}
}