private void LoadGame() { string pathToLoad = Application.persistentDataPath + "/save.dat"; if (!File.Exists(pathToLoad)) { Debug.Log("No saved profile found! Have you saved yet?"); return; } BinaryFormatter bf = new BinaryFormatter(); FileStream fs = File.Open(pathToLoad, FileMode.Open); SavedProfile loadedProfile = bf.Deserialize(fs) as SavedProfile; fs.Close(); resources.wood = loadedProfile.s_wood; resources.stones = loadedProfile.s_stones; resources.food = loadedProfile.s_food; for (int i = 0; i < loadedProfile.buildingsSavedData.Count; i++) { BuildingInfo buildingFromSave = loadedProfile.buildingsSavedData[i]; build.RebuildBuilding(buildingFromSave.id, buildingFromSave.connectedGridId, (int)buildingFromSave.level, buildingFromSave.yRot); Debug.Log(buildingFromSave.id); } }
private void SaveGame() { if (profile == null) { profile = new SavedProfile(); } profile.s_wood = resources.wood; profile.s_stones = resources.stones; profile.s_food = resources.food; foreach (GameObject g in buildings.builtObjects) { BuildingInfo b = g.GetComponent <Building>().info; profile.buildingsSavedData.Add(b); } BinaryFormatter bf = new BinaryFormatter(); string path = Application.persistentDataPath + "/save.dat"; if (File.Exists(path)) { File.Delete(path); } FileStream fs = File.Open(path, FileMode.OpenOrCreate); bf.Serialize(fs, profile); fs.Close(); }
public void CreateOrUpdateProfile(ProfileType type, PlayerProfile profile, bool setActive = false) { if (profile.Skin.Texture == null) { if (Alex.Resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture)) { profile.Skin.Texture = TextureUtils.BitmapToTexture2D(Alex.GraphicsDevice, rawTexture); profile.Skin.Slim = true; } } SavedProfile savedProfile; if (Profiles.TryGetValue(profile.Uuid, out savedProfile)) { savedProfile.Profile = profile; Profiles[profile.Uuid] = savedProfile; } else { savedProfile = new SavedProfile(); savedProfile.Type = type; savedProfile.Profile = profile; Profiles.Add(profile.Uuid, savedProfile); } if (setActive) { //ActiveProfile = savedProfile; Alex.Services.GetService <IPlayerProfileService>()?.Force(profile); //_playerProfileService.Force(profile); } Alex.UIThreadQueue.Enqueue(SaveProfiles); }
public static void saveProfile() { string data = _profile.toJSON().ToString(); SavedProfile tmpProfile = new SavedProfile(data); SaveGameManager.saveDataByUser <SavedProfile>(GameConstants.profileKey, tmpProfile); }
private static bool ScheduleAllowScene(SavedProfile profile) { if (string.IsNullOrEmpty(profile.Schedule)) { return(true); } return((DateTime.Now.TimeOfDay >= TimeSpan.Parse(profile.Schedule + ":00")) && (DateTime.Now <= DateTime.Now.Date.AddDays(1).AddHours(4))); }
private void PlaybackCredits(PlaybackProgressEventArgs e, SavedProfile profile, PluginConfiguration config) { if (CreditSessions.Exists(s => s.Equals(e.Session.Id))) { return; //We've already triggered the event, it's in the list - move on } CreditSessions.Add(e.Session.Id); //Add the session ID to the list so this event doesn't trigger again logger.Info($"Samsung Smart Things Reports trigger Credit Scene on {e.DeviceName}"); //Log that shit. RunScene(profile.MediaItemCredits, config, "CreditScene"); }
private void PlaybackProgress(object sender, PlaybackProgressEventArgs e) { var config = Plugin.Instance.Configuration; SavedProfile profile = null; if (config.SaveSmartThingsProfiles.Exists(p => p.DeviceName.Equals(e.Session.DeviceName))) { profile = config.SaveSmartThingsProfiles.FirstOrDefault(p => p.DeviceName.Equals(e.DeviceName) && p.AppName.Equals(e.Session.Client)); } else { return; } // ReSharper disable once ComplexConditionExpression if (e.MediaInfo.Type.Equals("Movie") && e.Session.PlayState.PositionTicks >= (e.Item.RunTimeTicks - (profile.MediaItemCreditLength * 10000000))) { if (!ReferenceEquals(null, profile.MediaItemCredits)) { PlaybackCredits(e, profile, config); } } if (IgnoreEvents) { return; } if (PausedSessionsIds.Contains(e.Session.Id)) { if (!e.IsPaused || !e.Session.PlayState.IsPaused) { IgnoreEvents = true; PausedSessionsIds.RemoveAll(s => s.Equals(e.Session.Id)); PlaybackUnPaused(e, config, profile); IgnoreEvents = false; } return; } if (!PausedSessionsIds.Contains(e.Session.Id)) { if (e.IsPaused || e.Session.PlayState.IsPaused) { IgnoreEvents = true; PausedSessionsIds.Add(e.Session.Id); PlaybackPaused(e, config, profile); IgnoreEvents = false; } } }
public static Profile initProfile() { SavedProfile tmpProfile = SaveGameManager.loadDataByUser <SavedProfile>(GameConstants.profileKey); if (tmpProfile == null || String.IsNullOrEmpty(tmpProfile.Profile)) { _profile = new Profile(); _profile.reset(); } else { JSONNode js = JSON.Parse(tmpProfile.Profile); _profile = new Profile(js); } saveProfile(); return(_profile); }
public static void Pull(SavedProfile profile) { foreach (var mod in new HashSet <SRMod>(BindingRegistry.moddedActions.Values)) { var filename = Path.Combine(FileSystem.GetConfigPath(mod), KEYBIND_FILE_NAME); var modoptions = new ModOptionsV01(); var v = BindingRegistry.moddedActions.Where(x => x.Value == mod).Select(x => x.Key).ToList(); foreach (var action in v) { modoptions.bindings.bindings.Add(SRInput.ToBinding(action)); } using (var file = File.Open(filename, FileMode.OpenOrCreate)) { modoptions.Write(file); } } }
public void CreateOrUpdateProfile(string type, PlayerProfile profile, bool setActive = false) { IPlayerProfileService profileService = ServiceProvider.GetRequiredService <IPlayerProfileService>(); var alex = ServiceProvider.GetRequiredService <Alex>(); if (profile.Skin?.Texture == null) { profile.Skin = new Skin(); if (alex.Resources.TryGetBitmap("entity/alex", out var rawTexture)) { profile.Skin.Texture = TextureUtils.BitmapToTexture2D(alex.GraphicsDevice, rawTexture); profile.Skin.Slim = true; } } SavedProfile savedProfile; if (Profiles.TryGetValue(profile.Uuid, out savedProfile)) { savedProfile.Type = type; savedProfile.Profile = profile; Profiles[profile.Uuid] = savedProfile; } else { savedProfile = new SavedProfile(); savedProfile.Type = type; savedProfile.Profile = profile; Profiles.Add(profile.Uuid, savedProfile); } if (setActive) { //ActiveProfile = savedProfile; profileService?.Force(profile); //_playerProfileService.Force(profile); } alex.UIThreadQueue.Enqueue(SaveProfiles); }
private void LoadGame() { string pathToLoad = Application.persistentDataPath + "/save.dat"; if (!File.Exists(pathToLoad)) { Debug.Log("No saved profile found! Have you saved yet?"); return; } BinaryFormatter bF = new BinaryFormatter(); FileStream fS = File.Open(pathToLoad, FileMode.Open); SavedProfile loadedProfile = bF.Deserialize(fS) as SavedProfile; fS.Close(); resources.wood = loadedProfile.savedWood; resources.stones = loadedProfile.savedStones; resources.food = loadedProfile.savedFood; //RELOAD BUILDINGS AND REBUILD THEM. }
private static void LoadSettings_Postfix(SavedProfile @this) => SaveHandler.LoadSettings(@this.Settings);
// ReSharper disable once TooManyArguments private void PlaybackPaused(PlaybackProgressEventArgs e, PluginConfiguration config, SessionInfo session, SavedProfile profile) { logger.Info("Samsung Smart Things Reports Playback Paused..."); logger.Info($"Samsung Smart Things Found Session Device: { session.DeviceName }"); if (!ScheduleAllowScene(profile)) { logger.Info($"Samsung Smart Things profile not allowed to run at this time: { profile.DeviceName }"); return; } var sceneName = string.Empty; switch (e.MediaInfo.Type) { case "Movie": sceneName = profile.MoviesPlaybackPaused; break; case "TvChannel": sceneName = profile.LiveTvPlaybackPaused; break; case "Series": sceneName = profile.TvPlaybackPaused; break; case "Season": sceneName = profile.TvPlaybackPaused; break; case "Episode": sceneName = profile.TvPlaybackPaused; break; } RunScene(sceneName, config); }
public static void Prefix(SavedProfile __instance) { OptionsHandler.Pull(__instance); }
private static void SaveSettings_Prefix(SavedProfile @this) => SaveHandler.SaveSettings(@this.Settings);
private static void SaveProfile_Prefix(SavedProfile @this) => SaveHandler.SaveProfile(@this.Profile);
private static void LoadProfile_Postfix(SavedProfile @this) => SaveHandler.LoadProfile(@this.Profile);