Skip to content

Instantly share code, notes, and snippets.

@Meorawr
Last active September 6, 2022 14:32
Show Gist options
  • Save Meorawr/b92d0e1ca2ac09afc7b8440ac126987c to your computer and use it in GitHub Desktop.
Save Meorawr/b92d0e1ca2ac09afc7b8440ac126987c to your computer and use it in GitHub Desktop.
TextureAtlasViewer Atlas Compiler
#Requires -Version 7.1
<#
.SYNOPSIS
Generates an output document of atlases pulled from WoW client databases
suitable for use with the Texture Atlas Viewer addon.
#>
[CmdletBinding()]
param (
# Client version to generate atlases for, eg. "9.2.0.42069".
[Parameter(Mandatory=$true)]
[string] $Version
)
function New-LookupTable {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[Object[]] $InputObject,
[Parameter(Mandatory=$true)]
[string] $Property
)
begin {
$Table = @{}
}
process {
foreach ($Object in $InputObject) {
$Table[$Object.$Property] = $Object
}
}
end {
$Table
}
}
function Get-WowToolsDatabase([string] $Name) {
Invoke-WebRequest "https://wow.tools/dbc/api/export/?name=${Name}&build=${Version}&useHotfixes=true" `
| ConvertFrom-Csv
}
function Get-WowToolsListfile {
Invoke-WebRequest "https://wow.tools/casc/listfile/download/csv/unverified" `
| ConvertFrom-Csv -Delimiter ";" -Header "ID", "Name"
}
function Get-Atlases {
$Atlases = Get-WowToolsDatabase -Name "uitextureatlas" | New-LookupTable -Property ID
$Elements = Get-WowToolsDatabase -Name "uitextureatlaselement" | New-LookupTable -Property ID
$Members = Get-WowToolsDatabase -Name "uitextureatlasmember"
$Files = Get-WowToolsListfile | New-LookupTable -Property ID
$Members | ForEach-Object {
$Atlas = $Atlases[$_.UiTextureAtlasID]
$Element = $Elements[$_.UiTextureAtlasElementID]
$File = $Files[$Atlas.FileDataID]
@{
Name = $Element.Name
Left = $_.CommittedLeft / $Atlas.AtlasWidth
Right = $_.CommittedRight / $Atlas.AtlasWidth
Top = $_.CommittedTop / $Atlas.AtlasHeight
Bottom = $_.CommittedBottom / $Atlas.AtlasHeight
Width = ($_.OverrideWidth ? $_.OverrideWidth : $_.CommittedRight - $_.CommittedLeft)
Height = ($_.OverrideHeight ? $_.OverrideHeight : $_.CommittedBottom - $_.CommittedTop)
TileHorizontally = [bool] ($_.CommittedFlags -band 0x4)
TileVertically = [bool] ($_.CommittedFlags -band 0x2)
AtlasID = $Atlas.ID
FileDataID = $Atlas.FileDataID
FileName = ($File ? $File.Name.Substring(0, $File.Name.LastIndexOf(".")) : $Atlas.FileDataID)
}
}
}
function Write-GroupedAtlases {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[Object[]] $InputObject
)
begin {
"local _, _addon = ...;"
"_addon.dataBuild = $($Version.Split(".")[3]);"
"_addon.data = {"
}
process {
foreach ($GroupInfo in $InputObject) {
"`t[`"$($GroupInfo.Name)`"] = {"
foreach ($_ in $GroupInfo.Group) {
"`t`t[`"$($_.Name)`"] = { $($_.Width), $($_.Height), $($_.Left), $($_.Right), $($_.Top), $($_.Bottom), $($_.TileHorizontally ? "true" : "false"), $($_.TileVertically ? "true" : "false") },"
}
"`t},"
}
}
end {
"};"
}
}
Get-Atlases `
| Sort-Object -Property Name `
| Group-Object -Property FileName `
| Sort-Object -Property Name ` # Sorts by the grouped-by filename.
| Write-GroupedAtlases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment