mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-17 05:03:28 +00:00
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may not be viewable. --> <!-- You can view Contributing.MD for a detailed description of the pull request process. --> ## About The Pull Request Allows us to test for atoms that are required to be placed alongside another atom, such as APCs to cables. There are many situations where a structure spawner is not good enough: - APC cables need to be in any colour or any direction - Airlock mapping helpers may be any access to any airlock and would create too many subtypes. ## Why It's Good For The Game This allows us to have more comprehensive linting added to future mapping changes. This is needed to support the following lints: - Airlocks should not have an access helper if they have access requirement variables set. - Access requirement helpers MUST have an airlock placed on their tile. Needed to satisfy the following review: https://github.com/BeeStation/BeeStation-Hornet/pull/11469#discussion_r1757608360 ## Testing Photographs and Procedure ### Test required neighbors  ### Conditional Rulesets (I know this rule is useless since it mimics banned_variables, but we can make more complex rules with the other ones and with banned_neighbors)   Test a more complex query with set operations:    Super complex query:    Test like:    Not set:  Test is:   ## Changelog 🆑 add: Implements the ability to lint for required neighbors in maplint. add: Adds conditional linting rules in maplint, allowing a lint to apply only if certain conditions are met (Variable is/isn't set, Variable is/isn't a value, Variable matches a regex). /🆑 <!-- Both 🆑's are required for the changelog to work! You can put your name to the right of the first 🆑 if you want to overwrite your GitHub username as author ingame. --> <!-- You can use multiple of the same prefix (they're only used for the icon ingame) and delete the unneeded ones. Despite some of the tags, changelogs should generally represent how a player might be affected by the changes rather than a summary of the PR's contents. -->
41 lines
855 B
Python
41 lines
855 B
Python
import re
|
|
from dataclasses import dataclass
|
|
|
|
from .error import MapParseError
|
|
|
|
REGEX_TYPEPATH = re.compile(r'^/[\w/]+$')
|
|
|
|
class Typepath:
|
|
path: str
|
|
segments: list[str]
|
|
|
|
def __init__(self, path):
|
|
if not REGEX_TYPEPATH.match(path):
|
|
raise MapParseError(f"Invalid typepath {path!r}.")
|
|
|
|
self.path = path
|
|
self.segments = path.split('/')[1:]
|
|
|
|
def __eq__(self, other):
|
|
if not isinstance(other, Typepath):
|
|
return False
|
|
|
|
return self.path == other.path
|
|
|
|
def __str__(self) -> str:
|
|
return self.path
|
|
|
|
@dataclass
|
|
class Filename:
|
|
path: str
|
|
|
|
def __str__(self) -> str:
|
|
return self.path
|
|
|
|
@dataclass
|
|
class Null:
|
|
def __str__(self) -> str:
|
|
return "null"
|
|
|
|
Constant = str | float | Filename | Typepath | Null | list['Constant'] | dict['Constant', 'Constant']
|