当前位置: 首页>>代码示例>>Python>>正文


Python Action.fromXml方法代码示例

本文整理汇总了Python中action.Action.fromXml方法的典型用法代码示例。如果您正苦于以下问题:Python Action.fromXml方法的具体用法?Python Action.fromXml怎么用?Python Action.fromXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在action.Action的用法示例。


在下文中一共展示了Action.fromXml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: applyMod

# 需要导入模块: from action import Action [as 别名]
# 或者: from action.Action import fromXml [as 别名]
 def applyMod(self, world):
     for node in self.src:
         if node.tag == 'path':
             path = node.attrib['add']
             loader.addPath(path)
         
         elif node.tag == 'require':
             fname = node.attrib['file']
             worldregistry.loadMod(fname, world)
         
         elif node.tag == 'map':
             source = node.attrib['source']
             target = node.attrib['target']
             sType = node.get('source-type')
             tType = node.get('type')
             values = {}
             for record in node:
                 if record.tag == 'value':
                     values[convert(record.get('in'), sType)] = convert(record.get('out'), tType)
                 elif record.tag == 'copy':
                     expr = record.get('value')
                     if not expr or expr == 'value':
                         values = lambda value: value
                         break
                     else:
                         raise NotImplementedError('copying complex values is not supported yet')
             
             if not (target in world.attrList):
                 world.attrList[target] = []
             world.attrList[target].append(self.makeAttrFunc(target, source, values))
         
         elif node.tag == 'layers':
             order, content, emptyContent = baseentity.loadXMLLayers(node)
             worldregistry.world.addTileLayers(content, order)
         
         elif node.tag == 'action':
             action = Action.fromXml(node)
             world.actions[action.name] = action
         
         elif node.tag == 'bind':
             actionName = node.attrib['action']
             targetType = node.attrib['target']
             event = node.attrib['event']
             opt = {key:node.attrib[key] for key in node.attrib.keys() if not (key in (
                 'action', 'target', 'event'
             ))}
             args = {e.tag : e.attrib['value'] for e in node}
             world.addBinding(targetType, event, actionName, opt, args)
         
         elif node.tag == 'keymap':
             client = world
             # TODO: should it be here?
             for snode in node:
                 if snode.tag == 'action':
                     actionName = snode.attrib['name']
                     args = {}
                     for e in snode:
                         if e.tag == 'arg':
                             value = e.attrib['value']
                             action = e.get('action')                # for list
                             args[e.attrib['name']] = (value, action)
                     bindings = [
                         e.attrib['key'] for e in snode if e.tag == 'bind'
                     ]
                     client.bindKeys(bindings, actionName, args)
                 elif snode.tag == 'movement':
                     try:
                         movement = {
                             snode[i].attrib['key'] : UnDirect(i) \
                                 for i in range(9)
                         }
                     except IndexError:
                         logging.warning('not enough movement keys specified')
                     else:
                         client.movementKeys = movement
                 else:
                     logging.warning('unknown keymap mod xml node tagged "{0}"'.format(snode.tag))
         
         elif node.tag == 'display':
             client = world
             for snode in node:
                 if snode.tag == 'attr':
                     name = snode.attrib['name']
                     tn = snode.get('type')
                     t = getType(tn)
                     client.addDisplayAttribute(name, t)
                 else:
                     logging.warning('unknown display mod xml node tagged "{0}"'.format(snode.tag))
         
         else:
             logging.warning('unknown mod xml node tagged "{0}"'.format(node.tag))
开发者ID:caryoscelus,项目名称:tam-rogue,代码行数:93,代码来源:mod.py


注:本文中的action.Action.fromXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。