TouchyTickets/TouchyTickets/Options.cs

70 lines
1.9 KiB
C#
Raw Permalink Normal View History

2020-06-16 23:17:18 +02:00
using System.IO;
using System.Runtime.Serialization;
2020-06-22 14:13:59 +02:00
using Microsoft.Xna.Framework.Audio;
2020-06-16 23:17:18 +02:00
using Newtonsoft.Json;
2023-02-11 10:16:42 +01:00
namespace TouchyTickets;
[DataContract]
public class Options {
public static Options Instance { get; private set; }
[DataMember]
public int RainingTicketLimit = 300;
[DataMember]
public float SoundVolume {
get => this.soundVolume;
set {
this.soundVolume = value;
SoundEffect.MasterVolume = value;
}
2023-02-11 10:16:42 +01:00
}
private float soundVolume = 1;
[DataMember]
public bool WhileYouWereAwayMessage = true;
[DataMember]
public bool RenderUnderNotch {
get => this.renderUnderNotch;
set {
this.renderUnderNotch = value;
GameImpl.Instance.Platform.SetRenderUnderNotch(value);
}
}
[DataMember]
2023-02-11 10:16:42 +01:00
public bool KeepScreenOn {
get => this.keepScreenOn;
set {
this.keepScreenOn = value;
GameImpl.Instance.Platform.SetKeepScreenOn(value);
2020-06-16 23:17:18 +02:00
}
2023-02-11 10:16:42 +01:00
}
[DataMember]
public bool AutoBuyEnabled = true;
[DataMember]
public int MinTicketsForAutoBuy = 50000;
2020-06-16 23:17:18 +02:00
private bool renderUnderNotch;
private bool keepScreenOn;
2023-02-11 10:16:42 +01:00
public static void Save() {
var file = Options.GetOptionsFile(true);
using var stream = new JsonTextWriter(file.CreateText());
SaveHandler.Serializer.Serialize(stream, Options.Instance);
}
2020-06-16 23:17:18 +02:00
2023-02-11 10:16:42 +01:00
public static void Load() {
var file = Options.GetOptionsFile(false);
if (file.Exists) {
using var stream = new JsonTextReader(file.OpenText());
Options.Instance = SaveHandler.Serializer.Deserialize<Options>(stream);
} else {
Options.Instance = new Options();
2020-06-16 23:17:18 +02:00
}
2023-02-11 10:16:42 +01:00
}
2020-06-16 23:17:18 +02:00
2023-02-11 10:16:42 +01:00
private static FileInfo GetOptionsFile(bool create) {
return new FileInfo(Path.Combine(SaveHandler.GetGameDirectory(create).FullName, "Options"));
2020-06-16 23:17:18 +02:00
}
2023-02-11 10:16:42 +01:00
2020-06-16 23:17:18 +02:00
}