-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdat-convert.ps1
129 lines (110 loc) · 4.14 KB
/
dat-convert.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
$documents = [Environment]::GetFolderPath("MyDocuments")
$openRct2bin = "$($documents)\OpenRct2\bin"
$openRct2com = "$($openRct2bin)\openrct2.com"
$namespace = "fidwell"
function ExtractSprites(
[string]$objectPath,
[string]$imagePath,
[string]$customIdentifier,
[string]$rctIdentifier,
[string]$imagesJson,
[bool]$useOriginalImages,
[string]$tempPath)
{
Write-Host "Creating directories..."
New-Item -Path $objectPath -ItemType Directory -Force | Out-Null
New-Item -Path $imagePath -ItemType Directory -Force | Out-Null
$useCustomObject = $customIdentifier.Length -gt 0
$command = ""
$shouldRecolour = $false
if ($useCustomObject)
{
Write-Host "Extracting custom object..."
$command = "$($openRct2com) sprite exportalldat $($customIdentifier.ToUpper()) $($imagePath) > $($imagesJson)"
}
else
{
Write-Host "Extracting vanilla object..."
$command = "$($openRct2com) sprite exportalldat $($rctIdentifier.ToUpper()) $($imagePath) > $($imagesJson)"
$shouldRecolour = $true
}
Invoke-Expression -Command $command
if ($shouldRecolour) {
Write-Host "Recolouring vanilla object..."
$files = Get-ChildItem $imagePath -Filter *.png
Set-Location ./colourizer
foreach ($f in $files) {
java RecolourRctImage $f.FullName
}
Set-Location ..
}
if ($useCustomObject -and $useOriginalImages) {
Write-Host "Extracting original image data..."
$command = "$($openRct2com) sprite exportalldat $($rctIdentifier.ToUpper()) $($tempPath) > $($imagesJson)"
Invoke-Expression -Command $command
}
}
function CopyData(
[string]$openRct2bin,
[string]$originalGame,
[string]$objectType,
[string]$openRct2Identifier,
[string]$objectJson)
{
Write-Host "Copying json..."
$source = "$($openRct2bin)\data\object\$($originalGame)\$($objectType)\$($openRct2Identifier).json"
Copy-Item $source -Destination $objectJson
}
function EditJson(
[string]$openRct2Identifier,
[string]$objectJson,
[string]$newIdentifier,
[string]$groupId,
[string]$imagesJson)
{
Write-Host "Editing json..."
# Replace id
$regex = [regex]::Escape("""id"": ""$($openRct2Identifier)"",")
(Get-Content $objectJson) -replace $regex, """id"": ""$($newIdentifier)""," | Set-Content $objectJson
# Change or remove original id
$regex = "\""originalId\"": \"".*"
(Get-Content $objectJson) -replace $regex, """originalId"": """"," | Set-Content $objectJson
# Change source game
$regex = "\""sourceGame\"": .*"
(Get-Content $objectJson) -replace $regex, """sourceGame"": ""custom""," | Set-Content $objectJson
# Add recolorable flags
# to do
# Add images
# to do
# Update images.json for manual editing
(Get-Content $imagesJson) -replace "./objects/$($groupId)/$($newIdentifier)/", "" | Set-Content $imagesJson
(Get-Content $imagesJson) -replace "./objects/temp", "images" | Set-Content $imagesJson
}
function ConvertDat(
[string]$groupId,
[string]$openRct2Identifier,
[string]$customIdentifier,
[string]$useOriginalImagesStr
)
{
$identifiers = $openRct2Identifier.Split(".")
$originalGame = $identifiers[0]
$objectType = $identifiers[1]
$objectName = $identifiers[2]
$newIdentifier = "$($namespace).$($objectType).$($objectName)"
$objectPath = ".\objects\$($groupId)\$($newIdentifier)"
$imagePath = "$($objectPath)\images"
$objectJson = "$($objectPath)\object.json"
$imagesJson = "$($objectPath)\images.json"
$tempPath = ".\objects\temp"
$useOriginalImages = $useOriginalImagesStr.Length -gt 0
ExtractSprites $objectPath $imagePath $customIdentifier $objectName $imagesJson $useOriginalImages $tempPath
CopyData $openRct2bin $originalGame $objectType $openRct2Identifier $objectJson
EditJson $openRct2Identifier $objectJson $newIdentifier $groupId $imagesJson
Write-Host "Done"
}
if ($args.length -gt 1) {
ConvertDat $args[0] $args[1] $args[2] $args[3]
} else {
Write-Host "Usage: dat-convert groupId openRct2Identifier [customIdentifier] [useOriginalImages]"
}