コード例 #1
0
 def Run(self, *etc):
     service.Service.Run(self, *etc)
     util.LookupConstValue('', '')
     self.chars = None
     self.charCreationInfo = None
     self.raceData, self.raceDataByID = (None, None)
     self.bloodlineDataByRaceID, self.bloodlineDataByID = (None, None)
     self.dollState = None
     self.availableTypeIDs = None
コード例 #2
0
    def LoadTypeIcon(self, *args):
        attrs = self.attrs
        src = attrs.src
        typeID = None
        try:
            typeID = int(src[9:])
        except:
            log.LogInfo("couldn't convert string to typeID, looking up constvalue, Img::Load", src)
            typeID = util.LookupConstValue('type%s' % attrs.src[9:].strip().capitalize(), None)

        bumped = getattr(attrs, 'bumped', 0)
        showFitting = getattr(attrs, 'showfitting', 0)
        showTechLevel = getattr(attrs, 'showtechlevel', 0)
        isCopy = getattr(attrs, 'iscopy', 0)
        if not typeID:
            kw = htmlwriter.PythonizeArgs(src[9:])
            typeID = kw.get('typeID', None)
            bumped = kw.get('bumped', 0)
            isCopy = kw.get('isCopy', 0)
            showFitting = kw.get('showFitting', 0)
            showTechLevel = kw.get('showTechLevel', 0)
        if typeID:
            if bumped:
                if hasattr(self, 'icon') and self.icon:
                    self.icon.Close()
                self.icon = DraggableIcon(parent=self, typeID=typeID, isCopy=True if isCopy == 1 else False, state=uiconst.UI_DISABLED)
                if showFitting:
                    powerEffect = None
                    powerIcon = None
                    powerEffects = [const.effectHiPower, const.effectMedPower, const.effectLoPower]
                    for effect in cfg.dgmtypeeffects.get(typeID, []):
                        if effect.effectID in powerEffects:
                            powerEffect = cfg.dgmeffects.Get(effect.effectID, None)
                            powerIcon = {const.effectHiPower: 11,
                             const.effectMedPower: 10,
                             const.effectLoPower: 9}.get(powerEffect.effectID, None)
                            break

                    if powerIcon:
                        c = uiprimitives.Container(name='powericon', align=uiconst.BOTTOMRIGHT, parent=self.icon, width=attrs.width / 4, height=attrs.width / 4, idx=0)
                        uiprimitives.Line(parent=c, align=uiconst.TOLEFT, color=(1.0, 1.0, 1.0, 0.5))
                        uiprimitives.Line(parent=c, align=uiconst.TOTOP, color=(1.0, 1.0, 1.0, 0.5))
                        uiprimitives.Fill(parent=c, padRight=2, padBottom=2, color=(0.0, 0.0, 0.0, 1.0))
                        pwrIcon = uicontrols.Icon(icon='ui_8_64_%s' % powerIcon, parent=c, align=uiconst.TOALL, idx=0, hint=localization.GetByLabel('UI/Common/FitsToSlot', slotType=powerEffect.displayName), ignoreSize=True)
                if showTechLevel:
                    techSprite = uix.GetTechLevelIcon(None, 0, typeID)
                    if techSprite:
                        c = uiprimitives.Container(name='techIcon', align=uiconst.TOPLEFT, parent=self.icon, width=16, height=16, idx=0)
                        c.children.append(techSprite)
            else:
                uicontrols.Icon(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, pos=(0, 0, 0, 0), typeID=typeID, size=attrs.width, isCopy=isCopy)
        else:
            log.LogInfo('Couldnt convert', attrs.src[9:], 'to typeID')
コード例 #3
0
    def ParseExpression(self, expression, indent='', restricted=0, topLevel=0):
        typesByName = self.typesByName
        groupsByName = self.groupsByName
        dogma = sm.GetService('dogma')
        operandID = expression.operandID
        operand = dogma.operands[operandID]
        ret = None
        try:
            if restricted and operand.operandID not in dogma.restrictedStopList:
                return indent + 'pass'
            if operand.operandID in (const.operandDEFBOOL,
                                     const.operandDEFINT) and topLevel:
                return indent + 'return ' + expression.expressionValue
            if expression.operandID == const.operandUE:
                a1 = a2 = None
                if expression.arg1:
                    a1 = self.ParseExpression(
                        cfg.dgmexpressions[expression.arg1])
                if expression.arg2:
                    a2 = self.ParseExpression(
                        cfg.dgmexpressions[expression.arg2])
                return indent + 'dogma.UserError(env, ' + str(a1) + ', ' + str(
                    a2) + ')'
            if expression.operandID == const.operandDEFASSOCIATION:
                if expression.expressionValue == '9':
                    return '9'
                if expression.expressionValue == 'PreAssignment':
                    return str(const.dgmAssPreAssignment)
                if expression.expressionValue == 'PostAssignment':
                    return str(const.dgmAssPostAssignment)
            elif expression.operandID == const.operandDEFENVIDX:
                test = getattr(const, 'dgmEnv' + expression.expressionValue)
                if test == const.dgmEnvSelf:
                    return 'itemID'
                if test == const.dgmEnvShip:
                    return 'shipID'
                if test == const.dgmEnvTarget:
                    return 'targetID'
                if test == const.dgmEnvChar:
                    return 'charID'
                if test == const.dgmEnvOther:
                    return 'otherID'
            else:
                if expression.operandID == const.operandAIM:
                    arg1expression = cfg.dgmexpressions[expression.arg1]
                    affectingAttribute = self.ParseExpression(
                        cfg.dgmexpressions[expression.arg2])
                    affectedStuffExpression = cfg.dgmexpressions[
                        arg1expression.arg2]
                    affectedModule = self.ParseExpression(
                        cfg.dgmexpressions[affectedStuffExpression.arg1])
                    affectedAttribute = self.ParseExpression(
                        cfg.dgmexpressions[affectedStuffExpression.arg2])
                    affectType = self.ParseExpression(
                        cfg.dgmexpressions[arg1expression.arg1])
                    return indent + 'dogmaLM.AddModifier(%(aT)s, %(aM)s, %(aA)s, itemID, %(aA2)s)' % {
                        'aT': affectType,
                        'aA': affectedAttribute,
                        'aM': affectedModule,
                        'aA2': affectingAttribute
                    }
                if expression.operandID == const.operandRIM:
                    arg1expression = cfg.dgmexpressions[expression.arg1]
                    affectingAttribute = self.ParseExpression(
                        cfg.dgmexpressions[expression.arg2])
                    affectedStuffExpression = cfg.dgmexpressions[
                        arg1expression.arg2]
                    affectedModule = self.ParseExpression(
                        cfg.dgmexpressions[affectedStuffExpression.arg1])
                    affectedAttribute = self.ParseExpression(
                        cfg.dgmexpressions[affectedStuffExpression.arg2])
                    affectType = self.ParseExpression(
                        cfg.dgmexpressions[arg1expression.arg1])
                    return indent + 'dogmaLM.RemoveModifier(%(aT)s, %(aM)s, %(aA)s, itemID, %(aA2)s)' % {
                        'aT': affectType,
                        'aA': affectedAttribute,
                        'aM': affectedModule,
                        'aA2': affectingAttribute
                    }
                if expression.operandID == const.operandDEFATTRIBUTE:
                    if expression.expressionAttributeID:
                        return str(expression.expressionAttributeID)
                elif expression.operandID == const.operandDEFGROUP:
                    if expression.expressionGroupID:
                        return str(expression.expressionGroupID)
                    if expression.expressionValue:
                        groupName = expression.expressionValue.replace(' ', '')
                        groupName = 'group' + groupName[0].upper(
                        ) + groupName[1:]
                        if hasattr(const, groupName):
                            return str(getattr(const, groupName))
                elif expression.operandID == const.operandDEFTYPEID:
                    if expression.expressionTypeID:
                        return str(expression.expressionTypeID)
                    if expression.expressionValue:
                        typeName = expression.expressionValue.replace(' ', '')
                        typeName = 'type' + typeName[0].upper() + typeName[1:]
                        if hasattr(const, typeName):
                            return str(getattr(const, typeName))
            if expression.operandID == const.operandIF:
                arg1expression = cfg.dgmexpressions[expression.arg1]
                arg2expression = cfg.dgmexpressions[expression.arg2]
                if arg1expression.operandID == const.operandRS and restricted:
                    ret = self.ParseExpression(arg2expression,
                                               restricted=restricted)
                else:
                    ret = 'if %s:\n%s' % (
                        self.ParseExpression(arg1expression,
                                             restricted=restricted),
                        self.ParseExpression(
                            arg2expression, '    ', restricted=restricted))
            elif expression.operandID == const.operandINC:
                arg1expression = cfg.dgmexpressions[expression.arg1]
                arg2expression = cfg.dgmexpressions[expression.arg2]
                ret = 'dogmaLM.IncreaseItemAttribute' + self.ParseExpression(
                    arg1expression, restricted=restricted
                )[:-1] + ', itemID, ' + self.ParseExpression(
                    arg2expression, restricted=restricted) + ')'
            elif expression.operandID == const.operandINCN:
                arg1expression = cfg.dgmexpressions[expression.arg1]
                arg2expression = cfg.dgmexpressions[expression.arg2]
                ret = 'dogmaLM.IncreaseItemAttributeEx' + self.ParseExpression(
                    arg1expression,
                    restricted=restricted)[:-1] + ', ' + self.ParseExpression(
                        arg2expression, restricted=restricted) + ')'
            elif expression.operandID == const.operandDEC:
                arg1expression = cfg.dgmexpressions[expression.arg1]
                arg2expression = cfg.dgmexpressions[expression.arg2]
                ret = 'dogmaLM.DecreaseItemAttribute' + self.ParseExpression(
                    arg1expression, restricted=restricted
                )[:-1] + ', itemID, ' + self.ParseExpression(
                    arg2expression, restricted=restricted) + ')'
            elif expression.operandID == const.operandDECN:
                arg1expression = cfg.dgmexpressions[expression.arg1]
                arg2expression = cfg.dgmexpressions[expression.arg2]
                ret = 'dogmaLM.DecreaseItemAttributeEx' + self.ParseExpression(
                    arg1expression,
                    restricted=restricted)[:-1] + ', ' + self.ParseExpression(
                        arg2expression, restricted=restricted) + ')'
            elif expression.operandID == const.operandSET:
                arg1expression = cfg.dgmexpressions[expression.arg1]
                arg2expression = cfg.dgmexpressions[expression.arg2]
                ret = 'dogmaLM.SetAttributeValue' + self.ParseExpression(
                    arg1expression,
                    restricted=restricted)[:-1] + ', ' + self.ParseExpression(
                        arg2expression, restricted=restricted) + ')'
            elif expression.operandID == const.operandOR:
                arg1expression = cfg.dgmexpressions[expression.arg1]
                arg2expression = cfg.dgmexpressions[expression.arg2]
                if arg1expression.operandID == const.operandIF:
                    ret = self.ParseExpression(
                        arg1expression, restricted=restricted
                    ) + '\nelse:\n' + self.ParseExpression(
                        arg2expression, '    ', restricted=restricted)
            elif expression.operandID == const.operandAND:
                arg1expression = cfg.dgmexpressions[expression.arg1]
                arg2expression = cfg.dgmexpressions[expression.arg2]
                if arg1expression.operandID == const.operandSKILLCHECK:
                    ret = self.ParseExpression(
                        arg1expression,
                        restricted=restricted) + '\n' + self.ParseExpression(
                            arg2expression, restricted=restricted)
            if ret is None:
                val = expression.expressionValue
                if expression.arg1:
                    arg1 = self.ParseExpression(
                        cfg.dgmexpressions[expression.arg1],
                        restricted=restricted)
                else:
                    arg1 = None
                if expression.arg2:
                    arg2 = self.ParseExpression(
                        cfg.dgmexpressions[expression.arg2],
                        restricted=restricted)
                else:
                    arg2 = None
                if arg1 and '\n' not in arg1:
                    arg1 = arg1.strip()
                if arg2 and '\n' not in arg2:
                    arg2 = arg2.strip()
                if expression.expressionAttributeID or expression.expressionTypeID or expression.expressionGroupID:
                    return '%s' % expression.expressionAttributeID or expression.expressionTypeID or expression.expressionGroupID
                if operand.operandID == const.operandDEFGROUP:
                    if groupsByName.has_key(expression.expressionValue):
                        return '%s' % groupsByName[
                            expression.expressionValue].groupID
                    elif util.ConstValueExists('group' +
                                               expression.expressionValue):
                        return '%s' % util.LookupConstValue(
                            'group' + expression.expressionValue)
                    else:
                        self.LogError('no such group, ',
                                      expression.expressionValue,
                                      expression.expressionID)
                        self.LogError('expression:', expression.expressionID,
                                      'needs fixing')
                        return '-1000'
                if operand.operandID == const.operandDEFTYPEID:
                    if typesByName.has_key(expression.expressionValue):
                        return '%s' % typesByName[
                            expression.expressionValue].typeID
                    else:
                        self.LogError('no such type, ',
                                      expression.expressionValue,
                                      expression.expressionID)
                        self.LogError('expression:', expression.expressionID,
                                      'needs fixing')
                        return '-10000'
                if operand.pythonFormat == ' ':
                    raise RuntimeError(
                        'Operand %s has still not been defined' %
                        operand.operandID)
                ret = self.GetPythonForOperand(operand, arg1, arg2, val)
                if ret is None:
                    try:
                        ret = operand.pythonFormat % {
                            'arg1': arg1,
                            'arg2': arg2,
                            'value': val
                        }
                    except ValueError:
                        self.LogError(
                            "Operand %s's pythonFormat errored, %s" %
                            (operand.operandID, operand.pythonFormat))
                        raise

            retlines = ret.split('\n')
            retlines2 = []
            totalIdt = indent
            for line in retlines:
                retlines2.append(totalIdt + line)

            ret = string.join(retlines2, '\n')
            if ret.startswith('const.'):
                ret = str(getattr(const, ret[6:]))
            return ret
        finally:
            if not self.modifyingExpr.has_key(expression.expressionID):
                modifierRating = self.approvedModifierOperands.get(
                    expression.operandID, 0)
                if modifierRating == 1:
                    self.modifyingExpr[expression.expressionID] = True
                elif modifierRating == 2:
                    modifiersOnly = 0
                    for sExprID in (expression.arg1, expression.arg2):
                        if sExprID:
                            sExpr = cfg.dgmexpressions[sExprID]
                            sModifierRating = self.approvedModifierOperands.get(
                                sExpr.operandID, 0)
                            if sModifierRating == 1 or sModifierRating == 2 and self.modifyingExpr.get(
                                    sExprID, 0):
                                modifiersOnly += 1
                        else:
                            modifiersOnly += 1

                    if modifiersOnly == 2:
                        self.modifyingExpr[expression.expressionID] = True