-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen-wiki.py
executable file
·505 lines (441 loc) · 18.3 KB
/
gen-wiki.py
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
#!/usr/bin/python
import os, re
SOURCE_DIR = os.path.join(os.getcwd(),"src")
ITEM_SPRITE_DIR = os.path.join(os.getcwd(),"RawResources","ItemSprites/")
GUN_SPRITE_DIR = os.path.join(os.getcwd(),"RawResources","Ammonomicon Encounter Icon Collection/")
WIKI_PARAMS = {
"summary" :
'''
GungeonCraft is a content mod for Enter the Gungeon, focused primarily on weapons, items, and NPCs that introduce novel and engaging mechanics.
You can download the mod or read more about it [https://thunderstore.io/c/enter-the-gungeon/p/CaptainPretzel/GungeonCraft/ on Thunderstore], view the source for the mod [https://github.com/pcrain/GungeonCraft on GitHub], and report issues with the mod [https://github.com/pcrain/GungeonCraft/issues on the GitHub issue tracker] or by pinging Captain Pretzel in the [https://discord.gg/uT7AwbcpyC Mod the Gungeon Discord].
<b>NOTE: the contents of this page are generated automatically using a script.</b> Manual edits might be overwritten (sorry)! Please contact Captain Pretzel in the Mod the Gungeon Discord if anything looks amiss!
''',
"iconwidth" : "88px",
"tablestyle" : '''class="wikitable sortable mw-collapsible" style="text-align:center; width: 100%;"''',
}
VANILLA_ITEMS = {
# "hyper_light_blaster" : ("Hyper Light Blaster", "Hyper_Light_Blaster.png"),
# "sunlight_javelin" : ("Sunlight Javelin", "Sunlight_Javelin.png"),
# "laser_lotus" : ("Laser Lotus", "Laser_Lotus.png"),
# "bubble_blaster" : ("Bubble Blaster", "Bubble_Blaster.png"),
# "gun_soul" : ("Gun Soul", "Gun_Soul.png"),
# "decoy" : ("Decoy", "Decoy.png"),
# "explosive_decoy" : ("Explosive Decoy", "Explosive_Decoy.png"),
# "nanomachines" : ("Nanomachines", "Nanomachines.png"),
# "heroine" : ("Heroine", "Heroine.png"),
# "master_of_unlocking" : ("Master of Unlocking", "Master_of_Unlocking.png"),
# "metronome" : ("Metronome", "Metronome.png"),
# "backpack" : ("Backpack", "Backpack.png"),
# "laser_sight" : ("Laser Sight", "Laser_Sight.png"),
# "amulet_of_the_pit_lord" : ("Amulet of the Pit Lord", "Amulet_of_the_Pit_Lord.png"),
# "singularity" : ("Singularity", "Singularity.png"),
# "stuffed_star" : ("Stuffed Star", "Stuffed_Star.png"),
# "shotgun_coffee" : ("Shotgun Coffee", "Shotgun_Coffee.png"),
# "loot_bag" : ("Loot Bag", "Loot_Bag.png"),
# "grappling_hook" : ("Grappling Hook", "Grappling_Hook.png"),
# "disarming_personality" : ("Disarming Personality", "Disarming_Personality.png"),
# "portable_table_device" : ("Portable Table Device", "Portable_Table_Device.png"),
}
def applyGunDataOverrides(gunData):
gunData["Bouncer"]["speed"] = "Varies"
gunData["Carpet Bomber"]["speed"] = "Varies"
gunData["Aimu Hakurei"]["spread"] = "Varies"
gunData["Aimu Hakurei"]["firerate"] = "Varies"
gunData["Aimu Hakurei"]["ammo"] = "{{infinity}}"
gunData["Quarter Pounder"]["ammo"] = "# of casings"
gunData["Subtractor Beam"]["damage"] = "Varies"
gunData["Pistol Whip"]["damage"] = "30 (Whip), 15 (Proj.)"
gunData["Pistol Whip"]["firerate"] = "0.42" # 0.40 + 1/60, rounded
gunData["Vacuum Cleaner"]["damage"] = "N/A"
gunData["Vacuum Cleaner"]["speed"] = "N/A"
gunData["Vacuum Cleaner"]["range"] = "N/A"
gunData["Vacuum Cleaner"]["knockback"] = "N/A"
gunData["Pincushion"]["firerate"] = "0.02" # 1/60, rounded
gunData["Pincushion"]["damage"] = "0.35" # as set by _NEEDLE_DAMAGE
def main():
passiveData, passiveDataByClass = scanPassives()
WIKI_PARAMS["passives"] = "".join([PASSIVE_TEMPLATE.format(**v) for k,v in passiveData.items()])
activeData, activeDataByClass = scanActives()
WIKI_PARAMS["actives"] = "".join([ACTIVE_TEMPLATE.format(**v) for k,v in activeData.items()])
masteryData = scanMasteries()
gunData, gunDataByClass = scanGuns(masteryData)
applyGunDataOverrides(gunData)
WIKI_PARAMS["guns"] = "".join([GUN_TEMPLATE.format(**v) for k,v in gunData.items()])
synergyData = scanSynergies(passiveDataByClass, activeDataByClass, gunDataByClass)
WIKI_PARAMS["synergies"] = "".join([SYNERGY_TEMPLATE.format(**v) for k,v in synergyData.items()])
npcData = getNPCs()
WIKI_PARAMS["npcs"] = "".join([NPC_TEMPLATE.format(**v) for k,v in npcData.items()])
wikitext = WIKI_TEMPLATE.format(**WIKI_PARAMS)
print(wikitext)
def getSourceFiles(sourcedir):
for f in sorted(os.listdir(sourcedir)):
if f.startswith("_"):
continue
path = os.path.join(sourcedir, f)
if not os.path.isfile(path):
continue
yield path
def readAllLines(path):
with open(path, 'r') as fin:
return fin.read()
def findPattern(text, patt, default = "???", resolveVars = False):
m = re.search(patt, text)
if m is None:
return default
res = m.groups()[0]
if not resolveVars:
return res
return resolveVariable(res, text)
def cleanItemName(item):
return item.replace(" ","_").replace(".","").replace("'","").replace(":","").replace("-","").lower()
def imageFor(filepath):
return f"""[[File:{filepath}]]"""
def iconForItem(item, nameOnly = False):
name = f"""{cleanItemName(item)}_icon.png"""
if nameOnly:
return name
return os.path.join(ITEM_SPRITE_DIR, name)
def iconForGun(gun, nameOnly = False):
name = f"""{cleanItemName(gun)}_ammonomicon.png"""
if nameOnly:
return name
return os.path.join(GUN_SPRITE_DIR, name)
def computeUses(text):
if findPattern(text, r"""item\.consumable\s*=\s*(.*);""") == "false":
return "{{infinity}}"
uses = findPattern(text, r"""item\.numberOfUses\s*=\s*(.*);""", default=None)
if uses is None:
return 1
return int(uses)
def resolveVariable(var, text):
if re.match(r"""[0-9\.]+f""", var):
var = var[:-1] # remove trailing f from floats
try: return int(var)
except: pass
try: return float(var)
except: pass
varbase = var.split(".")[-1]
res = findPattern(text, rf"""{varbase}\s*=\s*([0-9\.]+)""", default=None)
if res is not None:
return resolveVariable(res, text)
# print(f" could not resolve {var}")
return "???"
def computeItemCooldown(text):
timed = findPattern(text, r"""ItemBuilder\.CooldownType\.Timed\s*,\s*(.+)\)""", default=None)
if timed is not None:
timed = resolveVariable(timed, text)
return f"""{timed} Second{("" if (float(timed) == 1) else "s")}"""
damage = findPattern(text, r"""ItemBuilder\.CooldownType\.Damage\s*,\s*(.+)\)""", default=None)
if damage is not None:
damage = resolveVariable(damage, text)
return f"""{damage} Damage"""
room = findPattern(text, r"""ItemBuilder\.CooldownType\.PerRoom\s*,\s*(.+)\)""", default=None)
if room is not None:
room = resolveVariable(room, text)
return f"""{room} Room{("" if (float(room) == 1) else "s")}"""
return "Instant"
def computeClipSize(text):
size = findPattern(text, r"""clipSize\s*:\s*(.*?)[\s,\)]""")
size = resolveVariable(size, text)
if size == -1:
return "{{infinity}}"
return size
def computeAmmo(text):
infAmmo = findPattern(text, r"""infiniteAmmo\s*:\s*(.*?)(?:\.0)?f?[,\)]""") # range of pea shooter, the default gun
if infAmmo == "true":
return "{{infinity}}"
ammo = findPattern(text, r"""ammo\s*:\s*(.*?)[,\)]""", resolveVars = True)
return ammo
def computeRange(text):
gunRange = findPattern(text, r"""range\s*:\s*(.*?)(?:\.0)?f?[,\)]""", default="20") # range of pea shooter, the default gun
gunRange = resolveVariable(gunRange, text)
if (gunRange > 1000):
return "{{infinity}}"
return gunRange
def computeReloadTime(text):
reloadTime = findPattern(text, r"""reloadTime\s*:\s*(.*?)(?:\.0)?f?[,\)]""", default="1.5", resolveVars = True) # reload time of pea shooter, the default gun
if (reloadTime == 0.0):
return "Instant"
return reloadTime
def makePrettyDescription(text):
return text.replace("\\n","<br/>")
def scanPassives():
data = {}
classdata = {}
for f in getSourceFiles(os.path.join(SOURCE_DIR,"Cwaff-Passives")):
text = readAllLines(f)
itemname = findPattern(text, r"""ItemName\s*=\s*\"(.*)\";""")
classname = findPattern(text, r"""public class (.*) : Cwaff""")
entry = {
"classname" : classname,
"filename" : imageFor(iconForItem(itemname, nameOnly = True)),
"size" : "42",
"itemname" : itemname,
"quality" : findPattern(text, r"""item\.quality\s*=\s*ItemQuality\.(.);"""),
"description" : makePrettyDescription(findPattern(text, r"""LongDescription\s*=\s*\"(.*)\";""")),
}
data[itemname] = entry
classdata[classname] = entry
return data, classdata
def scanActives():
data = {}
classdata = {}
for f in getSourceFiles(os.path.join(SOURCE_DIR,"Cwaff-Actives")):
text = readAllLines(f)
itemname = findPattern(text, r"""ItemName\s*=\s*\"(.*)\";""")
classname = findPattern(text, r"""public class (.*) : Cwaff""")
entry = {
"classname" : classname,
"filename" : imageFor(iconForItem(itemname, nameOnly = True)),
"size" : "42",
"itemname" : itemname,
"quality" : findPattern(text, r"""item\.quality\s*=\s*ItemQuality\.(.);"""),
"description" : makePrettyDescription(findPattern(text, r"""LongDescription\s*=\s*\"(.*)\";""")),
"cooldown" : computeItemCooldown(text),
"numuses" : computeUses(text),
}
data[itemname] = entry
classdata[classname] = entry
return data, classdata
def scanMasteries():
data = {}
masteryFile = os.path.join(SOURCE_DIR, "Cwaff-Misc", "CwaffSynergies.cs")
lines = readAllLines(masteryFile).split("\n")
mrx = re.compile(r"""^\s*NewMastery.*,\s*([A-Za-z0-9]+)\.ItemName""")
for i, line in enumerate(lines):
if not (r := mrx.match(line)):
continue
gun = r.groups()[0]
desc = re.sub(r"""^\s*//\s*""","", lines[i-1])
data[gun] = desc
return data
def scanSynergies(passives, actives, guns):
data = {}
synergyFile = os.path.join(SOURCE_DIR, "Cwaff-Misc", "CwaffSynergies.cs")
lines = readAllLines(synergyFile).split("\n")
srx = re.compile(r"""^\s*NewSynergy.*?,\s*\"([^\"]+)\",\s*new\[\]\{(.*)\}""")
for i, line in enumerate(lines):
if not (r := srx.match(line)):
continue
synergyname = r.groups()[0]
mandatories = [s.strip() for s in r.groups()[1].split(",")]
filenames = []
itemnames = []
for m in mandatories:
if m.startswith("IName"): # one of our items
itemname = m.split("(")[1].split(".")[0]
if (e := passives.get(itemname, None)) is not None:
filenames.append(e["filename"])
itemnames.append(e["itemname"])
continue
if (e := actives.get(itemname, None)) is not None:
filenames.append(e["filename"])
itemnames.append(e["itemname"])
continue
if (e := guns.get(itemname, None)) is not None:
filenames.append(e["filename"])
itemnames.append(e["itemname"])
continue
continue
item_id = m.replace('"',"")
if (e := VANILLA_ITEMS.get(item_id, None)) is not None:
filenames.append(f"""[[File:{e[1]}]]""")
itemnames.append(e[0])
else:
cap_item = " ".join([(w if w in ["of", "the"] else w.title()) for w in item_id.replace("_"," ").split()])
filenames.append(f"""[[File:{cap_item.replace(" ","_")}.png]]""")
itemnames.append(cap_item)
if len(filenames) < 2:
continue
desc = re.sub(r"""^\s*//\s*""","", lines[i-1])
# data[gun] = desc
entry = {
"synergyname" : synergyname,
"filename1" : filenames[0],
"item1" : itemnames[0],
"filename2" : filenames[1],
"item2" : itemnames[1],
"description" : desc,
}
data[synergyname] = entry
# Sort synergies by name before returning
return { k : data[k] for k in sorted(data.keys())}
def scanGuns(masteryData):
# clipSize: -1
data = {}
classdata = {}
for f in getSourceFiles(os.path.join(SOURCE_DIR,"Cwaff-Guns")):
text = readAllLines(f)
itemname = findPattern(text, r"""ItemName\s*=\s*\"(.*)\";""")
classname = findPattern(text, r"""public class (.*) : Cwaff""")
if classname == "Exceptional":
continue
entry = {
"classname" : classname,
"filename" : imageFor(iconForGun(itemname, nameOnly = True)),
"size" : "42",
"itemname" : itemname,
"quality" : findPattern(text, r"""quality\s*:\s*ItemQuality\.(.)"""),
"type" : findPattern(text, r"""shootStyle\s*:\s*ShootStyle\.([A-Za-z_]+)""").replace("SemiAutomatic", "Semi-Automatic"),
"class" : findPattern(text, r"""GunClass\.([A-Z_]+)[,\)]"""),
"magazine" : computeClipSize(text),
"ammo" : computeAmmo(text),
"damage" : findPattern(text, r"""damage\s*:\s*(.*?)(?:\.0)?f?[,\)]""", default="4", resolveVars = True), # damage of pea shooter, the default gun
"speed" : findPattern(text, r"""speed\s*:\s*(.*?)(?:\.0)?f?[,\)]""", default="20"), # velocity of pea shooter, the default gun
"range" : computeRange(text),
"knockback" : findPattern(text, r"""force\s*:\s*([0-9\.]+?)(?:\.0)?f?[,\)]""", default="20", resolveVars = True), # force of pea shooter, the default gun
"firerate" : findPattern(text, r"""cooldown\s*:\s*(.*?)(?:\.0)?f?[,\)]""", default="0.15", resolveVars = True), # cooldown of pea shooter, the default gun
"reloadspeed" : computeReloadTime(text),
"spread" : findPattern(text, r"""angleVariance\s*:\s*(.*?)(?:\.0)?f?[,\)]""", default="10"), # spread of pea shooter, the default gun
"description" : makePrettyDescription(findPattern(text, r"""LongDescription\s*=\s*\"(.*)\";""")),
"mastery" : "",
}
masteryDesc = masteryData.get(entry["classname"], None)
if masteryDesc is not None:
entry["mastery"] = f"{MASTERY_TEMPLATE}{masteryDesc}"
if entry["speed"] == "-1":
entry["speed"] = "{{infinity}}"
data[itemname] = entry
classdata[classname] = entry
return data, classdata
def getNPCs():
return {
"cammy" : {
"filename" : imageFor("cammy_idle_001.png"),
"npcname" : "Cammy",
"icon" : imageFor("cammy_icon.png"),
"type" : "Shopkeeper",
"condition" : "Guaranteed to spawn in Keep of the Lead Lord.",
"description" : "Sells 3 random unlocked companions at a 30% discount. Cannot be stolen from.",
},
"bart" : {
"filename" : imageFor("bart_idle_001.png"),
"npcname" : "Bart",
"icon" : imageFor("bart_icon.png"),
"type" : "Shopkeeper",
"condition" : "Guaranteed to spawn in the Gungeon Proper or Mines.",
"description" : "Barters 3 random D-A quality items for any higher-tiered item. Bartering is done by dropping a single item on the floor within the shop room and attempting to purchase an item. Bartered items are destroyed upon a successful trade.",
},
"kevlar" : {
"filename" : imageFor("kevlar_idle_001.png"),
"npcname" : "Kevlar",
"icon" : imageFor("kevlar_icon.png"),
"type" : "Shopkeeper",
"condition" : "Guaranteed to spawn when entering a floor while possessing an {{Quality|S}} or {{Quality|A}} quality item.",
"description" : "Sells Insurance Policies for 30 casings each. Insurance Policies can be used on any grounded item or gun to insure it, making the item spawn in a special chest at the beginning of your next run.",
},
"skeleton" : {
"filename" : "",
"npcname" : "???",
"icon" : "",
"type" : "Friend? Enemy?",
"condition" : "Maybe Bello knows something?",
"description" : "A mysterious figure from a different time and place that somehow ended up in the Gungeon.",
},
}
PASSIVE_TEMPLATE='''
|-
|<div style="min-height: 56px; transform-origin: top; transform: scale(2);">{filename}</div>{itemname}
|{{{{Quality|{quality}}}}}
|{description}
'''
ACTIVE_TEMPLATE='''
|-
|<div style="min-height: 56px; transform-origin: top; transform: scale(2);">{filename}</div>{itemname}
|{{{{Quality|{quality}}}}}
|{cooldown}
|{numuses}
|{description}
'''
GUN_TEMPLATE='''
|-
|<div style="min-height: 56px; transform-origin: top; transform: scale(2);">{filename}</div>{itemname}
|{{{{Quality|{quality}}}}}
|{type}
|{class}
|{magazine}
|{ammo}
|{damage}
|{speed}
|{range}
|{knockback}
|{firerate}
|{reloadspeed}
|{spread}
|{description}{mastery}
'''
SYNERGY_TEMPLATE='''
|-
|{synergyname}
|<div style="min-height: 56px; transform-origin: top; transform: scale(2);">{filename1}</div>{item1}
|<div style="min-height: 56px; transform-origin: top; transform: scale(2);">{filename2}</div>{item2}
|{description}
'''
MASTERY_TEMPLATE='''<br/>[[File:Mastery.png]] <b><span style="color:#ee6099">Mastery</span></b>: '''
NPC_TEMPLATE='''
|- style="vertical-align:middle; height: 128px;"
|<div style="transform-origin: center; transform: scale(2);">{filename}</div>
|{npcname}
|<div style="transform-origin: center; transform: scale(2);">{icon}</div>
|{type}
|{condition}
|{description}
'''
WIKI_TEMPLATE='''
[[Category:Modding]]
{{{{DISPLAYTITLE:GungeonCraft}}}}{{{{Modding}}}}<!--Non-official notice-->
{summary}
== Guns ==
{{| {tablestyle}
!style="width: {iconwidth}"|Name
!Qual.
!Type
!Class
!{{{{Hover|[[File:Drum_Clip.png]]|Clip Size}}}}
!{{{{Hover|[[File:Ammo_Belt.png]]|Ammo Capacity}}}}
!{{{{Hover|[[File:-1_Bullets.png]]|Projectile Damage}}}}
!{{{{Hover|[[File:Rocket-Powered Bullets.png]]|Projectile Velocity}}}}
!{{{{Hover|[[File:Grappling_Hook.png]]|Projectile Range}}}}
!{{{{Hover|[[File:Heavy_Bullets.png]]|Projectile Knockback}}}}
!{{{{Hover|[[File:Lichy Trigger Finger.png]]|Rate of fire: delay between shots; lower number means higher fire rate}}}}
!{{{{Hover|[[File:Oiled_Cylinder.png]]|Reload Speed: Number of seconds it takes to reload}}}}
!{{{{Hover|[[File:Scope.png]]|Spread: higher number means less accuracy}}}}
!style="width: 50%"|Effect
{guns}
|}}
== Active Items ==
{{| {tablestyle}
!style="width: {iconwidth}"|Name
!style="width: 48px;"|Quality
!Cooldown
!Uses
!style="width: 50%"|Effect
{actives}
|}}
== Passive Items ==
{{| {tablestyle}
!style="width: {iconwidth}"|Name
!style="width: 48px;"|Quality
!Effect
{passives}
|}}
== Synergies ==
{{| {tablestyle}
!style="width: {iconwidth}"|Name
!colspan="2"|Items
!Effect
{synergies}
|}}
== NPCs ==
{{| {tablestyle}
!style="font-weight: bold; width: 112px;"|Icon
!Name
!Room Icon
!Type
!Spawn Condition (Classic)
!style="width: 50%"|Description
{npcs}
|}}
'''
if __name__ == "__main__":
main()