def render_process(self, ctx, data): request = ctx.locate(inevow.IRequest) args = normalize_args(request.args) roomid = int(args['roomid']) room = tzindex.get(roomid) xname = args['xname'] xclass = args['xclass'] bxname = args['bxname'] bxclass = args['bxclass'] destid = args['dest'] if destid != 'None': destid = int(destid) dest = tzindex.get(destid) else: dest = None newroomcls = args['newroom'] newroomname = args['newroomname'] if newroomcls == 'None' and newroomname: newroomcls = 'Room' elif newroomcls == 'None': newroomcls = None if dest is None and newroomcls is None: self.goback(request, 'Choose existing room, or room type to clone.') return elif dest is not None and newroomcls is not None: self.goback(request, 'Choose only one target room: Existing room or New room.') return elif newroomcls and newroomcls in rooms.classes(): cls = getattr(rooms, newroomcls) newroomname = args['newroomname'] if newroomname: newroom = cls(newroomname) else: newroom = cls() dest = newroom print 'NR', dest, dest.name if xname and xclass in exits.classes(): xcls = getattr(exits, xclass) if bxname and bxclass in exits.classes(): bxcls = getattr(exits, xclass) bx = bxcls(bxname, room=dest) x = xcls(xname, room=room, destination=dest, return_name=bxname) else: x = xcls(xname, room=room, destination=dest) tzid = x.tzid editpage = '/edit/%s' % roomid request.redirect(editpage) else: self.goback(request, 'Give a name for the exit.')
def cmd_list(s, r): '''list |players|items|rooms|mobs|exits| List all objects of the given type. ''' listing = r['type'] if listing == 'players': objs = players.ls() classes = [] elif listing == 'items': objs = items.ls() classes = items.classes() elif listing == 'rooms': objs = rooms.ls() classes = rooms.classes() elif listing == 'mobs': objs = mobs.ls() classes = mobs.classes() elif listing == 'exits': objs = exits.ls() classes = exits.classes() if objs: s.message('Existing objects:') objs.sort(key=operator.attrgetter('tzid')) msgs = [] for obj in objs: tzid = '(%s)' % obj.tzid msgs.append('%s %s' % (tzid.rjust(4, ' '), obj)) s.mlmessage(msgs, indent=4) else: s.message('No', listing, 'yet.') if classes: classes = list(classes) classes.sort() if objs: s.message() s.message('Cloneable:') s.columns_v(classes, color=colors.white)
def render_addexitform(self, ctx, data): if self.bse != 'Room': return '' tzid = self.tzid # to know which room to add the exit to action = '/exits/add/' lines = [T.h2['Add Exit to Room']] exitclasses = exits.classes() exitclasses.sort() choices = [(cls, cls) for cls in exitclasses] xinfo = dict(name='xclass', choices=choices, selected='Exit') bxinfo = dict(name='bxclass', choices=choices, selected='Exit') row = T.tr[T.td['Exit type...', T.br, self.render_form_select(xinfo), T.br, 'named...', T.br, T.input(name='xname')], T.td['to...', T.br, '-->'], T.td(align="center")[self.rooms_widget('dest', None), T.br, 'or', T.br, self.new_room_widget('newroom'), T.br, 'named...', T.br, T.input(name='newroomname'), T.br, T.input(type='submit', value=' Add ')], T.td[T.br, '<--'], T.td['return by...', T.br, 'Exit type...', T.br, self.render_form_select(bxinfo), T.br, 'named...', T.br, T.input(name='bxname')]] tbl = T.table(_class="center")[row] lines.append(tbl) lines.append(T.input(_type="hidden", name="roomid", value=tzid)) form = T.form(action=action, method='POST')[lines] return T.div(_class='addexit')[form]
def _clone_exit(s, objname, objtzid, newname=''): # Finally, try to clone an Exit # fist look at existing exits in this room orig = s.room.exitname(objname) or \ s.room.exit(objtzid) # if it is not there, it might be an Exit class if orig is None: if objname in exits.classes(): cls = getattr(exits, objname) obj = cls() else: obj = None else: obj = copy.copy(orig) if obj: if newname: obj.name = newname s.room.addexit(obj) s.message(obj, 'created.') s.room.action(dict(act='clone_exit', actor=s.player, x=obj)) return obj
def render_process(self, ctx, data): request = ctx.locate(inevow.IRequest) args = normalize_args(request.args) roomid = int(args['roomid']) room = tzindex.get(roomid) xname = args['xname'] xclass = args['xclass'] bxname = args['bxname'] bxclass = args['bxclass'] destid = args['dest'] if destid != 'None': destid = int(destid) dest = tzindex.get(destid) else: dest = None newroomcls = args['newroom'] newroomname = args['newroomname'] if newroomcls == 'None' and newroomname: newroomcls = 'Room' elif newroomcls == 'None': newroomcls = None if dest is None and newroomcls is None: self.goback(request, 'Choose existing room, or room type to clone.') return elif dest is not None and newroomcls is not None: self.goback( request, 'Choose only one target room: Existing room or New room.') return elif newroomcls and newroomcls in rooms.classes(): cls = getattr(rooms, newroomcls) newroomname = args['newroomname'] if newroomname: newroom = cls(newroomname) else: newroom = cls() dest = newroom print 'NR', dest, dest.name if xname and xclass in exits.classes(): xcls = getattr(exits, xclass) if bxname and bxclass in exits.classes(): bxcls = getattr(exits, xclass) bx = bxcls(bxname, room=dest) x = xcls(xname, room=room, destination=dest, return_name=bxname) else: x = xcls(xname, room=room, destination=dest) tzid = x.tzid editpage = '/edit/%s' % roomid request.redirect(editpage) else: self.goback(request, 'Give a name for the exit.')