-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathPrototypeCreation.ps1
More file actions
105 lines (89 loc) · 3.46 KB
/
Copy pathPrototypeCreation.ps1
File metadata and controls
105 lines (89 loc) · 3.46 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
93
94
95
96
97
98
99
100
101
102
103
104
105
# This script looks for prototypes created in data-updates or data-final-fixes.
# ==============================
# CONFIGURATION
# ==============================
$sourcePath = $PSScriptRoot
$scanned = @{}
# ==============================
# FUNCTIONS
# ==============================
function Scan-LuaFile($filePath, $modFolder) {
if ($scanned[$filePath]) { return @() }
$scanned[$filePath] = $true
if (!(Test-Path $filePath)) { return @() }
$lines = Get-Content $filePath
$entities = @()
for ($i = 0; $i -lt $lines.Length; $i++) {
$line = $lines[$i]
# Follow require("...") calls
if ($line -match 'require\(["'']([^"'']+)["'']\)') {
$reqPath = $matches[1] -replace '\.', '\\'
$reqFile = Join-Path $modFolder ($reqPath + ".lua")
$entities += Scan-LuaFile $reqFile $modFolder
}
# ------------------------------
# data:extend block
# ------------------------------
if ($line -match 'data:extend\s*\(\s*{') {
$blockLines = @()
$braceCount = 1
$j = $i + 1
while ($j -lt $lines.Length -and $braceCount -gt 0) {
$l = $lines[$j]
$blockLines += $l
$braceCount += ($l -split '{').Count - 1
$braceCount -= ($l -split '}').Count - 1
$j++
}
# Capture all objects with "type" and "name"
$inObject = $false
$skipChildren = $false
$skipBraceCount = 0
foreach ($l in $blockLines) {
# Detect start of ingredients/results block
if (-not $skipChildren -and $l -match '^\s*(ingredients|results)\s*=\s*{') {
$skipChildren = $true
# Count initial { in this line
$skipBraceCount = ($l -split '{').Count - 1
$skipBraceCount -= ($l -split '}').Count - 1
continue
}
# If skipping, track braces until block ends
if ($skipChildren) {
$skipBraceCount += ($l -split '{').Count - 1
$skipBraceCount -= ($l -split '}').Count - 1
if ($skipBraceCount -le 0) {
$skipChildren = $false
}
continue
}
# Normal object parsing
if ($l -match 'type\s*=\s*"([^"]+)"') {
$currentType = $matches[1]
$inObject = $true
}
if ($inObject -and $l -match 'name\s*=\s*"([^"]+)"') {
$currentName = $matches[1]
$entities += "${currentType}: ${currentName}"
$inObject = $false
}
}
}
}
return $entities
}
# ==============================
# MAIN
# ==============================
# Scan all mods: data-updates.lua and data-final-fixes.lua recursively
$files = @()
$files += Get-ChildItem -Path $sourcePath -Recurse -Filter "data-updates.lua" -File
$files += Get-ChildItem -Path $sourcePath -Recurse -Filter "data-final-fixes.lua" -File
foreach ($file in $files) {
$modFolder = Split-Path $file.Directory -Leaf
$entities = Scan-LuaFile $file.FullName $modFolder
if ($entities.Count -gt 0) {
Write-Output "`n-----$modFolder-----"
$entities | Sort-Object -Unique | ForEach-Object { Write-Output $_ }
}
}