mirror of
https://github.com/evennia/evennia.git
synced 2026-03-20 23:06:31 +01:00
Fix doc generation of all evadventure modules
This commit is contained in:
parent
eafc3d41ad
commit
4529e1a588
14 changed files with 58 additions and 45 deletions
|
|
@ -439,6 +439,7 @@ It's convenient to have the `EquipmentHandler` easily tell you what weapon is cu
|
|||
# mygame/evadventure/equipment.py
|
||||
|
||||
from .enums import WieldLocation, Ability
|
||||
from .objects import get_empty_hand
|
||||
|
||||
# ...
|
||||
|
||||
|
|
@ -469,16 +470,15 @@ class EquipmentHandler:
|
|||
if not weapon:
|
||||
weapon = slots[WieldLocation.WEAPON_HAND]
|
||||
# if we still don't have a weapon, we return None here
|
||||
if not weapon:
|
||||
~ weapon = get_bare_hands()
|
||||
return weapon
|
||||
|
||||
```
|
||||
|
||||
In the `.armor()` method we get the item (if any) out of each relevant wield-slot (body, shield, head), and grab their `armor` Attribute. We then `sum()` them all up.
|
||||
|
||||
In `.weapon()`, we simply check which of the possible weapon slots (weapon-hand or two-hands) have
|
||||
something in them. If not we fall back to the 'fake' weapon `WeaponEmptyHand` which is just a 'dummy'
|
||||
object that represents your bare hands with damage and all.
|
||||
(created in [The Object tutorial](./Beginner-Tutorial-Objects.md#your-bare-hands) earlier).
|
||||
In `.weapon()`, we simply check which of the possible weapon slots (weapon-hand or two-hands) have something in them. If not we fall back to the 'Bare Hands' object we created in the [Object tutorial lesson](./Beginner-Tutorial-Objects.md#your-bare-hands) earlier.
|
||||
|
||||
|
||||
## Extra credits
|
||||
|
|
|
|||
|
|
@ -448,6 +448,8 @@ We will use this in the upcoming [Equipment tutorial lesson](./Beginner-Tutoria
|
|||
|
||||
from evennia import search_object, create_object
|
||||
|
||||
_BARE_HANDS = None
|
||||
|
||||
# ...
|
||||
|
||||
class WeaponBareHands(EvAdventureWeapon)
|
||||
|
|
@ -459,15 +461,24 @@ class WeaponBareHands(EvAdventureWeapon)
|
|||
quality = None # let's assume fists are indestructible ...
|
||||
|
||||
|
||||
# common to put this at the bottom of module
|
||||
BARE_HANDS = search_object("Bare hands", typeclass=WeaponBareHands).first()
|
||||
if not BARE_HANDS:
|
||||
BARE_HANDS = create_object(WeaponBareHands, key="Bare hands")
|
||||
|
||||
def get_bare_hands():
|
||||
"""Get the bare hands"""
|
||||
global _BARE_HANDS
|
||||
if not _BARE_HANDS:
|
||||
_BARE_HANDS = search_object("Bare hands", typeclass=WeaponBareHands).first()
|
||||
if not _BARE_HANDS:
|
||||
_BARE_HANDS = create_object(WeaponBareHands, key="Bare hands")
|
||||
return _BARE_HANDS
|
||||
```
|
||||
|
||||
Since everyone's empty hands are the same (in our game), we create _one_ `Bare hands` weapon object that everyone shares. We do this by searching for the object with `search_object` (the `.first()` means we grab the first one even if we should by accident have created multiple hands, see [The Django querying tutorial](../Part1/Beginner-Tutorial-Django-queries.md) for more info). If we find none, we create it. This way the `BARE_HANDS` object can be used by everyone (we just need to import `objects.BARE_HANDS`).
|
||||
```{sidebar}
|
||||
Creating a single instance of something that is used everywhere is called to create a _Singleton_.
|
||||
```
|
||||
Since everyone's empty hands are the same (in our game), we create _one_ `Bare hands` weapon object that everyone shares. We do this by searching for the object with `search_object` (the `.first()` means we grab the first one even if we should by accident have created multiple hands, see [The Django querying tutorial](../Part1/Beginner-Tutorial-Django-queries.md) for more info). If we find none, we create it.
|
||||
|
||||
By use of the `global` Python keyword, we cache the bare hands object get/create in a module level property `_BARE_HANDS`. So this acts as a cache to not have to search the database more than necessary.
|
||||
|
||||
From now on, other modules can just import and run this function to get the bare hands.
|
||||
|
||||
## Testing and Extra credits
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue