def __init__ (self, trackingSystem: ReproductionShared.ReproductiveSystem): super().__init__(trackingSystem) self.EffectAddedEvent = Events.EventHandler() self.EffectRemovedEvent = Events.EventHandler() self._activeEffects = list() # type: typing.List[EffectsBase.EffectBase]
def __init__(self, trackingSystem: ReproductionShared.ReproductiveSystem): super().__init__(trackingSystem) self.HandlerAddedEvent = Events.EventHandler() self.HandlerRemovedEvent = Events.EventHandler() self._activeHandlers = list( ) # type: typing.List[HandlersBase.HandlerBase] def handlerSaveSkipTest( testingHandler: HandlersBase.HandlerBase) -> bool: if not isinstance(testingHandler, HandlersBase.HandlerBase): return True return testingHandler.ShouldSave self.RegisterSavableAttribute( Savable.ListedSavableAttributeHandler( "ActiveHandlers", "_activeHandlers", lambda typeIdentifier: HandlersTypes.GetHandlerType( typeIdentifier)(self.TrackingSystem), lambda: list(), requiredSuccess=False, skipEntrySaveTest=handlerSaveSkipTest, multiType=True, typeFetcher=lambda attributeValue: attributeValue. TypeIdentifier, ))
def __init__ (self, effectingSystem: ReproductionShared.ReproductiveSystem): super().__init__(effectingSystem) self.BuffAddedEvent = Events.EventHandler() self.BuffRemovedEvent = Events.EventHandler() self.BuffSelectionTestingEvent = Events.EventHandler() self._buffCoolDown = None # type: typing.Optional[float] self.RegisterSavableAttribute(Savable.StandardAttributeHandler("BuffCoolDown", "BuffCoolDown", self.BuffCoolDown)) self.BuffSelectionTestingEvent += self._BuffSelectionTestingCallback
def Generate (self, generationArguments: CycleEvents.SpermGeneratingArguments) -> None: """ Fill the sperm object's attributes with instruction from the input. :param generationArguments: Event arguments to instruct how to set the sperm's attributes. :type generationArguments: EventsSperm.SpermGeneratingArguments """ if not isinstance(generationArguments, CycleEvents.SpermGeneratingArguments): raise Exceptions.IncorrectTypeException(generationArguments, "generationArguments", (CycleEvents.SpermGeneratingArguments,)) generationArguments.PreGenerationEvent.Invoke(generationArguments, Events.EventArguments()) self._GenerateInternal(generationArguments) generationArguments.PostGenerationEvent.Invoke(generationArguments, Events.EventArguments())
def __init__(self, trackingSystem: ReproductionShared.ReproductiveSystem): super().__init__(trackingSystem) self.PregnancyStartedEvent = Events.EventHandler() self.PregnancyEndedEvent = Events.EventHandler() self.FetusGeneratingEvent = Events.EventHandler() self.MonitoringPregnancy = False self._cachedPregnancyTestResult = None # type: typing.Optional[bool] self._cachedPregnancyTestGameMinutesRemaining = None # type: typing.Optional[float] self._nonPregnantBellyModifier = 0 # type: float self._pregnancyVisualsActive = False # type: bool self.PregnancyStartedEvent += self._PregnancyStartedCallback
def __init__(self, seed: int, targetedObject: typing.Any, *args, **kwargs): """ Reproductive event arguments for when a new object needs its values randomized. :param seed: The seed used in the creation of random values for this event. The seed should be mixed with another number specific to each randomization operation, otherwise everything would generate the same numbers. :type seed: int :param targetedObject: The object the event has been triggered for. :type targetedObject: typing.Any """ super().__init__(seed=seed, targetedObject=targetedObject, *args, **kwargs) self.PreGenerationEvent = Events.EventHandler() self.PostGenerationEvent = Events.EventHandler()
def _InvokeOnLoadWrapperEvent () -> Events.EventArguments: eventArguments = Events.EventArguments() # type: Events.EventArguments for updateCallback in _onUpdateWrapper: # type: typing.Callable[[types.ModuleType, Events.EventArguments], None] try: updateCallback(sys.modules[__name__], eventArguments) except: Debug.Log("Failed to run the 'OnLoadWrapper' callback '" + Types.GetFullName(updateCallback) + "'.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__) return eventArguments
def __init__ (self, trackingSystem: ReproductionShared.ReproductiveSystem): super().__init__(trackingSystem) self.SpermGeneratingEvent = Events.EventHandler() self.SpermGeneratingEvent += self._SpermGeneratingCallback self._spermObjectsGenerated = 0 # type: int self.RegisterSavableAttribute(Savable.StandardAttributeHandler("SpermObjectsGenerated", "_spermObjectsGenerated", self.SpermObjectsGenerated, requiredSuccess = False))
def __init__(self, currentVersion: Version.Version, hostNamespace: str = This.Mod.Namespace, alwaysSaveValues: bool = False): """ :param currentVersion: The current version of what ever will be controlling this persistence object. This value can allow you to correct outdated persistent data. :type currentVersion: Version.Version :param hostNamespace: Errors made by this persistent object will show up under this namespace. :type hostNamespace: str :param alwaysSaveValues: If this value is true this persistence object will save all values. Otherwise this object will not save values that have not been set or were reset at some point. :type alwaysSaveValues: bool """ if not isinstance(currentVersion, Version.Version): raise Exceptions.IncorrectTypeException(currentVersion, "currentVersion", (Version.Version, )) if not isinstance(hostNamespace, str): raise Exceptions.IncorrectTypeException(hostNamespace, "hostNamespace", (str, )) self.CurrentVersion = currentVersion # type: Version.Version self.HostNamespace = hostNamespace # type: str self.OnUpdate = Events.EventHandler( ) # type: Events.EventHandler # An event that is triggered to notify listeners of a changed value. self.OnLoad = Events.EventHandler( ) # type: Events.EventHandler # An event that is triggered when new data is loaded. self._loadedData = dict() # type: typing.Dict[str, typing.Any] self._loadedLastVersion = None # type: typing.Optional[Version.Version] self._alwaysSaveValues = alwaysSaveValues # type: bool self._storage = dict() # type: typing.Dict[str, Persistent.Value]
def __init__(self, currentVersion: Version.Version, hostNamespace: str = This.Mod.Namespace): """ :param currentVersion: The current version of what ever will be controlling this persistence object. This value can allow you to correct outdated persistent data. :type currentVersion: Version.Version :param hostNamespace: Errors made by this persistent object will show up under this namespace. :type hostNamespace: str """ if not isinstance(currentVersion, Version.Version): raise Exceptions.IncorrectTypeException(currentVersion, "currentVersion", (Version.Version, )) if not isinstance(hostNamespace, str): raise Exceptions.IncorrectTypeException(hostNamespace, "hostNamespace", (str, )) self.CurrentVersion = currentVersion # type: Version.Version self.HostNamespace = hostNamespace # type: str self.OnUpdate = Events.EventHandler( ) # type: Events.EventHandler # An event that is triggered to notify listeners of a changed value. self.OnLoad = Events.EventHandler( ) # type: Events.EventHandler # An event that is triggered when new data is loaded. self._loadedData = dict() # type: typing.Dict[str, typing.Any] self._loadedLastVersion = None # type: typing.Optional[Version.Version] self._storage = dict( ) # type: typing.Dict[str, PersistentBranched.Value] self._managedBranches = list() # type: typing.List[str] self._updateStorage = list() # type: list
def _InvokeOnLoadEvent(self) -> Events.EventArguments: eventArguments = Events.EventArguments() # type: Events.EventArguments for loadCallback in self.OnLoad: # type: typing.Callable[[PersistentBranched, Events.EventArguments], None] try: loadCallback(self, eventArguments) except: Debug.Log("Failed to run the 'OnLoad' callback '" + Types.GetFullName(loadCallback) + "'.", This.Mod.Namespace, Debug.LogLevels.Exception, group=This.Mod.Namespace, owner=__name__) return eventArguments
def __init__ (self, trackingSystem: ReproductionShared.ReproductiveSystem): super().__init__(trackingSystem) self.CycleStartTestingEvent = Events.EventHandler() self.CycleAbortTestingEvent = Events.EventHandler() self.CycleGeneratingEvent = Events.EventHandler() self.CycleChangedEvent = Events.EventHandler() self.CycleCompletedEvent = Events.EventHandler() self.CycleReleaseOvumTestingEvent = Events.EventHandler() self.CycleStartTestingEvent += self._CycleStartTestingCallback self.CycleAbortTestingEvent += self._CycleAbortTestingCallback self.CompletedInitialCycle = False self.CompletedFirstCycle = False self.CycleStartTestingSeed = None self.TimeSinceLastCycle = None self.LastCycleCompletionReason = None self.CurrentCycle = None self._cycleObjectsGenerated = 0 # type: int encodeLastCycleCompletionReason = lambda value: value.name if value is not None else None decodeLastCycleCompletionReason = lambda valueString: Parse.ParsePythonEnum(valueString, CycleShared.CompletionReasons) if valueString is not None else None self.RegisterSavableAttribute(Savable.StandardAttributeHandler("CompletedInitialCycle", "CompletedInitialCycle", self.CompletedInitialCycle, requiredSuccess = False)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("CompletedFirstCycle", "CompletedFirstCycle", self.CompletedFirstCycle, requiredSuccess = False)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("CycleStartTestingSeed", "CycleStartTestingSeed", self.CycleStartTestingSeed, requiredSuccess = False)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("TimeSinceLastCycle", "TimeSinceLastCycle", self.TimeSinceLastCycle, requiredSuccess = False)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler( "LastCycleCompletionReason", "LastCycleCompletionReason", self.LastCycleCompletionReason, requiredSuccess = False, encoder = encodeLastCycleCompletionReason, decoder = decodeLastCycleCompletionReason )) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("CycleObjectsGenerated", "_cycleObjectsGenerated", self.CycleObjectsGenerated, requiredSuccess = False)) self.RegisterSavableAttribute(Savable.DynamicSavableAttributeHandler( "CurrentCycle", "CurrentCycle", lambda typeIdentifier: CycleTypes.GetCycleType(typeIdentifier)(), lambda: None, requiredSuccess = False, nullable = True, multiType = True, typeFetcher = lambda attributeValue: attributeValue.TypeIdentifier, typeSavingKey = "CurrentCycleType" ))
from NeonOcean.S4.Cycle import This from NeonOcean.S4.Main import Debug, Language, LoadingShared from NeonOcean.S4.Main.Abstract import Settings as AbstractSettings from NeonOcean.S4.Main.Data import Persistence from NeonOcean.S4.Main.Tools import Events, Exceptions, Types, Version from NeonOcean.S4.Main.UI import Settings as UISettings, SettingsShared as UISettingsShared from sims4 import localization SettingsFilePath = os.path.join(This.Mod.PersistentPath, "Settings.json") # type: str SettingsPersistence = None # type: typing.Optional[Persistence.PersistentFile] AllSettings = list() # type: typing.List[typing.Type[Setting]] _previousValues = dict() # type: typing.Dict[str, typing.Any] _onUpdateWrapper = Events.EventHandler() # type: Events.EventHandler _onLoadWrapper = Events.EventHandler() # type: Events.EventHandler class UpdateEventArguments(Events.EventArguments): def __init__ (self, changedSettings: typing.Set[str]): self.ChangedSettings = changedSettings def Changed (self, key: str) -> bool: """ Get whether or not a setting has been changed between the last update and this one. """ return key in self.ChangedSettings class Setting(AbstractSettings.SettingAbstract): IsSetting = False # type: bool
from __future__ import annotations import sys from NeonOcean.S4.Main import Debug, Mods, This from NeonOcean.S4.Main.Tools import Events, Exceptions, Types ModLoadedEvent = Events.EventHandler() ModUnloadedEvent = Events.EventHandler() # type: Events.EventHandler class ModLoadedEventArguments(Events.EventArguments): def __init__(self, mod: Mods.Mod): if not isinstance(mod, Mods.Mod): raise Exceptions.IncorrectTypeException(mod, "mod", (Mods.Mod, )) self.Mod = mod # type: Mods.Mod class ModUnloadedEventArguments(Events.EventArguments): def __init__(self, mod: Mods.Mod, exiting: bool): if not isinstance(mod, Mods.Mod): raise Exceptions.IncorrectTypeException(mod, "mod", (Mods.Mod, )) if not isinstance(exiting, bool): raise Exceptions.IncorrectTypeException(exiting, "exiting", (bool, )) self.Mod = mod # type: Mods.Mod self.Exiting = exiting # type: bool
from __future__ import annotations import sys import random import typing import time from NeonOcean.S4.Cycle import ReproductionShared, Saving, This from NeonOcean.S4.Main import Debug from NeonOcean.S4.Main.Saving import SectionBranched from NeonOcean.S4.Main.Tools import Events, Exceptions, Python, Types from sims import sim_info RegisteredReproductiveSystemEvent = Events.EventHandler( ) # type: Events.EventHandler UnregisteredReproductiveSystemEvent = Events.EventHandler( ) # type: Events.EventHandler #The event arguments will be of the type RegistrationChangedArguments for both of these. _reproductiveSystems = dict( ) # type: typing.Dict[sim_info.SimInfo, ReproductionShared.ReproductiveSystem] _fullUpdateTimes = list() # type: typing.List[float] _individualUpdateTimes = list() # type: typing.List[float] # TODO let the reset interaction to reset the save. class RegistrationChangedArguments(Events.EventArguments): def __init__(self, reproductiveSystem: ReproductionShared.ReproductiveSystem): if not isinstance(reproductiveSystem,