Skip to content

Commit

Permalink
invert first if, fix missed Direction reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvris committed Mar 15, 2024
1 parent c8a0e53 commit a76b008
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,34 +1075,34 @@ def validate_plando_connections(cls, connections: typing.Iterable[PlandoConnecti

@classmethod
def from_any(cls, data: PlandoConFromAnyType) -> Self:
if isinstance(data, typing.Iterable):
value: typing.List[PlandoConnection] = []
for connection in data:
if isinstance(connection, typing.Mapping):
percentage = connection.get("percentage", 100)
if random.random() < float(percentage / 100):
entrance = connection.get("entrance", None)
exit = connection.get("exit", None)
direction = connection.get("direction", "both")

if not entrance or not exit:
raise Exception("Plando connection must have an entrance and an exit.")
value.append(PlandoConnection(
entrance,
exit,
direction,
percentage
))
elif isinstance(connection, PlandoConnection):
if random.random() < float(connection.percentage / 100):
value.append(connection)
else:
raise Exception(f"Cannot create connection from non-Dict type, got {type(connection)}.")
cls.validate_plando_connections(value)
return cls(value)
else:
if not isinstance(data, typing.Iterable):
raise Exception(f"Cannot create plando connections from non-List value, got {type(data)}.")

value: typing.List[PlandoConnection] = []
for connection in data:
if isinstance(connection, typing.Mapping):
percentage = connection.get("percentage", 100)
if random.random() < float(percentage / 100):
entrance = connection.get("entrance", None)
exit = connection.get("exit", None)
direction = connection.get("direction", "both")

if not entrance or not exit:
raise Exception("Plando connection must have an entrance and an exit.")
value.append(PlandoConnection(
entrance,
exit,
direction,
percentage
))
elif isinstance(connection, PlandoConnection):
if random.random() < float(connection.percentage / 100):
value.append(connection)
else:
raise Exception(f"Cannot create connection from non-Dict type, got {type(connection)}.")
cls.validate_plando_connections(value)
return cls(value)

def verify(self, world: typing.Type[World], player_name: str, plando_options: "PlandoOptions") -> None:
from BaseClasses import PlandoOptions
if not (PlandoOptions.connections & plando_options):
Expand All @@ -1114,8 +1114,8 @@ def verify(self, world: typing.Type[World], player_name: str, plando_options: "P
@classmethod
def get_option_name(cls, value: typing.List[PlandoConnection]) -> str:
return ", ".join(["%s %s %s" % (connection.entrance,
"<=>" if connection.direction == cls.Direction.Both else
"<=" if connection.direction == cls.Direction.Exit else
"<=>" if connection.direction == PlandoConnection.Direction.both else
"<=" if connection.direction == PlandoConnection.Direction.exit else
"=>",
connection.exit) for connection in value])

Expand Down

0 comments on commit a76b008

Please sign in to comment.