Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions worlds/crosscode/codegen/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def generate_python_file_item_pools(self):

item_pools_complete = template.render(
item_pools=self.lists.item_pools,
item_groups=self.lists.item_groups,
**self.common_args
)

Expand Down
43 changes: 41 additions & 2 deletions worlds/crosscode/codegen/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ListInfo:
dynamic_items: dict[str, ItemData]

item_pools: dict[str, list[ItemPoolEntry]]
item_groups: dict[str, list[ItemData]]

reward_amounts: dict[str, int]

Expand Down Expand Up @@ -96,6 +97,7 @@ def __init__(self, ctx: Context):
self.dynamic_items = {}

self.item_pools = {}
self.item_groups = {}

self.reward_amounts = {}

Expand Down Expand Up @@ -153,6 +155,8 @@ def build(self):

self.__add_progressive_chains(file["progressiveChains"])

self.__add_item_group_list(self.ctx.rando_data["itemGroups"])

self.__add_vars(self.ctx.rando_data["vars"])

def __get_cached_location_id(self, name: str) -> typing.Optional[int]:
Expand Down Expand Up @@ -344,6 +348,14 @@ def __add_shop(self, shop_display_name: str, raw_shop: dict[str, typing.Any]):
"en_US": f"Unlocks \\c[3]all item slots\\c[0] in the shop \\c[3]{real_name}\\c[0]."
}

shop_unlocks = self.item_groups.setdefault(f"Shop Unlocks", [])
if by_shop_item not in shop_unlocks:
shop_unlocks.append(by_shop_item)

global_item_group = self.item_groups.setdefault("Global Slot Unlocks", [])
slots_item_group = self.item_groups.setdefault("Slot Unlocks", [])
this_shop_item_group = self.item_groups.setdefault(f"Slot Unlocks: {shop_base_name}", [])

for item_name in raw_shop["slots"]:
item_data = self.ctx.rando_data["items"][item_name]

Expand Down Expand Up @@ -376,6 +388,9 @@ def __add_shop(self, shop_display_name: str, raw_shop: dict[str, typing.Any]):
by_shop_and_id_item = self.__add_shop_unlock_item(by_shop_and_id_name)
self.shop_unlock_by_shop_and_id[shop_name, item_id] = by_shop_and_id_item

slots_item_group.append(by_shop_and_id_item)
this_shop_item_group.append(by_shop_and_id_item)

self.descriptions[by_shop_and_id_item.combo_id] = {
"en_US": f"Unlocks the slot selling \\c[3]{item_name}\\c[0] in \\c[3]{real_name}\\c[0]."
}
Expand Down Expand Up @@ -409,6 +424,8 @@ def __add_shop(self, shop_display_name: str, raw_shop: dict[str, typing.Any]):
self.shop_unlock_by_id[item_id] = by_id_item
self.global_shop_locations[item_id] = global_location

global_item_group.append(by_id_item)

self.locations_data[global_location.name] = global_location

self.descriptions[by_id_item.combo_id] = {
Expand Down Expand Up @@ -441,10 +458,15 @@ def __add_item_data_list(self, item_list: dict[str, dict[str, typing.Any]]):
for name, raw_item in item_list.items():
self.__add_item_data(name, raw_item)

def __add_item_pool(self, name: str, raw: list[dict[str, typing.Any]]):
def __add_item_pool(self, name: str, raw: dict[str, typing.Any] | list[dict[str, typing.Any]], make_group: bool = True):
"""
Add an item pool to the list of item pools.
"""

if isinstance(raw, dict):
self.__add_item_pool(name, raw["items"], raw.get("group", True))
return

pool: list[ItemPoolEntry] = []
for data in raw:
item = self.__add_reward(data["item"])
Expand All @@ -456,13 +478,23 @@ def __add_item_pool(self, name: str, raw: list[dict[str, typing.Any]]):

self.item_pools[name] = pool

def __add_item_pool_list(self, raw: dict[str, list[dict[str, typing.Any]]]):
if make_group:
self.item_groups[name] = [e.item for e in pool]

def __add_item_pool_list(self, raw: dict[str, dict[str, typing.Any] | list[dict[str, typing.Any]]]):
"""
Add a list of item pools to the list of item pools.
"""
for name, pool in raw.items():
self.__add_item_pool(name, pool)

def __add_item_group(self, name: str, raw: list[list[typing.Any]]):
self.item_groups[name] = [self.__add_reward(item) for item in raw]

def __add_item_group_list(self, raw: dict[str, list[list[typing.Any]]]):
for name, pool in raw.items():
self.__add_item_group(name, pool)

def __add_reward(self, reward: list[dict[str, typing.Any]]) -> ItemData:
"""
Ensure an item reward is in the list of items.
Expand Down Expand Up @@ -497,6 +529,13 @@ def __add_progressive_chain(self, name: str, raw: dict[str, typing.Any]):
raw["reserved"] = True
_, item = self.__add_item_data(f"Progressive {chain.display_name}", raw)
self.progressive_items[name] = item
if raw.get("group", False) and isinstance(chain, ProgressiveItemChainSingle):
if isinstance(raw["group"], str):
group_name = raw["group"]
else:
group_name = chain.display_name
self.item_groups[group_name] = [entry.item for entry in chain.items]
self.item_groups[group_name].append(item)

def __add_progressive_chains(self, raw: dict[str, dict[str, typing.Any]]):
"""
Expand Down
Loading
Loading