def _readNationConfigSection(xmlCtx, section): config = {} firstNames = {} lastNames = {} icons = {} for kindName in component_constants.TANKMEN_GROUPS: groups = [] totalWeight = 0.0 for sname, subsection in _xml.getChildren(xmlCtx, section, kindName): ctx = (xmlCtx, kindName + '/' + sname) group = _readTankmenGroup(ctx, subsection, firstNames, lastNames, icons) totalWeight += group.weight groups.append(group) totalWeight = max(0.001, totalWeight) for group in groups: group.weight /= totalWeight config[kindName] = tuple(groups) ranks = _readRanks((xmlCtx, 'ranks'), _xml.getChildren(xmlCtx, section, 'ranks')) config['roleRanks'] = _readRoleRanks((xmlCtx, 'roleRanks'), _xml.getSubsection(xmlCtx, section, 'roleRanks'), ranks) if IS_CLIENT or IS_WEB: config['firstNames'] = firstNames config['lastNames'] = lastNames config['icons'] = icons config['ranks'] = ranks else: config['firstNames'] = frozenset(firstNames) config['lastNames'] = frozenset(lastNames) config['icons'] = frozenset(icons) return tankmen_components.NationConfig(xmlCtx[1], **config)
def _parseGuiItem(xmlCtx, section, flags, itemFlags): itemID = parseID(xmlCtx, section, 'Specify a GUI item ID') props = {} tags = section.keys() if 'properties' in tags: for _, subSec in _xml.getChildren(xmlCtx, section, 'properties'): propType, propSec = subSec.items()[0] props[subSec.asString] = readVarValue(propType, propSec) item = chapter.GuiItemRef(itemID, props, conditions=_parseConditions( xmlCtx, section, flags)) if 'on-scene-effects' in tags: for _, effectSec in _xml.getChildren(xmlCtx, section, 'on-scene-effects'): effect = _parseEffect(xmlCtx, effectSec, itemFlags) if effect is not None: item.addOnSceneEffect(effect) if 'not-on-scene-effects' in tags: for _, effectSec in _xml.getChildren(xmlCtx, section, 'not-on-scene-effects'): effect = _parseEffect(xmlCtx, effectSec, itemFlags) if effect is not None: item.addNotOnSceneEffect(effect) return item
def _parseScene(self, xmlCtx, section, scene, flags, itemFlags, afterBattle=False, frontEffects=False): for _, subSec in _xml.getChildren(xmlCtx, section, 'gui-items'): item = sub_parsers._parseGuiItem(xmlCtx, subSec, flags, itemFlags) if item is not None: scene.addGuiItem(item) front = -1 for _, subSec in _xml.getChildren(xmlCtx, section, 'post-effects'): effect = sub_parsers._parseEffect(xmlCtx, subSec, flags, afterBattle=afterBattle) if effect is not None: if frontEffects: front += 1 scene.addPostEffect(effect, front=front) front = -1 for _, subSec in _xml.getChildren(xmlCtx, section, 'runtime-effects'): effect = sub_parsers._parseEffect(xmlCtx, subSec, flags, afterBattle=afterBattle) if effect is not None: if frontEffects: front += 1 scene.addEffect(effect, front=front)
def __readSharedMetrics(self, shared, xmlCtx, section): precessed = _xml.getChildren(xmlCtx, section, 'grids') for name, gridSection in precessed: gridName = gridSection.asString xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, gridName) gridCtx = (None, xPath) subSec = _xml.getSubsection(xmlCtx, gridSection, 'root') xmlCtx = (None, '{0:>s}/root'.format(xPath)) rootPos = { 'start': _xml.readVector2(xmlCtx, subSec, 'start').tuple(), 'step': _xml.readInt(xmlCtx, subSec, 'step') } subSec = _xml.getSubsection(gridCtx, gridSection, 'vertical') xmlCtx = (None, '{0:>s}/vertical'.format(xPath)) vertical = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step')) subSec = _xml.getSubsection(gridCtx, gridSection, 'horizontal') xmlCtx = (None, '{0:>s}/horizontal'.format(xPath)) horizontal = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step')) shared['grids'][gridName] = { 'root': rootPos, 'vertical': vertical, 'horizontal': horizontal } precessed = _xml.getChildren(xmlCtx, section, 'lines') lines = shared['lines'] for name, sub in precessed: xPath = '{0:>s}/{1:>s}'.format(TREE_SHARED_REL_FILE_PATH, name) xmlCtx = (None, xPath) pinsSec = _xml.getChildren(xmlCtx, sub, 'inPin') inPins = dict( ((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec)) pinsSec = _xml.getChildren(xmlCtx, sub, 'outPin') outPins = dict( ((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec)) pinsSec = _xml.getChildren(xmlCtx, sub, 'viaPin') viaPins = defaultdict(dict) for outPin, setSec in pinsSec: for inPin, pSec in setSec.items(): viaPins[outPin][inPin] = map( lambda section: section[1].asVector2.tuple(), pSec.items()) defSec = sub['default'] default = {} if defSec is not None: xmlCtx = (None, '{0:>s}/default'.format(xPath)) default = { 'outPin': _xml.readString(xmlCtx, defSec, 'outPin'), 'inPin': _xml.readString(xmlCtx, defSec, 'inPin') } lines[name] = { 'inPins': inPins, 'outPins': outPins, 'viaPins': viaPins, 'default': default }
def parseTrigger(xmlCtx, section, flags, chapter): triggerID = parseID(xmlCtx, section, 'Specify a trigger ID') trigger = None triggerType = _xml.readString(xmlCtx, section, 'type') parser = _TRIGGER_SUB_PARSERS.get(triggerType) if parser is not None: trigger = parser(xmlCtx, section, chapter, triggerID) if 'on-effects' in section.keys(): for _, effectSec in _xml.getChildren(xmlCtx, section, 'on-effects'): effect = _parseEffect(xmlCtx, effectSec, flags) if effect is not None: trigger.addOnEffect(effect) if 'off-effects' in section.keys(): for _, effectSec in _xml.getChildren(xmlCtx, section, 'off-effects'): effect = _parseEffect(xmlCtx, effectSec, flags) if effect is not None: trigger.addOffEffect(effect) if 'exclude-triggers' in section.keys(): for _, triggerSec in _xml.getChildren(xmlCtx, section, 'exclude-triggers'): trigger.addExcludeTriggerID(triggerSec.asString) else: LOG_ERROR('Trigger is not supported:', triggerType) return trigger
def _readTankmenGroup(xmlCtx, subsection, firstNames, lastNames, icons): """Reads section containing data of tankmen group and stores it to NationGroup. :param xmlCtx: tuple(root ctx or None, path to section). :param subsection: instance of DataSection. :param firstNames: dict(ID of first name: string or None) :param lastNames: dict(ID of last name: string or None) :param icons: dict(ID of icon: string or None) :return: instance of NationGroup. """ if IS_CLIENT or IS_WEB: parseName = _parseName parseIcon = _parseIcon else: parseName = parseIcon = None return tankmen_components.NationGroup( subsection.asString, 'female' == _xml.readNonEmptyString(xmlCtx, subsection, 'sex'), subsection.readBool('notInShop', False), _readIDs((xmlCtx, 'firstNames'), _xml.getChildren(xmlCtx, subsection, 'firstNames'), firstNames, parseName), _readIDs((xmlCtx, 'lastNames'), _xml.getChildren(xmlCtx, subsection, 'lastNames'), lastNames, parseName), _readIDs((xmlCtx, 'icons'), _xml.getChildren(xmlCtx, subsection, 'icons'), icons, parseIcon), _xml.readNonNegativeFloat(xmlCtx, subsection, 'weight'), _readGroupTags((xmlCtx, 'tags'), subsection, 'tags'), _readGroupRoles((xmlCtx, 'roles'), subsection, 'roles'))
def _readNationConfigSection(xmlCtx, section): res = {} firstNames = {} lastNames = {} icons = {} for kindName in ('normalGroups', 'premiumGroups'): groups = [] res[kindName] = groups totalWeight = 0.0 for sname, subsection in _xml.getChildren(xmlCtx, section, kindName): ctx = (xmlCtx, kindName + '/' + sname) group = { 'notInShop': subsection.readBool('notInShop', False), 'isFemales': 'female' == _xml.readNonEmptyString(ctx, subsection, 'sex'), 'firstNames': _readIDs((ctx, 'firstNames'), _xml.getChildren(ctx, subsection, 'firstNames'), firstNames, _parseName), 'lastNames': _readIDs((ctx, 'lastNames'), _xml.getChildren(ctx, subsection, 'lastNames'), lastNames, _parseName), 'icons': _readIDs((ctx, 'icons'), _xml.getChildren(ctx, subsection, 'icons'), icons, _parseIcon) } group['firstNamesList'] = list(group['firstNames']) group['lastNamesList'] = list(group['lastNames']) group['iconsList'] = list(group['icons']) weight = _xml.readNonNegativeFloat(ctx, subsection, 'weight') totalWeight += weight group['weight'] = weight groups.append(group) totalWeight = max(0.001, totalWeight) for group in groups: group['weight'] /= totalWeight ranks, rankIDsByNames = _readRanks( (xmlCtx, 'ranks'), _xml.getChildren(xmlCtx, section, 'ranks')) res['roleRanks'] = _readRoleRanks( (xmlCtx, 'roleRanks'), _xml.getSubsection(xmlCtx, section, 'roleRanks'), rankIDsByNames) if IS_CLIENT or IS_WEB: res['firstNames'] = firstNames res['lastNames'] = lastNames res['icons'] = icons res['ranks'] = ranks else: res['firstNames'] = frozenset(firstNames) res['lastNames'] = frozenset(lastNames) res['icons'] = frozenset(icons) return res
def __readCommandsSection(self, xmlCtx, section): self.__commands.clear() for _, subSection in _xml.getChildren(xmlCtx, section, 'gui-commands'): commandID = sub_parsers._parseID(xmlCtx, subSection, 'Specify a command ID') cmdType = _xml.readString(xmlCtx, subSection, 'type') command = _xml.readString(xmlCtx, subSection, 'name') argsSec = _xml.getChildren(xmlCtx, subSection, 'args') args = [] for name, argSec in argsSec: args.append(sub_parsers._readVarValue(name, argSec)) self.__commands[commandID] = CommandData(cmdType, command, args)
def _readPlayerCommand(xmlCtx, section, _): cmdID = parseID(xmlCtx, section, 'Specify a player command ID') name = _xml.readString(xmlCtx, section, 'name') argsSec = _xml.getChildren(xmlCtx, section, 'args') kwargsSec = _xml.getChildren(xmlCtx, section, 'kwargs') cmdArgs = [] for name, argSec in argsSec: cmdArgs.append(readVarValue(name, argSec)) cmdKwargs = {} for name, kwargSec in kwargsSec: argType, subSec = kwargSec.items()[0] cmdKwargs[name] = readVarValue(argType, subSec) return chapter.PlayerCommand(cmdID, name, cmdArgs=tuple(cmdArgs), cmdKwargs=cmdKwargs)
def _readPlayerCommand(xmlCtx, section, _): cmdID = parseID(xmlCtx, section, 'Specify a player command ID') name = _xml.readString(xmlCtx, section, 'name') argsSec = _xml.getChildren(xmlCtx, section, 'args') kwargsSec = _xml.getChildren(xmlCtx, section, 'kwargs') cmdArgs = [] for name, argSec in argsSec: cmdArgs.append(readVarValue(name, argSec)) cmdKwargs = {} for name, kwargSec in kwargsSec: argType, subSec = kwargSec.items()[0] cmdKwargs[name] = readVarValue(argType, subSec) return tutorial_chapter.PlayerCommand(cmdID, name, cmdArgs=tuple(cmdArgs), cmdKwargs=cmdKwargs)
def _readCustomizationSlotIdRanges(): filePath = _CUSTOMIZATION_CONSTANTS_PATH section = ResMgr.openSection(filePath) if section is None: _xml.raiseWrongXml(None, filePath, 'can not open or read') xmlCtx = (None, filePath) slots = _xml.getSubsection(xmlCtx, section, 'slot_id_ranges') for partName, part in _xml.getChildren(xmlCtx, section, 'slot_id_ranges'): partIds = __customizationSlotIdRanges[partName] for itemName, item in _xml.getChildren(xmlCtx, slots, partName): range_min = _xml.readInt(xmlCtx, item, 'range_min') range_max = _xml.readInt(xmlCtx, item, 'range_max') partIds[itemName] = (range_min, range_max) return
def _readNationConfigSection(xmlCtx, section): res = {} firstNames = {} lastNames = {} icons = {} for kindName in ("normalGroups", "premiumGroups"): groups = [] res[kindName] = groups totalWeight = 0.0 for sname, subsection in _xml.getChildren(xmlCtx, section, kindName): ctx = (xmlCtx, kindName + "/" + sname) group = { "notInShop": subsection.readBool("notInShop", False), "isFemales": "female" == _xml.readNonEmptyString(ctx, subsection, "sex"), "firstNames": _readIDs( (ctx, "firstNames"), _xml.getChildren(ctx, subsection, "firstNames"), firstNames, _parseName ), "lastNames": _readIDs( (ctx, "lastNames"), _xml.getChildren(ctx, subsection, "lastNames"), lastNames, _parseName ), "icons": _readIDs((ctx, "icons"), _xml.getChildren(ctx, subsection, "icons"), icons, _parseIcon), } group["firstNamesList"] = list(group["firstNames"]) group["lastNamesList"] = list(group["lastNames"]) group["iconsList"] = list(group["icons"]) weight = _xml.readNonNegativeFloat(ctx, subsection, "weight") totalWeight += weight group["weight"] = weight groups.append(group) totalWeight = max(0.001, totalWeight) for group in groups: group["weight"] /= totalWeight ranks, rankIDsByNames = _readRanks((xmlCtx, "ranks"), _xml.getChildren(xmlCtx, section, "ranks")) res["roleRanks"] = _readRoleRanks( (xmlCtx, "roleRanks"), _xml.getSubsection(xmlCtx, section, "roleRanks"), rankIDsByNames ) if IS_CLIENT or IS_WEB: res["firstNames"] = firstNames res["lastNames"] = lastNames res["icons"] = icons res["ranks"] = ranks else: res["firstNames"] = frozenset(firstNames) res["lastNames"] = frozenset(lastNames) res["icons"] = frozenset(icons) return res
def __readGuiItemsSection(self, xmlCtx, section): self.__guiItems.clear() for _, subSection in _xml.getChildren(xmlCtx, section, 'gui-items'): itemID = sub_parsers._parseID(xmlCtx, subSection, 'Specify a GUI item ID') path = _xml.readString(xmlCtx, subSection, 'path') self.__guiItems[itemID] = {'path': path, 'locked': True}
def readGroundNodesAndGroups(xmlCtx, section): """Reads section 'groundNodes' for each chassis if it has. :param xmlCtx: tuple(root ctx or None, path to section). :param section: instance of DataSection. :return: tuple(sequence of groups, sequence of nodes). """ if section['groundNodes'] is None: return (component_constants.EMPTY_TUPLE, component_constants.EMPTY_TUPLE) else: groundGroups = [] groundNodes = [] for sname, subsection in _xml.getChildren(xmlCtx, section, 'groundNodes'): if sname == 'group': ctx = (xmlCtx, 'groundNodes/group') group = chassis_components.GroundNodeGroup( isLeft=_xml.readBool(ctx, subsection, 'isLeft'), minOffset=_xml.readFloat(ctx, subsection, 'minOffset'), maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'), template=_xml.readNonEmptyString(ctx, subsection, 'template'), count=_xml.readInt(ctx, subsection, 'count', 1), startIndex=subsection.readInt('startIndex', 0)) groundGroups.append(group) elif sname == 'node': ctx = (xmlCtx, 'groundNodes/node') groundNode = chassis_components.GroundNode( name=_xml.readNonEmptyString(ctx, subsection, 'name'), isLeft=_xml.readBool(ctx, subsection, 'isLeft'), minOffset=_xml.readFloat(ctx, subsection, 'minOffset'), maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset')) groundNodes.append(groundNode) return (tuple(groundGroups), tuple(groundNodes))
def readWheelsAndGroups(xmlCtx, section): """Reads sections 'wheels/group' and 'wheels/wheel' for each chassis. :param xmlCtx: tuple(root ctx or None, path to section). :param section: instance of DataSection. :return: tuple(sequence of groups, sequence of wheels). """ wheelGroups = [] wheels = [] defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60) for sname, subsection in _xml.getChildren(xmlCtx, section, 'wheels'): if sname == 'group': ctx = (xmlCtx, 'wheels/group') group = chassis_components.WheelGroup( isLeft=_xml.readBool(ctx, subsection, 'isLeft'), template=_xml.readNonEmptyString(ctx, subsection, 'template'), count=_xml.readInt(ctx, subsection, 'count', 1), startIndex=subsection.readInt('startIndex', 0), radius=_xml.readPositiveFloat(ctx, subsection, 'radius')) wheelGroups.append(group) elif sname == 'wheel': ctx = (xmlCtx, 'wheels/wheel') w = chassis_components.Wheel( isLeft=_xml.readBool(ctx, subsection, 'isLeft'), radius=_xml.readPositiveFloat(ctx, subsection, 'radius'), nodeName=_xml.readNonEmptyString(ctx, subsection, 'name'), isLeading=subsection.readBool('isLeading', False), leadingSyncAngle=subsection.readFloat('syncAngle', defSyncAngle)) wheels.append(w) return (tuple(wheelGroups), tuple(wheels))
def _parseScenes(self, xmlCtx, section, chapter, flags, itemFlags, afterBattle, initial): for _, sceneSec in _xml.getChildren(xmlCtx, section, 'scenes'): sceneID = sub_parsers.parseID(xmlCtx, sceneSec, 'Specify a unique name for the scene') scene = Scene(entityID=sceneID) self._parseScene(xmlCtx, sceneSec, scene, flags, itemFlags, afterBattle=afterBattle) self._parseSharedScene(chapter, scene, flags, itemFlags) chapter.addScene(scene)
def _readSetFilterSection(xmlCtx, section, _, conditions): filterID = sub_parsers._parseID(xmlCtx, section, 'Specify a filter ID') value = [] for name, subSec in _xml.getChildren(xmlCtx, section, 'value'): value.append(sub_parsers._readVarValue(name, subSec)) return chapter.SetFilter(filterID, tuple(value), conditions=conditions)
def _readProgressSection(xmlCtx, section, _): progressID = sub_parsers.parseID(xmlCtx, section, 'Specify a progress ID') conditions = [] for _, subSec in _xml.getChildren(xmlCtx, section, 'steps'): conditions.append(chapter.HasIDConditions(sub_parsers.parseID(xmlCtx, subSec, 'Specify a condition ID'), sub_parsers.readConditions(xmlCtx, subSec, []))) return chapter.ChapterProgress(progressID, conditions)
def __readSceneAliasesSection(self, xmlCtx, section): self.__sceneAliases.clear() self.__sceneMethods.clear() for tagName, subSection in _xml.getChildren(xmlCtx, section, 'scene-aliases'): sceneID = subSection.asString self.__sceneAliases[tagName] = sceneID self.__sceneMethods[sceneID] = _xml.readString(xmlCtx, subSection, 'go-to')
def _readDispatcherTriggerSection(xmlCtx, section, _, triggerID): triggerIDs = set() for _, subSec in _xml.getChildren(xmlCtx, section, 'includes'): triggerIDs.add( sub_parsers.parseID(xmlCtx, subSec, 'Specify a trigger ID')) return triggers.TriggersDispatcher(triggerID, triggerIDs)
def _parseTriggers(self, xmlCtx, section, flags, chapter): for _, subSec in _xml.getChildren(xmlCtx, section, 'triggers'): trigger = sub_parsers.parseTrigger(xmlCtx, subSec, flags, chapter) if trigger is not None: chapter.addTrigger(trigger) return
def writeWheelsAndGroups(wheelsConfig, section): wheelId = 0 groupId = 0 defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60) for sname, subsection in _xml.getChildren(None, section, 'wheels'): if sname == 'group': group = wheelsConfig.groups[groupId] _xml.rewriteString(subsection, 'template', group.template) _xml.rewriteInt(subsection, 'count', group.count, 1) _xml.rewriteInt(subsection, 'startIndex', group.startIndex, 0) _xml.rewriteFloat(subsection, 'radius', group.radius) groupId += 1 if sname == 'wheel': from items.vehicles import _writeHitTester, _writeArmor index = _xml.readIntOrNone(None, subsection, 'index') if index is not None: wheelId = index wheel = wheelsConfig.wheels[wheelId] radiusKey = 'radius' if subsection.has_key('radius') else 'geometry/radius' _xml.rewriteInt(subsection, 'index', wheelId, createNew=False) _xml.rewriteFloat(subsection, radiusKey, wheel.radius) _xml.rewriteString(subsection, 'name', wheel.nodeName) _xml.rewriteBool(subsection, 'isLeading', wheel.isLeading) _xml.rewriteFloat(subsection, 'syncAngle', wheel.leadingSyncAngle, defSyncAngle) _xml.rewriteVector3(subsection, 'wheelPos', wheel.position, Vector3(0, 0, 0)) _writeHitTester(wheel.hitTester, None, subsection, 'hitTester') _writeArmor(wheel.materials, None, subsection, 'armor', optional=True, index=wheelId) wheelId += 1 return
def __readWWmusicDroneSection(wwmusicDroneSetup, section, defaultXml, gameplayName): if section.has_key(wwmusicDroneSetup): dataSection = section else: dataSection = defaultXml outcome = defaultdict(_DroneSettingHolder) droneChildren = sorted(_xml.getChildren(defaultXml, dataSection, wwmusicDroneSetup), key=lambda item: len(item[1].items())) valueTag = 'value' for settingName, settingChildren in droneChildren: if settingChildren.has_key(valueTag): settingValue = settingChildren.readInt(valueTag) if settingChildren.has_key('arena_type_label'): if settingChildren.has_key('gameplay_name'): if gameplayName == settingChildren.readString( 'gameplay_name'): outcome[settingName].setValue( settingChildren.readString('arena_type_label'), settingValue) else: outcome[settingName].setValue( settingChildren.readString('arena_type_label'), settingValue) elif settingChildren.has_key('gameplay_name'): if gameplayName == settingChildren.readString('gameplay_name'): outcome[settingName].setDefault(settingValue) else: outcome[settingName].setDefault(settingValue) raise SoftException('"{}" section missed the key "{}"!'.format( settingName, valueTag)) return outcome
def readWheelsAndGroups(xmlCtx, section): wheelGroups = [] wheels = [] wheelId = 0 defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60) for sname, subsection in _xml.getChildren(xmlCtx, section, 'wheels'): if sname == 'group': ctx = (xmlCtx, 'wheels/group') group = chassis_components.WheelGroup(isLeft=_xml.readBool(ctx, subsection, 'isLeft'), template=intern(_xml.readNonEmptyString(ctx, subsection, 'template')), count=_xml.readInt(ctx, subsection, 'count', 1), startIndex=subsection.readInt('startIndex', 0), radius=_xml.readPositiveFloat(ctx, subsection, 'radius')) wheelGroups.append(group) if sname == 'wheel': from items.vehicles import _readHitTester, _readArmor ctx = (xmlCtx, 'wheels/wheel[{}]'.format(wheelId)) radiusKey = 'radius' if subsection.has_key('radius') else 'geometry/radius' index = _xml.readIntOrNone(ctx, subsection, 'index') actualIndex = wheelId if index is None else index w = chassis_components.Wheel(index=index, isLeft=_xml.readBool(ctx, subsection, 'isLeft'), radius=_xml.readPositiveFloat(ctx, subsection, radiusKey), nodeName=intern(_xml.readNonEmptyString(ctx, subsection, 'name')), isLeading=subsection.readBool('isLeading', False), leadingSyncAngle=subsection.readFloat('syncAngle', defSyncAngle), hitTesterManager=_readHitTester(ctx, subsection, 'hitTester', optional=True), materials=_readArmor(ctx, subsection, 'armor', optional=True, index=actualIndex), position=subsection.readVector3('wheelPos', (0, 0, 0))) if IS_EDITOR: w.editorData.defSyncAngle = defSyncAngle wheels.append(w) wheelId += 1 wheelIndices = [ wheel.index for wheel in wheels ] if sorted(wheelIndices) == range(len(wheels)): sortedWheels = [None] * len(wheels) for wheel in wheels: sortedWheels[wheel.index] = wheel wheels = sortedWheels elif wheelIndices == [None] * len(wheels): pass else: LOG_ERROR('Invalid wheel index detected', xmlCtx, wheels) return (tuple(wheelGroups), tuple(wheels))
def _parseEntities(xmlCtx, section, flags, chapter): for name, subSec in _xml.getChildren(xmlCtx, section, 'has-id'): entity = _parseEntity(xmlCtx, name, subSec, flags) if entity is not None: chapter.addEntity(entity) return
def _parseEntities(self, xmlCtx, section, flags, chapter): for name, subSec in _xml.getChildren(xmlCtx, section, 'has-id'): entity = sub_parsers.parseEntity(xmlCtx, name, subSec, flags) if entity is not None: chapter.addHasIDEntity(entity) return
def readTrackNodes(xmlCtx, section): if section['trackNodes'] is None: return component_constants.EMPTY_TUPLE else: defElasticity = _xml.readFloat(xmlCtx, section, 'trackNodes/elasticity', 1500.0) defDamping = _xml.readFloat(xmlCtx, section, 'trackNodes/damping', 1.0) defForwardElastK = _xml.readFloat(xmlCtx, section, 'trackNodes/forwardElastK', 1.0) defBackwardElastK = _xml.readFloat(xmlCtx, section, 'trackNodes/backwardElastK', 1.0) defOffset = _xml.readFloat(xmlCtx, section, 'trackNodes/offset', 0.0) trackNodes = [] xmlCtx = (xmlCtx, 'trackNodes') for sname, subsection in _xml.getChildren(xmlCtx, section, 'trackNodes'): if sname == 'node': ctx = (xmlCtx, 'trackNodes/node') name = _xml.readStringOrNone(ctx, subsection, 'leftSibling') if name is not None: leftNodeName = intern(name) else: leftNodeName = None name = _xml.readStringOrNone(ctx, subsection, 'rightSibling') if name is not None: rightNodeName = intern(name) else: rightNodeName = None trackNode = chassis_components.TrackNode(name=intern(_xml.readNonEmptyString(ctx, subsection, 'name')), isLeft=_xml.readBool(ctx, subsection, 'isLeft'), initialOffset=_xml.readFloat(ctx, subsection, 'offset', defOffset), leftNodeName=leftNodeName, rightNodeName=rightNodeName, damping=_xml.readFloat(ctx, subsection, 'damping', defDamping), elasticity=_xml.readFloat(ctx, subsection, 'elasticity', defElasticity), forwardElasticityCoeff=_xml.readFloat(ctx, subsection, 'forwardElastK', defForwardElastK), backwardElasticityCoeff=_xml.readFloat(ctx, subsection, 'backwardElastK', defBackwardElastK)) trackNodes.append(trackNode) return tuple(trackNodes)
def readExtras(xmlCtx, section, subsectionName, moduleName): try: mod = importlib.import_module(moduleName) except ImportError: LOG_DEBUG('No module', moduleName) noneExtra = mod.NoneExtra('_NoneExtra', 0, '', None) extras = [noneExtra] extrasDict = {noneExtra.name: noneExtra} for extraName, extraSection in _xml.getChildren(xmlCtx, section, subsectionName): extraName = intern(extraName) ctx = (xmlCtx, subsectionName + '/' + extraName) if extrasDict.has_key(extraName): _xml.raiseWrongXml(ctx, '', 'name is not unique') clientName, sep, serverName = extraSection.asString.partition(':') className = (clientName if IS_CLIENT or IS_BOT else serverName).strip() classObj = getattr(mod, className, None) if classObj is None: _xml.raiseWrongXml( ctx, '', "class '%s' is not found in '%s'" % (className, mod.__name__)) extra = classObj(extraName, len(extras), xmlCtx[1], extraSection) extras.append(extra) extrasDict[extraName] = extra if len(extras) > 200: _xml.raiseWrongXml(xmlCtx, subsectionName, 'too many extras') return (tuple(extras), extrasDict)
def readLeveredSuspension(xmlCtx, section, cache): leveredSection = section['leveredSuspension'] if leveredSection is None: return else: levers = [] for sname, subsection in _xml.getChildren(xmlCtx, section, 'leveredSuspension'): if sname != 'lever': continue ctx = (xmlCtx, 'leveredSuspension/lever') limits = _xml.readVector2(ctx, subsection, 'limits') lever = chassis_components.SuspensionLever( startNodeName=intern( _xml.readNonEmptyString(ctx, subsection, 'startNode')), jointNodeName=intern( _xml.readNonEmptyString(ctx, subsection, 'jointNode')), trackNodeName=intern( _xml.readNonEmptyString(ctx, subsection, 'trackNode')), minAngle=math.radians(limits.x), maxAngle=math.radians(limits.y)) levers.append(lever) ctx = (xmlCtx, 'leveredSuspension') leveredSuspensionConfig = chassis_components.LeveredSuspensionConfig( levers=levers, interpolationSpeedMul=_xml.readFloat(ctx, leveredSection, 'interpolationSpeedMul', 10.0), lodSettings=shared_readers.readLodSettings(ctx, leveredSection, cache)) return leveredSuspensionConfig
def readGroundNodesAndGroups(xmlCtx, section): if section['groundNodes'] is None: return (component_constants.EMPTY_TUPLE, component_constants.EMPTY_TUPLE) else: groundGroups = [] groundNodes = [] for sname, subsection in _xml.getChildren(xmlCtx, section, 'groundNodes'): if sname == 'group': ctx = (xmlCtx, 'groundNodes/group') group = chassis_components.GroundNodeGroup( isLeft=_xml.readBool(ctx, subsection, 'isLeft'), minOffset=_xml.readFloat(ctx, subsection, 'minOffset'), maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'), template=intern( _xml.readNonEmptyString(ctx, subsection, 'template')), count=_xml.readInt(ctx, subsection, 'count', 1), startIndex=subsection.readInt('startIndex', 0)) groundGroups.append(group) if sname == 'node': ctx = (xmlCtx, 'groundNodes/node') groundNode = chassis_components.GroundNode( name=intern( _xml.readNonEmptyString(ctx, subsection, 'name')), isLeft=_xml.readBool(ctx, subsection, 'isLeft'), minOffset=_xml.readFloat(ctx, subsection, 'minOffset'), maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset')) groundNodes.append(groundNode) return (tuple(groundGroups), tuple(groundNodes))
def readWheelsAndGroups(xmlCtx, section): wheelGroups = [] wheels = [] defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60) for sname, subsection in _xml.getChildren(xmlCtx, section, 'wheels'): if sname == 'group': ctx = (xmlCtx, 'wheels/group') group = chassis_components.WheelGroup( isLeft=_xml.readBool(ctx, subsection, 'isLeft'), template=intern( _xml.readNonEmptyString(ctx, subsection, 'template')), count=_xml.readInt(ctx, subsection, 'count', 1), startIndex=subsection.readInt('startIndex', 0), radius=_xml.readPositiveFloat(ctx, subsection, 'radius')) wheelGroups.append(group) if sname == 'wheel': ctx = (xmlCtx, 'wheels/wheel') w = chassis_components.Wheel( isLeft=_xml.readBool(ctx, subsection, 'isLeft'), radius=_xml.readPositiveFloat(ctx, subsection, 'radius'), nodeName=intern( _xml.readNonEmptyString(ctx, subsection, 'name')), isLeading=subsection.readBool('isLeading', False), leadingSyncAngle=subsection.readFloat('syncAngle', defSyncAngle)) wheels.append(w) return (tuple(wheelGroups), tuple(wheels))
def readGroundNodesAndGroups(xmlCtx, section, cache): if section['groundNodes'] is None: return (component_constants.EMPTY_TUPLE, component_constants.EMPTY_TUPLE, False, None) else: groundGroups = [] groundNodes = [] for sname, subsection in _xml.getChildren(xmlCtx, section, 'groundNodes'): if sname == 'group': ctx = (xmlCtx, 'groundNodes/group') group = chassis_components.GroundNodeGroup(isLeft=_xml.readBool(ctx, subsection, 'isLeft'), minOffset=_xml.readFloat(ctx, subsection, 'minOffset'), maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'), nodesTemplate=intern(_xml.readNonEmptyString(ctx, subsection, 'template')), affectedWheelsTemplate=_xml.readStringOrNone(ctx, subsection, 'affectedWheelsTemplate'), nodesCount=_xml.readInt(ctx, subsection, 'count', 1), startIndex=subsection.readInt('startIndex', 0), collisionSamplesCount=subsection.readInt('collisionSamplesCount', 1), hasLiftMode=_xml.readBool(ctx, subsection, 'hasLiftMode', False)) groundGroups.append(group) if sname == 'node': ctx = (xmlCtx, 'groundNodes/node') groundNode = chassis_components.GroundNode(nodeName=intern(_xml.readNonEmptyString(ctx, subsection, 'name')), affectedWheelName=_xml.readStringOrEmpty(ctx, subsection, 'affectedWheelName'), isLeft=_xml.readBool(ctx, subsection, 'isLeft'), minOffset=_xml.readFloat(ctx, subsection, 'minOffset'), maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'), collisionSamplesCount=_xml.readInt(ctx, subsection, 'collisionSamplesCount', 1), hasLiftMode=_xml.readBool(ctx, subsection, 'hasLiftMode', False)) groundNodes.append(groundNode) activePostmortem = _xml.readBool(xmlCtx, section, 'groundNodes/activePostmortem', False) lodSettingsSection = section['groundNodes/lodSettings'] if lodSettingsSection is not None: lodSettings = shared_readers.readLodSettings(xmlCtx, section['groundNodes'], cache) else: lodSettings = None return (tuple(groundGroups), tuple(groundNodes), activePostmortem, lodSettings)
def __readControlsSounds(self, xmlCtx): """ Reading controls sounds data @param xmlCtx: [xml data section] xml context document """ controlsSection = _xml.getSubsection(xmlCtx, xmlCtx, self.CONTROLS) self.__default = doc_loaders.readDict(xmlCtx, controlsSection, self.CONTROLS_DEFAULT) controlsOverridesSection = _xml.getSubsection(xmlCtx, controlsSection, self.CONTROLS_OVERRIDES) for name in controlsOverridesSection.keys(): self.__overrides[name] = doc_loaders.readDict( xmlCtx, controlsOverridesSection, name) for schemaName, schemaSection in _xml.getChildren( xmlCtx, controlsSection, self.CONTROLS_SCHEMAS): self.__schemas[schemaName] = doc_loaders.readDict( xmlCtx, schemaSection, self.SCHEMA_SOUNDS) for groupName in _xml.getSubsection( xmlCtx, schemaSection, self.SCHEMA_GROUPS).asString.split(): if groupName in self.__groups: LOG_WARNING( 'Group has already been read. Will be overriden', groupName, schemaName) self.__groups[groupName] = schemaName
def readEmblemSlots(xmlCtx, section, subsectionName): """Reads section 'emblemSlots' to fetch sequence of emblem slots if they exist. :param xmlCtx: tuple(root ctx or None, path to section). :param section: instance of DataSection. :param subsectionName: string containing name of section to find slots configuration. :return: tuple containing EmblemSlot items. """ slots = [] for sname, subsection in _xml.getChildren(xmlCtx, section, subsectionName): if sname not in component_constants.ALLOWED_EMBLEM_SLOTS: _xml.raiseWrongXml(xmlCtx, 'emblemSlots/{}'.format(sname), 'expected {}'.format(_ALLOWED_EMBLEM_SLOTS)) ctx = (xmlCtx, 'emblemSlots/{}'.format(sname)) descr = shared_components.EmblemSlot( _xml.readVector3(ctx, subsection, 'rayStart'), _xml.readVector3(ctx, subsection, 'rayEnd'), _xml.readVector3(ctx, subsection, 'rayUp'), _xml.readPositiveFloat(ctx, subsection, 'size'), subsection.readBool('hideIfDamaged', False), _ALLOWED_EMBLEM_SLOTS[_ALLOWED_EMBLEM_SLOTS.index(sname)], subsection.readBool('isMirrored', False), subsection.readBool('isUVProportional', True), _xml.readIntOrNone(ctx, subsection, 'emblemId')) slots.append(descr) return tuple(slots)
def parse(self, chapter, afterBattle = False, initial = False): filePath = chapter.getFilePath(afterBattle=afterBattle) section = ResMgr.openSection(filePath) if section is None: _xml.raiseWrongXml(None, filePath, 'can not open or read') xmlCtx = (None, filePath) chapter.clear() flags = [] itemFlags = [] if 'initial-scene' in section.keys(): chapter.setInitialSceneID(_xml.readString(xmlCtx, section, 'initial-scene')) if 'default-scene' in section.keys(): chapter.setDefaultSceneID(_xml.readString(xmlCtx, section, 'default-scene')) for name, subSec in _xml.getChildren(xmlCtx, section, 'has-id'): entity = sub_parsers._parseEntity(xmlCtx, name, subSec, flags) if entity is not None: chapter.addHasIDEntity(entity) for _, subSec in _xml.getChildren(xmlCtx, section, 'triggers'): trigger = sub_parsers._parseTrigger(xmlCtx, subSec, flags, chapter) if trigger is not None: chapter.addTrigger(trigger) gVarIDs = [] for name, subSec in _xml.getChildren(xmlCtx, section, 'vars'): if name == 'var-set': chapter.addVarSet(sub_parsers._parseVarSet(xmlCtx, subSec, flags)) elif name == 'var-set-ref': gVarIDs.append(sub_parsers._parseID(xmlCtx, subSec, 'Specify a var ID')) else: _xml.raiseWrongXml(xmlCtx, name, 'Unknown tag') if len(gVarIDs): GlobalRefParser().parse(chapter, varIDs=gVarIDs, flags=flags) for _, sceneSec in _xml.getChildren(xmlCtx, section, 'scenes'): sceneID = sub_parsers._parseID(xmlCtx, sceneSec, 'Specify a unique name for the scene') scene = Scene(entityID=sceneID) self.__parseScene(xmlCtx, sceneSec, scene, flags, itemFlags, afterBattle=afterBattle) chapter.addScene(scene) if initial: scene = chapter.getInitialScene() self.__parseSharedScene(chapter, scene, flags, itemFlags) flags = filter(lambda flag: flag not in itemFlags, flags) chapter.setFlags(flags) chapter.setValid(True) return chapter
def __readSharedMetrics(self, shared, xmlCtx, section): precessed = _xml.getChildren(xmlCtx, section, 'grids') for name, gridSection in precessed: gridName = gridSection.asString xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, gridName) gridCtx = (None, xPath) subSec = _xml.getSubsection(xmlCtx, gridSection, 'root') xmlCtx = (None, '{0:>s}/root'.format(xPath)) rootPos = {'start': _xml.readVector2(xmlCtx, subSec, 'start').tuple(), 'step': _xml.readInt(xmlCtx, subSec, 'step')} subSec = _xml.getSubsection(gridCtx, gridSection, 'vertical') xmlCtx = (None, '{0:>s}/vertical'.format(xPath)) vertical = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step')) subSec = _xml.getSubsection(gridCtx, gridSection, 'horizontal') xmlCtx = (None, '{0:>s}/horizontal'.format(xPath)) horizontal = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step')) shared['grids'][gridName] = {'root': rootPos, 'vertical': vertical, 'horizontal': horizontal} precessed = _xml.getChildren(xmlCtx, section, 'lines') lines = shared['lines'] for name, sub in precessed: xPath = '{0:>s}/{1:>s}'.format(TREE_SHARED_REL_FILE_PATH, name) xmlCtx = (None, xPath) pinsSec = _xml.getChildren(xmlCtx, sub, 'inPin') inPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec)) pinsSec = _xml.getChildren(xmlCtx, sub, 'outPin') outPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec)) pinsSec = _xml.getChildren(xmlCtx, sub, 'viaPin') viaPins = defaultdict(dict) for outPin, setSec in pinsSec: for inPin, pSec in setSec.items(): viaPins[outPin][inPin] = map(lambda section: section[1].asVector2.tuple(), pSec.items()) defSec = sub['default'] default = {} if defSec is not None: xmlCtx = (None, '{0:>s}/default'.format(xPath)) default = {'outPin': _xml.readString(xmlCtx, defSec, 'outPin'), 'inPin': _xml.readString(xmlCtx, defSec, 'inPin')} lines[name] = {'inPins': inPins, 'outPins': outPins, 'viaPins': viaPins, 'default': default} return
def _readGuiItemPropertiesEffectSection(xmlCtx, section, _, conditions): itemID = parseID(xmlCtx, section, 'Specify a item ID') props = {} for _, subSec in _xml.getChildren(xmlCtx, section, 'properties'): propType, propSec = subSec.items()[0] props[subSec.asString] = readVarValue(propType, propSec) revert = section.readBool('revert') return effects.SetGuiItemProperty(itemID, props, conditions=conditions, revert=revert)
def _readDynamicGuiItemSection(xmlCtx, section, itemFlags, itemID, props, conditions): item = chapter.DynamicGuiItemRef(itemID, props, conditions=conditions) if 'find-criteria' in section.keys(): subSec = _xml.getSubsection(xmlCtx, section, 'find-criteria') parentID = _xml.readString(xmlCtx, subSec, 'parent-ref') varPath = _xml.readString(xmlCtx, subSec, 'var-path') varRef = _xml.readString(xmlCtx, subSec, 'var-ref') item.setFindCriteria([parentID, varPath, varRef]) for _, effectSec in _xml.getChildren(xmlCtx, section, 'not-on-scene-effects'): effect = _parseEffect(xmlCtx, effectSec, itemFlags) if effect is not None: item.addNotOnSceneEffect(effect) for _, effectSec in _xml.getChildren(xmlCtx, section, 'on-scene-effects'): effect = _parseEffect(xmlCtx, effectSec, itemFlags) if effect is not None: item.addOnSceneEffect(effect) return item
def parse(self): section = ResMgr.openSection(BONUSES_REFS_FILE_PATH) if section is None: _xml.raiseWrongXml(None, BONUSES_REFS_FILE_PATH, 'can not open or read') xmlCtx = (None, BONUSES_REFS_FILE_PATH) result = {} for _, subSec in _xml.getChildren(xmlCtx, section, 'bonuses'): bonusID = sub_parsers.parseID(xmlCtx, subSec, 'Specify a bonus ID') result[bonusID] = Bonus(subSec.readInt('id', -1), subSec.readString('message'), sub_parsers.readValues(subSec)) return result
def _parseVars(self, xmlCtx, section, flags, chapter): gVarIDs = [] for name, subSec in _xml.getChildren(xmlCtx, section, 'vars'): if name == 'var-set': chapter.addVarSet(sub_parsers.parseVarSet(xmlCtx, subSec, flags)) elif name == 'var-set-ref': gVarIDs.append(sub_parsers.parseID(xmlCtx, subSec, 'Specify a var ID')) else: _xml.raiseWrongXml(xmlCtx, name, 'Unknown tag') if gVarIDs: GlobalRefParser().parse(chapter, varIDs=gVarIDs, flags=flags)
def __parseScene(self, xmlCtx, section, scene, flags, itemFlags, afterBattle = False, frontEffects = False): for _, subSec in _xml.getChildren(xmlCtx, section, 'gui-items'): item = sub_parsers._parseGuiItem(xmlCtx, subSec, flags, itemFlags) if item is not None: scene.addGuiItem(item) front = -1 for _, subSec in _xml.getChildren(xmlCtx, section, 'post-effects'): effect = sub_parsers._parseEffect(xmlCtx, subSec, flags, afterBattle=afterBattle) if effect is not None: if frontEffects: front += 1 scene.addPostEffect(effect, front=front) front = -1 for _, subSec in _xml.getChildren(xmlCtx, section, 'runtime-effects'): effect = sub_parsers._parseEffect(xmlCtx, subSec, flags, afterBattle=afterBattle) if effect is not None: if frontEffects: front += 1 scene.addEffect(effect, front=front)
def _readNationConfigSection(xmlCtx, section): res = {} firstNames = {} lastNames = {} icons = {} for kindName in ('normalGroups', 'premiumGroups'): groups = [] res[kindName] = groups totalWeight = 0.0 for sname, subsection in _xml.getChildren(xmlCtx, section, kindName): ctx = (xmlCtx, kindName + '/' + sname) group = {'notInShop': subsection.readBool('notInShop', False), 'isFemales': 'female' == _xml.readNonEmptyString(ctx, subsection, 'sex'), 'firstNames': _readIDs((ctx, 'firstNames'), _xml.getChildren(ctx, subsection, 'firstNames'), firstNames, _parseName), 'lastNames': _readIDs((ctx, 'lastNames'), _xml.getChildren(ctx, subsection, 'lastNames'), lastNames, _parseName), 'icons': _readIDs((ctx, 'icons'), _xml.getChildren(ctx, subsection, 'icons'), icons, _parseIcon)} group['firstNamesList'] = list(group['firstNames']) group['lastNamesList'] = list(group['lastNames']) group['iconsList'] = list(group['icons']) weight = _xml.readNonNegativeFloat(ctx, subsection, 'weight') totalWeight += weight group['weight'] = weight groups.append(group) totalWeight = max(0.001, totalWeight) for group in groups: group['weight'] /= totalWeight ranks, rankIDsByNames = _readRanks((xmlCtx, 'ranks'), _xml.getChildren(xmlCtx, section, 'ranks')) res['roleRanks'] = _readRoleRanks((xmlCtx, 'roleRanks'), _xml.getSubsection(xmlCtx, section, 'roleRanks'), rankIDsByNames) if IS_CLIENT or IS_WEB: res['firstNames'] = firstNames res['lastNames'] = lastNames res['icons'] = icons res['ranks'] = ranks else: res['firstNames'] = frozenset(firstNames) res['lastNames'] = frozenset(lastNames) res['icons'] = frozenset(icons) return res
def parse(filePath, excludedHints): hints = HintsData() section = ResMgr.openSection(filePath) if section is None: _xml.raiseWrongXml(None, filePath, 'can not open or read') xmlCtx = (None, filePath) hints.setGuiFilePath(_xml.readString(xmlCtx, section, 'gui')) for _, subSec in _xml.getChildren(xmlCtx, section, 'hints'): hint = sub_parsers.parseHint(xmlCtx, subSec) if hint['hintID'] not in excludedHints: hints.addHint(hint) return hints
def parseAction(xmlCtx, section, flags): name = section.name if name not in ACTION_TAGS: LOG_ERROR('Action is not supported: ', name) return targetID = parseID(xmlCtx, section, 'Specify a target ID') action = chapter.Action(ACTION_TAGS[name], targetID) if 'effects' in section.keys(): for _, effectSec in _xml.getChildren(xmlCtx, section, 'effects'): effect = _parseEffect(xmlCtx, effectSec, flags) if effect is not None: action.addEffect(effect) return action
def _parseGuiItem(xmlCtx, section, flags, itemFlags): itemID = parseID(xmlCtx, section, 'Specify a GUI item ID') props = {} tags = section.keys() if 'properties' in tags: for _, subSec in _xml.getChildren(xmlCtx, section, 'properties'): propType, propSec = subSec.items()[0] props[subSec.asString] = readVarValue(propType, propSec) item = chapter.GuiItemRef(itemID, props, conditions=_parseConditions(xmlCtx, section, flags)) if 'on-scene-effects' in tags: for _, effectSec in _xml.getChildren(xmlCtx, section, 'on-scene-effects'): effect = _parseEffect(xmlCtx, effectSec, itemFlags) if effect is not None: item.addOnSceneEffect(effect) if 'not-on-scene-effects' in tags: for _, effectSec in _xml.getChildren(xmlCtx, section, 'not-on-scene-effects'): effect = _parseEffect(xmlCtx, effectSec, itemFlags) if effect is not None: item.addNotOnSceneEffect(effect) return item
def parse(self, chapter, varIDs = None, flags = None): if varIDs is None: varIDs = [] if flags is None: flags = [] section = ResMgr.openSection(GLOBAL_REFS_FILE_PATH) if section is None: _xml.raiseWrongXml(None, GLOBAL_REFS_FILE_PATH, 'can not open or read') xmlCtx = (None, GLOBAL_REFS_FILE_PATH) if len(varIDs): for _, subSec in _xml.getChildren(xmlCtx, section, 'vars'): varID = sub_parsers._parseID(xmlCtx, subSec, 'Specify a var ID') if varID in varIDs: chapter.addVarSet(sub_parsers._parseVarSet(xmlCtx, subSec, flags))
def __readAvailableNations(self, xmlCtx, root): names = [] indices = nations.INDICES for _, section in _xml.getChildren(xmlCtx, root, 'available-nations'): name = section.asString if name not in indices: _xml.raiseWrongXml(xmlCtx, 'available-nations', 'Nation {0:>s} not found'.format(name)) if name not in nations.AVAILABLE_NAMES: LOG_ERROR('Nation ignored, it not found in nations.AVAILABLE_NAMES', name) continue names.append(name) names = sorted(names, cmp=lambda item, other: cmp(GUI_NATIONS_ORDER_INDEX.get(item), GUI_NATIONS_ORDER_INDEX.get(other))) return names
def _readAction(xmlCtx, section, eventType, flags): actionID = parseID(xmlCtx, section, 'Specify a action ID') itemID = None if 'item-id' in section.keys(): itemID = parseID(xmlCtx, section['item-id'], 'Specify a item ID') else: _xml.raiseWrongXml(xmlCtx, section.name, 'Specify a item ID') action = chapter.Action(eventType, itemID) action.setID(actionID) for _, effectSec in _xml.getChildren(xmlCtx, section, 'effects'): effect = _parseEffect(xmlCtx, effectSec, flags) if effect is not None: action.addEffect(effect) return action
def _readQueueDialogSection(xmlCtx, section, _, dialogID, dialogType, content): content['avgTimeTextFormat'] = translation(_xml.readString(xmlCtx, section, 'avg-time-text')) subSec = _xml.getSubsection(xmlCtx, section, 'player-time-text') content['playerTimeTextStart'] = translation(_xml.readString(xmlCtx, subSec, 'start')) content['playerTimeTextEnd'] = translation(_xml.readString(xmlCtx, subSec, 'end')) pointcuts = [] for _, subSec in _xml.getChildren(xmlCtx, section, 'time-pointcuts'): value = subSec.asFloat if value > 0: pointcuts.append(subSec.asInt) if len(pointcuts) < 2: _xml.raiseWrongSection(xmlCtx, 'time-pointcuts: should be the minimum and maximum value') content['timePointcuts'] = sorted(pointcuts) return chapter.PopUp(dialogID, dialogType, content, _xml.readString(xmlCtx, section, 'var-ref'))
def _parseGuiItem(xmlCtx, section, flags, itemFlags): itemID = _parseID(xmlCtx, section, 'Specify a GUI item ID') lifeCycle = _xml.readString(xmlCtx, section, 'life-cycle') parser = GUI_ITEMS_SUB_PARSERS.get(lifeCycle) item = None if parser is not None: props = {} if 'properties' in section.keys(): for _, subSec in _xml.getChildren(xmlCtx, section, 'properties'): propType, propSec = subSec.items()[0] props[subSec.asString] = _readVarValue(propType, propSec) item = parser(xmlCtx, section, itemFlags, itemID, props, _parseConditions(xmlCtx, section, flags)) else: LOG_ERROR('Gui item is not supported:', lifeCycle) return item
def __readControlsSounds(self, xmlCtx): """ Reading controls sounds data @param xmlCtx: [xml data section] xml context document """ controlsSection = _xml.getSubsection(xmlCtx, xmlCtx, self.CONTROLS) self.__default = doc_loaders.readDict(xmlCtx, controlsSection, self.CONTROLS_DEFAULT) controlsOverridesSection = _xml.getSubsection(xmlCtx, controlsSection, self.CONTROLS_OVERRIDES) for name in controlsOverridesSection.keys(): self.__overrides[name] = doc_loaders.readDict(xmlCtx, controlsOverridesSection, name) for schemaName, schemaSection in _xml.getChildren(xmlCtx, controlsSection, self.CONTROLS_SCHEMAS): self.__schemas[schemaName] = doc_loaders.readDict(xmlCtx, schemaSection, self.SCHEMA_SOUNDS) for groupName in _xml.getSubsection(xmlCtx, schemaSection, self.SCHEMA_GROUPS).asString.split(): if groupName in self.__groups: LOG_WARNING('Group has already been read. Will be overriden', groupName, schemaName) self.__groups[groupName] = schemaName
def __parseChapterSummaries(self, xmlCtx, section, descriptor): for _, subSection in _xml.getChildren(xmlCtx, section, 'chapters'): chapterID = _xml.readString(xmlCtx, subSection, 'chapter-id') title = translation(_xml.readString(xmlCtx, subSection, 'title')) descSec = _xml.getSubsection(xmlCtx, subSection, 'description') defDesc = translation(descSec.asString) abDesc = translation(descSec.readString('after-battle', defDesc)) descriptions = (defDesc, abDesc) bonusSec = _xml.getSubsection(xmlCtx, subSection, 'bonus') bonus = Bonus(bonusSec.readInt('id', -1), bonusSec.readString('message'), sub_parsers._readBonusValues(bonusSec)) forcedLoading = subSection.readInt('forced-loading', -1) pathSec = _xml.getSubsection(xmlCtx, subSection, 'file-path') defFilePath = pathSec.asString afterBattleFilePath = pathSec.readString('after-battle', defFilePath) filePaths = (defFilePath, afterBattleFilePath) sharedScene = subSection.readString('shared-scene') descriptor.addChapter(Chapter(chapterID, title, descriptions, bonus, forcedLoading, filePaths, sharedScene))
def _parseActions(xmlCtx, section, flags): result = [] for name, subSec in section.items(): actionType = ACTION_TAGS.get(name) if actionType is None: LOG_ERROR('Action is not supported: ', name) continue targetID = _parseID(xmlCtx, subSec, 'Specify a target ID') action = chapter.Action(actionType, targetID) if 'effects' in subSec.keys(): for _, effectSec in _xml.getChildren(xmlCtx, subSec, 'effects'): effect = _parseEffect(xmlCtx, effectSec, flags) if effect is not None: action.addEffect(effect) result.append(action) return result