Finished presentation-grade version of @style.

This commit is contained in:
Andrew Bastien 2019-04-09 22:35:25 -04:00
parent cd5e38fe14
commit c3e2522da9
10 changed files with 198 additions and 24 deletions

View file

@ -20,6 +20,7 @@ from django.utils.module_loading import import_string
from evennia.typeclasses.models import TypeclassBase
from evennia.accounts.manager import AccountManager
from evennia.accounts.models import AccountDB
from evennia.accounts.styles import StyleHandler
from evennia.objects.models import ObjectDB
from evennia.comms.models import ChannelDB
from evennia.commands import cmdhandler
@ -1383,6 +1384,10 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
look_string = ("-" * 68) + "\n" + "".join(result) + "\n" + ("-" * 68)
return look_string
@lazy_property
def style(self):
return StyleHandler(self)
class DefaultGuest(DefaultAccount):
"""

View file

@ -0,0 +1,36 @@
"""
Styles (playing off CSS) are a way to change the colors and symbols used for standardized
displays used in Evennia. Accounts all have a StyleHandler accessible via .style which
retrieves per-Account settings, falling back to the global settings contained in settings.py.
"""
from django.conf import settings
class StyleHandler(object):
category = 'style'
def __init__(self, acc):
self.acc = acc
def set(self, option, value):
pass
def get(self, option):
"""
Get the stored Style information from this Account's Attributes if possible.
If not, fallback to the Global.
Args:
option (str): The key of the Style to retrieve.
Returns:
String or None
"""
stored = self.acc.attributes.get(option, category=self.category)
if stored:
return stored
default = settings.DEFAULT_STYLES.get(option, None)
if default:
return default[2]
return None