Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save options in xml format #1704

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
16042ad
renamed PersistTo to Scope
kianzarrin Nov 28, 2022
fac1c21
instantiate options in lifecycle
kianzarrin Nov 29, 2022
99f6d94
fix option usage in patches
kianzarrin Nov 29, 2022
849403c
moved classes to their own file
kianzarrin Nov 29, 2022
0fbb4e1
Merge branch 'master' into OptionsInstance
kianzarrin Nov 29, 2022
1939f8e
fixed debug build
kianzarrin Nov 29, 2022
54fdc36
undid Ldarga_S, 2
kianzarrin Nov 30, 2022
ea04bf7
fixed setvalue
kianzarrin Nov 30, 2022
d68db26
cache SavedGameOptions.Instance property
kianzarrin Nov 30, 2022
84bbc3d
kianzarrin Dec 1, 2022
4d3bd80
xml options
kianzarrin Dec 2, 2022
18e47ec
typo
kianzarrin Dec 5, 2022
46df582
Merge branch 'master' into OptionsInstance
kianzarrin Dec 5, 2022
daa2562
Merge branch 'master' into OptionsInstance
kianzarrin Dec 8, 2022
e22ceb1
increment version
kianzarrin Dec 8, 2022
5256557
fixed deserialize string
kianzarrin Dec 8, 2022
abb6114
polish
kianzarrin Dec 8, 2022
38f46b9
revert Strings.csv
kianzarrin Dec 11, 2022
4e75c11
fix UI Values are not updated between loads
kianzarrin Dec 11, 2022
16d60cb
Merge branch 'OptionsInstance' into options-XML3
kianzarrin Dec 13, 2022
f7e0606
bugfix: update UI
kianzarrin Dec 13, 2022
a79a95a
save options instance.
kianzarrin Dec 13, 2022
92b0a59
save options as XML string
kianzarrin Dec 16, 2022
8053d31
Merge branch 'master' into options-XML3
kianzarrin Dec 16, 2022
226d875
bugfixes
kianzarrin Dec 16, 2022
ef1af28
merge
kianzarrin Dec 16, 2022
5327723
save options in TMPE_Options_XML
kianzarrin Dec 16, 2022
1ae4714
drop path find version
kianzarrin Dec 16, 2022
227a5b8
Merge branch 'master' into options-XML3
kianzarrin Jan 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions TLM/TLM/Custom/PathFinding/PathfinderUpdates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class PathfinderUpdates {
// Edition History:
// 0 - An old save, unknown pathfinder edition
// 1 - #1338 Aircraft pathfinding fix
// TODO: This feature is not used and does not persist. if we increment this we need to also serialize this.

/// <summary>
/// Update this each time a despawn-requiring change is
Expand All @@ -27,6 +28,8 @@ public static class PathfinderUpdates {
[SuppressMessage("Usage", "RAS0002:Readonly field for a non-readonly struct", Justification = "Not performance critical.")]
internal static readonly byte LatestPathfinderEdition = 1;

public static byte SavegamePathfinderEdition = LatestPathfinderEdition;

/// <summary>
/// Checks savegame pathfinder edition and, if necessary, despawns
/// any vehicles that might have invalid paths due to bugs in the
Expand All @@ -38,13 +41,13 @@ public static class PathfinderUpdates {
public static ExtVehicleType DespawnVehiclesIfNecessary() {
var filter = ExtVehicleType.None;

if (SavedGameOptions.Instance.SavegamePathfinderEdition == LatestPathfinderEdition) {
if (SavegamePathfinderEdition == LatestPathfinderEdition) {
return filter; // nothing to do, everything is fine
}

Log.Info($"Pathfinder update from {SavedGameOptions.Instance.SavegamePathfinderEdition} to {LatestPathfinderEdition}.");
Log.Info($"Pathfinder update from {SavegamePathfinderEdition} to {LatestPathfinderEdition}.");

if (SavedGameOptions.Instance.SavegamePathfinderEdition < 1) {
if (SavegamePathfinderEdition < 1) {
filter |= ExtVehicleType.Plane; // #1338
}

Expand All @@ -60,7 +63,7 @@ public static ExtVehicleType DespawnVehiclesIfNecessary() {
}

// this will be stored in savegame
SavedGameOptions.Instance.SavegamePathfinderEdition = LatestPathfinderEdition;
SavegamePathfinderEdition = LatestPathfinderEdition;

return filter;
}
Expand Down
32 changes: 22 additions & 10 deletions TLM/TLM/Lifecycle/SerializableDataExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace TrafficManager.Lifecycle {
using TrafficManager.Manager.Impl;
using TrafficManager.Manager.Impl.LaneConnection;
using TrafficManager.State;
using Util;
using TrafficManager.Util;
using TrafficManager.Custom.PathFinding;

[UsedImplicitly]
public class SerializableDataExtension
Expand All @@ -21,6 +22,9 @@ public class SerializableDataExtension

private const string DATA_ID = "TrafficManager_v1.0";
private const string VERSION_INFO_DATA_ID = "TrafficManager_VersionInfo_v1.0";
private const string OPTIONS_ID = "TMPE_OptionsXML";
private const string OPTIONS_LEGACY_ID = "TMPE_Options";


private static ISerializableData SerializableData => SimulationManager.instance.m_SerializableDataWrapper;
private static Configuration _configuration;
Expand Down Expand Up @@ -79,16 +83,21 @@ public static void Load() {
if (TMPELifecycle.InGameOrEditor()) {
// Always force default options on new game
// See: https://github.com/CitiesSkylinesMods/TMPE/pull/1425
byte[] options = TMPELifecycle.IsNewGame
? null
: SerializableData.LoadData("TMPE_Options");

if (!OptionsManager.Instance.LoadData(options ?? new byte[0])) {
loadingSucceeded = false;
if (!TMPELifecycle.IsNewGame) {
if (Version <= 3) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a bug, or you should swap bodies because LoadData(data) is loading XML Options (OPTIONS_ID)
which does not exist if version is equal or lower than 3

byte[] data = SerializableData.LoadData(OPTIONS_ID);
if (data != null) {
loadingSucceeded &= OptionsManager.Instance.LoadData(data);
}
} else {
byte[] data = SerializableData.LoadData(OPTIONS_LEGACY_ID);
if (data != null) {
loadingSucceeded &= OptionsManager.Instance.LoadDataLegacy(data);
}
}
}
}
}
catch (Exception e) {
} catch (Exception e) {
Log.Error($"OnLoadData: Error while loading options: {e}");
loadingSucceeded = false;
}
Expand Down Expand Up @@ -450,7 +459,10 @@ public static void Save() {

try {
if (TMPELifecycle.PlayMode) {
SerializableData.SaveData("TMPE_Options", OptionsManager.Instance.SaveData(ref success));
SerializableData.SaveData(OPTIONS_ID, OptionsManager.Instance.SaveData(ref success));

// forward compatibility. only needed for a short time:
SerializableData.SaveData(OPTIONS_LEGACY_ID, OptionsManager.Instance.SaveDataLegacy(ref success));
}
} catch (Exception ex) {
Log.Error("Unexpected error while saving options: " + ex.Message);
Expand Down
2 changes: 2 additions & 0 deletions TLM/TLM/Lifecycle/TMPELifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ internal void Load() {

IsGameLoaded = true;

SerializableUIOptionBase.UpdateAll();

ModUI.OnLevelLoaded();
if (PlayMode) {
Log._Debug("PlayMode");
Expand Down
Loading