mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
Doc, SoE: Logic mixin: no underscore for public members (#1049)
* Doc: logic mixin, drop underscore, clarify conventionally, we added a leading underscore to logic mixins' function names. This is noisy in the warning section of IDEs. Leading underscores should only be used for private/protected functions. In addition, the use of self.world and/or requirement to (no) pass in stuff was not made clear earlier. * SoE: fix _ warnings for logic mixin
This commit is contained in:
@@ -617,8 +617,10 @@ the name of the implementing world. This is due to sharing a namespace with all
|
||||
other logic mixins.
|
||||
|
||||
Typical uses are defining methods that are used instead of `state.has`
|
||||
in lambdas, e.g.`state._mygame_has(custom, world, player)` or recurring checks
|
||||
like `state._mygame_can_do_something(world, player)` to simplify lambdas.
|
||||
in lambdas, e.g.`state.mygame_has(custom, player)` or recurring checks
|
||||
like `state.mygame_can_do_something(player)` to simplify lambdas.
|
||||
Private members, only accessible from mixins, should start with `_mygame_`,
|
||||
public members with `mygame_`.
|
||||
|
||||
More advanced uses could be to add additional variables to the state object,
|
||||
override `World.collect(self, state, item)` and `remove(self, state, item)`
|
||||
@@ -633,9 +635,10 @@ Please do this with caution and only when neccessary.
|
||||
from worlds.AutoWorld import LogicMixin
|
||||
|
||||
class MyGameLogic(LogicMixin):
|
||||
def _mygame_has_key(self, world: MultiWorld, player: int):
|
||||
def mygame_has_key(self, player: int):
|
||||
# Arguments above are free to choose
|
||||
# it may make sense to use World as argument instead of MultiWorld
|
||||
# MultiWorld can be accessed through self.world, explicitly passing in
|
||||
# MyGameWorld instance for easy options access is also a valid approach
|
||||
return self.has("key", player) # or whatever
|
||||
```
|
||||
```python
|
||||
@@ -648,7 +651,7 @@ class MyGameWorld(World):
|
||||
# ...
|
||||
def set_rules(self):
|
||||
set_rule(self.world.get_location("A Door", self.player),
|
||||
lamda state: state._mygame_has_key(self.world, self.player))
|
||||
lamda state: state.mygame_has_key(self.player))
|
||||
```
|
||||
|
||||
### Generate Output
|
||||
|
Reference in New Issue
Block a user