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:
parent
3466e406f6
commit
88c0087fbd
13 changed files with 66 additions and 43 deletions
48
ev.py
48
ev.py
|
|
@ -2,34 +2,40 @@
|
||||||
|
|
||||||
Central API for Evennia MUD/MUX/MU* system.
|
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
|
Import this from ./manage.py shell or set DJANGO_SETTINGS_MODULE manually for proper
|
||||||
functionality.
|
functionality.
|
||||||
|
|
||||||
This module tries to group the most commonly useful modules in a flat(ter) structure.
|
1) You should import things excplicitly from the root of this module - you can generally
|
||||||
Some notes:
|
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
|
db_objects is an alias for ObjectDB.objects). These allows for exploring the database in
|
||||||
various ways. Please note that
|
various ways. Please note that the evennia-specific methods in the managers return
|
||||||
the evennia-specific methods in the managers return typeclasses (or lists of
|
typeclasses (or lists of typeclasses), whereas the default django ones (filter etc)
|
||||||
typeclasses), whereas the default django ones (filter etc) return database objects.
|
return database objects. You can convert between the two easily via dbobj.typeclass and
|
||||||
You can convert between the two easily via dbobj.typeclass and typeclass.dbobj, but
|
typeclass.dbobj, but it's worth to remember this difference.
|
||||||
it's worth to remember.
|
3) You -have- to use the methods of the "create" module to create new Typeclassed game
|
||||||
2) 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
|
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
|
-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.
|
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
|
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.
|
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
|
# Stop erroneous direct run (would give a traceback since django is
|
||||||
# not yet initialized)
|
# not yet initialized)
|
||||||
|
|
||||||
|
|
@ -41,12 +47,20 @@ if __name__ == "__main__":
|
||||||
To start the server, see game/manage.py and game/evennia.py.
|
To start the server, see game/manage.py and game/evennia.py.
|
||||||
More help can be found at http://www.evennia.com.
|
More help can be found at http://www.evennia.com.
|
||||||
"""
|
"""
|
||||||
import sys
|
|
||||||
sys.exit()
|
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)
|
# 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
|
# help entries
|
||||||
from src.help.models import HelpEntry
|
from src.help.models import HelpEntry
|
||||||
db_helpentries = HelpEntry.objects
|
db_helpentries = HelpEntry.objects
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,14 @@ new cmdset class.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from src.commands.cmdset import CmdSet
|
from ev import CmdSet, Command
|
||||||
from src.commands.default import cmdset_default, cmdset_unloggedin, cmdset_ooc
|
from ev import default_cmds
|
||||||
from game.gamesrc.commands.basecommand import Command
|
|
||||||
|
|
||||||
#from contrib import menusystem, lineeditor
|
#from contrib import menusystem, lineeditor
|
||||||
#from contrib import misc_commands
|
#from contrib import misc_commands
|
||||||
#from contrib import chargen
|
#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
|
This is an example of how to overload the default command
|
||||||
set defined in src/commands/default/cmdset_default.py.
|
set defined in src/commands/default/cmdset_default.py.
|
||||||
|
|
@ -52,7 +51,7 @@ class DefaultCmdSet(cmdset_default.DefaultCmdSet):
|
||||||
#self.add(lineeditor.CmdEditor())
|
#self.add(lineeditor.CmdEditor())
|
||||||
#self.add(misc_commands.CmdQuell())
|
#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
|
This is an example of how to overload the command set of the
|
||||||
unlogged in commands, defined in
|
unlogged in commands, defined in
|
||||||
|
|
@ -76,7 +75,7 @@ class UnloggedinCmdSet(cmdset_unloggedin.UnloggedinCmdSet):
|
||||||
# any commands you add below will overload the default ones.
|
# 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
|
This is set is available to the player when they have no
|
||||||
character connected to them (i.e. they are out-of-character, ooc).
|
character connected to them (i.e. they are out-of-character, ooc).
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@ See src/commands/default/muxcommand.py for an example.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from src.commands.command import Command as BaseCommand
|
from ev import Command as BaseCommand
|
||||||
from src.commands.default.muxcommand import MuxCommand as BaseMuxCommand
|
from ev import default_cmd
|
||||||
from src.utils import utils
|
from ev import utils
|
||||||
|
|
||||||
class MuxCommand(BaseMuxCommand):
|
class MuxCommand(default_cmd.MuxCommand):
|
||||||
"""
|
"""
|
||||||
This sets up the basis for a Evennia's 'MUX-like' command
|
This sets up the basis for a Evennia's 'MUX-like' command
|
||||||
style. The idea is that most other Mux-related commands should
|
style. The idea is that most other Mux-related commands should
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ cmdset - this way you can often re-use the commands too.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import random
|
import random
|
||||||
from src.commands.cmdset import CmdSet
|
from ev import CmdSet
|
||||||
from game.gamesrc.commands.basecommand import Command
|
from ev import Command
|
||||||
|
|
||||||
# Some simple commands for the red button
|
# Some simple commands for the red button
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,11 @@ New instances of Objects (inheriting from these typeclasses)
|
||||||
are created with src.utils.create.create_object(typeclass, ...)
|
are created with src.utils.create.create_object(typeclass, ...)
|
||||||
where typeclass is the python path to the class you want to use.
|
where typeclass is the python path to the class you want to use.
|
||||||
"""
|
"""
|
||||||
from src.objects.objects import Object as BaseObject
|
from ev import Object as BaseObject
|
||||||
from src.objects.objects import Character as BaseCharacter
|
from ev import Character as BaseCharacter
|
||||||
from src.objects.objects import Room as BaseRoom
|
from ev import Room as BaseRoom
|
||||||
from src.objects.objects import Exit as BaseExit
|
from ev import Exit as BaseExit
|
||||||
from src.players.player import Player as BasePlayer
|
from ev import Player as BasePlayer
|
||||||
|
|
||||||
class Object(BaseObject):
|
class Object(BaseObject):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ Create this button with
|
||||||
Note that if you must drop the button before you can see its messages!
|
Note that if you must drop the button before you can see its messages!
|
||||||
"""
|
"""
|
||||||
import random
|
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.scripts.examples import red_button_scripts as scriptexamples
|
||||||
from game.gamesrc.commands.examples import cmdset_red_button as cmdsetexamples
|
from game.gamesrc.commands.examples import cmdset_red_button as cmdsetexamples
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
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):
|
class Script(BaseScript):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ or you won't see any messages!
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import random
|
import random
|
||||||
from game.gamesrc.scripts.basescript import Script
|
from ev import Script
|
||||||
|
|
||||||
class BodyFunctions(Script):
|
class BodyFunctions(Script):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ red_button object type in gamesrc/types/examples. A few variations
|
||||||
on uses of scripts are included.
|
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
|
from game.gamesrc.commands.examples import cmdset_red_button as cmdsetexamples
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
# everything in this block will be appended to the beginning of
|
# everything in this block will be appended to the beginning of
|
||||||
# all other #CODE blocks when they are executed.
|
# 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.examples import red_button
|
||||||
from game.gamesrc.objects import baseobjects
|
from game.gamesrc.objects import baseobjects
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
# Get Evennia version
|
# Get Evennia version
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
try:
|
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:
|
except IOError:
|
||||||
VERSION = "Unknown version"
|
VERSION = "Unknown version"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
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 import syscommands
|
||||||
from src.commands.default.system import *
|
from src.commands.default.system import *
|
||||||
from src.commands.default.unloggedin 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
|
||||||
|
|
|
||||||
|
|
@ -222,9 +222,10 @@ def get_evennia_version():
|
||||||
"""
|
"""
|
||||||
Check for the evennia version info.
|
Check for the evennia version info.
|
||||||
"""
|
"""
|
||||||
version_file_path = "%s%s%s" % (settings.BASE_PATH, os.sep, "VERSION")
|
|
||||||
try:
|
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:
|
except IOError:
|
||||||
return "Unknown version"
|
return "Unknown version"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue