feat: add pattern alias mode to crafting shortcode
This commit is contained in:
+21
-6
@@ -77,16 +77,31 @@ try {
|
||||
Write-Step '2/4 扫描组件物品 id'
|
||||
$ids = @{}
|
||||
$shortcodePat = [regex]'(?s){{<[ ]*crafting\b(.*?)}}'
|
||||
$paramPat = [regex]'(?:a[123]|b[123]|c[123]|out)="([^"]*)"'
|
||||
$pairPat = [regex]'(\w+)="([^"]*)"'
|
||||
$slotKeys = @('a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3', 'out')
|
||||
|
||||
function Add-ItemId([string]$raw) {
|
||||
$v = $raw.Trim()
|
||||
if ($v.Length -gt 0) {
|
||||
$id = ($v -split ':')[0].Trim()
|
||||
if ($id.Length -gt 0) { $ids[$id] = $true }
|
||||
}
|
||||
}
|
||||
|
||||
Get-ChildItem -Path $contentDir -Recurse -Filter '*.md' -File | ForEach-Object {
|
||||
$text = Get-Content -LiteralPath $_.FullName -Raw -Encoding UTF8
|
||||
foreach ($m in $shortcodePat.Matches($text)) {
|
||||
foreach ($p in $paramPat.Matches($m.Groups[1].Value)) {
|
||||
$val = $p.Groups[1].Value.Trim()
|
||||
if ($val.Length -gt 0) {
|
||||
$id = ($val -split ':')[0].Trim()
|
||||
if ($id.Length -gt 0) { $ids[$id] = $true }
|
||||
$params = @{}
|
||||
foreach ($p in $pairPat.Matches($m.Groups[1].Value)) { $params[$p.Groups[1].Value] = $p.Groups[2].Value }
|
||||
foreach ($key in $slotKeys) {
|
||||
if ($params.ContainsKey($key)) { Add-ItemId $params[$key] }
|
||||
}
|
||||
if ($params.ContainsKey('pattern')) {
|
||||
$pat = $params['pattern'] -replace '\\n|;|\r?\n', ' '
|
||||
foreach ($tok in @($pat -split '\s+' | Where-Object { $_ })) {
|
||||
if ($tok -eq '.') { continue }
|
||||
if ($params.ContainsKey($tok)) { Add-ItemId $params[$tok] }
|
||||
elseif ($tok -match '^[a-z0-9_]+$') { Add-ItemId $tok }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user