/
preloader.ts
61 lines (51 loc) · 1.3 KB
/
preloader.ts
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
const abilityId = util.s2id("ANcl")
const maxPreloadSize = 259
const noDataMarker = "NO_DATA_PRESENT"
export function read(filename: string): string | undefined {
BlzSetAbilityIcon(abilityId, noDataMarker)
Preloader(filename)
const data = BlzGetAbilityIcon(abilityId)
if (data == noDataMarker) {
return undefined
} else {
return data
}
}
function escapePreload(input: string): string {
return string.format('")\n%s\n//', input)
}
const prelude = `
//! beginusercode
local a=""
Preload=function(s)a=a..s end
PreloadEnd=function()end
//! endusercode
`
const postlude = string.format(
`
//! beginusercode
BlzSetAbilityIcon(%s, a)
//! endusercode
`,
abilityId
)
export function writeRaw(filename: string, ...args: string[]): void {
PreloadGenClear()
PreloadGenStart()
for (const [, content] of ipairs(args)) {
for (const part of string.partition(content, maxPreloadSize)) {
Preload(part)
}
}
PreloadGenEnd(filename)
}
export function write(filename: string, content: string): void {
PreloadGenClear()
PreloadGenStart()
Preload(escapePreload(prelude))
for (const part of string.partition(content, maxPreloadSize)) {
Preload(part)
}
Preload(escapePreload(postlude))
PreloadGenEnd(filename)
}