- Made many small bugfixes to the @parent and @create functions as well as their underlying methods.
- Made it so user #1 is also affected by the on_player_creation() function. - Added an event folder for custom events, including a working example - Expanded the example commands and parents to include the changes to how they should be initialized. - Added an optional ansi scheme (not active by default)
This commit is contained in:
parent
a32840002c
commit
a9dbac8aae
16 changed files with 397 additions and 35 deletions
36
src/ansi.py
36
src/ansi.py
|
|
@ -105,10 +105,42 @@ class MuxANSIParser(BaseParser):
|
|||
(r'%cw', ANSITable.ansi["white"]),
|
||||
(r'%cW', ANSITable.ansi["back_white"]),
|
||||
]
|
||||
|
||||
class ExtendedANSIParser(MuxANSIParser):
|
||||
"""
|
||||
Extends the standard mux colour commands with {-style commands
|
||||
(shortcuts for writing light/dark text without background)
|
||||
"""
|
||||
def __init__(self):
|
||||
super(ExtendedANSIParser, self).__init__()
|
||||
hilite = ANSITable.ansi['hilite']
|
||||
normal = ANSITable.ansi['normal']
|
||||
self.ansi_subs.extend( [
|
||||
(r'{r', hilite + ANSITable.ansi['red']),
|
||||
(r'{R', normal + ANSITable.ansi['red']),
|
||||
(r'{g', hilite + ANSITable.ansi['green']),
|
||||
(r'{G', normal + ANSITable.ansi['green']),
|
||||
(r'{y', hilite + ANSITable.ansi['yellow']),
|
||||
(r'{Y', normal + ANSITable.ansi['yellow']),
|
||||
(r'{b', hilite + ANSITable.ansi['blue']),
|
||||
(r'{B', normal + ANSITable.ansi['blue']),
|
||||
(r'{m', hilite + ANSITable.ansi['magenta']),
|
||||
(r'{M', normal + ANSITable.ansi['magenta']),
|
||||
(r'{c', hilite + ANSITable.ansi['cyan']),
|
||||
(r'{C', normal + ANSITable.ansi['cyan']),
|
||||
(r'{w', hilite + ANSITable.ansi['white']), #white
|
||||
(r'{W', normal + ANSITable.ansi['white']), #light grey
|
||||
(r'{x', hilite + ANSITable.ansi['black']), #dark grey
|
||||
(r'{X', normal + ANSITable.ansi['black']), #pure black
|
||||
(r'{n', normal) #reset
|
||||
] )
|
||||
|
||||
def parse_ansi(string, strip_ansi=False, strip_formatting=False, parser=MuxANSIParser()):
|
||||
ANSI_PARSER = MuxANSIParser()
|
||||
#ANSI_PARSER = ExtendedANSIParser()
|
||||
|
||||
def parse_ansi(string, strip_ansi=False, strip_formatting=False, parser=ANSI_PARSER):
|
||||
"""
|
||||
Parses a string, subbing color codes as needed.
|
||||
"""
|
||||
return parser.parse_ansi(string, strip_ansi=strip_ansi,
|
||||
strip_formatting=strip_formatting)
|
||||
strip_formatting=strip_formatting)
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ def cmd_examine(command):
|
|||
con_exits.append(obj)
|
||||
elif obj.is_thing():
|
||||
con_things.append(obj)
|
||||
|
||||
|
||||
# Render Contents display.
|
||||
if con_players or con_things:
|
||||
s += str("%sContents:%s" % (ANSITable.ansi["hilite"],
|
||||
|
|
|
|||
|
|
@ -51,17 +51,18 @@ def cmd_parent(command):
|
|||
# Clear parent if command was @parent obj= or obj=none
|
||||
if not parent_name or parent_name.lower() == "none":
|
||||
target_obj.set_script_parent(None)
|
||||
target_obj.scriptlink.at_object_creation()
|
||||
new_parent = target_obj.scriptlink()
|
||||
source_object.emit_to("%s reverted to its default parent (%s)." %
|
||||
(target_obj, new_parent))
|
||||
return
|
||||
|
||||
# If we reach this point, attempt to change parent.
|
||||
|
||||
# If we reach this point, attempt to change parent.
|
||||
former_parent = target_obj.get_scriptlink()
|
||||
if target_obj.set_script_parent(parent_name):
|
||||
#new script path added; initialize the parent
|
||||
target_obj.scriptlink.at_object_creation()
|
||||
|
||||
s = "%s's parent is now %s (instead of %s).\n\r"
|
||||
s += "Note that the new parent type could have overwritten "
|
||||
s += "same-named attributes on the existing object."
|
||||
|
|
|
|||
|
|
@ -32,4 +32,4 @@ class HelpEntry(models.Model):
|
|||
"""
|
||||
Gets the entry text for in-game viewing.
|
||||
"""
|
||||
return ansi.parse_ansi(self.entrytext)
|
||||
return ansi.parse_ansi(self.entrytext)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ def create_objects():
|
|||
# Create the matching PLAYER object in the object DB.
|
||||
god_user_obj = Object(id=1, type=defines_global.OTYPE_PLAYER)
|
||||
god_user_obj.set_name(god_user.username)
|
||||
god_user_obj.scriptlink.at_player_creation()
|
||||
god_user_obj.save()
|
||||
|
||||
# Limbo is the initial starting room.
|
||||
|
|
@ -39,6 +40,7 @@ def create_objects():
|
|||
limbo_obj.set_owner(god_user_obj)
|
||||
limbo_obj.set_name('%ch%ccLimbo%cn')
|
||||
limbo_obj.set_description("Welcome to your new Evennia-based game. From here you are ready to begin development. If you should need help or would like to participate in community discussions, visit http://evennia.com.")
|
||||
limbo_obj.scriptlink.at_object_creation()
|
||||
limbo_obj.save()
|
||||
|
||||
# Now that Limbo exists, set the user up in Limbo.
|
||||
|
|
@ -71,7 +73,7 @@ def create_config_values():
|
|||
Creates the initial config values.
|
||||
"""
|
||||
ConfigValue(conf_key="default_home", conf_value="2").save()
|
||||
ConfigValue(conf_key="idle_timeout", conf_value="1800").save()
|
||||
ConfigValue(conf_key="idle_timeout", conf_value="3600").save()
|
||||
ConfigValue(conf_key="money_name_singular", conf_value="Credit").save()
|
||||
ConfigValue(conf_key="money_name_plural", conf_value="Credits").save()
|
||||
ConfigValue(conf_key="player_dbnum_start", conf_value="2").save()
|
||||
|
|
|
|||
|
|
@ -79,6 +79,15 @@ class ObjectManager(models.Manager):
|
|||
return o_query.exclude(type__in=[defines_global.OTYPE_GARBAGE,
|
||||
defines_global.OTYPE_GOING])
|
||||
|
||||
def global_object_script_parent_search(self, script_parent):
|
||||
"""
|
||||
Searches through all objects returning those which has a certain script parent.
|
||||
"""
|
||||
o_query = self.filter(script_parent__exact=script_parent)
|
||||
return o_query.exclude(type__in=[defines_global.OTYPE_GARBAGE,
|
||||
defines_global.OTYPE_GOING])
|
||||
|
||||
|
||||
def list_search_object_namestr(self, searchlist, ostring, dbref_only=False,
|
||||
limit_types=False, match_type="fuzzy"):
|
||||
"""
|
||||
|
|
@ -350,4 +359,4 @@ class ObjectManager(models.Manager):
|
|||
user_object.emit_to("Welcome to %s, %s.\n\r" % (
|
||||
ConfigValue.objects.get_configvalue('site_name'),
|
||||
user_object.get_name(show_dbref=False)))
|
||||
command.session.add_default_channels()
|
||||
command.session.add_default_channels()
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ from src import logger
|
|||
import src.flags
|
||||
from src.util import functions_general
|
||||
|
||||
from src.logger import log_infomsg
|
||||
|
||||
class Attribute(models.Model):
|
||||
"""
|
||||
Attributes are things that are specific to different types of objects. For
|
||||
|
|
@ -598,8 +600,8 @@ class Object(models.Model):
|
|||
attrib_obj.attr_value = new_value
|
||||
attrib_obj.save()
|
||||
else:
|
||||
if not new_value:
|
||||
# Attribute object and we have given a doesn't exist, create it.
|
||||
if new_value:
|
||||
# No object currently exist, so create it.
|
||||
new_attrib = Attribute()
|
||||
new_attrib.attr_name = attribute
|
||||
new_attrib.attr_value = new_value
|
||||
|
|
@ -800,10 +802,10 @@ class Object(models.Model):
|
|||
|
||||
attrib: (str) The attribute's name.
|
||||
"""
|
||||
if self.has_attribute(attrib):
|
||||
if self.has_attribute(attrib):
|
||||
attrib = Attribute.objects.filter(attr_object=self).filter(attr_name=attrib)
|
||||
return attrib[0].attr_value
|
||||
else:
|
||||
else:
|
||||
return default
|
||||
|
||||
def get_attribute_obj(self, attrib):
|
||||
|
|
|
|||
|
|
@ -20,5 +20,12 @@ def add_event(event):
|
|||
Args:
|
||||
* event: (IntervalEvent) The event to add to the scheduler.
|
||||
"""
|
||||
schedule.append(event)
|
||||
event.start_event_loop()
|
||||
|
||||
#don't add multiple instances of the same event
|
||||
if event in schedule:
|
||||
return
|
||||
#i = schedule.index(event)
|
||||
#schedule[i] = event
|
||||
else:
|
||||
schedule.append(event)
|
||||
event.start_event_loop()
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ def scriptlink(source_obj, scriptname):
|
|||
# Store the module reference for later fast retrieval.
|
||||
CACHED_SCRIPTS[scriptname] = modreference
|
||||
except ImportError:
|
||||
logger.log_infomsg('Error importing %s: %s' % (modname, format_exc()))
|
||||
logger.log_infomsg('Error importing %s: %s' % (scriptname, format_exc()))
|
||||
os.chdir(settings.BASE_PATH)
|
||||
return
|
||||
except OSError:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue