mirror of
https://github.com/evennia/evennia.git
synced 2026-03-28 10:37:16 +01:00
Add attr= support to create_channel. Resolve #3078
This commit is contained in:
parent
75f3a6b63a
commit
95fc26877b
5 changed files with 99 additions and 13 deletions
|
|
@ -112,7 +112,37 @@ This again retrieve 20 lines, but starting 30 lines back (so you'll get lines
|
|||
|
||||
### Channel administration
|
||||
|
||||
To create/destroy a new channel you can do
|
||||
Evennia can create certain channels when it starts. Channels can also
|
||||
be created on-the-fly in-game.
|
||||
|
||||
#### Default channels from settings
|
||||
|
||||
You can specify 'default' channels you want to auto-create from the Evennia
|
||||
settings. New accounts will automatically be subscribed to such 'default' channels if
|
||||
they have the right permissions. This is a list of one dict per channel (example is the default public channel):
|
||||
|
||||
```python
|
||||
# in mygame/server/conf/settings.py
|
||||
DEFAULT_CHANNELS = [
|
||||
{
|
||||
"key": "Public",
|
||||
"aliases": ("pub",),
|
||||
"desc": "Public discussion",
|
||||
"locks": "control:perm(Admin);listen:all();send:all()",
|
||||
},
|
||||
]
|
||||
```
|
||||
|
||||
Each dict is fed as `**channeldict` into the [create_channel](evennia.utils.create.create_channel) function, and thus supports all the same keywords.
|
||||
|
||||
Evennia also has two system-related channels:
|
||||
|
||||
- `CHANNEL_MUDINFO` is a dict describing the "MudInfo" channel. This is assumed to exist and is a place for Evennia to echo important server information. The idea is that server admins and staff can subscribe to this channel to stay in the loop.
|
||||
- `CHANNEL_CONECTINFO` is not defined by default. It will receive connect/disconnect-messages and could be visible also for regular players. If not given, connection-info will just be logged quietly.
|
||||
|
||||
#### Managing channels in-game
|
||||
|
||||
To create/destroy a new channel on the fly you can do
|
||||
|
||||
channel/create channelname;alias;alias = description
|
||||
channel/destroy channelname
|
||||
|
|
|
|||
|
|
@ -440,6 +440,45 @@ class Character(DefaultCharacter):
|
|||
|
||||
```
|
||||
|
||||
## Adding additional TraitHandlers
|
||||
|
||||
Sometimes, it is easier to top-level classify traits, such as stats, skills, or other categories of traits you want to handle independantly of each other. Here is an example showing an example on the object typeclass, expanding on the first installation example:
|
||||
|
||||
```python
|
||||
# mygame/typeclasses/objects.py
|
||||
|
||||
from evennia import DefaultCharacter
|
||||
from evennia.utils import lazy_property
|
||||
from evennia.contrib.rpg.traits import TraitHandler
|
||||
|
||||
# ...
|
||||
|
||||
class Character(DefaultCharacter):
|
||||
...
|
||||
@lazy_property
|
||||
def traits(self):
|
||||
# this adds the handler as .traits
|
||||
return TraitHandler(self)
|
||||
|
||||
@lazy_property
|
||||
def stats(self):
|
||||
# this adds the handler as .stats
|
||||
return TraitHandler(self, db_attribute_key="stats")
|
||||
|
||||
@lazy_property
|
||||
def skills(self):
|
||||
# this adds the handler as .skills
|
||||
return TraitHandler(self, db_attribute_key="skills")
|
||||
|
||||
|
||||
def at_object_creation(self):
|
||||
# (or wherever you want)
|
||||
self.stats.add("str", "Strength", trait_type="static", base=10, mod=2)
|
||||
self.traits.add("hp", "Health", trait_type="gauge", min=0, max=100)
|
||||
self.skills.add("hunting", "Hunting Skill", trait_type="counter",
|
||||
base=10, mod=1, min=0, max=100)
|
||||
```
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
|
|
|||
|
|
@ -1354,14 +1354,9 @@ rooms without editing the map files outside of the game.
|
|||
## Installation
|
||||
|
||||
1. If you haven't before, install the extra contrib requirements.
|
||||
<<<<<<< HEAD
|
||||
You can do so by doing `pip install evennia[extra]`, or if you used `git` to
|
||||
install, do `pip install --upgrade -e .[extra]` from the `evennia/` repo
|
||||
folder.
|
||||
=======
|
||||
You can do so by doing `pip install evennia[extra]` from the
|
||||
`evennia/` folder.
|
||||
>>>>>>> f4253e600eac5c55445e8cb599e49d5cf060494a
|
||||
2. Import and add the `evennia.contrib.grid.xyzgrid.commands.XYZGridCmdSet` to the
|
||||
`CharacterCmdset` cmdset in `mygame/commands.default_cmds.py`. Reload
|
||||
the server. This makes the `map`, `goto/path` and modified `teleport` and
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ Base typeclass for in-game Channels.
|
|||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.urls import reverse
|
||||
from django.utils.text import slugify
|
||||
|
||||
from evennia.comms.managers import ChannelManager
|
||||
from evennia.comms.models import ChannelDB
|
||||
from evennia.typeclasses.models import TypeclassBase
|
||||
|
|
@ -98,6 +97,8 @@ class DefaultChannel(ChannelDB, metaclass=TypeclassBase):
|
|||
self.attributes.add("desc", cdict["desc"])
|
||||
if cdict.get("tags"):
|
||||
self.tags.batch_add(*cdict["tags"])
|
||||
if cdict.get("attrs"):
|
||||
self.attributes.batch_add(*cdict["attrs"])
|
||||
|
||||
def basetype_setup(self):
|
||||
self.locks.add("send:all();listen:all();control:perm(Admin)")
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ Comm system components.
|
|||
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
|
||||
from evennia.server import signals
|
||||
from evennia.typeclasses.managers import TypeclassManager, TypedObjectManager
|
||||
from evennia.utils import logger
|
||||
|
|
@ -291,7 +290,14 @@ class MsgManager(TypedObjectManager):
|
|||
message_search = search_message
|
||||
|
||||
def create_message(
|
||||
self, senderobj, message, receivers=None, locks=None, tags=None, header=None, **kwargs
|
||||
self,
|
||||
senderobj,
|
||||
message,
|
||||
receivers=None,
|
||||
locks=None,
|
||||
tags=None,
|
||||
header=None,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Create a new communication Msg. Msgs represent a unit of
|
||||
|
|
@ -308,7 +314,7 @@ class MsgManager(TypedObjectManager):
|
|||
to, or a list of them. If a string, it's an identifier for an external
|
||||
receiver.
|
||||
locks (str): Lock definition string.
|
||||
tags (list): A list of tags or tuples `(tag, category)`.
|
||||
tags (list): A list of tags or tuples `(tag[,category[,data]])`.
|
||||
header (str): Mime-type or other optional information for the message
|
||||
|
||||
Notes:
|
||||
|
|
@ -446,7 +452,15 @@ class ChannelDBManager(TypedObjectManager):
|
|||
return channels
|
||||
|
||||
def create_channel(
|
||||
self, key, aliases=None, desc=None, locks=None, keep_log=True, typeclass=None, tags=None
|
||||
self,
|
||||
key,
|
||||
aliases=None,
|
||||
desc=None,
|
||||
locks=None,
|
||||
keep_log=True,
|
||||
typeclass=None,
|
||||
tags=None,
|
||||
attrs=None,
|
||||
):
|
||||
"""
|
||||
Create A communication Channel. A Channel serves as a central hub
|
||||
|
|
@ -466,7 +480,8 @@ class ChannelDBManager(TypedObjectManager):
|
|||
keep_log (bool): Log channel throughput.
|
||||
typeclass (str or class): The typeclass of the Channel (not
|
||||
often used).
|
||||
tags (list): A list of tags or tuples `(tag, category)`.
|
||||
tags (list): A list of tags or tuples `(tag[,category[,data]])`.
|
||||
attrs (list): List of attributes on form `(name, value[,category[,lockstring]])`
|
||||
|
||||
Returns:
|
||||
channel (Channel): A newly created channel.
|
||||
|
|
@ -483,7 +498,13 @@ class ChannelDBManager(TypedObjectManager):
|
|||
|
||||
# store call signature for the signal
|
||||
new_channel._createdict = dict(
|
||||
key=key, aliases=aliases, desc=desc, locks=locks, keep_log=keep_log, tags=tags
|
||||
key=key,
|
||||
aliases=aliases,
|
||||
desc=desc,
|
||||
locks=locks,
|
||||
keep_log=keep_log,
|
||||
tags=tags,
|
||||
attrs=attrs,
|
||||
)
|
||||
|
||||
# this will trigger the save signal which in turn calls the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue