-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-wiki.js
257 lines (230 loc) · 8.38 KB
/
example-wiki.js
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
import * as SCParser from "./index.js";
import fs from 'fs'
let mod = await SCParser.createMod({
//data from 'core' mods will not be added to the output mod
core: [
'./mods/Core',
'./mods/Liberty',
'./mods/Swarm',
'./mods/Void',
'./mods/Multi',
],
mods: [
'C:\\Program Files (x86)\\StarCraft II\\mods\\all-races-mods\\factions\\Hybrids.SC2Mod'
]
})
//do not add the following entities and its children to the output data
mod.ignoreEntities({
unit: [
"DESTRUCTIBLE",
"POWERUP",
"STARMAP",
"SS_Plane",
"SS_BackgroundSpace",
"Shape",
"MISSILE_INVULNERABLE",
"MISSILE",
"MISSILE_HALFLIFE",
"PLACEHOLDER",
"PLACEHOLDER_AIR",
"PATHINGBLOCKER",
"BEACON",
"SMCHARACTER",
"SMCAMERA",
"SMSET",
"ITEM",
]
})
//pick specific races
// mod.pick({race: ["Terr","Zerg","Prot"]})
mod.index()
//replace text strings expressions with data values
mod.resolveTextValues()
//load the list of available icons
mod.readImages('./../wiki/src/icons')
//check entities icons and use the available ones
mod.checkImages()
//add actor data to units
mod.resolveUnitActors()
let strings = mod.locales.enUS.GameStrings
function flagArray(property){
return property && Object.entries(property).filter(([key,value]) => value).map(([key,value]) => key)
}
function weaponInfo (entity){
let data = entity.getResolvedData()
let effect = data.DisplayEffect && mod.cache.effect[data.DisplayEffect]?.getResolvedData()
return {
...shortInfo(entity),
Amount: effect?.Amount?.value,
AttributeBonus: effect?.AttributeBonus,
Kind: effect?.Kind,
DisplayAttackCount: data.DisplayAttackCount,
TargetFilters: data.TargetFilters?.split(";")[0].replace(",Visible","").replace("Visible",""),
Range: data.Range || data.MinScanRange,
Period: data.Period,
}
}
function shortInfo(entity){
let data = entity.getResolvedData()
return {
Id: entity.id,
Icon: entity.Icon || entity.InfoIcon,
Tooltip: strings[data.Tooltip],
Description: strings[data.Description],
Name: strings[data.Name]
}
}
function getCardData(entity) {
let commands = []
let data = entity.getResolvedData()
if (!data.CardLayouts) {
return null;
}
let layouts = []
for (let cl of data.CardLayouts) {
let layout = []
if (cl.LayoutButtons) {
cl.LayoutButtons = cl.LayoutButtons.filter(lb => lb.Face && lb.Type && lb.Type !== 'Undefined' && (!lb.Row || lb.Row < 3) && (!lb.Column || lb.Column < 5))
for (let lb of cl.LayoutButtons) {
let btn = mod.cache.button[lb.Face]
if (!btn) {
console.warn(`Entity not found: button.${lb.Face}`)
continue;
}
if(lb.AbilCmd){
commands.push({
...shortInfo(btn),
AbilCmd: lb.AbilCmd
})
}
let buttonData = btn.getResolvedData()
let hotkey = mod.locales.enUS.GameHotkeys[buttonData.Hotkey];
if (SCParser.SCGame.specialHotkeys[hotkey]) {
hotkey = SCParser.SCGame.specialHotkeys[hotkey]
}
layout.push({
...buttonData,
...shortInfo(btn),
Hotkey: hotkey
})
}
}
layouts.push(layout)
}
return {layouts,commands}
}
function getProduction (commands){
let units =[], upgrades = []
for(let abilcmd of commands){
let [abilId, cmdIndex] = abilcmd.split(",");
let abil = mod.cache.abil[abilId]?.getResolvedData();
if(!abil)continue;
if(cmdIndex === 'Execute') cmdIndex = 0;
let unitinfo = abil.InfoArray?.[cmdIndex]?.Unit;
if(unitinfo){
if(unitinfo?.constructor === Array ){
for(let unit of unitinfo) if(!units.includes(unit))units.push(unitinfo)
}
else{
if(!units.includes(unitinfo)) units.push(unitinfo)
}
}
let upgradeinfo = abil.InfoArray?.[cmdIndex]?.Upgrade;
if(upgradeinfo){
if(upgradeinfo?.constructor === Array ){
for(let upgrade of upgradeinfo) if(!upgrades.includes(upgrade))upgrades.push(upgradeinfo)
}
else{
if(!upgrades.includes(upgradeinfo)) upgrades.push(upgradeinfo)
}
}
}
return {
producedUnits: units,
producedUpgrades: upgrades
}
}
function addUnit (unit){
let unitData = unit.getResolvedData()
let actor = unit.getActor()
let {layouts,commands} = getCardData(unit)
let {producedUnits, producedUpgrades} = getProduction(commands.map(cmd => cmd.AbilCmd))
let {requiredUnits, requiredUpgrades, producingUnits} = unit.getRequirements()
let {affectingUpgrades} = unit.$$references.map(ref => ref.target).filter(entity => entity.$$resolved?.class === 'CUpgrade').map(shortInfo)
let shortUnitData = shortInfo(unit)
shortUnitData.Icon = actor?.UnitIcon || actor?.Wireframe?.Image?.[0]
let categories = unitData.EditorCategories?.split(",").map(cat => cat.split(':')).reduce((acc, [category, value]) => ({...acc, [category]: value}), {})
let unitType = categories?.ObjectType === 'Structure' ? 'structures' : 'units'
output[`unit\\${unit.id}`] = {
...unitData,
...shortUnitData,
LifeArmorIcon: actor?.LifeArmorIcon,
ShieldArmorIcon: actor?.ShieldArmorIcon,
LifeArmorName: strings[unitData.LifeArmorName],
ShieldArmorName: strings[unitData.ShieldArmorName],
id: null,
class: null,
BehaviorArray: null,
WeaponArray: null,
AbilArray: null,
Card: layouts,
Weapons: unitData.WeaponArray?.filter(w => w.Link).map(w => ({Turret: w.Turret, ...weaponInfo(mod.cache.weapon[w.Link])})),
Behaviors: unitData.BehaviorArray?.filter(b => b.Link).map(b => shortInfo(mod.cache.behavior[b.Link])),
Abilities: unitData.AbilArray?.filter(a => a.Link).map(a => shortInfo(mod.cache.abil[a.Link])),
Upgrades: affectingUpgrades,
Requirements: [...requiredUnits, ...requiredUpgrades],
Production: [...producedUnits,...producedUpgrades],
Producers: producingUnits,
Commands: commands,
EditorFlags: flagArray(unitData.EditorFlags),
FlagArray: flagArray(unitData.FlagArray),
PlaneArray: flagArray(unitData.PlaneArray),
Collide: flagArray(unitData.Collide),
Attributes: flagArray(unitData.Attributes)
}
let raceObject = output.races.find(r => r.Id === unitData.Race)
if(!raceObject[unitType]){
raceObject[unitType] = []
}
let i = raceObject[unitType].findIndex(e => e.priority > unitData.GlossaryPriority)
if(i === -1){
i = raceObject[unitType].length
}
raceObject[unitType].splice(i,0,{
...shortUnitData,
priority: unitData.GlossaryPriority
})
output.units.push(shortUnitData);
}
let output = {
races: mod.catalogs.race.map(shortInfo),
weapons: mod.catalogs.weapon.map(shortInfo),
upgrades: mod.catalogs.upgrade.map(shortInfo),
abils: mod.catalogs.abil.map(shortInfo),
buttons: mod.catalogs.button.map(shortInfo),
behaviors: mod.catalogs.behavior.map(shortInfo),
images: mod.images,
units: []
};
for (let unit of mod.catalogs.unit) {
let unitData = unit.getResolvedData()
if (
//skip units from dependency mods and ignored units
unit.isCore() || unitData.ignore ||
//skip units without defined race
!unitData.Race || unitData.Race === 'Neut' ||
//skip units without required fields
!unitData.GlossaryPriority || unitData.EditorFlags?.NoPalettes || unitData.EditorFlags?.NoPlacement
){
continue;
}
//add short info to the race data object
addUnit(unit)
}
let outputDirectory = 'C:\\Program Files (x86)\\StarCraft II\\output'
for (let file in output){
let foutput = outputDirectory + "\\" + file
fs.mkdirSync(foutput.substring(0, foutput.lastIndexOf('\\')), {recursive: true});
fs.writeFileSync(foutput + '.json', SCParser.formatData(output[file],'json' ),'utf-8')
}
console.log("Finished!")