Skip to content

Commit

Permalink
save options as XML string
Browse files Browse the repository at this point in the history
  • Loading branch information
kianzarrin committed Dec 16, 2022
1 parent a79a95a commit 92b0a59
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
6 changes: 3 additions & 3 deletions TLM/TLM/Lifecycle/SerializableDataExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ private static void LoadDataState(out bool error) {
// load Path Find Update
PathfinderUpdates.SavegamePathfinderEdition = _configuration.SavegamePathfinderEdition;

if(_configuration.Options != null) {
OptionsManager.Instance.LoadData(_configuration.Options);
if(!string.IsNullOrEmpty(_configuration.SavedGameOptionsXML)) {
OptionsManager.Instance.LoadData(_configuration.SavedGameOptionsXML);
}

// load ext. citizens
Expand Down Expand Up @@ -459,7 +459,7 @@ public static void Save() {

try {
if (TMPELifecycle.PlayMode) {
configuration.Options = OptionsManager.Instance.SaveData(ref success);
configuration.SavedGameOptionsXML = OptionsManager.Instance.SaveData(ref success);

// forward compatibility. only needed for a short time:
SerializableData.SaveData("TMPE_Options", OptionsManager.Instance.SaveDataLegacy(ref success));
Expand Down
10 changes: 5 additions & 5 deletions TLM/TLM/Manager/Impl/OptionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace TrafficManager.Manager.Impl {

public class OptionsManager
: AbstractCustomManager,
IOptionsManager, ICustomDataManager<SavedGameOptions> {
IOptionsManager, ICustomDataManager<string> {

public static OptionsManager Instance = new OptionsManager();

Expand Down Expand Up @@ -102,20 +102,20 @@ private static void ToOption(byte[] data, uint idx, ILegacySerializableOption op
/// </summary>
/// <param name="success">Current success state of SaveData operation.</param>
/// <returns>Returns <c>true</c> if successful, otherwise <c>false</c>.</returns>
public SavedGameOptions SaveData(ref bool success) {
public string SaveData(ref bool success) {
try {
return SavedGameOptions.Instance.Save();
return SavedGameOptions.Instance.Serialize();
} catch (Exception ex) {
ex.LogException();
success = false;
return null; // try and salvage some of the settings
}
}

public bool LoadData(SavedGameOptions options) {
public bool LoadData(string xml) {
try {
SavedGameOptions.Available = false;
SavedGameOptions.Load(options);
SavedGameOptions.Deserialize(xml);
return true;
} catch(Exception ex) {
ex.LogException();
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/State/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public ExtCitizenData(uint citizenId) {
}
}

public SavedGameOptions Options;
public string SavedGameOptionsXML;

/// <summary>
/// Stored ext. citizen data
Expand Down
9 changes: 0 additions & 9 deletions TLM/TLM/State/SavedGameOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,4 @@ public static bool Deserialize(string xml) {
}
return false;
}

public SavedGameOptions Save() {
return this.MemberwiseClone() as SavedGameOptions;
}

public static void Load(SavedGameOptions options) {
Instance = options ?? new();
Instance.Awake();
}
}

0 comments on commit 92b0a59

Please sign in to comment.