Archipelago
Archipelago copied to clipboard
Core: Add functions to check whether an Entrance/Region/Location exists
People are doing goofy shit like
if entrance_name in self.multiworld.regions.entrance_cache[self.player]
and
try:
self.get_entrance(entrance_name)
except KeyError:
...
in their world code. Let's stop that.
Alternatives
We could just make the get_[spot] methods return None if the spot doesn't exist. Maybe we could even add an optional argument called return_none_if_not_exists=False for the sake of worlds already relying on the KeyError behavior.
(This would make that function significantly slower though)
We could also make alternative methods called try_get_[spot].
I thought this would be the simplest but I'm obviously willing to hear other opinions
Also:
Are the multiworld versions necessary? I'm not sure whether we should be adding multiworld methods for things at this point, I did it more out of "tradition" than anything
I definitely prefer the try_get_[spot] -> Optional to [spot]_exists -> bool. I have no opinion on if making it a behavior of get_[spot] is better or not, though.
I definitely prefer the
try_get_[spot] -> Optionalto[spot]_exists -> bool. I have no opinion on if making it a behavior ofget_[spot]is better or not, though.
Imma be honest I kinda just hate the name lol (also getting something to check whether it exists is pretty slow but that'd probably not be so bad, I don't think this would be a hot code path)
Apparently this is not wanted so I guess someone can close it if they want to, I will never 😭