Skip to content

Commit 5415935

Browse files
committed
回退AnalyzeVictoryPoints逻辑
1 parent 1a492c4 commit 5415935

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

VModer.Core/Analyzers/StateAnalyzerService.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public List<Diagnostic> Analyze(Node node, string filePath)
5050
return list;
5151
}
5252

53-
AnalyzeVictoryPoints(filePath, historyNode, list);
53+
AnalyzeVictoryPoints(stateNode, historyNode, list);
5454
AnalyzeBuildings(historyNode, list);
5555

5656
return list;
5757
}
5858

59-
private void AnalyzeVictoryPoints(string filePath, Node historyNode, List<Diagnostic> list)
59+
private void AnalyzeVictoryPoints(Node stateNode, Node historyNode, List<Diagnostic> list)
6060
{
6161
var victoryPoints = new List<(VictoryPoint, Position.Range)>();
6262
foreach (
@@ -89,15 +89,25 @@ var item in historyNode.Nodes.Where(node =>
8989
return;
9090
}
9191

92-
if (!_statesProvincesMapService.TryGetProvinces(filePath, out int[]? provinceIds))
92+
if (!stateNode.TryGetNode("provinces", out var provincesNode))
9393
{
94-
provinceIds = [];
94+
return;
9595
}
9696

97-
var provinceIdsSpan = provinceIds.AsSpan();
97+
// 手动解析而不是调用 StatesProvincesMapService 是为了防止无法获取用户缓冲区中对provinces的修改.
98+
var provinceIds = provincesNode
99+
.LeafValues.AsValueEnumerable()
100+
.Where(leafValue => leafValue.Value.IsInt)
101+
.Select(leafValue =>
102+
{
103+
leafValue.Value.TryGetInt(out int id);
104+
return id;
105+
})
106+
.ToHashSet();
107+
98108
foreach (var (victoryPoint, range) in victoryPoints)
99109
{
100-
if (!provinceIdsSpan.Contains(victoryPoint.ProvinceId))
110+
if (!provinceIds.Contains(victoryPoint.ProvinceId))
101111
{
102112
list.Add(
103113
new Diagnostic

0 commit comments

Comments
 (0)