-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoMapStateListener.cs
More file actions
42 lines (36 loc) · 1.1 KB
/
AutoMapStateListener.cs
File metadata and controls
42 lines (36 loc) · 1.1 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
using Bindito.Core;
using Timberborn.Automation;
using Timberborn.BaseComponentSystem;
namespace Calloatti.AutoTools
{
// FIX: Added IAwakableComponent so Timberborn actually calls Awake()
public class AutoMapStateListener : BaseComponent, IAwakableComponent, IAutomatorListener
{
private AutoMapService _autoMapService;
private Automator _automator;
[Inject]
public void InjectDependencies(AutoMapService autoMapService)
{
_autoMapService = autoMapService;
}
public void Awake()
{
_automator = GetComponent<Automator>();
}
public void OnAutomatorStateChanged()
{
// 1. Guard against volatile loading phases. Completely ignore until PostLoad finishes!
if (_autoMapService == null || !_autoMapService.IsReady)
{
return;
}
// 2. Defensive check just in case, and verify it's a transmitter
if (_automator == null || !_automator.IsTransmitter)
{
return;
}
// Tell the global service to update the lines for this specific building
_autoMapService.UpdateLineColors(_automator);
}
}
}