-
Notifications
You must be signed in to change notification settings - Fork 22
/
LineWatcher.cs
101 lines (92 loc) · 3.06 KB
/
LineWatcher.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
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
// Decompiled with JetBrains decompiler
// Type: ImprovedPublicTransport.LineWatcher
// Assembly: ImprovedPublicTransport, Version=1.0.6177.17409, Culture=neutral, PublicKeyToken=null
// MVID: 76F370C5-F40B-41AE-AA9D-1E3F87E934D3
// Assembly location: C:\Games\Steam\steamapps\workshop\content\255710\424106600\ImprovedPublicTransport.dll
using ColossalFramework;
using System.Collections.Generic;
using ImprovedPublicTransport2.OptionsFramework;
using ImprovedPublicTransport2.Data;
using ImprovedPublicTransport2.Util;
using UnityEngine;
namespace ImprovedPublicTransport2
{
public class LineWatcher : MonoBehaviour
{
private HashSet<ushort> _knownLines = new HashSet<ushort>();
public static LineWatcher instance;
private bool _initialized;
public int KnownLineCount
{
get
{
return this._knownLines.Count;
}
}
public int SimulationLineCount
{
get
{
return Mathf.Max(0, Singleton<TransportManager>.instance.m_lineCount - 1);
}
}
private void Awake()
{
LineWatcher.instance = this;
}
private void Update()
{
if (!this._initialized)
return;
if (this.SimulationLineCount > this.KnownLineCount)
{
Array16<TransportLine> lines = Singleton<TransportManager>.instance.m_lines;
for (ushort lineID = 0; (uint) lineID < lines.m_size; ++lineID)
{
if (LineWatcher.IsValid(ref lines.m_buffer[(int) lineID]) && this._knownLines.Add(lineID))
{
CachedTransportLineData.SetLineDefaults(lineID);
DepotUtil.AutoAssignLineDepot( lineID, out var position);
if (OptionsWrapper<Settings.Settings>.Options.ShowLineInfo &&
lines.m_buffer[(int) lineID].Info?.m_class?.m_service != ItemClass.Service.Disaster)
WorldInfoPanel.Show<PublicTransportWorldInfoPanel>(position, new InstanceID()
{
TransportLine = lineID
});
}
}
}
else
{
if (this.SimulationLineCount >= this.KnownLineCount)
return;
Array16<TransportLine> lines = Singleton<TransportManager>.instance.m_lines;
for (ushort lineID = 0; (uint) lineID < lines.m_size; ++lineID)
{
if (!LineWatcher.IsValid(ref lines.m_buffer[(int) lineID]))
this._knownLines.Remove(lineID);
}
}
}
private void OnDestroy()
{
LineWatcher.instance = (LineWatcher) null;
}
public void Init()
{
Array16<TransportLine> lines = Singleton<TransportManager>.instance.m_lines;
for (ushort index = 0; (uint) index < lines.m_size; ++index)
{
if (LineWatcher.IsValid(ref lines.m_buffer[(int) index]))
this._knownLines.Add(index);
}
this._initialized = true;
}
private static bool IsValid(ref TransportLine line)
{
if ((line.m_flags & TransportLine.Flags.Complete) != TransportLine.Flags.None)
return (line.m_flags & TransportLine.Flags.Temporary) == TransportLine.Flags.None;
return false;
}
}
}