def _readReplenishAmmoDialogSection(xmlCtx, section, _, dialogID, type, content): content['_submitLabel'] = translation(_xml.readString(xmlCtx, section, 'submit-label')) content['_align'] = _xml.readString(xmlCtx, section, 'align') vector = _xml.readVector2(xmlCtx, section, 'offset') content['_popupOffsetX'] = vector.x content['_popupOffsetY'] = vector.y return chapter.PopUp(dialogID, type, content)
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 readShot(xmlCtx, section, nationID, projectileSpeedFactor, cache): """Reads section 'gun/shots/<shell_name>'. :param xmlCtx: tuple(root ctx or None, path to section). :param section: instance of DataSection. :param nationID: integer containing ID of nation. :param projectileSpeedFactor: float containing factor that is applied to projectile speeds and gravities at reading from configs. :param cache: instance of vehicles.Cache to get desired shell by name. :return: instance of GunShot. """ shellName = section.name shellID = cache.shellIDs(nationID).get(shellName) if shellID is None: _xml.raiseWrongXml(xmlCtx, '', 'unknown shell type name') shellDescr = cache.shells(nationID)[shellID] return gun_components.GunShot( shellDescr, 0.0 if not section.has_key('defaultPortion') else _xml.readFraction( xmlCtx, section, 'defaultPortion'), _xml.readVector2(xmlCtx, section, 'piercingPower'), _xml.readPositiveFloat(xmlCtx, section, 'speed') * projectileSpeedFactor, _xml.readNonNegativeFloat(xmlCtx, section, 'gravity') * projectileSpeedFactor**2, _xml.readPositiveFloat(xmlCtx, section, 'maxDistance'), section.readFloat('maxHeight', 1000000.0))
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 readShot(xmlCtx, section, nationID, projectileSpeedFactor, cache): shellName = section.name shellID = cache.shellIDs(nationID).get(shellName) if shellID is None: _xml.raiseWrongXml(xmlCtx, '', 'unknown shell type name') shellDescr = cache.shells(nationID)[shellID] return gun_components.GunShot( shellDescr, ZERO_FLOAT if not section.has_key('defaultPortion') else _xml.readFraction(xmlCtx, section, 'defaultPortion'), _xml.readVector2(xmlCtx, section, 'piercingPower'), _xml.readPositiveFloat(xmlCtx, section, 'speed') * projectileSpeedFactor, _xml.readNonNegativeFloat(xmlCtx, section, 'gravity') * projectileSpeedFactor**2, _xml.readPositiveFloat(xmlCtx, section, 'maxDistance'), _xml.readFloat(xmlCtx, section, 'maxHeight', 1000000.0))
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 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), collisionSamplesCount=subsection.readInt('collisionSamplesCount', 1), hasLiftMode=_xml.readBool(ctx, subsection, 'hasLiftMode', False), affectedWheelName=_xml.readStringOrEmpty(ctx, subsection, 'affectedWheelName')) 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), activePostmortem=_xml.readBool(ctx, leveredSection, 'activePostmortem', False)) return leveredSuspensionConfig
def readLeveredSuspension(xmlCtx, section, cache): """Reads levered suspension section. :param xmlCtx: tuple(root ctx or None, path to section). :param section: instance of DataSection. :param cache: instance of vehicles.Cache. :return: instance of SuspensionLever for levered suspension or None. """ 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=_xml.readNonEmptyString(ctx, subsection, 'startNode'), jointNodeName=_xml.readNonEmptyString(ctx, subsection, 'jointNode'), trackNodeName=_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=leveredSection.readFloat( 'interpolationSpeedMul', 10.0), lodSettings=shared_readers.readLodSettings(ctx, leveredSection, cache)) return leveredSuspensionConfig
def __readShared(self, clearCache = False): if clearCache: ResMgr.purge(TREE_SHARED_REL_FILE_PATH) shared = {'settings': {}, 'grids': {}, 'default': {}, 'lines': {}} section = ResMgr.openSection(TREE_SHARED_REL_FILE_PATH) if section is None: _xml.raiseWrongXml(None, TREE_SHARED_REL_FILE_PATH, 'can not open or read') xmlCtx = (None, TREE_SHARED_REL_FILE_PATH) precessed = _xml.getChildren(xmlCtx, section, 'settings-set') for name, settingsSec in precessed: settingsName = settingsSec.asString xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, settingsName) xmlCtx = (None, xPath) settings = {} for _, settingSec in settingsSec.items(): name = _xml.readString(xmlCtx, settingSec, 'name') if name not in DISPLAY_SETTINGS: LOG_ERROR('Setting is invalid', name) continue reader = DISPLAY_SETTINGS[name] value = getattr(_xml, reader)(xmlCtx, settingSec, 'value') settings[name] = value for name in DISPLAY_SETTINGS.iterkeys(): if name not in settings: raise _ConfigError(xmlCtx, 'Setting not found') shared['settings'][settingsName] = settings 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} if self.__availableNations is None: self.__availableNations = self.__readAvailableNations((None, TREE_SHARED_REL_FILE_PATH), section) 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(_makeDict) 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} defSec = _xml.getSubsection(xmlCtx, section, 'default-line') xPath = '{0:>s}/default-line'.format(TREE_SHARED_REL_FILE_PATH) xmlCtx = (None, xPath) name = _xml.readString(xmlCtx, defSec, 'line') outPin = _xml.readString(xmlCtx, defSec, 'outPin') inPin = _xml.readString(xmlCtx, defSec, 'inPin') self.__getLineInfo(xmlCtx, name, 0, outPin, inPin, lines) shared['default'] = {'line': name, 'inPin': inPin, 'outPin': outPin} return shared
def __readShared(self, clearCache=False): if clearCache: ResMgr.purge(TREE_SHARED_REL_FILE_PATH) shared = {'settings': {}, 'grids': {}, 'default': {}, 'lines': {}} section = ResMgr.openSection(TREE_SHARED_REL_FILE_PATH) if section is None: _xml.raiseWrongXml(None, TREE_SHARED_REL_FILE_PATH, 'can not open or read') xmlCtx = (None, TREE_SHARED_REL_FILE_PATH) precessed = _xml.getChildren(xmlCtx, section, 'settings-set') for name, settingsSec in precessed: settingsName = settingsSec.asString xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, settingsName) xmlCtx = (None, xPath) settings = {} for _, settingSec in settingsSec.items(): name = _xml.readString(xmlCtx, settingSec, 'name') if name not in DISPLAY_SETTINGS: LOG_ERROR('Setting is invalid', name) continue reader = DISPLAY_SETTINGS[name] value = getattr(_xml, reader)(xmlCtx, settingSec, 'value') settings[name] = value for name in DISPLAY_SETTINGS.iterkeys(): if name not in settings: raise _ConfigError(xmlCtx, 'Setting not found') shared['settings'][settingsName] = settings 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 } if self.__availableNations is None: self.__availableNations = self.__readAvailableNations( (None, TREE_SHARED_REL_FILE_PATH), section) 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(_makeDict) 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 } defSec = _xml.getSubsection(xmlCtx, section, 'default-line') xPath = '{0:>s}/default-line'.format(TREE_SHARED_REL_FILE_PATH) xmlCtx = (None, xPath) name = _xml.readString(xmlCtx, defSec, 'line') outPin = _xml.readString(xmlCtx, defSec, 'outPin') inPin = _xml.readString(xmlCtx, defSec, 'inPin') self.__getLineInfo(xmlCtx, name, 0, outPin, inPin, lines) shared['default'] = {'line': name, 'inPin': inPin, 'outPin': outPin} return shared