Updated game/ for the ev API. There will likely be some changes happening in the game/folder, in the way new objects are inherited. This should use the API rather than inherit from the basecommand/baseobject modules (these will probably into the example folders as vanilla templates instead).

This commit is contained in:
Griatch 2012-03-25 13:09:17 +02:00
parent 3466e406f6
commit 88c0087fbd
13 changed files with 66 additions and 43 deletions

48
ev.py
View file

@ -2,34 +2,40 @@
Central API for Evennia MUD/MUX/MU* system.
This basically a set of shortcuts to the main modules in src/.
Import this from ./manage.py shell or set DJANGO_SETTINGS_MODULE manually for proper
functionality.
This module tries to group the most commonly useful modules in a flat(ter) structure.
Some notes:
1) You should import things excplicitly from the root of this module - you can generally
not use dot-notation to import deeper. Hence, to access a default command, you can do
the following:
1) db_* are shortcuts to initiated versions of Evennia's django database managers (e.g.
import ev
ev.default_cmds.CmdLook
or
from ev import default_cmds
default_cmds.CmdLook
But trying to import CmdLook directly with "from ev.default_cmds import CmdLook" will
not work since default_cmds is a property on the "ev" module, not a module of its own.
2) db_* are shortcuts to initiated versions of Evennia's django database managers (e.g.
db_objects is an alias for ObjectDB.objects). These allows for exploring the database in
various ways. Please note that
the evennia-specific methods in the managers return typeclasses (or lists of
typeclasses), whereas the default django ones (filter etc) return database objects.
You can convert between the two easily via dbobj.typeclass and typeclass.dbobj, but
it's worth to remember.
2) You -have- to use the methods of the "create" module to create new Typeclassed game
various ways. Please note that the evennia-specific methods in the managers return
typeclasses (or lists of typeclasses), whereas the default django ones (filter etc)
return database objects. You can convert between the two easily via dbobj.typeclass and
typeclass.dbobj, but it's worth to remember this difference.
3) You -have- to use the methods of the "create" module to create new Typeclassed game
entities (Objects, Scripts or Players). Just initializing e.g. the Player class will
-not- set up Typeclasses correctly and will lead to errors. Other types of database objects
can be created normally, but the "create" module offers convenient methods for those too.
3) The API accesses all relevant methods/classes, but might not always include all helper-methods
4) The API accesses all relevant methods/classes, but might not always include all helper-methods
referenced from each such entity. To get to those, access the modules in src/ directly. You
can always do this anyway, if you do not want to go through this API.
Philosophy is to keep the API as flat as possible, so as to not have to remember which nested
packages to traverse. Most of the important stuff should be made visible from this module.
As said, one can of course still import from src/ directly should one prefer!
"""
import sys, os
# Stop erroneous direct run (would give a traceback since django is
# not yet initialized)
@ -41,12 +47,20 @@ if __name__ == "__main__":
To start the server, see game/manage.py and game/evennia.py.
More help can be found at http://www.evennia.com.
"""
import sys
sys.exit()
try:
f = open(os.path.dirname(os.path.abspath(__file__)) + os.sep + "VERSION", 'r')
__version__ = "Evennia %s-r%s" % (f.read().strip(), os.popen("hg id -i").read().strip())
f.close()
del f
except IOError:
__version__ = "Evennia (unknown version)"
del sys, os
# Start Evennia API (easiest is to import this module interactively to explore it)
README = "Evennia flat API. See the module header for usage information."
# help entries
from src.help.models import HelpEntry
db_helpentries = HelpEntry.objects

View file

@ -18,15 +18,14 @@ new cmdset class.
"""
from src.commands.cmdset import CmdSet
from src.commands.default import cmdset_default, cmdset_unloggedin, cmdset_ooc
from game.gamesrc.commands.basecommand import Command
from ev import CmdSet, Command
from ev import default_cmds
#from contrib import menusystem, lineeditor
#from contrib import misc_commands
#from contrib import chargen
class DefaultCmdSet(cmdset_default.DefaultCmdSet):
class DefaultCmdSet(default_cmds.DefaultCmdSet):
"""
This is an example of how to overload the default command
set defined in src/commands/default/cmdset_default.py.
@ -52,7 +51,7 @@ class DefaultCmdSet(cmdset_default.DefaultCmdSet):
#self.add(lineeditor.CmdEditor())
#self.add(misc_commands.CmdQuell())
class UnloggedinCmdSet(cmdset_unloggedin.UnloggedinCmdSet):
class UnloggedinCmdSet(default_cmds.UnloggedinCmdSet):
"""
This is an example of how to overload the command set of the
unlogged in commands, defined in
@ -76,7 +75,7 @@ class UnloggedinCmdSet(cmdset_unloggedin.UnloggedinCmdSet):
# any commands you add below will overload the default ones.
#
class OOCCmdSet(cmdset_ooc.OOCCmdSet):
class OOCCmdSet(default_cmds.OOCCmdSet):
"""
This is set is available to the player when they have no
character connected to them (i.e. they are out-of-character, ooc).

View file

@ -8,11 +8,11 @@ See src/commands/default/muxcommand.py for an example.
"""
from src.commands.command import Command as BaseCommand
from src.commands.default.muxcommand import MuxCommand as BaseMuxCommand
from src.utils import utils
from ev import Command as BaseCommand
from ev import default_cmd
from ev import utils
class MuxCommand(BaseMuxCommand):
class MuxCommand(default_cmd.MuxCommand):
"""
This sets up the basis for a Evennia's 'MUX-like' command
style. The idea is that most other Mux-related commands should

View file

@ -8,8 +8,8 @@ cmdset - this way you can often re-use the commands too.
"""
import random
from src.commands.cmdset import CmdSet
from game.gamesrc.commands.basecommand import Command
from ev import CmdSet
from ev import Command
# Some simple commands for the red button

View file

@ -20,11 +20,11 @@ New instances of Objects (inheriting from these typeclasses)
are created with src.utils.create.create_object(typeclass, ...)
where typeclass is the python path to the class you want to use.
"""
from src.objects.objects import Object as BaseObject
from src.objects.objects import Character as BaseCharacter
from src.objects.objects import Room as BaseRoom
from src.objects.objects import Exit as BaseExit
from src.players.player import Player as BasePlayer
from ev import Object as BaseObject
from ev import Character as BaseCharacter
from ev import Room as BaseRoom
from ev import Exit as BaseExit
from ev import Player as BasePlayer
class Object(BaseObject):
"""

View file

@ -11,7 +11,7 @@ Create this button with
Note that if you must drop the button before you can see its messages!
"""
import random
from game.gamesrc.objects.baseobjects import Object
from ev import Object
from game.gamesrc.scripts.examples import red_button_scripts as scriptexamples
from game.gamesrc.commands.examples import cmdset_red_button as cmdsetexamples

View file

@ -15,7 +15,7 @@ src.utils.create.create_script(scriptclass, ...) where scriptclass
is the python path to the specific class of script you want to use.
"""
from src.scripts.scripts import Script as BaseScript
from ev import Script as BaseScript
class Script(BaseScript):
"""

View file

@ -12,7 +12,7 @@ or you won't see any messages!
"""
import random
from game.gamesrc.scripts.basescript import Script
from ev import Script
class BodyFunctions(Script):
"""

View file

@ -6,7 +6,7 @@ red_button object type in gamesrc/types/examples. A few variations
on uses of scripts are included.
"""
from game.gamesrc.scripts.basescript import Script
from ev import Script
from game.gamesrc.commands.examples import cmdset_red_button as cmdsetexamples
#

View file

@ -43,7 +43,7 @@
# everything in this block will be appended to the beginning of
# all other #CODE blocks when they are executed.
from src.utils import create, search
from ev import create, search
from game.gamesrc.objects.examples import red_button
from game.gamesrc.objects import baseobjects

View file

@ -15,7 +15,8 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Get Evennia version
#------------------------------------------------------------
try:
VERSION = open("%s%s%s" % (os.pardir, os.sep, 'VERSION')).readline().strip()
with open(os.pardir + os.sep + 'VERSION') as f:
VERSION = "%s-r%s" % (f.read().strip(), os.popen("hg id -i").read().strip())
except IOError:
VERSION = "Unknown version"

View file

@ -1,5 +1,9 @@
"""
Central package for importing the default commands from the API.
Groups all default commands for access from the API.
To use via ev API, import this module with
from ev import default_cmds,
you can then access the command classes as members of default_cmds.
"""
from src.commands.default.cmdset_default import DefaultCmdSet
@ -17,3 +21,7 @@ from src.commands.default.help import *
from src.commands.default import syscommands
from src.commands.default.system import *
from src.commands.default.unloggedin import *
del cmdset_default, cmdset_ooc, cmdset_unloggedin, muxcommand
del admin, batchprocess, building, comms, general,
del help, system, unloggedin

View file

@ -222,9 +222,10 @@ def get_evennia_version():
"""
Check for the evennia version info.
"""
version_file_path = "%s%s%s" % (settings.BASE_PATH, os.sep, "VERSION")
try:
return open(version_file_path).readline().strip('\n').strip()
with open(settings.BASE_PATH + os.sep + "VERSION") as f:
return "%s-r%s" % (f.read().strip(), os.popen("hg id -i").read().strip())
return
except IOError:
return "Unknown version"