-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprep-content.ps1
More file actions
378 lines (330 loc) · 14 KB
/
prep-content.ps1
File metadata and controls
378 lines (330 loc) · 14 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
param (
$runFuncs
)
function Get-Master-Zip {
$zipURL = "https://api.github.com/repos/foundryvtt/pf2e/zipball/master"
Invoke-RestMethod -Uri $zipURL -OutFile pf2e-master.zip
}
function Expand-Master-Zip {
#Expand-Archive -LiteralPath pf2e-master.zip -DestinationPath pf2e-master
if (Test-Path "./pf2e-master/" ){
Remove-Item -Recurse -Force pf2e-master
}
7z x pf2e-master.zip -o"pf2e-master" */packs/* */static/lang/* -r
}
function Get-Foundry-Sources {
$base_content_url = "http://api.github.com/repos/foundryvtt/pf2e/contents"
$base_pack_url = ""
$script:sources = $script:sources
$response = Invoke-RestMethod -Uri $base_content_url
ForEach ($item in $response) {
if ($item.name -eq "packs") {
$base_pack_url = $item.git_url + "?recursive=true"
continue
}
}
$response = Invoke-RestMethod -Uri $base_pack_url
ForEach ($p in $response.tree) {
if ($p.type -eq "tree") {
if (!$script:unwantedPacks.Contains($p.path)) {
$newSource = @{name = $p.path; content = @{}; enabled = $false; }
$sources[$p.path] = $newSource
}
}
elseif ($p.type -eq "blob") {
$split_array = $p.path -split "/"
$parent = $split_array[0]
if (!$script:unwantedPacks.Contains($parent)) {
$name = $split_array[$split_array.length - 1]
if ($sources.ContainsKey($parent)) {
$new_data_file = @{name = $name; path = $p.path; }
$sources[$parent]["content"][$name] = $new_data_file
}
}
}
}
$sources | ConvertTo-Json -depth 100 -Compress | Out-File -Encoding ascii ".\library\public\data\pf2e_source.json"
}
function Import-All-Sources {
$sourceList = Get-ChildItem .\pf2e-master\*\packs\* | ForEach-Object { $_.FullName }
#Load More Important Sources First
$coreContent = @("actions","ancestries","backgrounds","classes","classfeatures","conditions","equipment","feats","hazards","spells","spell-effects","pathfinder-monster-core")
$skipItems = @()
ForEach ($source in $sourceList) {
ForEach($coreItem in $coreContent){
if ($source.Contains("\packs\"+$coreItem)) {
$skipItems += $source
$splitArray = $source -split "\\"
$sourceName = $splitArray[$splitArray.length - 1 ]
if (!$script:unwantedPacks.Contains($sourceName)) {
import-source $source $sourceName
}
}
}
}
ForEach ($source in $sourceList) {
$splitArray = $source -split "\\"
$sourceName = $splitArray[$splitArray.length - 1 ]
if (!$script:unwantedPacks.Contains($sourceName) -and !$skipItems.Contains($source)) {
#Write-Host "Importing " $sourceName
import-source $source $sourceName
}
else {
#Write-Host "Skipping" $sourceName
}
}
}
function import-source {
param (
[Parameter(Mandatory = $true)] [System.Object] $sourcePath,
[Parameter(Mandatory = $true)] [string] $sourceName
)
$childList = Get-ChildItem -Recurse $sourcePath | ForEach-Object { $_.FullName }
$counter = 0
$total = $childList.Length
$importText = "Importing " + $sourceName
ForEach ($file in $childList) {
if ( -not ($file -like "*.json")) {
continue
}
$splitArray = $file -split "\\"
$childName = $splitArray[$splitArray.length - 1 ]
#Write-Host "Reading " $childName
#Write-Host $file
$subPath = ""
$begin = $false
ForEach ($p in $splitArray){
if (( $p -eq "packs" -or $begin ) -and $p -ne $childName){
$begin = $true
$subPath += "/" + $p
}
}
import-source-file $file $sourceName $childName $subPath
$counter = $counter + 1
$percentProgress = $counter / $total * 100
Write-Progress -Activity $importText -Status "$percentProgress% Complete:" -PercentComplete $percentProgress
}
}
function import-source-file {
param (
$filePath,
$fileDir,
$fileName,
$subPath
)
$script:packData = $script:packData
#$data = Invoke-RestMethod -Uri $fileURL
try {
$data = Get-Content -Encoding UTF8 $filePath | ConvertFrom-JSON
}
Catch {
Write-Host "Error reading" $filePath
return
}
if (($data.getType().FullName -eq "System.Object[]")){
return
}
$storeData = @{}
$script:wantedSources = $script:wantedSources
$script:foundSources = $script:foundSources
$script:tagData = $script:tagData
$storeData.name = $data.name
$storeData.type = $data.type
$storeData.id = $data._id
$baseNameSplit = $fileName -split "\.";
$storeData.baseName = $baseNameSplit[0]
if ($data.system.traits.PSObject.Properties.name -contains "otherTags"){
ForEach ($tagDef in $data.system.traits.otherTags){
if ( -not ($tagData.Contains($tagDef))){
$tagData[$tagDef] = [System.Collections.ArrayList]@()
}
$tagData[$tagDef].Add($data.name) | Out-Null
}
}
if ($null -eq $data.type) {
$storeData.type = "null"
}
elseif ($data.type -eq "npc") {
$storeData.traits = $data.system.traits.value
$storeData.level = $data.system.details.level.value
$storeData.npcType = $data.system.details.creatureType
$storeData.rarity = $data.system.traits.rarity
$storeData.size = $data.system.traits.size.value
$storeData.source = $data.system.details.publication.title
}
elseif ($data.type -eq "action") {
$storeData.traits = $data.system.traits.value
$storeData.actionCost = $data.system.actions.value
$storeData.actionType = $data.system.actionType.value
$storeData.category = $data.system.category
$storeData.requirements = $data.system.requirements
$storeData.description = $data.system.description.value
$storeData.source = $data.system.publication.title;
}
elseif ($data.type -eq "ancestry") {
$storeData.traits = $data.system.traits.value
$storeData.rarity = $data.system.traits.rarity
$storeData.source = $data.system.publication.title
}
elseif ($data.type -eq "condition") {
$storeData.description = $data.system.description.value
$storeData.overrides = $data.system.overrides
$storeData.value = $data.system.value
$storeData.rules = $data.system.rules
$storeData.source = $data.system.publication.title
}
elseif ($data.type -eq "class") {
$storeData.source = $data.system.publication.title;
$storeData.rarity = $data.system.traits.rarity;
}
elseif ($data.type -eq "feat") {
$storeData.source = $data.system.publication.title;
$storeData.rarity = $data.system.traits.rarity;
$storeData.traits = $data.system.traits.value;
$storeData.actionCost = $data.system.actions.value;
$storeData.actionType = $data.system.actionType.value;
$storeData.level = $data.system.level.value;
if ($storeData.name -eq "Aquatic Adaptation" -and $storeData.traits.Contains("lizardfolk")) {
$storeData.name = "Aquatic Adaptation (Lizardfolk)";
}
}
elseif ($data.type -eq "spell") {
$storeData.source = $data.system.publication.title;
$storeData.rarity = $data.system.traits.rarity;
$storeData.traits = $data.system.traits.value;
$storeData.traditions = $data.system.traits.traditions;
$storeData.level = $data.system.level.value;
}
elseif ($data.type -eq "hazard") {
$storeData.source = $data.system.details.publication.title;
$storeData.rarity = $data.system.traits.rarity;
$storeData.traits = $data.system.traits.value;
$storeData.level = $data.system.details.level.value;
$storeData.isComplex = $data.system.isComplex;
$storeData.hazardType = $data.system.value;
}
elseif ($data.type -eq "effect") {
$storeData.source = $data.system.publication.title;
$storeData.duration = $data.system.duration;
$storeData.rules = $data.system.rules;
$storeData.start = $data.system.start;
$storeData.rarity = $data.system.traits.rarity;
$storeData.traits = $data.system.traits.value;
$storeData.level = $data.system.level.value;
}
elseif ($data.type -eq "heritage") {
$storeData.source = $data.system.publication.title;
$storeData.description = $data.system.description.value;
$storeData.ancestry = $data.system.ancestry;
$storeData.rules = $data.system.rules;
$storeData.traits = $data.system.traits.value;
$storeData.rarity = $data.system.traits.rarity;
}
elseif ($data.type -eq "weapon" -or $data.type -eq "armor" -or $data.type -eq "consumable" -or $data.type -eq "equipment" -or $data.type -eq "shield" -or $data.type -eq "treasure" -or $data.type -eq "backpack") {
$storedata.type = "item";
$storeData.source = $data.system.publication.title;
$storeData.rules = $data.system.rules;
$storeData.traits = $data.system.traits.value;
$storeData.rarity = $data.system.traits.rarity;
$storeData.itemType = $data.system.type;
$storeData.level = $data.system.level.value;
$storeData.bulk = $data.system.bulk.value;
}
else {
#Write-Host "Unknown Type: " $data.type
}
if ($wantedSources.Contains($storeData.source)){
$storeData.items = $data.items
$storeData.system = $data.system
}else{
$storeData.fileURL = "https://raw.githubusercontent.com/foundryvtt/pf2e/master" + $subPath + "/" + $fileName
}
if ( !$foundSources.Contains($storeData.source)) {
$foundSources.Add($storeData.source) | Out-Null
}
if ( !$packData.ContainsKey("pf2e_" + $storedata.type)) {
$packData["pf2e_" + $storedata.type] = @{}
}
if (!$packData["pf2e_" + $storedata.type].Contains($storeData.name)){
$packData["pf2e_" + $storedata.type][$storeData.name] = $storeData
}#DUPLICATE NAMED ENTRIES IGNORED
}
function import-lang-file {
$script:langData = $script:langData
$langSources = Get-ChildItem .\pf2e-master\*\static\lang\*
$data = $null
ForEach ( $source in $langSources ){
$rawData = Get-Content -Encoding UTF8 $source
#Windows PS doesn't do case sensitive keys in JSON -
$data = $rawData.replace("""condition""", "conditionList").replace("""ui""", "_ui") | ConvertFrom-JSON
$outFile = ".\library\public\lang_data\"+$source.Name
$data | ConvertTo-Json -depth 100 -Compress | Out-File -Encoding UTF8 $outFile
}
}
function write-data-files {
$script:packData = $script:packData
$script:foundSources | ConvertTo-Json -depth 100 -Compress | Out-File -Encoding UTF8 ".\library\public\data\pf2e_publications.json"
$script:wantedSources | ConvertTo-Json -depth 100 -Compress | Out-File -Encoding UTF8 ".\library\public\data\pf2e_enabledSources.json"
$script:tagData | ConvertTo-Json -depth 100 -Compress | Out-File -Encoding UTF8 ".\library\public\data\pf2e_tagData.json"
ForEach ($dataType in $packData.Keys) {
$dataSet = $packData[$dataType]
$outFile = ".\library\public\data\" + $dataType + ".json"
$dataSet | ConvertTo-Json -depth 100 -Compress | Out-File -Encoding UTF8 $outFile
}
}
function Invoke-Diff-Check-Prep {
$script:diffCheckFiles = $script:diffCheckFiles
if (Test-Path pf2e-master){
Foreach ($file in $diffCheckFiles){
Get-ChildItem -Path "./pf2e-master" -Recurse -File -Filter $file | Copy-Item -Destination "diffChecks"
}
}
}
function Invoke-Diff-Checks {
Foreach ($file in $diffCheckFiles){
$test = Compare-Object -DifferenceObject (Get-Content "diffChecks/$file") -ReferenceObject (Get-ChildItem -Path "./pf2e-master" -Recurse -File -Filter $file | Get-Content) | Out-Null
if ($test){
Write-Host "Differences found in" $file
}
}
}
$diffCheckFiles = @("black-dragon-adult.json", "heal.json", "force-barrage.json", "affix-a-talisman.json", "recall-knowledge.json", "off-guard.json")
$unwantedPacks = @("paizo-pregens", "rollable-tables", "vehicles", "kingmaker-features", "macros", "deities", "kingmaker-bestiary", "journals", "kingmaker-features", "iconics", "criticaldeck", "action-macros")
$wantedSources = @("Pathfinder Core Rulebook", "Pathfinder Player Core", "Pathfinder Player Core 2", "Pathfinder Rage of Elements", "Pathfinder GM Core", "Pathfinder Advanced Player's Guide", "Pathfinder Treasure Vault", "Pathfinder Dark Archive", "Pathfinder Gamemastery Guide", "Pathfinder Secrets of Magic", "Pathfinder Bestiary", "Pathfinder Bestiary 2", "Pathfinder Bestiary 3", "Pathfinder Book of the Dead", "Pathfinder Guns & Gears","Pathfinder Monster Core", "Pathfinder NPC Core")
$sources = @{}
$packData = @{}
$langData = @{}
$tagData = @{}
$foundSources = [System.Collections.ArrayList]@()
if ($runFuncs -eq "all" -or $runFuncs -eq "download") {
Write-Host "Downloading Data"
Get-Master-Zip
Write-Host "Downloaded Foundry Data"
}
if ($runFuncs -eq "all" -or $runFuncs -eq "expand") {
Write-Host "Expanding Data"
Expand-Master-Zip
Write-Host "Expanded Data"
}
if ($runFuncs -eq "all" -or $runFuncs -eq "lang") {
import-lang-file
}
if ($runFuncs -eq "all" -or $runFuncs -eq "source") {
Write-Host "Preparing Sources"
Get-Foundry-Sources
Write-Host "Source Data Prepared"
}
if ($runFuncs -eq "diffCheckTest"){
Invoke-Diff-Check-Prep
Invoke-Diff-Checks
}
if ($runFuncs -eq "all" -or $runFuncs -eq "import") {
Invoke-Diff-Check-Prep
Write-Host "Importing Sources"
Import-All-Sources
Write-Host "Sources Imported"
Write-Host "Writing Files"
write-data-files
Write-Host "Files Written"
Invoke-Diff-Checks
}