Beispiel #1
0
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 _readEmblemSlot(ctx, subsection, slotType):
    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), slotType,
        subsection.readBool('isMirrored', False),
        subsection.readBool('isUVProportional', True),
        _xml.readIntOrNone(ctx, subsection, 'emblemId'))
    return descr
Beispiel #3
0
def _readEmblemSlot(ctx, subsection, slotType):
    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), slotType,
        subsection.readBool('isMirrored', False),
        subsection.readBool('isUVProportional', True),
        _xml.readIntOrNone(ctx, subsection, 'emblemId'),
        _xml.readInt(ctx, subsection, 'slotId'),
        subsection.readBool('applyToFabric', True),
        _readCompatibleModels(subsection, ctx))
    _verifySlotId(ctx, slotType, descr.slotId)
    return descr
Beispiel #4
0
def _readProjectionDecalSlot(ctx, subsection, slotType):
    descr = shared_components.ProjectionDecalSlotDescription(
        slotType=slotType,
        slotId=_xml.readInt(ctx, subsection, 'slotId'),
        position=_xml.readVector3OrNone(ctx, subsection, 'position'),
        rotation=_xml.readVector3OrNone(ctx, subsection, 'rotation'),
        scale=_xml.readVector3OrNone(ctx, subsection, 'scale'),
        scaleFactors=_xml.readVector3(
            ctx, subsection, 'scaleFactors',
            c11n_constants.DEFAULT_DECAL_SCALE_FACTORS),
        doubleSided=_xml.readBool(ctx, subsection, 'doubleSided', False),
        hiddenForUser=_xml.readBool(ctx, subsection, 'hiddenForUser', False),
        canBeMirroredVertically=_xml.readBool(ctx, subsection,
                                              'verticalMirror', False),
        showOn=_xml.readIntOrNone(ctx, subsection, 'showOn'),
        tags=readOrderedTagsOrEmpty(ctx, subsection,
                                    _customizationSlotTagsValidator),
        clipAngle=_xml.readFloat(ctx, subsection, 'clipAngle',
                                 c11n_constants.DEFAULT_DECAL_CLIP_ANGLE),
        anchorShift=_xml.readFloat(ctx, subsection, 'anchorShift',
                                   c11n_constants.DEFAULT_DECAL_ANCHOR_SHIFT))
    _verifySlotId(ctx, slotType, descr.slotId)
    _verifyMatchingSlotSettings(ctx, descr)
    if descr.showOn is not None:
        availableShowOnRegions = c11n_constants.ApplyArea.HULL | c11n_constants.ApplyArea.TURRET | c11n_constants.ApplyArea.GUN
        if descr.showOn | availableShowOnRegions != availableShowOnRegions:
            _xml.raiseWrongSection(ctx, 'showOn')
    if subsection.has_key('compatibleModels'):
        descr.compatibleModels = _xml.readTupleOfStrings(
            ctx, subsection, 'compatibleModels')
    if subsection.has_key('itemId'):
        descr.itemId = _xml.readInt(ctx, subsection, 'itemId')
    if subsection.has_key('options'):
        descr.options = _xml.readNonNegativeInt(ctx, subsection, 'options')
    return descr
Beispiel #5
0
def _readTeleportMarkerSection(xmlCtx, section, markerID, varRef):
    subSec = _xml.getSubsection(xmlCtx, section, 'world')
    worldData = {
        'offset': _xml.readVector3(xmlCtx, subSec, 'offset'),
        'yaw': _xml.readFloat(xmlCtx, subSec, 'yaw')
    }
    return chapter.AreaMarker(markerID, varRef, {}, {}, worldData, {})
def _readWorldMarkerSection(xmlCtx, section):
    subSec = _xml.getSubsection(xmlCtx, section, 'world')
    return {
        'shape': _xml.readString(xmlCtx, subSec, 'shape'),
        'min-distance': _xml.readFloat(xmlCtx, subSec, 'min-distance'),
        'max-distance': _xml.readFloat(xmlCtx, subSec, 'max-distance'),
        'offset': _xml.readVector3(xmlCtx, subSec, 'offset')
    }
Beispiel #7
0
def _readModelMarkerSection(xmlCtx, section, name = 'model'):
    result = {}
    if name in section.keys():
        subSec = _xml.getSubsection(xmlCtx, section, name)
        result = {'path': _xml.readString(xmlCtx, subSec, 'path'),
         'action': _xml.readString(xmlCtx, subSec, 'action'),
         'offset': _xml.readVector3(xmlCtx, subSec, 'offset')}
    return result
Beispiel #8
0
def _readModelMarkerSection(xmlCtx, section, name = 'model'):
    result = {}
    if name in section.keys():
        subSec = _xml.getSubsection(xmlCtx, section, name)
        result = {'path': _xml.readString(xmlCtx, subSec, 'path'),
         'action': _xml.readString(xmlCtx, subSec, 'action'),
         'offset': _xml.readVector3(xmlCtx, subSec, 'offset')}
    return result
Beispiel #9
0
def readEmblemSlots(xmlCtx, section, subsectionName):
    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 _readSlotsAnchor(ctx, subsection, slotType):
    applyTo = _xml.readIntOrNone(ctx, subsection, 'applyTo')
    if applyTo is not None:
        if applyTo not in c11n_constants.ApplyArea.RANGE:
            _xml.raiseWrongSection(ctx, 'applyTo')
    showOn = _xml.readIntOrNone(ctx, subsection, 'showOn')
    if showOn is not None:
        availableShowOnRegions = c11n_constants.ApplyArea.HULL | c11n_constants.ApplyArea.TURRET | c11n_constants.ApplyArea.GUN
        if showOn | availableShowOnRegions != availableShowOnRegions:
            _xml.raiseWrongSection(ctx, 'showOn')
    descr = shared_components.SlotsAnchor(
        type=slotType,
        anchorPosition=_xml.readVector3(ctx, subsection, 'anchorPosition'),
        anchorDirection=_xml.readVector3(ctx, subsection, 'anchorDirection'),
        applyTo=applyTo,
        slotId=_xml.readInt(ctx, subsection, 'slotId'),
        position=_xml.readVector3OrNone(ctx, subsection, 'position'),
        rotation=_xml.readVector3OrNone(ctx, subsection, 'rotation'),
        scale=_xml.readVector3OrNone(ctx, subsection, 'scale'),
        scaleFactors=_xml.readVector3OrNone(ctx, subsection, 'scaleFactors'),
        doubleSided=_xml.readBool(ctx, subsection, 'doubleSided', False),
        showOn=showOn)
    return descr
def _readProjectionDecalSlot(ctx, subsection, slotType):
    descr = shared_components.ProjectionDecalSlotDescription(
        slotType=slotType,
        slotId=_xml.readInt(ctx, subsection, 'slotId'),
        anchorPosition=_xml.readVector3OrNone(ctx, subsection,
                                              'anchorPosition'),
        anchorDirection=_xml.readVector3OrNone(ctx, subsection,
                                               'anchorDirection'),
        position=_xml.readVector3OrNone(ctx, subsection, 'position'),
        rotation=_xml.readVector3OrNone(ctx, subsection, 'rotation'),
        scale=_xml.readVector3OrNone(ctx, subsection, 'scale'),
        scaleFactors=_xml.readVector3(
            ctx, subsection, 'scaleFactors',
            c11n_constants.DEFAULT_DECAL_SCALE_FACTORS),
        doubleSided=_xml.readBool(ctx, subsection, 'doubleSided', False),
        canBeMirroredVertically=_xml.readBool(ctx, subsection,
                                              'verticalMirror', False),
        showOn=_xml.readIntOrNone(ctx, subsection, 'showOn'),
        tags=readOrderedTagsOrEmpty(ctx, subsection,
                                    _customizationSlotTagsValidator),
        clipAngle=_xml.readFloat(ctx, subsection, 'clipAngle',
                                 c11n_constants.DEFAULT_DECAL_CLIP_ANGLE))
    _verifySlotId(ctx, slotType, descr.slotId)
    if descr.showOn is not None:
        availableShowOnRegions = c11n_constants.ApplyArea.HULL | c11n_constants.ApplyArea.TURRET | c11n_constants.ApplyArea.GUN
        if descr.showOn | availableShowOnRegions != availableShowOnRegions:
            _xml.raiseWrongSection(ctx, 'showOn')
    if subsection.has_key('attachedPart'):
        attachedPartsData = _xml.readString(ctx, subsection, 'attachedPart')
        descr.attachedParts = defaultdict(set)
        for partData in attachedPartsData.split():
            pType, pName = partData.split(':')
            if pType != 'hull':
                descr.attachedParts[pType].add(pName)

    if subsection.has_key('compatibleModels'):
        descr.compatibleModels = _xml.readTupleOfStrings(
            ctx, subsection, 'compatibleModels')
    if subsection.has_key('itemId'):
        descr.itemId = _xml.readInt(ctx, subsection, 'itemId')
    if subsection.has_key('options'):
        descr.options = _xml.readNonNegativeInt(ctx, subsection, 'options')
    return descr
Beispiel #12
0
def _readTeleportMarkerSection(xmlCtx, section, markerID, varRef):
    subSec = _xml.getSubsection(xmlCtx, section, 'world')
    worldData = {'offset': _xml.readVector3(xmlCtx, subSec, 'offset'),
     'yaw': _xml.readFloat(xmlCtx, subSec, 'yaw')}
    return chapter.AreaMarker(markerID, varRef, {}, {}, worldData, {})
Beispiel #13
0
def _readWorldMarkerSection(xmlCtx, section):
    subSec = _xml.getSubsection(xmlCtx, section, 'world')
    return {'shape': _xml.readString(xmlCtx, subSec, 'shape'),
     'min-distance': _xml.readFloat(xmlCtx, subSec, 'min-distance'),
     'max-distance': _xml.readFloat(xmlCtx, subSec, 'max-distance'),
     'offset': _xml.readVector3(xmlCtx, subSec, 'offset')}
def _readModelSetting(ctx, section):
    return ModelSetting(scale=_xml.readVector3(ctx, section, 'scale'),
                        spacing=_xml.readFloat(ctx, section, 'spacing'),
                        color=int(_xml.readString(ctx, section, 'color'), 0))