2
2
3
3
import argparse
4
4
import logging
5
+ import os
5
6
import random
6
- import urllib . request
7
+ import string
7
8
import urllib .parse
8
- from typing import Set , Dict , Tuple , Callable , Any , Union
9
- import os
9
+ import urllib .request
10
10
from collections import Counter , ChainMap
11
- import string
12
- import enum
11
+ from typing import Dict , Tuple , Callable , Any , Union
13
12
14
13
import ModuleUpdate
15
14
18
17
import Utils
19
18
from worlds .alttp import Options as LttPOptions
20
19
from worlds .generic import PlandoConnection
21
- from Utils import parse_yamls , version_tuple , __version__ , tuplize_version , get_options , local_path , user_path
20
+ from Utils import parse_yamls , version_tuple , __version__ , tuplize_version , get_options , user_path
22
21
from worlds .alttp .EntranceRandomizer import parse_arguments
23
22
from Main import main as ERmain
24
- from BaseClasses import seeddigits , get_seed
23
+ from BaseClasses import seeddigits , get_seed , PlandoOptions
25
24
import Options
26
25
from worlds .alttp .Text import TextTable
27
26
from worlds .AutoWorld import AutoWorldRegister
28
27
import copy
29
28
30
29
31
- class PlandoSettings (enum .IntFlag ):
32
- items = 0b0001
33
- connections = 0b0010
34
- texts = 0b0100
35
- bosses = 0b1000
36
-
37
- @classmethod
38
- def from_option_string (cls , option_string : str ) -> PlandoSettings :
39
- result = cls (0 )
40
- for part in option_string .split ("," ):
41
- part = part .strip ().lower ()
42
- if part :
43
- result = cls ._handle_part (part , result )
44
- return result
45
-
46
- @classmethod
47
- def from_set (cls , option_set : Set [str ]) -> PlandoSettings :
48
- result = cls (0 )
49
- for part in option_set :
50
- result = cls ._handle_part (part , result )
51
- return result
52
-
53
- @classmethod
54
- def _handle_part (cls , part : str , base : PlandoSettings ) -> PlandoSettings :
55
- try :
56
- part = cls [part ]
57
- except Exception as e :
58
- raise KeyError (f"{ part } is not a recognized name for a plando module. "
59
- f"Known options: { ', ' .join (flag .name for flag in cls )} " ) from e
60
- else :
61
- return base | part
62
30
63
- def __str__ (self ) -> str :
64
- if self .value :
65
- return ", " .join (flag .name for flag in PlandoSettings if self .value & flag .value )
66
- return "Off"
67
31
68
32
69
33
def mystery_argparse ():
@@ -97,7 +61,7 @@ def resolve_path(path: str, resolver: Callable[[str], str]) -> str:
97
61
args .weights_file_path = os .path .join (args .player_files_path , args .weights_file_path )
98
62
if not os .path .isabs (args .meta_file_path ):
99
63
args .meta_file_path = os .path .join (args .player_files_path , args .meta_file_path )
100
- args .plando : PlandoSettings = PlandoSettings .from_option_string (args .plando )
64
+ args .plando : PlandoOptions = PlandoOptions .from_option_string (args .plando )
101
65
return args , options
102
66
103
67
@@ -170,6 +134,7 @@ def main(args=None, callback=ERmain):
170
134
f"A mix is also permitted." )
171
135
erargs = parse_arguments (['--multi' , str (args .multi )])
172
136
erargs .seed = seed
137
+ erargs .plando_options = args .plando
173
138
erargs .glitch_triforce = options ["generator" ]["glitch_triforce_room" ]
174
139
erargs .spoiler = args .spoiler
175
140
erargs .race = args .race
@@ -226,7 +191,7 @@ def main(args=None, callback=ERmain):
226
191
elif not erargs .name [player ]: # if name was not specified, generate it from filename
227
192
erargs .name [player ] = os .path .splitext (os .path .split (path )[- 1 ])[0 ]
228
193
erargs .name [player ] = handle_name (erargs .name [player ], player , name_counter )
229
-
194
+
230
195
player += 1
231
196
except Exception as e :
232
197
raise ValueError (f"File { path } is destroyed. Please fix your yaml." ) from e
@@ -443,7 +408,7 @@ def roll_triggers(weights: dict, triggers: list) -> dict:
443
408
return weights
444
409
445
410
446
- def handle_option (ret : argparse .Namespace , game_weights : dict , option_key : str , option : type (Options .Option ), plando_options : PlandoSettings ):
411
+ def handle_option (ret : argparse .Namespace , game_weights : dict , option_key : str , option : type (Options .Option ), plando_options : PlandoOptions ):
447
412
if option_key in game_weights :
448
413
try :
449
414
if not option .supports_weighting :
@@ -459,7 +424,7 @@ def handle_option(ret: argparse.Namespace, game_weights: dict, option_key: str,
459
424
setattr (ret , option_key , option .from_any (option .default )) # call the from_any here to support default "random"
460
425
461
426
462
- def roll_settings (weights : dict , plando_options : PlandoSettings = PlandoSettings .bosses ):
427
+ def roll_settings (weights : dict , plando_options : PlandoOptions = PlandoOptions .bosses ):
463
428
if "linked_options" in weights :
464
429
weights = roll_linked_options (weights )
465
430
@@ -472,7 +437,7 @@ def roll_settings(weights: dict, plando_options: PlandoSettings = PlandoSettings
472
437
if tuplize_version (version ) > version_tuple :
473
438
raise Exception (f"Settings reports required version of generator is at least { version } , "
474
439
f"however generator is of version { __version__ } " )
475
- required_plando_options = PlandoSettings .from_option_string (requirements .get ("plando" , "" ))
440
+ required_plando_options = PlandoOptions .from_option_string (requirements .get ("plando" , "" ))
476
441
if required_plando_options not in plando_options :
477
442
if required_plando_options :
478
443
raise Exception (f"Settings reports required plando module { str (required_plando_options )} , "
@@ -506,12 +471,12 @@ def roll_settings(weights: dict, plando_options: PlandoSettings = PlandoSettings
506
471
if option_key not in world_type .option_definitions and \
507
472
(option_key not in Options .common_options or option_key in game_weights ):
508
473
handle_option (ret , game_weights , option_key , option , plando_options )
509
- if PlandoSettings .items in plando_options :
474
+ if PlandoOptions .items in plando_options :
510
475
ret .plando_items = game_weights .get ("plando_items" , [])
511
476
if ret .game == "Minecraft" or ret .game == "Ocarina of Time" :
512
477
# bad hardcoded behavior to make this work for now
513
478
ret .plando_connections = []
514
- if PlandoSettings .connections in plando_options :
479
+ if PlandoOptions .connections in plando_options :
515
480
options = game_weights .get ("plando_connections" , [])
516
481
for placement in options :
517
482
if roll_percentage (get_choice ("percentage" , placement , 100 )):
@@ -626,7 +591,7 @@ def roll_alttp_settings(ret: argparse.Namespace, weights, plando_options):
626
591
raise Exception (f"unknown Medallion { medallion } for { 'misery mire' if index == 0 else 'turtle rock' } " )
627
592
628
593
ret .plando_texts = {}
629
- if PlandoSettings .texts in plando_options :
594
+ if PlandoOptions .texts in plando_options :
630
595
tt = TextTable ()
631
596
tt .removeUnwantedText ()
632
597
options = weights .get ("plando_texts" , [])
@@ -638,7 +603,7 @@ def roll_alttp_settings(ret: argparse.Namespace, weights, plando_options):
638
603
ret .plando_texts [at ] = str (get_choice_legacy ("text" , placement ))
639
604
640
605
ret .plando_connections = []
641
- if PlandoSettings .connections in plando_options :
606
+ if PlandoOptions .connections in plando_options :
642
607
options = weights .get ("plando_connections" , [])
643
608
for placement in options :
644
609
if roll_percentage (get_choice_legacy ("percentage" , placement , 100 )):
0 commit comments