Skip to content

Commit 7681b36

Browse files
committed
ur welcom lyra
1 parent bb0425b commit 7681b36

File tree

2 files changed

+80
-42
lines changed

2 files changed

+80
-42
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ A collection of PowerShell scripts to make a few niche things in the 5eTools pro
44

55
- [How2PowerShell](#how2powershell)
66
- [The scripts](#the-scripts)
7-
- [Creature Fluff Tagger](#creature-fluff-tagger)
87
- [Creature Imager](#creature-imager)
98
- [Entries Tagger](#entries-tagger)
9+
- [Fluff Tagger](#fluff-tagger)
1010
- [Homebrew Merger](#homebrew-merger)
1111
- [Mask Rescaler](#mask-rescaler)
1212
- [Tag Checker](#tag-checker)
@@ -23,10 +23,6 @@ Otherwise, you'll need to [install](https://learn.microsoft.com/en-us/powershell
2323

2424
## The scripts
2525

26-
### Creature Fluff Tagger
27-
28-
This script adds the `hasFluff` and `hasFluffImages` properties, as appropriate, to creatures with a referenced `_monsterFluff` object.
29-
3026
### Creature Imager
3127

3228
This script applies images and tokens to a brew file in bulk by reading from a `.csv` file. Useful for creature-heavy conversions and art updates.
@@ -35,6 +31,10 @@ This script applies images and tokens to a brew file in bulk by reading from a `
3531

3632
This script looks throughout a brew file for `entries`-like properties, and then proceeds to (try to) automatically tag things.
3733

34+
### Fluff Tagger
35+
36+
This script adds the `hasFluff` and `hasFluffImages` properties, as appropriate, to (most) datatypes with a referenced `_<datatype>Fluff` object.
37+
3838
### Homebrew Merger
3939

4040
This script stitches 5eTools-style homebrew JSONs together to output a single JSON with all the content included, saving you having to lug around many files at once.

creature-fluff-tagger.ps1 renamed to fluff-tagger.ps1

Lines changed: 75 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
# 5eTools Creature Fluff Tagger
1+
# 5eTools Fluff Tagger
22
# =============================
33
#
4-
# On the bestiary page, you will find the "Has Info" and "Has Images" filters under the Miscellaneous category. A
5-
# creature satisfies this filter if it either has the appropriate object in its `fluff` object, or if it has the
6-
# `hasFluff` or `hasFluffImages` properties respectively. For creatures with a referenced `_monsterFluff` object in
7-
# its fluff, this necessitates the last two properties (as appropriate).
4+
# On some list pages, you will find the "Has Info" and "Has Images" filters under the Miscellaneous category. A
5+
# statblock satisfies this filter if it either has the appropriate object in its `fluff` object, or if it has the
6+
# `hasFluff` or `hasFluffImages` properties respectively. For statblocks with a referenced `_<datatype>Fluff`
7+
# object in its fluff, this necessitates the last two properties (as appropriate).
88
#
99
# This script looks through a JSON file, or recursively scans a directory for JSON files, and then inspects each
10-
# creature. If that creature has a `_monsterFluff` object referencing some fluff *in the same file*, this script
11-
# will add the `hasFluff` and `hasFluffImages` properties as appropriate to the creature. The script can handle
12-
# nested `_copy` references, as long as those references stay within the same file.
10+
# statblock. If that statblock has a `_<datatype>Fluff` object referencing some fluff *in the same file*, this
11+
# script will add the `hasFluff` and `hasFluffImages` properties as appropriate to the statblock. The script can
12+
# handle nested `_copy` references, as long as those references stay within the same file.
13+
#
14+
# Note: this script doesn't handle 'shared-fluff' datatypes. For instance, `subrace`s will not be tagged, nor will
15+
# `baseitem`s. You can inspect the exact list of datatypes that are tagged yourself (see the `$fluffyDatatypes`
16+
# array below), but, in general, the script will only operate on content properties named "<datatype>" which have
17+
# a corresponding fluff property named "<datatype>Fluff".
1318
#
1419
# Note: this script exports JSON in a compressed (one-line) format. I recommend you run a prettifier (such as the
1520
# homebrew repo's `npm run build:clean`) afterwards.
@@ -27,12 +32,12 @@
2732
# files which have *not* been changed; "All" displays all logs.
2833
#
2934
# Examples:
30-
# & .\creature-fluff-tagger.ps1 -Path '.\homebrew'
31-
# & .\creature-fluff-tagger.ps1 -Path '.\homebrew\creature\badooga; Better Greatwyrms.json' -Log Changes
32-
# & .\creature-fluff-tagger.ps1 -Path '.\homebrew' -Log All
35+
# & .\fluff-tagger.ps1 -Path '.\homebrew'
36+
# & .\fluff-tagger.ps1 -Path '.\homebrew\creature\badooga; Better Greatwyrms.json' -Log Changes
37+
# & .\fluff-tagger.ps1 -Path '.\homebrew' -Log All
3338
#
3439
#
35-
# Spappz 2023
40+
# Spappz 2024
3641
#
3742
# MIT License
3843

@@ -50,11 +55,36 @@ PARAM (
5055

5156
$Log = $Log.toLower()
5257

58+
$fluffyDatatypes = @(
59+
'background'
60+
'charoption'
61+
'class'
62+
'condition'
63+
'disease'
64+
'feat'
65+
'hazard'
66+
'item'
67+
'language'
68+
'monster'
69+
'object'
70+
'optionalfeature'
71+
'race'
72+
'recipe'
73+
'reward'
74+
'spell'
75+
'subclass'
76+
'trap'
77+
'vehicle'
78+
)
79+
5380
function Test-Fluff {
5481
PARAM (
5582
[Parameter(Mandatory, ValueFromPipeline, Position = 0)]
5683
[PSCustomObject]$InputObject,
5784

85+
[Parameter(Mandatory)]
86+
[String]$DataType,
87+
5888
[Parameter(Mandatory)]
5989
[String]$For
6090
)
@@ -81,7 +111,8 @@ function Test-Fluff {
81111
) {
82112
Write-Output $true
83113
} elseif ($InputObject._copy.source -in $brew._meta.sources.json) {
84-
Write-Output (Test-Fluff $brew.monsterFluff[$brew.monsterFluff.name.indexOf($InputObject._copy.name)] -For $For)
114+
$datatypeFluff = $DataType + 'Fluff'
115+
Write-Output (Test-Fluff $brew.$datatypeFluff[$brew.$datatypeFluff.name.indexOf($InputObject._copy.name)] -DataType $DataType -For $For)
85116
} else {
86117
Write-Output $false
87118
}
@@ -101,38 +132,45 @@ if ((Test-Path $Path)) {
101132
Write-Warning ('Invalid JSON in ' + $target)
102133
}
103134
}
104-
if ($brew.monsterFluff) {
105-
$tagsApplied = $false
106-
$brew.monster = @(
107-
$brew.monster | ForEach-Object {
108-
if ($_.fluff._monsterFluff -and $_.fluff._monsterFluff.source -in $brew._meta.sources.json) {
109-
$fluff = $brew.monsterFluff[$brew.monsterFluff.name.indexOf($_.fluff._monsterFluff.name)]
110135

111-
if (-not $_.hasFluff -and (Test-Fluff $fluff -For entries)) {
112-
$_ | Add-Member -MemberType NoteProperty -Name hasFluff -Value $true
113-
$tagsApplied = $true
114-
}
136+
$appliedTags = [System.Collections.Generic.List[String]]::new()
137+
foreach ($datatype in $fluffyDatatypes) {
138+
$datatypeFluff = $datatype + 'Fluff'
139+
$_datatypeFluff = '_' + $datatype + 'Fluff'
140+
if ($brew.$datatype -and $brew.$datatypeFluff) {
141+
$brew.$datatype = @(
142+
$brew.$datatype | ForEach-Object {
143+
if ($_.fluff.$_datatypeFluff -and $_.fluff.$_datatypeFluff.source -in $brew._meta.sources.json) {
144+
$fluff = $brew.$datatypeFluff[$brew.$datatypeFluff.name.indexOf($_.fluff.$_datatypeFluff.name)]
145+
146+
if (-not $_.hasFluff -and (Test-Fluff $fluff -DataType $datatype -For entries)) {
147+
$_ | Add-Member -MemberType NoteProperty -Name hasFluff -Value $true
148+
$appliedTags.Add($datatype)
149+
}
115150

116-
if (-not $_.hasFluffImages -and (Test-Fluff $fluff -For images)) {
117-
$_ | Add-Member -MemberType NoteProperty -Name hasFluffImages -Value $true
118-
$tagsApplied = $true
151+
if (-not $_.hasFluffImages -and (Test-Fluff $fluff -DataType $datatype -For images)) {
152+
$_ | Add-Member -MemberType NoteProperty -Name hasFluffImages -Value $true
153+
$appliedTags.Add($datatype)
154+
}
119155
}
156+
Write-Output $_
120157
}
121-
Write-Output $_
122-
}
123-
)
158+
)
159+
}
160+
}
124161

125-
if ($tagsApplied) {
126-
if ($Log -in @('changes', 'all')) {
127-
Write-Host (' Tagged ' + ($target -replace '^.*[\\/]([^\\/]+[\\/][^\\/]+)$', '$1'))
128-
}
129-
ConvertTo-Json $brew -Depth 99 | Out-File -FilePath $target -Encoding Utf8
130-
} elseif ($Log -in @('skips', 'all')) {
131-
Write-Host (' Left unchanged ' + ($target -replace '^.*[\\/]([^\\/]+[\\/][^\\/]+)$', '$1'))
162+
if ($appliedtags.Count) {
163+
ConvertTo-Json $brew -Depth 99 | Out-File -FilePath $target -Encoding Utf8
164+
if ($Log -eq 'changes') {
165+
Write-Host (' Tagged: ' + ($target -replace '^.*[\\/]([^\\/]+[\\/][^\\/]+)$', '$1'))
166+
} elseif ($Log -eq 'all') {
167+
Write-Host (' Tagged: ' + ($target -replace '^.*[\\/]([^\\/]+[\\/][^\\/]+)$', '$1'))
168+
Write-Host (' ' + ($appliedtags | Select-Object -Unique | Join-String -Separator ', '))
132169
}
133170
} elseif ($Log -in @('skips', 'all')) {
134-
Write-Host (' Left unchanged ' + ($target -replace '^.*[\\/]([^\\/]+[\\/][^\\/]+)$', '$1'))
171+
Write-Host (' Left unchanged: ' + ($target -replace '^.*[\\/]([^\\/]+[\\/][^\\/]+)$', '$1'))
135172
}
173+
136174
} elseif ($target.Attributes.HasFlag([System.IO.FileAttributes]::Directory)) {
137175
$baseFiles = Get-ChildItem $target -File
138176
$i = $baseFiles.Name.IndexOf('.gitignore')

0 commit comments

Comments
 (0)