示例#1
0
	def DoOperation (self, baseValue: float, currentOffsetValue: float, currentValue: float) -> float:
		if not isinstance(baseValue, (float, int)):
			raise Exceptions.IncorrectTypeException(baseValue, "baseValue", (float, int))

		if not isinstance(currentOffsetValue, (float, int)):
			raise Exceptions.IncorrectTypeException(currentOffsetValue, "currentOffsetValue", (float, int))

		if not isinstance(currentValue, (float, int)):
			raise Exceptions.IncorrectTypeException(currentValue, "currentValue", (float, int))

		expressionString = self._expression  # type: str

		try:
			expressionObject = ast.parse(expressionString, mode = "eval")  # type: ast.Expression
		except:
			Debug.Log("Failed to parse an adjustment expression.\nExpression" + expressionString, This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__, lockIdentifier = __name__ + ":" + str(Python.GetLineNumber()))
			return currentOffsetValue

		binaryOperators = self.BinaryOperators
		unaryOperators = self.UnaryOperators

		functions = self.Functions

		variables = {
			"Base": baseValue,
			"CurrentOffset": currentOffsetValue,
			"Current": currentValue,
			**self.Variables
		}  # type: typing.Dict[str, float]

		try:
			expressionResults = self._EvaluateExpressionNode(expressionObject.body, binaryOperators, unaryOperators, functions, variables)  # type: float

			if not isinstance(expressionResults, float):
				raise Exceptions.IncorrectReturnTypeException(expressionResults, "expression", (float, int))

			if math.isinf(expressionResults) or math.isnan(expressionResults):
				raise ValueError("Adjustment expressions cannot return positive infinity, negative infinity, or nan.")

			return expressionResults
		except ZeroDivisionError:
			return currentOffsetValue
		except:
			Debug.Log("Failed to evaluate an adjustment expression.\nExpression" + expressionString, This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__, lockIdentifier = __name__ + ":" + str(Python.GetLineNumber()))
			return currentOffsetValue
示例#2
0
	def _SaveToDictionaryInternal (self) -> typing.Tuple[bool, dict]:
		superOperationSuccessful, data = super()._SaveToDictionaryInternal()  # type: bool, dict

		operationSuccessful = True  # type: bool
		operationInformation = self.SavableOperationInformation  # type: str

		effectsSavingKey = self._effectsSavingKey  # type: str
		effectsDataSavingKey = "Data"  # type: str
		effectsTypeSavingKey = "Type"  # type: str

		effectsListData = list()  # type: typing.List[typing.Optional[dict]]

		for activeEffect in self._activeEffects:  # type: EffectsBase.EffectBase
			if not isinstance(activeEffect, EffectsBase.EffectBase):
				Debug.Log("Found an object in the effects list that was not an effect.\n%s" % operationInformation, self.HostNamespace, Debug.LogLevels.Warning, group = self.HostNamespace, owner = __name__, lockIdentifier = __name__ + ":EffectSavingOperationNotEffectType")
				continue

			try:
				effectContainerData = dict()  # type: dict
				entryOperationSuccessful, effectData = activeEffect.SaveToDictionary()  # type: bool, dict

				if not entryOperationSuccessful:
					operationSuccessful = False

				effectTypeIdentifier = activeEffect.TypeIdentifier  # type: str

				if not isinstance(effectTypeIdentifier, str):
					raise Exceptions.IncorrectReturnTypeException(effectTypeIdentifier, "typeFetcher", (str,))

				effectContainerData[effectsTypeSavingKey] = effectTypeIdentifier
				effectContainerData[effectsDataSavingKey] = effectData

				effectsListData.append(effectContainerData)
			except:
				Debug.Log("Save operation in a savable object failed to save the effect data of an effect with the identifier '%s'.\n%s" % (activeEffect.TypeIdentifier, operationInformation), self.HostNamespace, Debug.LogLevels.Warning, group = self.HostNamespace, owner = __name__)
				operationSuccessful = False

			data[effectsSavingKey] = effectsListData

		if not operationSuccessful:
			return False, data

		return superOperationSuccessful, data
示例#3
0
def GetWickedWhimsDisablingCyclePatches() -> typing.Iterable[str]:
    """
	Get the patches that Cycle would normally do to Cycle (if WickedWhims is installed), except that WickedWhims is indicating should be skipped.
	"""

    try:
        # noinspection PyUnresolvedReferences
        from wickedwhims.main.game_handlers.neonocean.cycle import patches as WickedWhimsCyclePatches
    except ModuleNotFoundError:
        return list()

    disabledCyclePatches = WickedWhimsCyclePatches.get_wicked_whims_disabling_cycle_patches(
    )  # type: typing.Iterable[str]

    if not iter(disabledCyclePatches):
        raise Exceptions.IncorrectReturnTypeException(
            disabledCyclePatches, "get_wicked_whims_disabling_cycle_patches",
            (collections.Iterable, ))

    return disabledCyclePatches
示例#4
0
    def _SaveToDictionaryInternal(self) -> typing.Tuple[bool, dict]:
        superOperationSuccessful, data = super()._SaveToDictionaryInternal(
        )  # type: bool, dict

        operationSuccessful = True  # type: bool
        operationInformation = self.SavableOperationInformation  # type: str

        handlersSavingKey = self._handlersSavingKey  # type: str
        handlersDataSavingKey = "Data"  # type: str
        handlersTypeSavingKey = "Type"  # type: str

        handlersListData = list()  # type: typing.List[typing.Optional[dict]]

        for activeHandler in self._activeHandlers:  # type: HandlersBase.HandlerBase
            if not isinstance(activeHandler, HandlersBase.HandlerBase):
                Debug.Log(
                    "Found an object in the handlers list that was not a handler.\n%s"
                    % operationInformation,
                    self.HostNamespace,
                    Debug.LogLevels.Warning,
                    group=self.HostNamespace,
                    owner=__name__,
                    lockIdentifier=__name__ +
                    ":HandlerSavingOperationNotHandlerType")
                continue

            try:
                handlerContainerData = dict()  # type: dict
                entryOperationSuccessful, handlerData = activeHandler.SaveToDictionary(
                )  # type: bool, dict

                if not entryOperationSuccessful:
                    operationSuccessful = False

                handlerTypeIdentifier = activeHandler.TypeIdentifier  # type: str

                if not isinstance(handlerTypeIdentifier, str):
                    raise Exceptions.IncorrectReturnTypeException(
                        handlerTypeIdentifier, "typeFetcher", (str, ))

                handlerContainerData[
                    handlersTypeSavingKey] = handlerTypeIdentifier
                handlerContainerData[handlersDataSavingKey] = handlerData

                handlersListData.append(handlerContainerData)
            except:
                Debug.Log(
                    "Save operation in a savable object failed to save the handler data of a handler with the identifier '%s'.\n%s"
                    % (activeHandler.TypeIdentifier, operationInformation),
                    self.HostNamespace,
                    Debug.LogLevels.Warning,
                    group=self.HostNamespace,
                    owner=__name__)
                operationSuccessful = False

            data[handlersSavingKey] = handlersListData

        if not operationSuccessful:
            return False, data

        return superOperationSuccessful, data