-
Notifications
You must be signed in to change notification settings - Fork 0
/
npcs.ps1
130 lines (121 loc) · 3.3 KB
/
npcs.ps1
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
[CmdletBinding()]
param (
[switch]$uglies = $false,
[switch]$rewrite = $false
)
$npcs = (Get-Content _data/npcs.json) | ConvertFrom-Json
$publicNpcs = (Get-Content _data/public-npcs.json) | ConvertFrom-Json
$vehicles = (Get-Content _data/vehicles.json) | ConvertFrom-Json
$ugly = (Get-Content _data/ugly.json) | ConvertFrom-Json
function Main {
Set-GM-NPCs
Set-Players-NPCs
if ($uglies) {
Set-Ugly
}
}
# Enfore Ugly's creation
function Set-Ugly {
Write-Host "===============" -ForegroundColor Cyan
Write-Host "Handling Ugly's" -ForegroundColor Cyan
Write-Host "===============" -ForegroundColor Cyan
$ugly.PsObject.Properties | ForEach-Object {
$name = $_.Name
$path = "_ugly/$name.md"
$content = @"
---
title: $name
---
"@
Set-FileContent -name $name -path $path -content $content
}
}
# Enforce GM npcs
function Set-GM-NPCs {
Write-Host "================" -ForegroundColor Cyan
Write-Host "Handling GM NPCs" -ForegroundColor Cyan
Write-Host "================" -ForegroundColor Cyan
$npcs.PsObject.Properties | ForEach-Object {
$name = $_.Name
$path = "_gm-npcs/$name.md"
$content = @"
---
title: $name
---
"@
Set-FileContent -name $name -path $path -content $content
}
Write-Host "====================" -ForegroundColor Cyan
Write-Host "Handling GM VEHICLES" -ForegroundColor Cyan
Write-Host "====================" -ForegroundColor Cyan
$vehicles.PsObject.Properties | ForEach-Object {
$name = $_.Name
$path = "_gm-vehicles/$name.md"
$content = @"
---
title: $name
---
"@
Set-FileContent -name $name -path $path -content $content
}
}
# Enfore PCs npcs
function Set-Players-NPCs {
Write-Host "================" -ForegroundColor Cyan
Write-Host "Handling PCs NPCs" -ForegroundColor Cyan
Write-Host "=================" -ForegroundColor Cyan
$publicNpcs.npcs | ForEach-Object {
$name = $_.name
$path = "_npcs/$name.md"
$frontMatter = $_.frontMatter
if (!$frontMatter) {
$frontMatter = @()
}
$content = @"
---
title: $name
$([String]::Join("`n", $frontMatter))
---
"@
Set-FileContent -name $name -path $path -content $content
}
Write-Host "=====================" -ForegroundColor Cyan
Write-Host "Handling PCs VEHICLES" -ForegroundColor Cyan
Write-Host "=====================" -ForegroundColor Cyan
$publicNpcs.vehicles | ForEach-Object {
$name = $_.name
$path = "_vehicles/$name.md"
$frontMatter = $_.frontMatter
if (!$frontMatter) {
$frontMatter = @()
}
$content = @"
---
title: $name
$([String]::Join("`n", $frontMatter))
---
"@
Set-FileContent -name $name -path $path -content $content
}
}
function Set-FileContent {
param (
[string]$name,
[string]$path,
[string]$content
)
$fileExists = Test-Path $path;
if (!$fileExists -or $rewrite) {
Set-Content -Value $content -Path $path
if ($fileExists) {
Write-Host "File $name updated" -ForegroundColor DarkMagenta
}
else {
Write-Host "File $name created" -ForegroundColor DarkGreen
}
}
else {
Write-Verbose "File exists $name"
}
}
Main