Rename all at_before/after hooks to at_pre/post. Old names still work but are deprecated. Resolves #1454.
This commit is contained in:
parent
7b25299be4
commit
36e985557f
21 changed files with 106 additions and 102 deletions
|
|
@ -101,6 +101,8 @@ Up requirements to Django 3.2+, Twisted 21+
|
||||||
`msg_contents`.
|
`msg_contents`.
|
||||||
- Update defauklt website to show Telnet/SSL/SSH connect info. Added new
|
- Update defauklt website to show Telnet/SSL/SSH connect info. Added new
|
||||||
`SERVER_HOSTNAME` setting for use in the server:port stanza.
|
`SERVER_HOSTNAME` setting for use in the server:port stanza.
|
||||||
|
- Changed all `at_before/after_*` hooks to `at_pre/post_*` for consistency
|
||||||
|
across Evennia (the old names still work but are deprecated)
|
||||||
|
|
||||||
|
|
||||||
### Evennia 0.9.5 (2019-2020)
|
### Evennia 0.9.5 (2019-2020)
|
||||||
|
|
|
||||||
|
|
@ -170,14 +170,14 @@ object).
|
||||||
1. The Exit command triggers `at_traverse(obj, destination)` on the Exit object.
|
1. The Exit command triggers `at_traverse(obj, destination)` on the Exit object.
|
||||||
1. In `at_traverse`, `object.move_to(destination)` is triggered. This triggers the following hooks,
|
1. In `at_traverse`, `object.move_to(destination)` is triggered. This triggers the following hooks,
|
||||||
in order:
|
in order:
|
||||||
1. `obj.at_before_move(destination)` - if this returns False, move is aborted.
|
1. `obj.at_pre_move(destination)` - if this returns False, move is aborted.
|
||||||
1. `origin.at_before_leave(obj, destination)`
|
1. `origin.at_pre_leave(obj, destination)`
|
||||||
1. `obj.announce_move_from(destination)`
|
1. `obj.announce_move_from(destination)`
|
||||||
1. Move is performed by changing `obj.location` from source location to `destination`.
|
1. Move is performed by changing `obj.location` from source location to `destination`.
|
||||||
1. `obj.announce_move_to(source)`
|
1. `obj.announce_move_to(source)`
|
||||||
1. `destination.at_object_receive(obj, source)`
|
1. `destination.at_object_receive(obj, source)`
|
||||||
1. `obj.at_after_move(source)`
|
1. `obj.at_post_move(source)`
|
||||||
1. On the Exit object, `at_after_traverse(obj, source)` is triggered.
|
1. On the Exit object, `at_post_traverse(obj, source)` is triggered.
|
||||||
|
|
||||||
If the move fails for whatever reason, the Exit will look for an Attribute `err_traverse` on itself
|
If the move fails for whatever reason, the Exit will look for an Attribute `err_traverse` on itself
|
||||||
and display this as an error message. If this is not found, the Exit will instead call
|
and display this as an error message. If this is not found, the Exit will instead call
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,12 @@ for more info.
|
||||||
**Q:** How does one keep a character from using any exit, if they meet a certain condition? (I.E. in
|
**Q:** How does one keep a character from using any exit, if they meet a certain condition? (I.E. in
|
||||||
combat, immobilized, etc.)
|
combat, immobilized, etc.)
|
||||||
|
|
||||||
**A:** The `at_before_move` hook is called by Evennia just before performing any move. If it returns
|
**A:** The `at_pre_move` hook is called by Evennia just before performing any move. If it returns
|
||||||
`False`, the move is aborted. Let's say we want to check for an [Attribute](../Components/Attributes.md) `cantmove`.
|
`False`, the move is aborted. Let's say we want to check for an [Attribute](../Components/Attributes.md) `cantmove`.
|
||||||
Add the following code to the `Character` class:
|
Add the following code to the `Character` class:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def at_before_move(self, destination):
|
def at_pre_move(self, destination):
|
||||||
"Called just before trying to move"
|
"Called just before trying to move"
|
||||||
if self.db.cantmove: # replace with condition you want to test
|
if self.db.cantmove: # replace with condition you want to test
|
||||||
self.msg("Something is preventing you from moving!")
|
self.msg("Something is preventing you from moving!")
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ This requires a change to our Character typeclass. Open `mygame/typeclasses/char
|
||||||
class Character(DefaultCharacter):
|
class Character(DefaultCharacter):
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
def at_before_move(self, destination):
|
def at_pre_move(self, destination):
|
||||||
"""
|
"""
|
||||||
Called by self.move_to when trying to move somewhere. If this returns
|
Called by self.move_to when trying to move somewhere. If this returns
|
||||||
False, the move is immediately cancelled.
|
False, the move is immediately cancelled.
|
||||||
|
|
@ -49,7 +49,7 @@ class Character(DefaultCharacter):
|
||||||
```
|
```
|
||||||
|
|
||||||
When moving somewhere, [character.move_to](evennia.objects.objects.DefaultObject.move_to) is called. This in turn
|
When moving somewhere, [character.move_to](evennia.objects.objects.DefaultObject.move_to) is called. This in turn
|
||||||
will call `character.at_before_move`. Here we look for an Attribute `is_resting` (which we will assign below)
|
will call `character.at_pre_move`. Here we look for an Attribute `is_resting` (which we will assign below)
|
||||||
to determine if we are stuck on the chair or not.
|
to determine if we are stuck on the chair or not.
|
||||||
|
|
||||||
## Making the Chair itself
|
## Making the Chair itself
|
||||||
|
|
|
||||||
|
|
@ -81,14 +81,14 @@ This room checks the typeclass of objects entering it (using `utils.inherits_fro
|
||||||
contents and inform any `NPCs inside by calling their `at_char_entered` method.
|
contents and inform any `NPCs inside by calling their `at_char_entered` method.
|
||||||
|
|
||||||
You'll also see that we have added a 'look' into this code. This is because, by default, the
|
You'll also see that we have added a 'look' into this code. This is because, by default, the
|
||||||
`at_object_receive` is carried out *before* the character's `at_after_move` which, we will now
|
`at_object_receive` is carried out *before* the character's `at_post_move` which, we will now
|
||||||
overload. This means that a character entering would see the NPC perform its actions before the
|
overload. This means that a character entering would see the NPC perform its actions before the
|
||||||
'look' command. Deactivate the look command in the default `Character` class within the
|
'look' command. Deactivate the look command in the default `Character` class within the
|
||||||
`typeclasses.characters` module:
|
`typeclasses.characters` module:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Add this hook in any blank area within your Character class.
|
# Add this hook in any blank area within your Character class.
|
||||||
def at_after_move(self, source_location):
|
def at_post_move(self, source_location):
|
||||||
"""
|
"""
|
||||||
Default is to look around after a move
|
Default is to look around after a move
|
||||||
Note: This has been moved to Room.at_object_receive
|
Note: This has been moved to Room.at_object_receive
|
||||||
|
|
|
||||||
|
|
@ -427,8 +427,8 @@ class CmdGet(COMMAND_DEFAULT_CLASS):
|
||||||
caller.msg("You can't get that.")
|
caller.msg("You can't get that.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# calling at_before_get hook method
|
# calling at_pre_get hook method
|
||||||
if not obj.at_before_get(caller):
|
if not obj.at_pre_get(caller):
|
||||||
return
|
return
|
||||||
|
|
||||||
success = obj.move_to(caller, quiet=True)
|
success = obj.move_to(caller, quiet=True)
|
||||||
|
|
@ -477,8 +477,8 @@ class CmdDrop(COMMAND_DEFAULT_CLASS):
|
||||||
if not obj:
|
if not obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Call the object script's at_before_drop() method.
|
# Call the object script's at_pre_drop() method.
|
||||||
if not obj.at_before_drop(caller):
|
if not obj.at_pre_drop(caller):
|
||||||
return
|
return
|
||||||
|
|
||||||
success = obj.move_to(caller.location, quiet=True)
|
success = obj.move_to(caller.location, quiet=True)
|
||||||
|
|
@ -530,8 +530,8 @@ class CmdGive(COMMAND_DEFAULT_CLASS):
|
||||||
caller.msg("You are not holding %s." % to_give.key)
|
caller.msg("You are not holding %s." % to_give.key)
|
||||||
return
|
return
|
||||||
|
|
||||||
# calling at_before_give hook method
|
# calling at_pre_give hook method
|
||||||
if not to_give.at_before_give(caller, target):
|
if not to_give.at_pre_give(caller, target):
|
||||||
return
|
return
|
||||||
|
|
||||||
# give object
|
# give object
|
||||||
|
|
@ -597,14 +597,14 @@ class CmdSay(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
speech = self.args
|
speech = self.args
|
||||||
|
|
||||||
# Calling the at_before_say hook on the character
|
# Calling the at_pre_say hook on the character
|
||||||
speech = caller.at_before_say(speech)
|
speech = caller.at_pre_say(speech)
|
||||||
|
|
||||||
# If speech is empty, stop here
|
# If speech is empty, stop here
|
||||||
if not speech:
|
if not speech:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Call the at_after_say hook on the character
|
# Call the at_post_say hook on the character
|
||||||
caller.at_say(speech, msg_self=True)
|
caller.at_say(speech, msg_self=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -643,7 +643,7 @@ class CmdWhisper(COMMAND_DEFAULT_CLASS):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Call a hook to change the speech before whispering
|
# Call a hook to change the speech before whispering
|
||||||
speech = caller.at_before_say(speech, whisper=True, receivers=receivers)
|
speech = caller.at_pre_say(speech, whisper=True, receivers=receivers)
|
||||||
|
|
||||||
# no need for self-message if we are whispering to ourselves (for some reason)
|
# no need for self-message if we are whispering to ourselves (for some reason)
|
||||||
msg_self = None if caller in receivers else True
|
msg_self = None if caller in receivers else True
|
||||||
|
|
|
||||||
|
|
@ -290,7 +290,7 @@ class EventCharacter(DefaultCharacter):
|
||||||
|
|
||||||
super().announce_move_to(source_location, msg=string, mapping=mapping)
|
super().announce_move_to(source_location, msg=string, mapping=mapping)
|
||||||
|
|
||||||
def at_before_move(self, destination):
|
def at_pre_move(self, destination):
|
||||||
"""
|
"""
|
||||||
Called just before starting to move this object to
|
Called just before starting to move this object to
|
||||||
destination.
|
destination.
|
||||||
|
|
@ -330,7 +330,7 @@ class EventCharacter(DefaultCharacter):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def at_after_move(self, source_location):
|
def at_post_move(self, source_location):
|
||||||
"""
|
"""
|
||||||
Called after move has completed, regardless of quiet mode or
|
Called after move has completed, regardless of quiet mode or
|
||||||
not. Allows changes to the object due to the location it is
|
not. Allows changes to the object due to the location it is
|
||||||
|
|
@ -340,7 +340,7 @@ class EventCharacter(DefaultCharacter):
|
||||||
source_location (Object): Wwhere we came from. This may be `None`.
|
source_location (Object): Wwhere we came from. This may be `None`.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
super().at_after_move(source_location)
|
super().at_post_move(source_location)
|
||||||
|
|
||||||
origin = source_location
|
origin = source_location
|
||||||
destination = self.location
|
destination = self.location
|
||||||
|
|
@ -410,7 +410,7 @@ class EventCharacter(DefaultCharacter):
|
||||||
|
|
||||||
super().at_pre_unpuppet()
|
super().at_pre_unpuppet()
|
||||||
|
|
||||||
def at_before_say(self, message, **kwargs):
|
def at_pre_say(self, message, **kwargs):
|
||||||
"""
|
"""
|
||||||
Before the object says something.
|
Before the object says something.
|
||||||
|
|
||||||
|
|
@ -646,7 +646,7 @@ class EventExit(DefaultExit):
|
||||||
normally by calling
|
normally by calling
|
||||||
`traversing_object.move_to(target_location)`. It is normally
|
`traversing_object.move_to(target_location)`. It is normally
|
||||||
only implemented by Exit objects. If it returns False (usually
|
only implemented by Exit objects. If it returns False (usually
|
||||||
because `move_to` returned False), `at_after_traverse` below
|
because `move_to` returned False), `at_post_traverse` below
|
||||||
should not be called and instead `at_failed_traverse` should be
|
should not be called and instead `at_failed_traverse` should be
|
||||||
called.
|
called.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -970,7 +970,7 @@ class CmdSay(RPCommand): # replaces standard say
|
||||||
return
|
return
|
||||||
|
|
||||||
# calling the speech modifying hook
|
# calling the speech modifying hook
|
||||||
speech = caller.at_before_say(self.args)
|
speech = caller.at_pre_say(self.args)
|
||||||
# preparing the speech with sdesc/speech parsing.
|
# preparing the speech with sdesc/speech parsing.
|
||||||
targets = self.caller.location.contents
|
targets = self.caller.location.contents
|
||||||
send_emote(self.caller, targets, speech, anonymous_add=None)
|
send_emote(self.caller, targets, speech, anonymous_add=None)
|
||||||
|
|
@ -1614,7 +1614,7 @@ class ContribRPCharacter(DefaultCharacter, ContribRPObject):
|
||||||
# initializing sdesc
|
# initializing sdesc
|
||||||
self.sdesc.add("A normal person")
|
self.sdesc.add("A normal person")
|
||||||
|
|
||||||
def at_before_say(self, message, **kwargs):
|
def at_pre_say(self, message, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called before the object says or whispers anything, return modified message.
|
Called before the object says or whispers anything, return modified message.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ class SlowExit(DefaultExit):
|
||||||
"This callback will be called by utils.delay after move_delay seconds."
|
"This callback will be called by utils.delay after move_delay seconds."
|
||||||
source_location = traversing_object.location
|
source_location = traversing_object.location
|
||||||
if traversing_object.move_to(target_location):
|
if traversing_object.move_to(target_location):
|
||||||
self.at_after_traverse(traversing_object, source_location)
|
self.at_post_traverse(traversing_object, source_location)
|
||||||
else:
|
else:
|
||||||
if self.db.err_traverse:
|
if self.db.err_traverse:
|
||||||
# if exit has a better error message, let's use it.
|
# if exit has a better error message, let's use it.
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,7 @@ class TBBasicCharacter(DefaultCharacter):
|
||||||
can be changed at creation and factor into combat calculations.
|
can be changed at creation and factor into combat calculations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def at_before_move(self, destination):
|
def at_pre_move(self, destination):
|
||||||
"""
|
"""
|
||||||
Called just before starting to move this object to
|
Called just before starting to move this object to
|
||||||
destination.
|
destination.
|
||||||
|
|
|
||||||
|
|
@ -588,7 +588,7 @@ class TBEArmor(DefaultObject):
|
||||||
-4
|
-4
|
||||||
) # Amount to modify defense value (pos = harder to hit, neg = easier)
|
) # Amount to modify defense value (pos = harder to hit, neg = easier)
|
||||||
|
|
||||||
def at_before_drop(self, dropper):
|
def at_pre_drop(self, dropper):
|
||||||
"""
|
"""
|
||||||
Can't drop in combat.
|
Can't drop in combat.
|
||||||
"""
|
"""
|
||||||
|
|
@ -605,7 +605,7 @@ class TBEArmor(DefaultObject):
|
||||||
dropper.db.worn_armor = None
|
dropper.db.worn_armor = None
|
||||||
dropper.location.msg_contents("%s removes %s." % (dropper, self))
|
dropper.location.msg_contents("%s removes %s." % (dropper, self))
|
||||||
|
|
||||||
def at_before_give(self, giver, getter):
|
def at_pre_give(self, giver, getter):
|
||||||
"""
|
"""
|
||||||
Can't give away in combat.
|
Can't give away in combat.
|
||||||
"""
|
"""
|
||||||
|
|
@ -649,7 +649,7 @@ class TBEquipCharacter(DefaultCharacter):
|
||||||
can be changed at creation and factor into combat calculations.
|
can be changed at creation and factor into combat calculations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def at_before_move(self, destination):
|
def at_pre_move(self, destination):
|
||||||
"""
|
"""
|
||||||
Called just before starting to move this object to
|
Called just before starting to move this object to
|
||||||
destination.
|
destination.
|
||||||
|
|
|
||||||
|
|
@ -531,7 +531,7 @@ class TBItemsCharacter(DefaultCharacter):
|
||||||
can be changed at creation and factor into combat calculations.
|
can be changed at creation and factor into combat calculations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def at_before_move(self, destination):
|
def at_pre_move(self, destination):
|
||||||
"""
|
"""
|
||||||
Called just before starting to move this object to
|
Called just before starting to move this object to
|
||||||
destination.
|
destination.
|
||||||
|
|
|
||||||
|
|
@ -351,7 +351,7 @@ class TBMagicCharacter(DefaultCharacter):
|
||||||
self.db.max_mp = 20 # Set maximum MP to 20
|
self.db.max_mp = 20 # Set maximum MP to 20
|
||||||
self.db.mp = self.db.max_mp # Set current MP to maximum
|
self.db.mp = self.db.max_mp # Set current MP to maximum
|
||||||
|
|
||||||
def at_before_move(self, destination):
|
def at_pre_move(self, destination):
|
||||||
"""
|
"""
|
||||||
Called just before starting to move this object to
|
Called just before starting to move this object to
|
||||||
destination.
|
destination.
|
||||||
|
|
|
||||||
|
|
@ -799,7 +799,7 @@ class TBRangeCharacter(DefaultCharacter):
|
||||||
can be changed at creation and factor into combat calculations.
|
can be changed at creation and factor into combat calculations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def at_before_move(self, destination):
|
def at_pre_move(self, destination):
|
||||||
"""
|
"""
|
||||||
Called just before starting to move this object to
|
Called just before starting to move this object to
|
||||||
destination.
|
destination.
|
||||||
|
|
@ -833,7 +833,7 @@ class TBRangeObject(DefaultObject):
|
||||||
objects on your own turn.
|
objects on your own turn.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def at_before_drop(self, dropper):
|
def at_pre_drop(self, dropper):
|
||||||
"""
|
"""
|
||||||
Called by the default `drop` command before this object has been
|
Called by the default `drop` command before this object has been
|
||||||
dropped.
|
dropped.
|
||||||
|
|
@ -869,7 +869,7 @@ class TBRangeObject(DefaultObject):
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
This hook cannot stop the drop from happening. Use
|
This hook cannot stop the drop from happening. Use
|
||||||
permissions or the at_before_drop() hook for that.
|
permissions or the at_pre_drop() hook for that.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# If dropper is currently in combat
|
# If dropper is currently in combat
|
||||||
|
|
@ -878,7 +878,7 @@ class TBRangeObject(DefaultObject):
|
||||||
self.db.combat_range = {}
|
self.db.combat_range = {}
|
||||||
dropper.location.db.combat_turnhandler.join_rangefield(self, anchor_obj=dropper)
|
dropper.location.db.combat_turnhandler.join_rangefield(self, anchor_obj=dropper)
|
||||||
|
|
||||||
def at_before_get(self, getter):
|
def at_pre_get(self, getter):
|
||||||
"""
|
"""
|
||||||
Called by the default `get` command before this object has been
|
Called by the default `get` command before this object has been
|
||||||
picked up.
|
picked up.
|
||||||
|
|
@ -917,7 +917,7 @@ class TBRangeObject(DefaultObject):
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
This hook cannot stop the pickup from happening. Use
|
This hook cannot stop the pickup from happening. Use
|
||||||
permissions or the at_before_get() hook for that.
|
permissions or the at_pre_get() hook for that.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# If gotten, erase range values
|
# If gotten, erase range values
|
||||||
|
|
@ -932,7 +932,7 @@ class TBRangeObject(DefaultObject):
|
||||||
if is_in_combat(getter):
|
if is_in_combat(getter):
|
||||||
spend_action(getter, 1, action_name="get") # Use up one action.
|
spend_action(getter, 1, action_name="get") # Use up one action.
|
||||||
|
|
||||||
def at_before_give(self, giver, getter):
|
def at_pre_give(self, giver, getter):
|
||||||
"""
|
"""
|
||||||
Called by the default `give` command before this object has been
|
Called by the default `give` command before this object has been
|
||||||
given.
|
given.
|
||||||
|
|
@ -976,7 +976,7 @@ class TBRangeObject(DefaultObject):
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
This hook cannot stop the give from happening. Use
|
This hook cannot stop the give from happening. Use
|
||||||
permissions or the at_before_give() hook for that.
|
permissions or the at_pre_give() hook for that.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Spend an action if in combat
|
# Spend an action if in combat
|
||||||
|
|
|
||||||
|
|
@ -751,7 +751,7 @@ class CrumblingWall(TutorialObject, DefaultExit):
|
||||||
# call the parent to continue execution (will use the desc we just set)
|
# call the parent to continue execution (will use the desc we just set)
|
||||||
return super().return_appearance(caller)
|
return super().return_appearance(caller)
|
||||||
|
|
||||||
def at_after_traverse(self, traverser, source_location):
|
def at_post_traverse(self, traverser, source_location):
|
||||||
"""
|
"""
|
||||||
This is called after we traversed this exit. Cleans up and resets
|
This is called after we traversed this exit. Cleans up and resets
|
||||||
the puzzle.
|
the puzzle.
|
||||||
|
|
|
||||||
|
|
@ -347,7 +347,7 @@ class WildernessScript(DefaultScript):
|
||||||
# ... but that other wilderness room belongs to another
|
# ... but that other wilderness room belongs to another
|
||||||
# wilderness map
|
# wilderness map
|
||||||
create_new_room = True
|
create_new_room = True
|
||||||
old_room.wilderness.at_after_object_leave(obj)
|
old_room.wilderness.at_post_object_leave(obj)
|
||||||
else:
|
else:
|
||||||
for item in old_room.contents:
|
for item in old_room.contents:
|
||||||
if item.has_account:
|
if item.has_account:
|
||||||
|
|
@ -451,7 +451,7 @@ class WildernessScript(DefaultScript):
|
||||||
# And finally put this room away in storage
|
# And finally put this room away in storage
|
||||||
self.db.unused_rooms.append(room)
|
self.db.unused_rooms.append(room)
|
||||||
|
|
||||||
def at_after_object_leave(self, obj):
|
def at_post_object_leave(self, obj):
|
||||||
"""
|
"""
|
||||||
Called after an object left this wilderness map. Used for cleaning up.
|
Called after an object left this wilderness map. Used for cleaning up.
|
||||||
|
|
||||||
|
|
@ -551,7 +551,7 @@ class WildernessRoom(DefaultRoom):
|
||||||
target_location (Object): Where `moved_obj` is going.
|
target_location (Object): Where `moved_obj` is going.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.wilderness.at_after_object_leave(moved_obj)
|
self.wilderness.at_post_object_leave(moved_obj)
|
||||||
|
|
||||||
def set_active_coordinates(self, new_coordinates, obj):
|
def set_active_coordinates(self, new_coordinates, obj):
|
||||||
"""
|
"""
|
||||||
|
|
@ -698,7 +698,7 @@ class WildernessExit(DefaultExit):
|
||||||
):
|
):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not traversing_object.at_before_move(None):
|
if not traversing_object.at_pre_move(None):
|
||||||
return False
|
return False
|
||||||
traversing_object.location.msg_contents(
|
traversing_object.location.msg_contents(
|
||||||
"{} leaves to {}".format(traversing_object.key, new_coordinates),
|
"{} leaves to {}".format(traversing_object.key, new_coordinates),
|
||||||
|
|
@ -712,7 +712,7 @@ class WildernessExit(DefaultExit):
|
||||||
exclude=[traversing_object],
|
exclude=[traversing_object],
|
||||||
)
|
)
|
||||||
|
|
||||||
traversing_object.at_after_move(None)
|
traversing_object.at_post_move(None)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class Character(DefaultCharacter):
|
||||||
(important!)sets locks so character cannot be picked up
|
(important!)sets locks so character cannot be picked up
|
||||||
and its commands only be called by itself, not anyone else.
|
and its commands only be called by itself, not anyone else.
|
||||||
(to change things, use at_object_creation() instead).
|
(to change things, use at_object_creation() instead).
|
||||||
at_after_move(source_location) - Launches the "look" command after every move.
|
at_post_move(source_location) - Launches the "look" command after every move.
|
||||||
at_post_unpuppet(account) - when Account disconnects from the Character, we
|
at_post_unpuppet(account) - when Account disconnects from the Character, we
|
||||||
store the current location in the pre_logout_location Attribute and
|
store the current location in the pre_logout_location Attribute and
|
||||||
move it to a None-location so the "unpuppeted" character
|
move it to a None-location so the "unpuppeted" character
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class Exit(DefaultExit):
|
||||||
at_traverse(traveller, target_loc) - called to do the actual traversal and calling of the other hooks.
|
at_traverse(traveller, target_loc) - called to do the actual traversal and calling of the other hooks.
|
||||||
If overloading this, consider using super() to use the default
|
If overloading this, consider using super() to use the default
|
||||||
movement implementation (and hook-calling).
|
movement implementation (and hook-calling).
|
||||||
at_after_traverse(traveller, source_loc) - called by at_traverse just after traversing.
|
at_post_traverse(traveller, source_loc) - called by at_traverse just after traversing.
|
||||||
at_failed_traverse(traveller) - called by at_traverse if traversal failed for some reason. Will
|
at_failed_traverse(traveller) - called by at_traverse if traversal failed for some reason. Will
|
||||||
not be called if the attribute `err_traverse` is
|
not be called if the attribute `err_traverse` is
|
||||||
defined, in which case that will simply be echoed.
|
defined, in which case that will simply be echoed.
|
||||||
|
|
|
||||||
|
|
@ -119,13 +119,13 @@ class Object(DefaultObject):
|
||||||
of a lock access check on this object. Return value
|
of a lock access check on this object. Return value
|
||||||
does not affect check result.
|
does not affect check result.
|
||||||
|
|
||||||
at_before_move(destination) - called just before moving object
|
at_pre_move(destination) - called just before moving object
|
||||||
to the destination. If returns False, move is cancelled.
|
to the destination. If returns False, move is cancelled.
|
||||||
announce_move_from(destination) - called in old location, just
|
announce_move_from(destination) - called in old location, just
|
||||||
before move, if obj.move_to() has quiet=False
|
before move, if obj.move_to() has quiet=False
|
||||||
announce_move_to(source_location) - called in new location, just
|
announce_move_to(source_location) - called in new location, just
|
||||||
after move, if obj.move_to() has quiet=False
|
after move, if obj.move_to() has quiet=False
|
||||||
at_after_move(source_location) - always called after a move has
|
at_post_move(source_location) - always called after a move has
|
||||||
been successfully performed.
|
been successfully performed.
|
||||||
at_object_leave(obj, target_location) - called when an object leaves
|
at_object_leave(obj, target_location) - called when an object leaves
|
||||||
this object in any fashion
|
this object in any fashion
|
||||||
|
|
@ -136,7 +136,7 @@ class Object(DefaultObject):
|
||||||
handles all moving across the exit, including
|
handles all moving across the exit, including
|
||||||
calling the other exit hooks. Use super() to retain
|
calling the other exit hooks. Use super() to retain
|
||||||
the default functionality.
|
the default functionality.
|
||||||
at_after_traverse(traversing_object, source_location) - (exit-objects only)
|
at_post_traverse(traversing_object, source_location) - (exit-objects only)
|
||||||
called just after a traversal has happened.
|
called just after a traversal has happened.
|
||||||
at_failed_traverse(traversing_object) - (exit-objects only) called if
|
at_failed_traverse(traversing_object) - (exit-objects only) called if
|
||||||
traversal fails and property err_traverse is not defined.
|
traversal fails and property err_traverse is not defined.
|
||||||
|
|
|
||||||
|
|
@ -840,7 +840,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
moving to a None location. If you want to run hooks, run them manually
|
moving to a None location. If you want to run hooks, run them manually
|
||||||
(and make sure they can manage None locations).
|
(and make sure they can manage None locations).
|
||||||
move_hooks (bool): If False, turn off the calling of move-related hooks
|
move_hooks (bool): If False, turn off the calling of move-related hooks
|
||||||
(at_before/after_move etc) with quiet=True, this is as quiet a move
|
(at_pre/post_move etc) with quiet=True, this is as quiet a move
|
||||||
as can be done.
|
as can be done.
|
||||||
|
|
||||||
Keyword Args:
|
Keyword Args:
|
||||||
|
|
@ -857,13 +857,13 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
|
|
||||||
The `DefaultObject` hooks called (if `move_hooks=True`) are, in order:
|
The `DefaultObject` hooks called (if `move_hooks=True`) are, in order:
|
||||||
|
|
||||||
1. `self.at_before_move(destination)` (if this returns False, move is aborted)
|
1. `self.at_pre_move(destination)` (if this returns False, move is aborted)
|
||||||
2. `source_location.at_object_leave(self, destination)`
|
2. `source_location.at_object_leave(self, destination)`
|
||||||
3. `self.announce_move_from(destination)`
|
3. `self.announce_move_from(destination)`
|
||||||
4. (move happens here)
|
4. (move happens here)
|
||||||
5. `self.announce_move_to(source_location)`
|
5. `self.announce_move_to(source_location)`
|
||||||
6. `destination.at_object_receive(self, source_location)`
|
6. `destination.at_object_receive(self, source_location)`
|
||||||
7. `self.at_after_move(source_location)`
|
7. `self.at_post_move(source_location)`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def logerr(string="", err=None):
|
def logerr(string="", err=None):
|
||||||
|
|
@ -890,10 +890,10 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# Before the move, call eventual pre-commands.
|
# Before the move, call eventual pre-commands.
|
||||||
if move_hooks:
|
if move_hooks:
|
||||||
try:
|
try:
|
||||||
if not self.at_before_move(destination, **kwargs):
|
if not self.at_pre_move(destination, **kwargs):
|
||||||
return False
|
return False
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logerr(errtxt.format(err="at_before_move()"), err)
|
logerr(errtxt.format(err="at_pre_move()"), err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Save the old location
|
# Save the old location
|
||||||
|
|
@ -943,9 +943,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# (usually calling 'look')
|
# (usually calling 'look')
|
||||||
if move_hooks:
|
if move_hooks:
|
||||||
try:
|
try:
|
||||||
self.at_after_move(source_location, **kwargs)
|
self.at_post_move(source_location, **kwargs)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logerr(errtxt.format(err="at_after_move"), err)
|
logerr(errtxt.format(err="at_post_move"), err)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -1244,7 +1244,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
self.aliases.batch_add(*cdict["aliases"])
|
self.aliases.batch_add(*cdict["aliases"])
|
||||||
if cdict.get("location"):
|
if cdict.get("location"):
|
||||||
cdict["location"].at_object_receive(self, None)
|
cdict["location"].at_object_receive(self, None)
|
||||||
self.at_after_move(None)
|
self.at_post_move(None)
|
||||||
if cdict.get("tags"):
|
if cdict.get("tags"):
|
||||||
# this should be a list of tags, tuples (key, category) or (key, category, data)
|
# this should be a list of tags, tuples (key, category) or (key, category, data)
|
||||||
self.tags.batch_add(*cdict["tags"])
|
self.tags.batch_add(*cdict["tags"])
|
||||||
|
|
@ -1452,7 +1452,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
|
|
||||||
# hooks called when moving the object
|
# hooks called when moving the object
|
||||||
|
|
||||||
def at_before_move(self, destination, **kwargs):
|
def at_pre_move(self, destination, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called just before starting to move this object to
|
Called just before starting to move this object to
|
||||||
destination.
|
destination.
|
||||||
|
|
@ -1473,6 +1473,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# return has_perm(self, destination, "can_move")
|
# return has_perm(self, destination, "can_move")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# deprecated alias
|
||||||
|
at_before_move = at_pre_move
|
||||||
|
|
||||||
def announce_move_from(self, destination, msg=None, mapping=None, **kwargs):
|
def announce_move_from(self, destination, msg=None, mapping=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called if the move is to be announced. This is
|
Called if the move is to be announced. This is
|
||||||
|
|
@ -1583,7 +1586,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
|
|
||||||
destination.msg_contents(string, exclude=(self,), from_obj=self, mapping=mapping)
|
destination.msg_contents(string, exclude=(self,), from_obj=self, mapping=mapping)
|
||||||
|
|
||||||
def at_after_move(self, source_location, **kwargs):
|
def at_post_move(self, source_location, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called after move has completed, regardless of quiet mode or
|
Called after move has completed, regardless of quiet mode or
|
||||||
not. Allows changes to the object due to the location it is
|
not. Allows changes to the object due to the location it is
|
||||||
|
|
@ -1597,6 +1600,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
at_after_move = at_post_move
|
||||||
|
|
||||||
def at_object_leave(self, moved_obj, target_location, **kwargs):
|
def at_object_leave(self, moved_obj, target_location, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called just before an object leaves from inside this object
|
Called just before an object leaves from inside this object
|
||||||
|
|
@ -1630,7 +1636,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
normally by calling
|
normally by calling
|
||||||
`traversing_object.move_to(target_location)`. It is normally
|
`traversing_object.move_to(target_location)`. It is normally
|
||||||
only implemented by Exit objects. If it returns False (usually
|
only implemented by Exit objects. If it returns False (usually
|
||||||
because `move_to` returned False), `at_after_traverse` below
|
because `move_to` returned False), `at_post_traverse` below
|
||||||
should not be called and instead `at_failed_traverse` should be
|
should not be called and instead `at_failed_traverse` should be
|
||||||
called.
|
called.
|
||||||
|
|
||||||
|
|
@ -1643,7 +1649,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def at_after_traverse(self, traversing_object, source_location, **kwargs):
|
def at_post_traverse(self, traversing_object, source_location, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called just after an object successfully used this object to
|
Called just after an object successfully used this object to
|
||||||
traverse to another object (i.e. this object is a type of
|
traverse to another object (i.e. this object is a type of
|
||||||
|
|
@ -1660,6 +1666,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
at_after_traverse = at_post_traverse
|
||||||
|
|
||||||
def at_failed_traverse(self, traversing_object, **kwargs):
|
def at_failed_traverse(self, traversing_object, **kwargs):
|
||||||
"""
|
"""
|
||||||
This is called if an object fails to traverse this object for
|
This is called if an object fails to traverse this object for
|
||||||
|
|
@ -1901,7 +1910,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def at_before_get(self, getter, **kwargs):
|
def at_pre_get(self, getter, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called by the default `get` command before this object has been
|
Called by the default `get` command before this object has been
|
||||||
picked up.
|
picked up.
|
||||||
|
|
@ -1920,6 +1929,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
at_before_get = at_pre_get
|
||||||
|
|
||||||
def at_get(self, getter, **kwargs):
|
def at_get(self, getter, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called by the default `get` command when this object has been
|
Called by the default `get` command when this object has been
|
||||||
|
|
@ -1932,12 +1944,12 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
This hook cannot stop the pickup from happening. Use
|
This hook cannot stop the pickup from happening. Use
|
||||||
permissions or the at_before_get() hook for that.
|
permissions or the at_pre_get() hook for that.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def at_before_give(self, giver, getter, **kwargs):
|
def at_pre_give(self, giver, getter, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called by the default `give` command before this object has been
|
Called by the default `give` command before this object has been
|
||||||
given.
|
given.
|
||||||
|
|
@ -1958,6 +1970,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
at_before_give = at_pre_give
|
||||||
|
|
||||||
def at_give(self, giver, getter, **kwargs):
|
def at_give(self, giver, getter, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called by the default `give` command when this object has been
|
Called by the default `give` command when this object has been
|
||||||
|
|
@ -1971,12 +1986,12 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
This hook cannot stop the give from happening. Use
|
This hook cannot stop the give from happening. Use
|
||||||
permissions or the at_before_give() hook for that.
|
permissions or the at_pre_give() hook for that.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def at_before_drop(self, dropper, **kwargs):
|
def at_pre_drop(self, dropper, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called by the default `drop` command before this object has been
|
Called by the default `drop` command before this object has been
|
||||||
dropped.
|
dropped.
|
||||||
|
|
@ -2002,6 +2017,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
at_before_drop = at_pre_drop
|
||||||
|
|
||||||
def at_drop(self, dropper, **kwargs):
|
def at_drop(self, dropper, **kwargs):
|
||||||
"""
|
"""
|
||||||
Called by the default `drop` command when this object has been
|
Called by the default `drop` command when this object has been
|
||||||
|
|
@ -2014,12 +2032,12 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
This hook cannot stop the drop from happening. Use
|
This hook cannot stop the drop from happening. Use
|
||||||
permissions or the at_before_drop() hook for that.
|
permissions or the at_pre_drop() hook for that.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def at_before_say(self, message, **kwargs):
|
def at_pre_say(self, message, **kwargs):
|
||||||
"""
|
"""
|
||||||
Before the object says something.
|
Before the object says something.
|
||||||
|
|
||||||
|
|
@ -2044,6 +2062,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
"""
|
"""
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
at_before_say = at_pre_say
|
||||||
|
|
||||||
def at_say(
|
def at_say(
|
||||||
self,
|
self,
|
||||||
message,
|
message,
|
||||||
|
|
@ -2339,7 +2360,7 @@ class DefaultCharacter(DefaultObject):
|
||||||
# add the default cmdset
|
# add the default cmdset
|
||||||
self.cmdset.add_default(settings.CMDSET_CHARACTER, persistent=True)
|
self.cmdset.add_default(settings.CMDSET_CHARACTER, persistent=True)
|
||||||
|
|
||||||
def at_after_move(self, source_location, **kwargs):
|
def at_post_move(self, source_location, **kwargs):
|
||||||
"""
|
"""
|
||||||
We make sure to look around after a move.
|
We make sure to look around after a move.
|
||||||
|
|
||||||
|
|
@ -2347,6 +2368,9 @@ class DefaultCharacter(DefaultObject):
|
||||||
if self.location.access(self, "view"):
|
if self.location.access(self, "view"):
|
||||||
self.msg(text=(self.at_look(self.location), {"type": "look"}))
|
self.msg(text=(self.at_look(self.location), {"type": "look"}))
|
||||||
|
|
||||||
|
# deprecated
|
||||||
|
at_after_move = at_post_move
|
||||||
|
|
||||||
def at_pre_puppet(self, account, session=None, **kwargs):
|
def at_pre_puppet(self, account, session=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Return the character from storage in None location in `at_post_unpuppet`.
|
Return the character from storage in None location in `at_post_unpuppet`.
|
||||||
|
|
@ -2811,7 +2835,7 @@ class DefaultExit(DefaultObject):
|
||||||
"""
|
"""
|
||||||
source_location = traversing_object.location
|
source_location = traversing_object.location
|
||||||
if traversing_object.move_to(target_location):
|
if traversing_object.move_to(target_location):
|
||||||
self.at_after_traverse(traversing_object, source_location)
|
self.at_post_traverse(traversing_object, source_location)
|
||||||
else:
|
else:
|
||||||
if self.db.err_traverse:
|
if self.db.err_traverse:
|
||||||
# if exit has a better error message, let's use it.
|
# if exit has a better error message, let's use it.
|
||||||
|
|
|
||||||
|
|
@ -39,34 +39,12 @@ class TestGeneralContext(TestCase):
|
||||||
"websocket_port": "websocket_client_port_testvalue",
|
"websocket_port": "websocket_client_port_testvalue",
|
||||||
"websocket_url": "websocket_client_url_testvalue",
|
"websocket_url": "websocket_client_url_testvalue",
|
||||||
"rest_api_enabled": True,
|
"rest_api_enabled": True,
|
||||||
|
"server_hostname": 'localhost',
|
||||||
|
"ssh_enabled": False,
|
||||||
|
"ssh_ports": False,
|
||||||
|
"telnet_enabled": True,
|
||||||
|
"telnet_ports": [4000],
|
||||||
|
"telnet_ssl_enabled": False,
|
||||||
|
"telnet_ssl_ports": [4003],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
# spec being an empty list will initially raise AttributeError in set_game_name_and_slogan to test defaults
|
|
||||||
@patch("evennia.web.utils.general_context.settings", spec=[])
|
|
||||||
@patch("evennia.web.utils.general_context.get_evennia_version")
|
|
||||||
def test_set_game_name_and_slogan(self, mock_get_version, mock_settings):
|
|
||||||
mock_get_version.return_value = "version 1"
|
|
||||||
# test default/fallback values
|
|
||||||
mock_settings.REST_API_ENABLED = False
|
|
||||||
general_context.set_game_name_and_slogan()
|
|
||||||
self.assertEqual(general_context.GAME_NAME, "Evennia")
|
|
||||||
self.assertEqual(general_context.GAME_SLOGAN, "version 1")
|
|
||||||
# test values when the settings are defined
|
|
||||||
mock_settings.SERVERNAME = "test_name"
|
|
||||||
mock_settings.GAME_SLOGAN = "test_game_slogan"
|
|
||||||
general_context.set_game_name_and_slogan()
|
|
||||||
self.assertEqual(general_context.GAME_NAME, "test_name")
|
|
||||||
self.assertEqual(general_context.GAME_SLOGAN, "test_game_slogan")
|
|
||||||
|
|
||||||
@patch("evennia.web.utils.general_context.settings")
|
|
||||||
def test_set_webclient_settings(self, mock_settings):
|
|
||||||
mock_settings.WEBCLIENT_ENABLED = "webclient"
|
|
||||||
mock_settings.WEBSOCKET_CLIENT_URL = "websocket_url"
|
|
||||||
mock_settings.WEBSOCKET_CLIENT_ENABLED = "websocket_client"
|
|
||||||
mock_settings.WEBSOCKET_CLIENT_PORT = 5000
|
|
||||||
general_context.set_webclient_settings()
|
|
||||||
self.assertEqual(general_context.WEBCLIENT_ENABLED, "webclient")
|
|
||||||
self.assertEqual(general_context.WEBSOCKET_URL, "websocket_url")
|
|
||||||
self.assertEqual(general_context.WEBSOCKET_CLIENT_ENABLED, "websocket_client")
|
|
||||||
self.assertEqual(general_context.WEBSOCKET_PORT, 5000)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue