def ZoneSave (cls, zoneReference: zone.Zone, saveSlotData: typing.Optional[typing.Any] = None) -> None: if saveSlotData is None: return commitSave = saveSlotData.slot_id != 0 # type: bool doOverrideBackupCommit = False # type: bool try: if commitSave: gameSaveFilePath = SaveShared.GetGameSaveFilePath(saveSlotData.slot_id) # type: str loadedSlotID = Save.GetLoadedSlotID() # type: typing.Optional[int] if loadedSlotID is not None: overridingSave = loadedSlotID != saveSlotData.slot_id and os.path.exists(gameSaveFilePath) # type: bool if overridingSave: gameSaveModifiedTime = datetime.datetime.fromtimestamp(os.path.getmtime(gameSaveFilePath)) # type: datetime.datetime overrideBackupMargin = datetime.timedelta(seconds = 3) if datetime.datetime.now() - overrideBackupMargin <= gameSaveModifiedTime: doOverrideBackupCommit = True except: Debug.Log("Failed to check if an override backup commit occurred.", This.Mod.Namespace, Debug.LogLevels.Warning, group = This.Mod.Namespace, owner = __name__) if doOverrideBackupCommit: Save.DoOverrideBackupCommit(saveSlotData.slot_id) Save.Save(saveSlotID = saveSlotData.slot_id, commitSave = commitSave)
def _Setup() -> None: global _savingObject _savingObject = SaveShared.Save( This.Mod, This.Mod.Namespace.replace(".", "_") + "_Save_Tracking") Save.RegisterSavingObject(_savingObject)
def _Setup() -> None: global _savingObject, _simsSection, _allSimsSection _savingObject = SaveShared.Save( This.Mod, This.Mod.Namespace.replace(".", "_") + "_Save") Save.RegisterSavingObject(_savingObject) _simsSection = SectionSims.SectionSims("Sims", _savingObject) _savingObject.RegisterSection(_simsSection) _allSimsSection = SectionStandard.SectionStandard("AllSims", _savingObject) _savingObject.RegisterSection(_allSimsSection)
def DialogCallback (dialogReference: ui_dialog_picker.UiObjectPicker) -> None: try: if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_CANCEL: return resultRows = dialogReference.picked_results # type: typing.Tuple[int] if len(resultRows) == 0: return selectedSaveDirectory = options.get(resultRows[0]) # type: typing.Optional[str] if selectedSaveDirectory is None: return Save.Load(services.get_persistence_service().get_save_slot_proto_buff().slot_id, selectedSaveDirectory, changingSave = True) except Exception as e: Debug.Log("Failed to run the callback for the select save dialog.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__, exception = e)
def _OnModUnloaded (owner: typing.Any, eventArguments: typing.Optional[LoadingEvents.ModUnloadedEventArguments]) -> None: if eventArguments.Exiting: return Save.UnloadWithHost(eventArguments.Mod)
def _OnStop (cause: LoadingShared.LoadingCauses) -> None: Save.PrepareForSaveChange()
def ZoneLoad (cls, zoneReference: zone.Zone) -> None: slotID = services.get_persistence_service().get_save_slot_proto_buff().slot_id # type: int Save.Load(slotID)
def ZoneOnToreDown (cls, zoneReference: zone.Zone, clientReference: client.Client): Save.UnloadAll()
def OnEnterMainMenu (cls) -> None: Save.PrepareForSaveChange()
def ShowSelectSaveDialog () -> None: gameSaveSlotID = str(services.get_persistence_service().get_save_slot_proto_buff().slot_id) # type: str gameSaveGUID = str(services.get_persistence_service().get_save_slot_proto_guid()) # type: str dialogArguments = { "owner": services.get_active_sim().sim_info, "title": SelectSaveDialogTitle, "text": SelectSaveDialogText.GetCallableLocalizationString(*(gameSaveSlotID, gameSaveGUID)) } dialogRows = list() options = { } # type: typing.Dict[int, str] loadedSaveDirectoryPath = Save.GetLoadedDirectoryPath() # type: typing.Optional[str] loadedSaveDirectoryPathObject = pathlib.Path(Save.GetLoadedDirectoryPath()) if loadedSaveDirectoryPath is not None else None # type: typing.Optional[pathlib.Path] for saveDirectoryName in os.listdir(Paths.SavesPath): # type: str saveDirectoryPath = os.path.join(Paths.SavesPath, saveDirectoryName) # type: str if os.path.isdir(saveDirectoryPath): saveDirectoryPathObject = pathlib.Path(saveDirectoryPath) # type: pathlib.Path currentOptionID = 50000 + len(options) options[currentOptionID] = saveDirectoryPath saveDirectoryMetaData = Save.GetSaveMetaData(saveDirectoryPath) # type: typing.Optional[Save.ModSaveMetaData] rowDescriptionTokens = (SelectSaveDialogDescriptionMatchUnknown.GetLocalizationString(),) if saveDirectoryMetaData is not None: saveDirectoryMatchType = saveDirectoryMetaData.MatchesGameSave() # type: Save.ModSaveMatchTypes if saveDirectoryMatchType in Save.ModSaveMatchTypes.Match: rowDescriptionTokens = (SelectSaveDialogDescriptionMatchMatches.GetLocalizationString(),) elif saveDirectoryMatchType in Save.ModSaveMatchTypes.MismatchedGUID: rowDescriptionTokens = (SelectSaveDialogDescriptionMatchMismatchGUID.GetLocalizationString(),) elif saveDirectoryMatchType in Save.ModSaveMatchTypes.MismatchedGameTick: rowDescriptionTokens = (SelectSaveDialogDescriptionMatchMismatchGameTick.GetLocalizationString(),) if loadedSaveDirectoryPathObject is not None: if loadedSaveDirectoryPathObject == saveDirectoryPathObject: rowDescription = SelectSaveDialogDescriptionCurrentlyLoaded.GetLocalizationString(*rowDescriptionTokens) else: rowDescription = SelectSaveDialogDescriptionNormal.GetLocalizationString(*rowDescriptionTokens) else: rowDescription = SelectSaveDialogDescriptionNormal.GetLocalizationString(*rowDescriptionTokens) if saveDirectoryMetaData is None: rowNameTokens = (saveDirectoryName,) else: rowNameTokens = (saveDirectoryName + " (" + saveDirectoryMetaData.Name + ")",) dialogRows.append(ui_dialog_picker.ObjectPickerRow( option_id = currentOptionID, name = Language.CreateLocalizationString(*rowNameTokens), row_description = rowDescription)) def DialogCallback (dialogReference: ui_dialog_picker.UiObjectPicker) -> None: try: if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_CANCEL: return resultRows = dialogReference.picked_results # type: typing.Tuple[int] if len(resultRows) == 0: return selectedSaveDirectory = options.get(resultRows[0]) # type: typing.Optional[str] if selectedSaveDirectory is None: return Save.Load(services.get_persistence_service().get_save_slot_proto_buff().slot_id, selectedSaveDirectory, changingSave = True) except Exception as e: Debug.Log("Failed to run the callback for the select save dialog.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__, exception = e) Dialogs.ShowObjectPickerDialog(DialogCallback, dialogRows, **dialogArguments)