예제 #1
0
def _OnStop (cause: LoadingShared.UnloadingCauses) -> None:
	Saving.GetSimsSection().UnregisterLoadCallback(_SimsSectionLoadCallback)
	Saving.GetSimsSection().UnregisterSaveCallback(_SimsSectionSaveCallback)
	Saving.GetSimsSection().UnregisterResetCallback(_SimsSectionResetCallback)

	if services.current_zone() is not None:
		_ResetZoneHandling()
예제 #2
0
파일: Dot.py 프로젝트: NeonOcean/S4.Cycle
	def Save (self, simsSection: SectionBranched.SectionBranched) -> bool:
		"""
		Save the reproductive system's data to this saving section. An exception will be raised if no valid sim has been set for this dot object.
		"""

		if self.TargetSimID is None or self.TargetSimInfo is None:
			raise Exception("Cannot save a dot information object with no target sim.")

		if not isinstance(simsSection, SectionBranched.SectionBranched):
			raise Exceptions.IncorrectTypeException(simsSection, "simsSection", (SectionBranched.SectionBranched,))

		if self.Outdated:
			self.Update()

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

		try:
			targetSimSavingKey = Saving.GetSimSimsSectionBranchKey(self.TargetSimInfo)  # type: str

			saveSuccessful, dotInformationData = self.SaveToDictionary()  # type: bool, dict
			simsSection.Set(targetSimSavingKey, DotSavingKey, dotInformationData)
		except:
			Debug.Log("Save operation in a dot information object aborted.\n" + operationInformation, self.HostNamespace, Debug.LogLevels.Exception, group = self.HostNamespace, owner = __name__)
			return False

		if not saveSuccessful:
			return False

		return operationSuccessful
예제 #3
0
def _OnSimAddCallback (simInfo: sim_info.SimInfo) -> None:
	if not This.Mod.IsLoaded():
		return

	try:
		if Reproduction.SimHasSystem(simInfo):
			Debug.Log("Went to create a reproductive system for a sim being added, but one already exists.", This.Mod.Namespace, Debug.LogLevels.Warning, group = This.Mod.Namespace, owner = __name__)
			return

		simSystem = Reproduction.InitiateReproductiveSystem(simInfo)
		simsSection = Saving.GetSimsSection()  # type: SectionBranched.SectionBranched

		if Saving.GetSimsSection().SavingObject.Loaded:
			simSystem.Load(simsSection)
	except:
		Debug.Log("Reproduction on sim add callback failed.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__)
예제 #4
0
파일: Dot.py 프로젝트: NeonOcean/S4.Cycle
def SaveAllDotInformation (simsSection: typing.Optional[SectionBranched.SectionBranched] = None) -> bool:
	operationSuccessful = True  # type: bool

	if simsSection is None:
		simsSection = Saving.GetSimsSection()  # type: SectionBranched.SectionBranched

	try:
		for targetDotInformation in _allDotInformation.values():  # type: DotInformation
			targetDotInformation.Save(simsSection)
	except:
		Debug.Log("At least partially failed to save all dot information.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__)
		operationSuccessful = False

	return operationSuccessful
예제 #5
0
파일: Base.py 프로젝트: NeonOcean/S4.Cycle
def _OnInitiate(cause: LoadingShared.LoadingCauses) -> None:
    global SettingsPersistence, DefaultSettings

    if cause:
        pass

    if SettingsPersistence is None:
        SettingsPersistence = PersistenceBranched.PersistentBranchedSection(
            Saving.GetSimsSection(),
            "Settings",
            This.Mod.Version,
            hostNamespace=This.Mod.Namespace)
        DefaultSettings = Persistence.PersistentSection(
            Saving.GetAllSimsSection(),
            "DefaultSettings",
            This.Mod.Version,
            hostNamespace=This.Mod.Namespace)

        for setting in AllSettings:
            setting.Setup()

        SettingsPersistence.OnUpdate += _OnUpdateCallback
        SettingsPersistence.OnLoad += _OnLoadCallback
예제 #6
0
def _OnSimAddCallback (simInfo: sim_info.SimInfo) -> None:
	if not This.Mod.IsLoaded():
		return

	try:
		if Dot.HasDotInformation(simInfo):
			Debug.Log("Went to create a dot information object for a sim being added, but one already exists.", This.Mod.Namespace, Debug.LogLevels.Warning, group = This.Mod.Namespace, owner = __name__)
			return

		dotInformation = Dot.CreateDotInformation(simInfo)
		simsSection = Saving.GetSimsSection()  # type: SectionBranched.SectionBranched

		if simsSection.SavingObject.Loaded:
			dotInformation.Load(simsSection)
	except:
		Debug.Log("Dot on sim add callback failed.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__)
예제 #7
0
파일: Dot.py 프로젝트: NeonOcean/S4.Cycle
	def Load (self, simsSection: SectionBranched.SectionBranched) -> bool:
		"""
		Load the reproductive system's data from this saving section. An exception will be raised if no valid sim has been set for this dot object.
		"""

		if self.TargetSimID is None or self.TargetSimInfo is None:
			raise Exception("Cannot load a dot information object with no target sim.")

		if not isinstance(simsSection, SectionBranched.SectionBranched):
			raise Exceptions.IncorrectTypeException(simsSection, "simsSection", (SectionBranched.SectionBranched,))

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

		try:
			targetSimSavingKey = Saving.GetSimSimsSectionBranchKey(self.TargetSimInfo)  # type: str

			dotInformationData = simsSection.GetValue(targetSimSavingKey, DotSavingKey, default = None)

			if dotInformationData is None:
				Debug.Log("'%s' has had a dot information object created for the first time, or at least, they had no saved data in the loaded save file.\n%s" % (ToolsSims.GetFullName(self.TargetSimInfo), operationInformation), self.HostNamespace, Debug.LogLevels.Info, group = self.HostNamespace, owner = __name__)
				dotInformationData = dict()

			if not isinstance(dotInformationData, dict):
				Debug.Log("Incorrect type in dot information data with the section key.\n" + operationInformation + "\n" + Exceptions.GetIncorrectTypeExceptionText(dotInformationData, "DotInformationData", (dict,)), self.HostNamespace, Debug.LogLevels.Warning, group = self.HostNamespace, owner = __name__)
				dotInformationData = dict()
				operationSuccessful = False

			if simsSection.SavingObject.DataHostVersion is not None:
				lastVersion = Version.Version(simsSection.SavingObject.DataHostVersion)  # type: typing.Optional[Version.Version]
			else:
				lastVersion = None  # type: typing.Optional[Version.Version]

			loadSuccessful = self.LoadFromDictionary(dotInformationData, lastVersion = lastVersion)
		except:
			Debug.Log("Load operation in a dot information object aborted.\n" + operationInformation, self.HostNamespace, Debug.LogLevels.Exception, group = self.HostNamespace, owner = __name__)
			self.Reset()
			return False

		if not loadSuccessful:
			return False

		return operationSuccessful
예제 #8
0
def SaveAllSystems(
        simsSection: SectionBranched.SectionBranched = None) -> bool:
    """
	Save all reproductive system data to this saving section.
	:param simsSection: The sims saving section the reproductive systems will be written to. If this is none this method will use Cycle's main sim saving section.
	:type simsSection: None | SectionSims.SectionSims
	:return: This function will return False if an error occurred. Otherwise this function will return True if it behaved as expected.
	:rtype: bool
	"""

    if not isinstance(
            simsSection,
            SectionBranched.SectionBranched) and simsSection is not None:
        raise Exceptions.IncorrectTypeException(
            simsSection, "simsSection",
            (SectionBranched.SectionBranched, "None"))

    operationSuccessful = True  # type: bool

    if simsSection is None:
        simsSection = Saving.GetSimsSection(
        )  # type: SectionBranched.SectionBranched

    allReproductiveSystems = GetAllSystems(
    )  # type: typing.List[ReproductionShared.ReproductiveSystem]

    for reproductiveSystem in allReproductiveSystems:  # type: ReproductionShared.ReproductiveSystem
        try:
            if not reproductiveSystem.Save(simsSection):
                operationSuccessful = False
        except:
            Debug.Log("Failed to save a reproductive system.\n." +
                      reproductiveSystem.DebugInformation,
                      This.Mod.Namespace,
                      Debug.LogLevels.Exception,
                      group=This.Mod.Namespace,
                      owner=__name__)
            operationSuccessful = False

    return operationSuccessful