Skip to content

Commit

Permalink
remove PlandoConnection stub, finish texts support
Browse files Browse the repository at this point in the history
the only world to use it is Tunic anyways
  • Loading branch information
Silvris committed Mar 5, 2024
1 parent 913a49a commit fea2a34
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
5 changes: 2 additions & 3 deletions Generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from worlds.alttp.EntranceRandomizer import parse_arguments
from worlds.alttp.Text import TextTable
from worlds.AutoWorld import AutoWorldRegister
from worlds.generic import PlandoConnection


def mystery_argparse():
Expand Down Expand Up @@ -463,12 +462,12 @@ def roll_settings(weights: dict, plando_options: PlandoOptions = PlandoOptions.b
if PlandoOptions.items in plando_options:
ret.plando_items = game_weights.get("plando_items", [])
if ret.game == "A Link to the Past":
roll_alttp_settings(ret, game_weights, plando_options)
roll_alttp_settings(ret, game_weights)

return ret


def roll_alttp_settings(ret: argparse.Namespace, weights, plando_options):
def roll_alttp_settings(ret: argparse.Namespace, weights):
ret.sprite_pool = weights.get('sprite_pool', [])
ret.sprite = get_choice_legacy('sprite', weights, "Link")
if 'random_sprite_on_event' in weights:
Expand Down
39 changes: 34 additions & 5 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,11 +900,18 @@ class ItemSet(OptionSet):
convert_name_groups = True


class PlandoTexts(Option[typing.Dict[str, str]], VerifyKeys):
class PlandoText(typing.NamedTuple):
at: str
text: str
percentage: int = 100


class PlandoTexts(Option[typing.List[PlandoText]], VerifyKeys):
default: typing.List = []
supports_weighting = False
display_name = "Plando Texts"

def __init__(self, value: typing.Dict[str, str]):
def __init__(self, value: typing.List[PlandoText]):
self.value = deepcopy(value)
super().__init__()

Expand All @@ -917,22 +924,41 @@ def verify(self, world: typing.Type[World], player_name: str, plando_options: "P
f"so text for {player_name} will be ignored.")

@classmethod
def from_any(cls, data: typing.List[typing.Any]) -> Option[typing.Dict[str, str]]:
texts = {}
def from_any(cls, data: typing.List[typing.Any]) -> Option[typing.List[PlandoText]]:
texts = []
if type(data) == list:
for text in data:
if type(text) == dict:
if random.random() < float(text.get("percentage", 100)/100):
at = text.get("at", None)
if at is not None:
texts[at] = text.get("text", "")
texts.append(PlandoText(
at,
text.get("text"),
text.get("percentage", 100)
))
elif type(text) == PlandoText:
if random.random() < float(text.percentage/100):
texts.append(text)
else:
raise Exception(f"Cannot create plando text from non-dictionary type, got {type(text)}")
cls.verify_keys([text.at for text in texts])
return cls(texts)
else:
raise NotImplementedError(f"Cannot Convert from non-list, got {type(data)}")

def get_option_name(self, value) -> str:
return str({text.at: text.text for text in value})

def __iter__(self):
yield from self.value

def __getitem__(self, item):
return self.value.__getitem__(item)

def __len__(self):
return self.value.__len__()


class ConnectionsMeta(AssembleOptions):
def __new__(mcs, name, bases, attrs):
Expand Down Expand Up @@ -1058,6 +1084,9 @@ def get_option_name(self, value):
"=>",
connection.exit) for connection in value])

def __getitem__(self, item):
return self.value.__getitem__(item)

def __iter__(self):
yield from self.value

Expand Down
2 changes: 1 addition & 1 deletion worlds/alttp/Rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,7 @@ def hint_text(dest, ped_hint=False):
tt['menu_start_2'] = "{MENU}\n{SPEED0}\n≥@'s house\n Dark Chapel\n{CHOICE3}"
tt['menu_start_3'] = "{MENU}\n{SPEED0}\n≥@'s house\n Dark Chapel\n Mountain Cave\n{CHOICE2}"

for at, text in world.plando_texts[player].items():
for at, text, _ in world.plando_texts[player]:

if at not in tt:
raise Exception(f"No text target \"{at}\" found.")
Expand Down
1 change: 0 additions & 1 deletion worlds/generic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from ..AutoWorld import World, WebWorld
from NetUtils import SlotType
from Options import PlandoConnection

class GenericWeb(WebWorld):
advanced_settings = Tutorial('Advanced YAML Guide',
Expand Down
2 changes: 1 addition & 1 deletion worlds/tunic/er_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .er_data import Portal, tunic_er_regions, portal_mapping, hallway_helper, hallway_helper_ur, \
dependent_regions_restricted, dependent_regions_nmg, dependent_regions_ur
from .er_rules import set_er_region_rules
from worlds.generic import PlandoConnection
from Options import PlandoConnection

if TYPE_CHECKING:
from . import TunicWorld
Expand Down

0 comments on commit fea2a34

Please sign in to comment.