-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_logic.py
576 lines (504 loc) · 27.6 KB
/
class_logic.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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
from html.parser import HTMLParser
from os import listdir
import yaml
DEFAULT_BASIC_OBJECT: dict = {
"name": "Default Name",
"in_game_description": "Default In-Game Description",
"player_description": "Default player description",
"base_health": [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 200],
"base_shields": [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 75],
"base_energy": [150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 300],
"chassis_item_name": "Default chassis name",
"neuroptics_item_name": "Default neuroptics name",
"systems_item_name": "Default systems name"
}
OFFICIAL_WARFRAME_DROP_TABLE_HTML_FILE = "Unminified_Warframe_DropTables.html"
class ObjectStorage:
def __init__(self):
self.warframe_list = WarframeList()
self.drop_table_reader = DropTableReader()
def load_all(self):
self.warframe_load_all()
self.drop_table_reader.read_file(OFFICIAL_WARFRAME_DROP_TABLE_HTML_FILE)
def warframe_load_all(self):
self.warframe_list.load_all()
def warframe_load(self, file_path: str):
self.warframe_list.load(file_path)
class DropTableReader(HTMLParser):
"""
This class reads and translates data from HTML downloaded from the official Warframe drop tables at
"https://n8k6e2y6.ssl.hwcdn.net/repos/hnfvc0o3jnfvc873njb03enrf56.html"
into data usable by the warframe info site.
"""
def __init__(self):
HTMLParser.__init__(self)
""" Constant names for various things. """
self.DROP_CHANCE_RARITY_NAMES: tuple = ("Very Common (", "Common (", "Uncommon (", "Rare (", "Ultra Rare (",
"Legendary (")
self.HEADER_2_NAMES: tuple = ("Rotation A", "Rotation B", "Rotation C", "Bounty Completion", "First Completion",
"Subsequent Completions", "Mod Drop Chance", "Blueprint/Item Drop Chance",
"Resource Drop Chance", "Sigil Drop Chance", "Additional Item Drop Chance")
""" Specific storage dictionaries. """
self.mission_storage: dict = {}
self.relic_storage: dict = {}
self.key_mission_storage: dict = {}
self.dynamic_mission_storage: dict = {}
# Dynamic mission storage includes sorties
self.open_world_mission_storage: dict = {}
self.enemy_drop_storage: dict = {}
self.mod_storage: dict = {}
self.item_storage: dict = {}
""" Temporary tags assigned by self.handle_starttag() and used in the handlers."""
self.temp_tag: str = ""
self.temp_section: str = ""
""" Temporary tags assigned and used by the various handlers. """
self.temp_header_1: str = "" # Used as the mission location, mission name, or relic name typically.
self.temp_header_2: str = "" # Used as the rotation name typically.
self.temp_header_3: str = "" # Used as the name of the stage typically.
self.temp_item_name: str = "" # Used as the name of the item being dropped.
self.temp_drop_chance: str = "" # Used as the chance for the item to be dropped.
self.temp_mod_drop_chance: str = ""
def export_full(self) -> dict:
"""
Export all the different storage dictionaries in a single dictionary. Good for exporting to a single YAML file.
:return: A dictionary with all the internal storage dictionaries in it.
"""
return {"missions": self.mission_storage, "relics": self.relic_storage,
"key_missions": self.key_mission_storage, "dynamic_missions": self.dynamic_mission_storage,
"enemy_drops": self.enemy_drop_storage, "mods": self.mod_storage,
"open_world_missions": self.open_world_mission_storage, "items": self.item_storage}
def read_file(self, file_path: str):
"""
Shortcut to quickly feed a file into the parser.
:param file_path: String path to the file.
:return:
"""
self.feed(open(file_path, "r").read())
def handle_starttag(self, tag: str, attrs: list):
"""
Runs when the parser encounters a starting HTML tag.
Assigns self.temp_tag to the latest tag found, and assigns self.temp_section when it reaches a new section of
the html page.
:param tag: The type of tag. Example: th, td, h3...
:param attrs: Attributes of the tag. Example: [], [("id", "transientRewards)]...
:return:
"""
self.temp_tag = tag
if tag == "h3" and attrs and "id" in attrs[0]:
print("Section found:", attrs[0][1])
self.clear_tags_and_headers()
self.temp_section = attrs[0][1]
def handle_data(self, data):
"""
If the data isn't empty or pure whitespace, run a handler function based on what the current section is.
:param data:
:return:
"""
if data.rstrip():
if self.temp_section == "missionRewards":
self.double_header_handler(self.mission_storage, data)
elif self.temp_section == "relicRewards":
self.single_header_handler(self.relic_storage, data)
elif self.temp_section == "keyRewards":
self.double_header_handler(self.key_mission_storage, data)
elif self.temp_section == "transientRewards" or self.temp_section == "sortieRewards":
self.double_header_handler(self.dynamic_mission_storage, data)
elif self.temp_section == "cetusRewards" or self.temp_section == "solarisRewards":
self.triple_header_handler(self.open_world_mission_storage, data)
elif self.temp_section == "modByAvatar":
self.double_header_handler(self.enemy_drop_storage, data)
elif self.temp_section == "modByDrop":
self.single_header_triple_tag_handler(self.mod_storage, data)
elif self.temp_section == "blueprintByAvatar":
self.double_header_handler(self.enemy_drop_storage, data)
elif self.temp_section == "blueprintByDrop":
self.single_header_triple_tag_handler(self.item_storage, data)
elif self.temp_section == "resourceByAvatar":
self.double_header_handler(self.enemy_drop_storage, data)
elif self.temp_section == "resourceByDrop":
self.single_header_triple_tag_handler(self.item_storage, data)
elif self.temp_section == "sigilByAvatar":
self.double_header_handler(self.enemy_drop_storage, data)
elif self.temp_section == "additionalItemByAvatar":
self.double_header_handler(self.enemy_drop_storage, data)
def handle_endtag(self, tag):
"""
Nothing to see here, move along.
:param tag: A string with the data inside the tag being read.
:return:
"""
pass
def error(self, message):
print("A BASE ERROR HAS OCCURRED:", message)
def single_header_handler(self, storage_location: dict, data: str):
"""
This handler assumes that there is only one th tag, and that whatever is in that tag should be the first and
only header. An expected layout follows as such:
Header 1 (in a th tag)
Item name 1 Percent chance to drop
Item name 2 Percent chance to drop
:param storage_location: Dictionary object to put data inside
:param data: A string with the data inside the tag being read.
:return:
"""
if self.temp_tag == "th":
self.header_1_handler(storage_location, data, [])
elif self.temp_tag == "td":
if any(substring in data for substring in self.DROP_CHANCE_RARITY_NAMES):
self.temp_drop_chance = data
else: # Should be the name of the item.
self.temp_item_name = data
if self.temp_item_name and self.temp_drop_chance:
self.item_and_drop_chance_handler(storage_location[self.temp_header_1])
def single_header_triple_tag_handler(self, storage_location: dict, data: str):
"""
This handler assumes that, except for certain key words, whatever is in the th tag should be the first and only
header. An expected layout follows as such:
Header 1 (in a th tag)
Ignored keyword (in th tag) Ignored keyword (in th tag) Ignored keyword (in th tag)
Item/Enemy name 1 Chance for the chance. Rarity of item with percent
Item/Enemy name 2 Chance for the chance. Rarity of item with percent
:param storage_location: Dictionary object to put data inside
:param data: A string with the data inside the tag being read.
:return:
"""
if self.temp_tag == "th" and data != "Enemy Name" and data != "Mod Drop Chance" and data != "Chance" and \
data != "Blueprint/Item Drop Chance" and data != "Resource Drop Chance":
self.header_1_handler(storage_location, data, [])
elif self.temp_tag == "td":
if any(substring in data for substring in self.DROP_CHANCE_RARITY_NAMES):
self.temp_drop_chance = data
elif "%" in data:
self.temp_mod_drop_chance = data
else:
self.temp_item_name = data
if self.temp_item_name and self.temp_drop_chance and self.temp_mod_drop_chance:
self.triple_tag_handler(storage_location[self.temp_header_1])
def double_header_handler(self, storage_location: dict, data: str):
"""
The most commonly used handler, expecting two headers instead of just one. Tests certain key words (located in
self.HEADER_2_NAMES) against the data given. If any of the key words are found, assign to header 2. Else, assign
to header 1. Here is the following expected format:
Header 1 (in a th tag)
Header 2 (in th tag)
Item that can drop Rarity of item with percent
Item that can drop 2 Rarity of item with percent
Because there is not always a second header, a default is created as well, and data may be placed in there
instead.
:param storage_location: Dictionary object to put data inside.
:param data: A string with the data inside the tag being read.
:return:
"""
if self.temp_tag == "th":
if any(substring in data for substring in self.HEADER_2_NAMES):
self.header_2_handler(storage_location, data, [])
else:
self.header_1_handler(storage_location, data, {}, create_default=True, default_type=[])
elif self.temp_tag == "td":
if any(substring in data for substring in self.DROP_CHANCE_RARITY_NAMES):
self.temp_drop_chance = data
else:
self.temp_item_name = data
if self.temp_item_name and self.temp_drop_chance:
self.item_and_drop_chance_handler(storage_location[self.temp_header_1][self.temp_header_2])
def triple_header_handler(self, storage_location: dict, data: str):
"""
This handler expects three headers, and uses key words to separate them. Self.HEADER_2_NAMES for header 2, the
word "Stage" for header 3, otherwise it is header 1. Here is the following expected format:
Header 1
Header 2
Header 3
Item 1 Rarity of item with percent
Item 2 Rarity of item with percent
:param storage_location: Dictionary object to put data inside.
:param data: A string with the data inside the tag being read.
:return:
"""
if self.temp_tag == "th":
if any(substring in data for substring in self.HEADER_2_NAMES):
self.header_2_handler(storage_location, data, {})
elif "Stage" in data:
self.header_3_handler(storage_location, data, [])
else:
self.header_1_handler(storage_location, data, {})
elif self.temp_tag == "td":
if any(substring in data for substring in self.DROP_CHANCE_RARITY_NAMES):
self.temp_drop_chance = data
else:
self.temp_item_name = data
if self.temp_item_name and self.temp_drop_chance:
self.item_and_drop_chance_handler(storage_location[self.temp_header_1][self.temp_header_2]
[self.temp_header_3])
def header_1_handler(self, storage: dict, data: str, set_type, create_default: bool = False, default_type=None):
"""
Mostly created to stop copy and pasting code everywhere. This takes a dictionary, creates a key,
and sets that key equal to to set_type (if it does not exist), preferably an empty list or dictionary.
:param storage: A dictionary, preferably the base level. Example, self.mission_storage.
:param data: Name of the key to create.
:param set_type: Object to make inside of the dictionary. Example, {} or []
:param create_default: Should a default be created.
:param default_type: Object that the default should be. Example, {} or []
:return:
"""
if storage.get(data, None) is None:
storage[data] = set_type
self.temp_header_1 = data
if create_default:
self.header_2_handler(storage, "default", default_type)
def header_2_handler(self, storage: dict, data: str, set_type):
"""
Mostly created to stop copy and pasting code everywhere. This takes a dictionary, creates a key inside of a
nested dictionary, and sets that key equal to to set_type (if it does not exist), preferably an empty list or
dictionary.
:param storage: A dictionary, preferably the base level. Example, self.mission_storage
:param data: Name of the key to create.
:param set_type: Object to make inside of the dictionary. Example, {} or []
:return:
"""
if storage[self.temp_header_1].get(data, None) is None:
storage[self.temp_header_1][data] = set_type
self.temp_header_2 = data
def header_3_handler(self, storage: dict, data: str, set_type):
"""
Mostly created to stop copy and pasting code everywhere. This takes a dictionary, creates a key inside of a
nest dictionary inside of a nested dictionary, and sets that key equal to set_type (if it does not exist).
:param storage: A dictionary, preferably the base level. Example, self.mission_storage
:param data: Name of the key to create.
:param set_type: Object to make inside of the dictionary. Example, {} or []
:return:
"""
if storage[self.temp_header_1][self.temp_header_2].get(data, None) is None:
storage[self.temp_header_1][self.temp_header_2][data] = set_type
self.temp_header_3 = data
def item_and_drop_chance_handler(self, storage: list):
"""
Appends a dictionary with self.temp_item_name and self.temp_drop_chance to the given storage variable.
:param storage: A list, preferably preferably one or two layers inside of a dictionary.
Example, self.mission_storage[self.temp_header_1][self.temp_header_2]
:return:
"""
storage.append({"item_name": self.temp_item_name, "drop_chance": self.temp_drop_chance})
self.temp_item_name = ""
self.temp_drop_chance = ""
def triple_tag_handler(self, storage_location: list):
"""
Appends a dictionary with self.temp_item_name, self.temp_drop_chance, and self.temp_mod_drop_chance to the given
storage variable.
:param storage_location: A list, preferably preferably one or two layers inside of a dictionary.
:return:
"""
storage_location.append({"item_name": self.temp_item_name, "drop_chance": self.temp_drop_chance,
"mod_drop_chance": self.temp_mod_drop_chance})
self.temp_item_name = ""
self.temp_drop_chance = ""
self.temp_mod_drop_chance = ""
def clear_tags_and_headers(self):
"""
A shortcut to wipe the temporary headers and item related variables.
:return:
"""
self.temp_header_1: str = ""
self.temp_header_2: str = ""
self.temp_header_3: str = ""
self.temp_item_name: str = ""
self.temp_drop_chance: str = ""
self.temp_mod_drop_chance: str = ""
"""
import yaml
import class_logic
test = class_logic.DropTableReader()
test.read_file("Unminified_Warframe_DropTables.html")
yaml.dump(test.export_full(), open("Test.yaml", "w"), default_flow_style=None)
exit()
"""
class WarframeList:
def __init__(self):
self.raw: list = []
self.warframes: dict = {}
self.names: list = []
self.file_names: list = []
def load_all(self):
file_list = listdir("data/warframes/")
for file in file_list:
self.load("data/warframes/{}".format(file))
def load(self, file_path: str):
warframe = BasicObject()
warframe.load_from_file(file_path)
self.raw.append(warframe)
self.names.append(warframe.get("name", "Name not found!"))
self.file_names.append(file_path.split("/")[-1].rsplit(".", 1)[0])
self.warframes[file_path.split("/")[-1].rsplit(".", 1)[0]] = warframe
class WarframeMaker:
def __init__(self):
self.ZERO_TO_30_TUPLE = [0, 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]
self.ZERO_TO_8_TUPLE = [1, 2, 3, 4, 5, 6, 7, 8]
self.ZERO_TO_3_TUPLE = [0, 1, 2, 3]
self.EMPTY_ABILITY_DICT = {"name": "", "in_game_description": "", "player_made_description": "",
"duration_effect": [{}, ],
"efficiency_effect": [{}, ],
"range_effect": [{}, ],
"strength_effect": [{}, ],
"misc_effect": [{}, ]}
self.EMPTY_POLARITY_DICT = {"main": [], "aura": "", "exilus": ""}
self.name: str = "PH"
self.in_game_description: str = "PH"
self.player_made_description: str = "PH"
self.base_health: list = self.ZERO_TO_30_TUPLE
self.base_armor: list = self.ZERO_TO_30_TUPLE
self.base_shield: list = self.ZERO_TO_30_TUPLE
self.base_energy: list = self.ZERO_TO_30_TUPLE
self.base_sprint_speed: list = self.ZERO_TO_30_TUPLE
self.in_game_passive: str = "PH"
self.player_made_passive: str = "PH"
self.abilities: list = [self.EMPTY_ABILITY_DICT, ]
self.polarities: dict = self.EMPTY_POLARITY_DICT
def to_dict(self) -> dict:
return {"name": self.name, "in_game_description": self.in_game_description,
"player_made_description": self.player_made_description, "base_health": self.base_health,
"base_armor": self.base_armor, "base_shields": self.base_shield, "base_energy": self.base_energy,
"base_sprint_speed": self.base_sprint_speed, "in_game_passive": self.in_game_passive,
"player_made_passive": self.player_made_passive, "abilities": self.abilities,
"polarities": self.polarities}
# def create(self):
# print("Series of questions to populate a warframe yaml file.")
# print("Don't enter anything to use the default in the brackets.")
#
# self.name = ask_question("Name of the Warframe", "PH")
# self.in_game_description = ask_question("In-game description", "PH")
# self.player_made_description = ask_question("Custom player made description", "PH")
# self.base_health = ask_question_for_length(31, "Set base health:", " Rank")
# self.base_armor = ask_question_for_length(31, "Set base armor:", " Rank")
# self.base_shield = ask_question_for_length(31, "Set base shields:", " Rank")
# self.base_energy = ask_question_for_length(31, "Set base energy:", " Rank")
# self.base_sprint_speed = ask_question_for_length(31, "Set base sprint speed:", " Rank")
# self.in_game_passive = ask_question("In-game description of passive", "PH")
# self.player_made_passive = ask_question("Custom player made description of passive", "PH")
#
# ability_count = ask_question("How many abilities", 4, int)
# self.abilities = []
# for i in range(ability_count):
# print("Ability #{}".format(i + 1))
# ability_ph = self.EMPTY_ABILITY_DICT.copy()
# ability_ph["name"] = ask_question(" Name of ability", "PH")
# ability_ph["in_game_description"] = ask_question(" In-game description", "PH")
# ability_ph["player_made_description"] = ask_question(" Custom player made description", "PH")
# ability_ph["duration_effect"] = ask_question_about_ability("Duration")
# ability_ph["efficiency_effect"] = ask_question_about_ability("Efficiency")
# ability_ph["range_effect"] = ask_question_about_ability("Range")
# ability_ph["strength_effect"] = ask_question_about_ability("Strength")
# ability_ph["misc_effect"] = ask_question_about_ability("Misc")
# self.abilities.append(ability_ph)
#
# polarity_count = ask_question("How many polarities, not including Aura or Exilus", 0, int)
# self.polarities["main"] = ask_question_for_length(polarity_count, "Give name of polarities", "#")
# self.polarities["aura"] = ask_question("Aura polarity, press enter for none.", "")
# self.polarities["exilus"] = ask_question("Exilus polarity, press enter for none.", "")
def create(self):
print("Series of questions to populate a warframe yaml file.")
print("Don't enter anything to use the default in the brackets.")
self.ask_basic()
self.ask_stats()
self.ask_passive()
self.ask_abilities()
self.ask_polarities()
print("Creation finished.")
def ask_basic(self):
self.name = ask_question("Name of the Warframe", "PH")
self.in_game_description = ask_question("In-game description", "PH")
self.player_made_description = ask_question("Custom player made description", "PH")
def ask_stats(self):
self.base_health = ask_question_for_length(31, "Set base health:", " Rank")
self.base_armor = ask_question_for_length(31, "Set base armor:", " Rank")
self.base_shield = ask_question_for_length(31, "Set base shields:", " Rank")
self.base_energy = ask_question_for_length(31, "Set base energy:", " Rank")
self.base_sprint_speed = ask_question_for_length(31, "Set base sprint speed:", " Rank")
def ask_passive(self):
self.in_game_passive = ask_question("In-game description of passive", "PH")
self.player_made_passive = ask_question("Custom player made description of passive", "PH")
def ask_abilities(self):
ability_count = ask_question("How many abilities", 4, int)
self.abilities = []
for i in range(ability_count):
print("Ability #{}".format(i + 1))
ability_ph = self.EMPTY_ABILITY_DICT.copy()
ability_ph["name"] = ask_question(" Name of ability", "PH")
ability_ph["in_game_description"] = ask_question(" In-game description", "PH")
ability_ph["player_made_description"] = ask_question(" Custom player made description", "PH")
ability_ph["duration_effect"] = ask_question_about_ability("Duration")
ability_ph["efficiency_effect"] = ask_question_about_ability("Efficiency")
ability_ph["range_effect"] = ask_question_about_ability("Range")
ability_ph["strength_effect"] = ask_question_about_ability("Strength")
ability_ph["misc_effect"] = ask_question_about_ability("Misc")
self.abilities.append(ability_ph)
def ask_polarities(self):
polarity_count = ask_question("How many polarities, not including Aura or Exilus", 0, int)
self.polarities["main"] = ask_question_for_length(polarity_count, "Give name of polarities", "#")
self.polarities["aura"] = ask_question("Aura polarity, press enter for none.", "")
self.polarities["exilus"] = ask_question("Exilus polarity, press enter for none.", "")
def import_from_file(self, file_name: str):
file = open("data/warframes/{}".format(file_name), "r")
data = yaml.full_load(file)
self.name = data.get("name", "PH")
self.in_game_description = data.get("in_game_description", "PH")
self.player_made_description = data.get("player_made_description", "PH")
self.base_health = data.get("base_health", self.ZERO_TO_30_TUPLE)
self.base_armor = data.get("base_armor", self.ZERO_TO_30_TUPLE)
self.base_shield = data.get("base_shield", self.ZERO_TO_30_TUPLE)
self.base_energy = data.get("base_energy", self.ZERO_TO_30_TUPLE)
self.base_sprint_speed = data.get("base_sprint_speed", self.ZERO_TO_30_TUPLE)
self.in_game_passive = data.get("in_game_passive", "PH")
self.player_made_passive = data.get("player_made_passive", "PH")
self.abilities = data.get("abilities", [self.EMPTY_ABILITY_DICT, ])
self.polarities = data.get("polarities", self.EMPTY_POLARITY_DICT)
def export_to_file(self, file_name: str):
file = open("data/warframes/{}".format(file_name), "w")
yaml.dump(self.to_dict(), file, default_flow_style=None)
"""
from class_logic import WarframeMaker
test = WarframeMaker()
test.create()
"""
class BasicObject(dict):
def __init__(self):
dict.__init__(self)
self.update(DEFAULT_BASIC_OBJECT.copy())
def load_from_file(self, file_path: str):
file = open(file_path, "r")
self.update(yaml.full_load(file))
def save_to_file(self, file_name: str):
file = open(file_name, "w")
yaml.dump(self.copy(), file, default_flow_style=None)
def ask_question_about_ability(effect: str) -> list:
# effects_int = int(ask_question(" How many different things does {} effect".format(effect), 1))
effects_int = ask_question(" How many different things does {} affect".format(effect), 1, int)
effect_list = []
for x in range(effects_int):
print(" {} Effect #{}".format(effect, x + 1))
effect_name = ask_question(" {} Effect Name".format(effect), "PH")
effect_stats = ask_question_for_length(4, " {} Effect Stats".format(effect), " Rank")
effect_list.append({"effect_name": effect_name, "effect_stats": effect_stats})
return effect_list
def ask_question_for_length(length: int, question_string: str, repeat_question_string: str) -> list:
print(question_string)
temp_list = []
for i in range(length):
if i != 0:
temp_list.append(ask_question("{} {}".format(repeat_question_string, i), temp_list[i - 1]))
else:
temp_list.append(ask_question("{} {}".format(repeat_question_string, i), 0))
return temp_list
def ask_question(question_string: str, default, returned_type: type = str):
given = None
while given is None:
try:
given = returned_type(input(question_string + " [{}]: ".format(default)))
except ValueError:
print("Value seemed to be an incorrect type, try again?")
if given != "":
return given
else:
return default