def ShowStatusNotification (targetSimInfo: sim_info.SimInfo) -> None: # TODO create quick glance notification, only show the times? if not isinstance(targetSimInfo, sim_info.SimInfo): raise Exceptions.IncorrectTypeException(targetSimInfo, "targetSimInfo", (sim_info.SimInfo,)) targetDotInformation = Dot.GetDotInformation(targetSimInfo) # type: typing.Optional[Dot.DotInformation] if targetDotInformation is None: Debug.Log("Attempted to show a dot app status notification on a sim missing a dot information object.\nSim ID: %s" % targetSimInfo.id, This.Mod.Namespace, Debug.LogLevels.Warning, group = This.Mod.Namespace, owner = __name__) return if not targetDotInformation.Enabled: Debug.Log("Attempted to show a dot app status notification on a sim its not enabled for.\nSim ID: %s" % targetSimInfo.id, This.Mod.Namespace, Debug.LogLevels.Warning, group = This.Mod.Namespace, owner = __name__) return dotCycle = targetDotInformation.GetCurrentCycle() # type: typing.Optional[Dot.DotCycle] if dotCycle is None: ShowErrorNotification(targetSimInfo) return text = Language.MakeLocalizationStringCallable(_BuildStatusText(targetSimInfo, dotCycle)) notificationArguments = { "owner": targetSimInfo, "title": StatusNotificationTitle.GetCallableLocalizationString(), "text": text, "icon": lambda *args, **kwargs: shared_messages.IconInfoData(icon_resource = resources.ResourceKeyWrapper(CycleUIResources.DotAppIconKey)), "secondary_icon": lambda *args, **kwargs: shared_messages.IconInfoData(obj_instance = targetSimInfo), } Notifications.ShowNotification(queue = False, **notificationArguments)
def _Enable(targetSimHandler: argument_helpers.RequiredTargetParam, _connection: int = None) -> None: try: targetSimInfo = targetSimHandler.get_target( services.sim_info_manager()) if not isinstance(targetSimInfo, sim_info.SimInfo): raise ValueError( "Failed to get the target sim, %s is not a valid sim id." % targetSimHandler.target_id) dotInformation = Dot.GetDotInformation( targetSimInfo) # type: typing.Optional[Dot.DotInformation] if dotInformation is None: raise Exception( "Missing dot information object for a sim with the id %s." % targetSimInfo.id) dotInformation.Enabled = True except: output = commands.CheatOutput(_connection) output("Failed to enable the dot app on the target sim's phone.") Debug.Log("Failed to enable the dot app on the target sim's phone.", This.Mod.Namespace, Debug.LogLevels.Exception, group=This.Mod.Namespace, owner=__name__)
def _CycleTrackerCycleCompletedCallback (self, owner: CycleTracker.CycleTracker, eventArguments: CycleEvents.CycleCompletedArguments) -> None: if eventArguments.CompletionReason == CycleShared.CompletionReasons.Finished: dotInformation = Dot.GetDotInformation(self.HandlingSystem.SimInfo) # type: typing.Optional[Dot.DotInformation] if dotInformation is not None: currentSimulation = self.HandlingSystem.Simulation # type: typing.Optional[ReproductionShared.Simulation] if currentSimulation is None: dotInformation.SetCycleStart(0) else: dotInformation.SetCycleStart(currentSimulation.RemainingMinutes)
def _HandleCycleTrackerAdded (self, tracker) -> None: tracker.CycleChangedEvent += self._CycleTrackerCycleChangedCallback tracker.CycleCompletedEvent += self._CycleTrackerCycleCompletedCallback dotInformation = Dot.GetDotInformation(self.HandlingSystem.SimInfo) # type: typing.Optional[Dot.DotInformation] if dotInformation is not None: if dotInformation.TimeSinceCycleStart is None: if tracker.TimeSinceLastCycle is not None: dotInformation.TimeSinceCycleStart = tracker.TimeSinceLastCycle else: if tracker.CurrentCycle is not None: dotInformation.TimeSinceCycleStart = tracker.CurrentCycle.Age
def _CycleTrackerCycleChangedCallback (self, owner: CycleTracker.CycleTracker, eventArguments: CycleEvents.CycleChangedArguments) -> None: dotInformation = Dot.GetDotInformation(self.HandlingSystem.SimInfo) # type: typing.Optional[Dot.DotInformation] if dotInformation is not None: if dotInformation.TimeSinceCycleStart is None: cycleTracker = self.HandlingSystem.GetTracker(FemalesShared.CycleTrackerIdentifier) # type: typing.Optional[CycleTracker.CycleTracker] if cycleTracker.CurrentCycle is None: return currentSimulation = self.HandlingSystem.Simulation # type: typing.Optional[ReproductionShared.Simulation] if currentSimulation is None: dotInformation.SetCycleStart(cycleTracker.CurrentCycle.Age) else: dotInformation.SetCycleStart(cycleTracker.CurrentCycle.Age + currentSimulation.RemainingMinutes - currentSimulation.NonUpdateTicks) # Subtracting the non update ticks because they will be manually simulated for the dot app at the end of the system's simulation
def _FixDotCycle(targetSimHandler: argument_helpers.RequiredTargetParam, _connection=None) -> None: try: if game_services.service_manager is None: return targetSimInfo = targetSimHandler.get_target( services.sim_info_manager()) if not isinstance(targetSimInfo, sim_info.SimInfo): raise ValueError( "Failed to get the target sim, %s is not a valid sim id." % targetSimHandler.target_id) targetDotInformation = Dot.GetDotInformation( targetSimInfo) # type: typing.Optional[Dot.DotInformation] if targetDotInformation is None: return targetSystem = Reproduction.GetSimSystem( targetSimInfo ) # type: typing.Optional[ReproductionShared.ReproductiveSystem] if targetSystem is None: return targetCycleTracker = targetSystem.GetTracker( FemalesShared.CycleTrackerIdentifier ) # type: typing.Optional[CycleTracker.CycleTracker] if targetCycleTracker is None: return if targetCycleTracker.CurrentCycle is not None: targetDotInformation.TimeSinceCycleStart = targetCycleTracker.CurrentCycle.Age else: if targetCycleTracker.TimeSinceLastCycle is not None: targetDotInformation.TimeSinceCycleStart = targetCycleTracker.TimeSinceLastCycle except Exception as e: Debug.Log("Failed to fix a sim's dot cycle.", This.Mod.Namespace, Debug.LogLevels.Exception, group=This.Mod.Namespace, owner=__name__, exception=e) raise e
def __call__(self, affordance: typing.Type[_DotAppInteraction], actors: typing.Tuple[sim_info.SimInfo, ...]): if affordance is None: return results.TestResult(False) if not issubclass(affordance, _DotAppInteraction): return results.TestResult(False) if len(actors) == 0: Debug.Log( "Dot app state test recived an empty actors parameter.", This.Mod.Namespace, Debug.LogLevels.Warning, group=This.Mod.Namespace, owner=__name__, lockIdentifier=__name__ + ":" + str(Python.GetLineNumber())) return results.TestResult(False) targetSimInfo = actors[0] # type: sim_info.SimInfo dotInformation = Dot.GetDotInformation( targetSimInfo) # type: typing.Optional[Dot.DotInformation] if dotInformation is None: Debug.Log( "Missing dot information for a sim with the id '%s'." % targetSimInfo.id, This.Mod.Namespace, Debug.LogLevels.Warning, group=This.Mod.Namespace, owner=__name__, lockIdentifier=__name__ + ":" + str(Python.GetLineNumber()), lockReference=targetSimInfo) return results.TestResult(False) if affordance.RequiredDotEnabledState is None: return results.TestResult(True) else: return results.TestResult(dotInformation.Enabled == affordance.RequiredDotEnabledState)
def _SimulateInternal (self, simulation: ReproductionShared.Simulation, ticks: int, reproductiveTimeMultiplier: float) -> None: if not simulation.LastTickStep: return cycleTracker = self.HandlingSystem.GetTracker(FemalesShared.CycleTrackerIdentifier) # type: typing.Optional[CycleTracker.CycleTracker] pregnancyTracker = self.HandlingSystem.GetTracker(FemalesShared.PregnancyTrackerIdentifier) # type: typing.Optional[PregnancyTracker.PregnancyTracker] if cycleTracker is None: return dotInformation = Dot.GetDotInformation(self.HandlingSystem.SimInfo) # type: typing.Optional[Dot.DotInformation] if dotInformation is not None: if simulation.NonUpdateTicks > 0: dotInformation.Simulate(simulation.NonUpdateTicks) if pregnancyTracker is not None: if dotInformation.TrackingMode != Dot.TrackingMode.Pregnancy and pregnancyTracker.IsPregnant and pregnancyTracker.PregnancyIsKnown(): dotInformation.TrackingMode = Dot.TrackingMode.Pregnancy elif dotInformation.TrackingMode != Dot.TrackingMode.Cycle and not pregnancyTracker.IsPregnant: dotInformation.TrackingMode = Dot.TrackingMode.Cycle else: if dotInformation.TrackingMode != Dot.TrackingMode.Cycle: dotInformation.TrackingMode = Dot.TrackingMode.Cycle
def _PregnancyTrackerPregnancyEndedCallback (self, owner: PregnancyTracker.PregnancyTracker, eventArguments: CycleEvents.PregnancyEndedArguments) -> None: dotInformation = Dot.GetDotInformation(self.HandlingSystem.SimInfo) # type: typing.Optional[Dot.DotInformation] if dotInformation is not None: dotInformation.TrackingMode = Dot.TrackingMode.Cycle dotInformation.SetCycleStart(0)