-
Notifications
You must be signed in to change notification settings - Fork 2
/
bionics.py
369 lines (344 loc) · 16.5 KB
/
bionics.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
import json
import sys
import pywikibot
from version import version
from name_hacks import trait_name
from name_hacks import bionics_name
from cddaWiki import GetName
from pprint import pprint
from Tkinter import Tk
root = Tk()
root.withdraw()
#Data can be automatically copied to the wiki bionic pages.
#Usage: python [location of pywikibotinstall]\pwb.py bionics.py
# Either input 'all' or 'ALL', and then your password, and wait for the pages to be updated.
# Or: Input a bionic ID from 'data/json/bionics.json' to get the position of that bionic in the data list.
# Or: Input an integer, which will print the generate page of that bionic on screen, and copy it to the clipboard.
#Doesn't work on bionics that are not defined in 'data\json\bionics.json'
with open('data/json/bionics.json') as data_file:
data = json.load(data_file)
with open('data/json/items/bionics.json') as data_file:
data1 = json.load(data_file)
with open('data/json/mutations/mutations.json') as data_file:
mutation_data = json.load(data_file)
with open('data/json/items/obsolete.json') as data_file:
obsolete = json.load(data_file)
ID_mut = dict()
for iterator in range(0, len(mutation_data)):
keyD = dict()
keyD['id_nr'] = iterator
keyD["name"] = GetName(mutation_data[iterator]["name"])
ID_mut[mutation_data[iterator]["id"]] = keyD
def MUT_ID_To_String(id):
if (id == trait_name(id)):
return ID_mut[id]["name"]
else:
return trait_name(id)
def isObsoleteID(id):
for it in range(0, len(obsolete)):
if('id' in obsolete[it]):
if( id == obsolete[it]['id']):
return True
return False
output = []
ID_bionic = dict()
for iterator in range(0, len(data)):
keyD = dict()
keyD['id_nr'] = iterator
keyD["name"] = GetName(data[iterator]["name"])
ID_bionic[data[iterator]["id"]] = keyD
ID_bio_item = dict()
for iterator in range(0, len(data1)):
keyD = dict()
keyD['id_nr'] = iterator
keyD["name"] = GetName((data1[iterator]["name"])
if ('id' in data1[iterator]):
ID_bio_item[data1[iterator]["id"]] = keyD
else:
data1[iterator]["id"] = data1[iterator]["abstract"]
ID_bio_item[data1[iterator]["id"]] = keyD
def ID_To_String(id):
return ID_bionic[id]["name"]
def ID_To_Bio_Int(id):
if(id in ID_bionic):
return ID_bionic[id]["id_nr"]
else:
return -1
def ID_To_Item_String(id):
return ID_bio_item[id]["name"]
def ID_To_Item_Int(id): #should return the location of the bionic inside the items file. However, not all bionics have items.
if(id in ID_bio_item):
return ID_bio_item[id]["id_nr"]
else:
return -1
def getValue(id, value): #returns the value field of the bionic item. It is a recursive function that takes into account the abstract item.
if(value in data1[id]):
return data1[id][value]
else:
return getValue(ID_To_Item_Int(data1[id]["copy-from"]), value)
def checkValue(id, value): #returns if the value field is defined in the item description. Or if it is defined in on of the abstracts.
if(value in data1[id]):
return True
if("copy-from" in data1[id]):
return checkValue(ID_To_Item_Int(data1[id]["copy-from"]), value)
else:
return False
def hasFlag (object, flag): #returns true if this json object has the flag defined in its "flags" list.
if('flags' in object):
if(flag in object['flags']):
return True
return False
def bionicPageName (var): #depending on if the bionic has a bionic item or not, this will return the correct name for the bionic page on the wiki.
retval = ''
if (data[var]['id'] != bionics_name(data[var]['id'])):
retval = bionics_name(data[var]['id'])
elif(ID_To_Item_Int(data[var]['id']) != -1):
item_id = ID_To_Item_Int(data[var]['id'])
if( not "abstract" in data1[item_id] ):
retval = ID_To_String(data1[item_id]['id'])
else: #bionic doesn't have an item. Which probably means it is a faulty bionic.
retval = GetName(data[var]['name'])
return retval
def generatePage (var): #generates all the data which should be in one of the wiki pages. var is the position of the bionic in the data master list of bionics. Returns empty string if the bionic is obsolete.
output = []
bionic_page_name = bionicPageName(var)
#Check if the bionic isn't in the obsolete list
if( not isObsoleteID(data[var]['id']) ):
#Add item if this bionic is made from an item.
if(ID_To_Item_Int(data[var]['id']) != -1):
item_id = ID_To_Item_Int(data[var]['id'])
#don't print if it is the abstract bionic.
if( not "abstract" in data1[item_id] ):
output.append( """<!-- Automatically generated by https://github.com/Soyweiser/CDDA-Wiki-Scripts The bionics.py script. Any edits made to this can and will be overwritten. Please contact [[User:Soyweiser|Soyweiser]] if you want make changes to this page.
--><noinclude>{{Infobox/Bionics</noinclude>
<includeonly>{{Row/Bionics</includeonly>
|name=""" )
output.append(GetName(data1[item_id]['name']))
output.append("\n|id=")
output.append(data1[item_id]['id'])
output.append("\n|b_id=")
output.append(str(data[var]['id']))
output.append("\n|glyph=")
output.append(getValue(item_id,'symbol'))
output.append("\n|color=")
output.append(getValue(item_id,'color'))
for it in range(0, len(getValue(item_id,'material'))):
output.append("\n|mat")
output.append(str(it+1))
output.append("=")
output.append(getValue(item_id,'material')[it])
output.append("\n|volume=")
output.append(str(getValue(item_id,'volume')))
output.append("\n|weight=")
output.append(str(getValue(item_id,'weight')))
output.append("\n|b_name=")
output.append(ID_To_String(data1[item_id]['id']))
output.append("\n|difficulty=")
output.append(str(getValue(item_id,'difficulty')))
if('capacity' in data[var]):
output.append("\n|capacity=")
output.append(str(data[var]['capacity']))
if(hasFlag(data[var], 'BIONIC_TOGGLED')):
output.append("\n|toggled=true")
if(hasFlag(data[var], 'BIONIC_POWER_SOURCE')):
output.append("\n|power_source=true")
if('act_cost' in data[var]):
output.append("\n|act_cost=")
output.append(str(data[var]['act_cost']))
if('react_cost' in data[var]):
output.append("\n|react_cost=")
output.append(str(data[var]['react_cost']))
if('time' in data[var]):
output.append("\n|time=")
output.append(str(data[var]['time']))
if('deact_cost' in data[var]):
output.append("\n|deact_cost=")
output.append(str(data[var]['deact_cost']))
if(hasFlag(data[var], 'BIONIC_FAULTY')):
output.append("\n|faulty=true")
if(checkValue(item_id,'price')):
output.append("\n|price=")
output.append(str(getValue(item_id,'price')))
else:
output.append("\n|price=0")
if(checkValue(item_id,'bashing')):
output.append("\n|bash=")
output.append(str(getValue(item_id,'bashing')))
else:
output.append("\n|bash=0")
if(checkValue(item_id,'cut')):
output.append("\n|cut=")
output.append(str(getValue(item_id,'cut')))
else:
output.append("\n|cut=0")
if(checkValue(item_id,'tohit')):
output.append("\n|tohit=")
output.append(str(getValue(item_id,'tohit')))
else:
output.append("\n|tohit=0")
if(checkValue(item_id,'description')):
output.append("\n|description=")
output.append(str(getValue(item_id,'description')))
if('description' in data[var]):
output.append("\n|b_description=")
output.append(str(data[var]['description']))
else: #bionic doesn't have an item. Which probably means it is a faulty bionic.
output.append( """<!-- Automatically generated by https://github.com/Soyweiser/CDDA-Wiki-Scripts The bionics.py script. Any edits made to this can and will be overwritten. Please contact [[User:Soyweiser|Soyweiser]] if you want make changes to this page.
--><noinclude>{{Infobox/Bionics</noinclude>
<includeonly>{{Row/Bionics</includeonly>
|name=""" )
output.append(GetName(data[var]['name']))
output.append("\n|b_id=")
output.append(str(data[var]['id']))
output.append("\n|b_name=")
output.append(GetName(data[var]['name']))
if('capacity' in data[var]):
output.append("\n|capacity=")
output.append(str(data[var]['capacity']))
if(hasFlag(data[var], 'BIONIC_TOGGLED')):
output.append("\n|toggled=true")
if(hasFlag(data[var], 'BIONIC_POWER_SOURCE')):
output.append("\n|power_source=true")
if('act_cost' in data[var]):
output.append("\n|act_cost=")
output.append(str(data[var]['act_cost']))
if('react_cost' in data[var]):
output.append("\n|react_cost=")
output.append(str(data[var]['react_cost']))
if('time' in data[var]):
output.append("\n|time=")
output.append(str(data[var]['time']))
if('deact_cost' in data[var]):
output.append("\n|deact_cost=")
output.append(str(data[var]['deact_cost']))
if(hasFlag(data[var], 'BIONIC_FAULTY')):
output.append("\n|faulty=true")
if('description' in data[var]):
output.append("\n|b_description=")
output.append(str(data[var]['description']))
#footer
output.append("""
}}<noinclude>
<div style="margin: 1em; border: 1px solid #aaa; background-color: #white; padding: 5px;">
<h2><span class="plainlinks" style="float: right; font-size: small">
([[{{lc:{{PAGENAME}}}}/doc|<span title="View user added notes">View</span>]] - [{{fullurl:{{lc:{{PAGENAME}}}}/doc|action=edit}} <span title="Edit user notes">Edit Notes</span>] )</span>Notes</h2>
<!-- *DO NOT EDIT THIS AREA, AUTOMATICALLY GENERATED, USE THE EDIT NOTES BUTTON* -->
""")
if('occupied_bodyparts' in data[var]):
output.append("* Uses the following [[Bionics#Bionic_Slots|bionic slot(s)]]:\n")
for it in range(0, len(data[var]["occupied_bodyparts"])):
output.append("** {{btt|")
output.append(str(data[var]["occupied_bodyparts"][it][0]))
output.append("}} ")
output.append(str(data[var]["occupied_bodyparts"][it][1]))
output.append(".\n")
if(hasFlag(data[var], 'BIONIC_FAULTY')):
output.append("* This is considered a [[Bionics#Malfunctioning_bionics|malfunctioning bionic]].\n")
if('capacity' in data[var]):
output.append("* This bionic adds ")
output.append(str(data[var]['capacity']))
output.append(" capacity.\n")
if(hasFlag(data[var], 'BIONIC_POWER_SOURCE')):
output.append("* This bionic is a source of power. The actual type of power source depends on the item. Could be chemical, kinetic, atomics, or anything else.\n")
toggle = False
if(hasFlag(data[var], 'BIONIC_TOGGLED')):
toggle = True
output.append("* This bionic can be turned on, which might have an power cost.\n")
if(not toggle):
if('act_cost' in data[var]):
output.append("* This bionic can be turned on, which might have an power cost.\n")
if('react_cost' in data[var]):
output.append("* This bionic can react automatically, which costs ")
output.append(str(data[var]['react_cost']))
output.append(" power units.\n")
if('included_bionics' in data[var]):
output.append("* Installing this bionic also gives the")
for it in range(0, len(data[var]["included_bionics"])):
if (it > 0):
output.append(",")
output.append(" [[")
output.append(ID_To_String(data[ID_To_Bio_Int(str(data[var]['included_bionics'][it]))]['id']))
output.append("]]")
output.append(" bionic")
if (len(data[var]["included_bionics"]) > 1):
output.append("s")
output.append(".\n")
if('fake_item' in data[var]):
output.append("* This gives the use of the following 'fake item' [http://cdda-trunk.chezzo.com/")
output.append(str(data[var]['fake_item']))
output.append(" ")
output.append(str(data[var]['fake_item']))
output.append("]")
toggle = False
if(hasFlag(data[var], 'BIONIC_TOGGLED')):
toggle = True
output.append(" when activated")
if(not toggle):
if('act_cost' in data[var]):
output.append(" when activated")
output.append(".\n")
if(hasFlag(data[var], 'BIONIC_GUN')):
output.append("* This bionic counts as a gun.\n")
if(hasFlag(data[var], 'BIONIC_WEAPON')):
output.append("* This bionic counts as a weapon.\n")
if('time' in data[var]):
output.append("* This bionic has an over time effect.\n")
if('upgraded_bionic' in data[var]):
output.append("* When installed this bionic upgrades the [[")
output.append(ID_To_String(data[ID_To_Bio_Int(str(data[var]['upgraded_bionic']))]['id']))
output.append("]] bionic. The old bionic will be removed.\n")
if('canceled_mutations' in data[var]):
output.append("* When installed this bionic removes the following [[Mutation|mutations]]:\n")
for it in range(0, len(data[var]["canceled_mutations"])):
output.append("** [[")
output.append(MUT_ID_To_String(str(data[var]["canceled_mutations"][it])))
output.append("]]\n")
if(hasFlag(data[var], 'BIONIC_ARMOR_INTERFACE')):
output.append("* This bionic can provide power to [[Power armor|powered armor]].\n")
if(hasFlag(data[var], 'BIONIC_NPC_USABLE')):
output.append("* This bionic can be used by [[NPC]]s.\n")
output.append("""<!--
*YOUR PERSONAL NOTES AND HINTS SHOULD GO IN THE """ + bionic_page_name +"""/doc PAGE DO NOT EDIT HERE*
-->
{{#ifexist:{{lc:{{PAGENAME}}}}/doc| {{:{{lc:{{PAGENAME}}}}/doc}} |}}<!-- list the doc page if it exists-->
<span class="plainlinks" style="font-size: small"><center>( [{{fullurl:{{lc:{{PAGENAME}}}}/doc|action=edit}} <span title="Edit user notes">Edit Notes</span>] )</center></span>
</div>
[[Category:CBMs]]
{{footer/CBM}}
""")
output.append(version)
output.append("</noinclude>")
output = "".join(output)
output.replace("\n", "\\n")
return output
var = raw_input(">")
while True:
while var.isdigit():
var = int(var)
if(var < 0):
root.update()
root.destroy()
exit()
text = generatePage(var)
print text
root.clipboard_clear()
root.clipboard_append(text)
root.update()
var = raw_input(">")
else:
if ( var == 'exit' ):
root.update()
root.destroy()
exit()
elif ( var == 'all' or var == 'ALL' ):
site = pywikibot.Site('en', 'cddawiki')
for x in range(0, len(data)):
text = generatePage(x)
if( text != []): #check if the bionic isn't obsolete.
page = pywikibot.Page(site, bionicPageName(x))
page.text = text
page.save('Updated text automatically via the https://github.com/Soyweiser/CDDA-Wiki-Scripts bionics.py script')
var = raw_input(">")
else:
print ID_To_Bio_Int(var)
var = raw_input(">")