-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLabelTracker.cs
More file actions
53 lines (42 loc) · 1.38 KB
/
LabelTracker.cs
File metadata and controls
53 lines (42 loc) · 1.38 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
using System.Collections.Generic;
using Diz.Core.Interfaces;
using Diz.LogWriter.util;
namespace Diz.LogWriter;
public class LabelTracker
{
private readonly ILogCreatorForGenerator logCreator;
public ILogCreatorDataSource<IData> Data => logCreator?.Data;
public List<int> VisitedLabelSnesAddresses { get; } = new();
private Dictionary<int, IReadOnlyLabel> cachedUnvisitedLabels;
public LabelTracker(ILogCreatorForGenerator logCreator)
{
this.logCreator = logCreator;
}
public Dictionary<int, IReadOnlyLabel> UnvisitedLabels
{
get
{
CacheUnvisitedLabels();
return cachedUnvisitedLabels;
}
}
public void OnLabelVisited(int snesAddress)
{
VisitedLabelSnesAddresses.Add(snesAddress);
cachedUnvisitedLabels = null;
}
private void CacheUnvisitedLabels()
{
if (cachedUnvisitedLabels != null) // pretty sure this is the right thing to do?
return;
cachedUnvisitedLabels = new Dictionary<int, IReadOnlyLabel>();
if (VisitedLabelSnesAddresses == null)
return;
foreach (var (snesAddress, label) in Data.Labels.Labels)
{
if (VisitedLabelSnesAddresses.Contains(snesAddress))
continue;
cachedUnvisitedLabels.Add(snesAddress, label);
}
}
}