Rules: Verify the default values of `Option`s. (#2403)
* Verify the default values of `Option`s. Since `Option.verify()` can handle normalization of option names, this allows options to define defaults which rely on that normalization. For example, it allows a world to exclude certain locations by default. This also makes it easier to catch errors if a world author accidentally sets an invalid default. * Update Generate.py Co-authored-by: Doug Hoskisson <beauxq@users.noreply.github.com> --------- Co-authored-by: Doug Hoskisson <beauxq@users.noreply.github.com> Co-authored-by: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									3cc434cd78
								
							
						
					
					
						commit
						9d478ba2bc
					
				
							
								
								
									
										14
									
								
								Generate.py
								
								
								
								
							
							
						
						
									
										14
									
								
								Generate.py
								
								
								
								
							| 
						 | 
				
			
			@ -409,19 +409,19 @@ def roll_triggers(weights: dict, triggers: list) -> dict:
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
def handle_option(ret: argparse.Namespace, game_weights: dict, option_key: str, option: type(Options.Option), plando_options: PlandoOptions):
 | 
			
		||||
    if option_key in game_weights:
 | 
			
		||||
        try:
 | 
			
		||||
    try:
 | 
			
		||||
        if option_key in game_weights:
 | 
			
		||||
            if not option.supports_weighting:
 | 
			
		||||
                player_option = option.from_any(game_weights[option_key])
 | 
			
		||||
            else:
 | 
			
		||||
                player_option = option.from_any(get_choice(option_key, game_weights))
 | 
			
		||||
            setattr(ret, option_key, player_option)
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            raise Options.OptionError(f"Error generating option {option_key} in {ret.game}") from e
 | 
			
		||||
        else:
 | 
			
		||||
            player_option.verify(AutoWorldRegister.world_types[ret.game], ret.name, plando_options)
 | 
			
		||||
            player_option = option.from_any(option.default)  # call the from_any here to support default "random"
 | 
			
		||||
        setattr(ret, option_key, player_option)
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        raise Options.OptionError(f"Error generating option {option_key} in {ret.game}") from e
 | 
			
		||||
    else:
 | 
			
		||||
        setattr(ret, option_key, option.from_any(option.default))  # call the from_any here to support default "random"
 | 
			
		||||
        player_option.verify(AutoWorldRegister.world_types[ret.game], ret.name, plando_options)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def roll_settings(weights: dict, plando_options: PlandoOptions = PlandoOptions.bosses):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue