Core: Add Region.add_event (#2965)

* region.add_event function

* Make it return the location bc why not

* Actually item bc that seems more useful

* Update BaseClasses.py

Co-authored-by: Aaron Wagener <mmmcheese158@gmail.com>

* Update BaseClasses.py

Co-authored-by: Aaron Wagener <mmmcheese158@gmail.com>

* add all the requested features from code review

* oop

* roughly sort args in order of importance (imo)

* Fix typing

---------

Co-authored-by: Aaron Wagener <mmmcheese158@gmail.com>
This commit is contained in:
NewSoupVi
2025-04-24 21:56:52 +02:00
committed by GitHub
parent e52d8b4dbd
commit 6ad042b349

View File

@@ -1198,6 +1198,48 @@ class Region:
for location, address in locations.items():
self.locations.append(location_type(self.player, location, address, self))
def add_event(
self,
location_name: str,
item_name: str | None = None,
rule: Callable[[CollectionState], bool] | None = None,
location_type: type[Location] | None = None,
item_type: type[Item] | None = None,
show_in_spoiler: bool = True,
) -> Item:
"""
Adds an event location/item pair to the region.
:param location_name: Name for the event location.
:param item_name: Name for the event item. If not provided, defaults to location_name.
:param rule: Callable to determine access for this event location within its region.
:param location_type: Location class to create the event location with. Defaults to BaseClasses.Location.
:param item_type: Item class to create the event item with. Defaults to BaseClasses.Item.
:param show_in_spoiler: Will be passed along to the created event Location's show_in_spoiler attribute.
:return: The created Event Item
"""
if location_type is None:
location_type = Location
if item_name is None:
item_name = location_name
if item_type is None:
item_type = Item
event_location = location_type(self.player, location_name, None, self)
event_location.show_in_spoiler = show_in_spoiler
if rule is not None:
event_location.access_rule = rule
event_item = item_type(item_name, ItemClassification.progression, None, self.player)
event_location.place_locked_item(event_item)
self.locations.append(event_location)
return event_item
def connect(self, connecting_region: Region, name: Optional[str] = None,
rule: Optional[Callable[[CollectionState], bool]] = None) -> Entrance:
"""