forked from mirror/Archipelago
Some checks failed
Analyze modified files / flake8 (push) Failing after 2m28s
Build / build-win (push) Has been cancelled
Build / build-ubuntu2204 (push) Has been cancelled
ctest / Test C++ ubuntu-latest (push) Has been cancelled
ctest / Test C++ windows-latest (push) Has been cancelled
Analyze modified files / mypy (push) Has been cancelled
Build and Publish Docker Images / Push Docker image to Docker Hub (push) Successful in 5m4s
Native Code Static Analysis / scan-build (push) Failing after 5m2s
type check / pyright (push) Successful in 1m7s
unittests / Test Python 3.11.2 ubuntu-latest (push) Failing after 16m23s
unittests / Test Python 3.12 ubuntu-latest (push) Failing after 28m19s
unittests / Test Python 3.13 ubuntu-latest (push) Failing after 14m49s
unittests / Test hosting with 3.13 on ubuntu-latest (push) Successful in 5m0s
unittests / Test Python 3.13 macos-latest (push) Has been cancelled
unittests / Test Python 3.11 windows-latest (push) Has been cancelled
unittests / Test Python 3.13 windows-latest (push) Has been cancelled
67 lines
2.8 KiB
Python
67 lines
2.8 KiB
Python
from __future__ import annotations
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from worlds.sonic_heroes import SonicHeroesWorld, SonicHeroesLocation, SonicHeroesItem
|
|
|
|
from .constants import *
|
|
from .logicfunctions import *
|
|
from BaseClasses import *
|
|
from worlds.generic.Rules import *
|
|
|
|
|
|
class RuleBuilder:
|
|
"""
|
|
Utility class to more easily build CollectionRule(s)
|
|
Thanks @EternalCode0
|
|
"""
|
|
def __init__(self) -> None:
|
|
self.world: SonicHeroesWorld
|
|
"""
|
|
Reference to world instance (needs to be initialized at Generate Early or later due to options)
|
|
"""
|
|
|
|
def init_world(self, world: SonicHeroesWorld):
|
|
self.world = world
|
|
|
|
|
|
@staticmethod
|
|
def always():
|
|
"""Constant rule to always allow access"""
|
|
return lambda state: True
|
|
|
|
@staticmethod
|
|
def never():
|
|
"""Constant rule to never allow access"""
|
|
return lambda state: False
|
|
|
|
def location(self, location_name: str, rule: CollectionRule = always()):
|
|
"""Sets a rule on the location_name"""
|
|
add_rule(self.world.get_location(location_name), rule) # type: ignore
|
|
|
|
def event(self, region_name: str, location_name: str, item_name: str | None = None,
|
|
rule: CollectionRule = always(), show_in_spoiler: bool = False):
|
|
"""Adds an event location to the world and sets the rule on it's access"""
|
|
region = self.world.get_region(region_name) # type: ignore
|
|
region.add_event(location_name, item_name, rule, SonicHeroesLocation, SonicHeroesItem, show_in_spoiler)
|
|
|
|
def connect(self, name: str, src: str, dest: str, rule: CollectionRule = always(),
|
|
randomization_group: int = 0, randomization_type: EntranceType = EntranceType.TWO_WAY):
|
|
"""Connects a region to another given an access rule.
|
|
Keeps tracks of whether the entrance created from this should later be randomized with `randomize_entrances`.
|
|
|
|
name -- The entrance name for display in text clients. Use SPMEntrance.
|
|
src -- The region.name to connect from. Use SPMRegion.
|
|
dest -- The region.name to connect to. Use SPMRegion.
|
|
rule -- What restricts going from `src` to `dest`.
|
|
randomization_group -- How can this entrance pair with others? Use EGroup with bitwise or (|) to combine these.
|
|
randomization_type -- Is the entrance one-way or two-way? Only applies if randomization_group is specified.
|
|
"""
|
|
src_region = self.world.get_region(src) # type: ignore
|
|
dest_region = self.world.get_region(dest) # type: ignore
|
|
entrance = src_region.connect(dest_region, name, rule)
|
|
if randomization_group > 0:
|
|
entrance.randomization_group = randomization_group
|
|
entrance.randomization_type = randomization_type
|
|
#self.entrance_rando.append(entrance)
|