HeavenStudio/Assets/Scripts/PersistentDataManager.cs
minenice55 caf7d9465f
Play Mode Features Part 1 (#413)
* add pause menu assets

* layout and animation for pause

* make play mode prefab function

re-assign unused class inheritance

* remove filepath

* don't init medals twice

* remove PlayerActionObject

* initial attempt at anti-note lock

TODO: circumvent inputs clearing themselves making the functionality not work

* properly implement input lock prevention

* fix error on editor open

* functional pause menu

* bugfix

* make unpausing not reset current play statistics

* serialize initializer components in inspector instead of procedurally generating

* sanity check

* note for fade

* make flashes in the camera prefabs instead of in world space

remove / reorganize script files
address issue #411

* fix bug with perfect campaign

make minigame transitions hide the game canvas
adjust animation of the song credits textbox

* fully functional intro scene (placeholder for future title screen)

refactored entire game loading procedure
re-organized some files

* add interaction query to disclaimer text

* reword legal

* anchor section medals to section display

more tempo change placement controls

* operation order bugfix

* prep for future ratings and stats

* loading text

* autoload opening scene

* splash screen adjustments

added setting to force enable splash screen

* adjust setting entry
2023-05-07 20:33:15 +00:00

185 lines
6.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using Newtonsoft.Json;
namespace HeavenStudio.Common
{
public static class PersistentDataManager
{
public enum PerfectChallengeType
{
Off, // no perfect challenge
Arcade, // "arcade rule"
Legacy, // "legacy rule"
On // "megamix rule"
}
[NonSerialized] public static GameSettings gameSettings;
public static void CreateDefaultSettings()
{
gameSettings = new GameSettings(
true,
false,
1,
GlobalGameManager.DEFAULT_SCREEN_SIZES[1].width,
GlobalGameManager.DEFAULT_SCREEN_SIZES[1].height,
0.8f,
512,
44100,
true,
true,
PerfectChallengeType.On,
true,
false,
true,
true
);
// disable if platform is mac
if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor)
gameSettings.discordRPCEnable = false;
else
gameSettings.discordRPCEnable = true;
gameSettings.timingDisplayComponents = new List<OverlaysManager.TimingDisplayComponent>()
{
OverlaysManager.TimingDisplayComponent.CreateDefaultDual()
};
gameSettings.skillStarComponents = new List<OverlaysManager.SkillStarComponent>()
{
OverlaysManager.SkillStarComponent.CreateDefault()
};
gameSettings.sectionComponents = new List<OverlaysManager.SectionComponent>()
{
OverlaysManager.SectionComponent.CreateDefault()
};
SaveSettings();
}
public static void LoadSettings()
{
if (File.Exists(Application.persistentDataPath + "/settings.json"))
{
string json = File.ReadAllText(Application.persistentDataPath + "/settings.json");
gameSettings = JsonUtility.FromJson<GameSettings>(json);
}
else
{
GlobalGameManager.IsFirstBoot = true;
CreateDefaultSettings();
}
}
public static void SaveSettings()
{
string json = JsonUtility.ToJson(gameSettings);
// save json to persistentDataPath
FileStream file = File.Create(Application.persistentDataPath + "/settings.json");
file.Write(System.Text.Encoding.ASCII.GetBytes(json), 0, json.Length);
file.Close();
}
public static void SaveTheme(string json)
{
// save json to persistentDataPath
FileStream file = File.Create(Application.persistentDataPath + "/editorTheme.json");
file.Write(System.Text.Encoding.ASCII.GetBytes(json), 0, json.Length);
file.Close();
}
[Serializable]
public struct GameSettings
{
// default settings constructor
public GameSettings(
bool showSplash = false,
bool isFullscreen = false,
int resolutionIndex = 0,
int resolutionWidth = 1280,
int resolutionHeight = 720,
float masterVolume = 0.8f,
int dspSize = 512,
int sampleRate = 44100,
bool editorCursorEnable = true,
bool discordRPCEnable = true,
PerfectChallengeType perfectChallengeType = PerfectChallengeType.On,
bool isMedalOn = true,
bool timingDisplayMinMode = false,
bool overlaysInEditor = true,
bool letterboxBgEnable = true,
bool letterboxFxEnable = true
)
{
this.showSplash = showSplash;
this.isFullscreen = isFullscreen;
this.resolutionIndex = resolutionIndex;
this.resolutionWidth = resolutionWidth;
this.resolutionHeight = resolutionHeight;
this.masterVolume = masterVolume;
this.dspSize = dspSize;
this.sampleRate = sampleRate;
this.editorCursorEnable = editorCursorEnable;
if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor)
this.discordRPCEnable = false;
else
this.discordRPCEnable = true;
this.perfectChallengeType = perfectChallengeType;
this.isMedalOn = isMedalOn;
this.timingDisplayMinMode = timingDisplayMinMode;
this.overlaysInEditor = overlaysInEditor;
this.letterboxBgEnable = true;
this.letterboxFxEnable = true;
this.timingDisplayComponents = new List<OverlaysManager.TimingDisplayComponent>()
{
OverlaysManager.TimingDisplayComponent.CreateDefaultDual()
};
this.skillStarComponents = new List<OverlaysManager.SkillStarComponent>()
{
OverlaysManager.SkillStarComponent.CreateDefault()
};
this.sectionComponents = new List<OverlaysManager.SectionComponent>()
{
OverlaysManager.SectionComponent.CreateDefault()
};
}
// Display / Audio Settings
public bool showSplash;
public bool isFullscreen;
public int resolutionIndex;
public int resolutionWidth;
public int resolutionHeight;
public float masterVolume;
public int dspSize;
public int sampleRate;
// Editor Settings
public bool editorCursorEnable;
public bool discordRPCEnable;
// Gameplay Settings
public PerfectChallengeType perfectChallengeType;
public bool isMedalOn;
public bool timingDisplayMinMode;
public bool overlaysInEditor;
public bool letterboxBgEnable;
public bool letterboxFxEnable;
public List<OverlaysManager.TimingDisplayComponent> timingDisplayComponents;
public List<OverlaysManager.SkillStarComponent> skillStarComponents;
public List<OverlaysManager.SectionComponent> sectionComponents;
}
}
}