Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions EmoTracker.Data/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ Sessions.SessionSettings ActiveSessionSettings
/// Called from <see cref="Sessions.TrackerState"/>'s adoption ctor
/// so a primary state inherits the user's pre-existing preferences
/// loaded from <c>ApplicationSettings.json</c>.
/// Also called from <see cref="Sessions.TrackerState.ActivatePackage"/>
/// to reset settings to the saved defaults before init.lua runs,
/// ensuring pack scripts start from the user's preferences and may
/// optionally override them.
/// </summary>
internal void SeedIntoSession(Sessions.SessionSettings target)
{
Expand All @@ -97,6 +101,54 @@ internal void SeedIntoSession(Sessions.SessionSettings target)
target.PinLocationsOnItemCapture = mbSeedPinLocationsOnItemCapture;
}

/// <summary>
/// Called by <see cref="Sessions.SessionSettings"/> when a tracked
/// property changes, so UI-driven setting changes are persisted to
/// <c>ApplicationSettings.json</c> as the new defaults for future
/// sessions / pack loads.
///
/// <para>
/// No-ops when called while a pack is loading (i.e.
/// <see cref="Sessions.PackageLoader.IsLoading"/> is true) to avoid
/// init.lua-driven changes overwriting the user's saved preferences.
/// </para>
/// </summary>
internal void SyncSeedsFromSession(Sessions.SessionSettings source)
{
if (source == null) return;
if (Sessions.PackageLoader.IsLoading) return;

bool changed = false;
if (mbSeedIgnoreAllLogic != source.IgnoreAllLogic)
{
mbSeedIgnoreAllLogic = source.IgnoreAllLogic;
changed = true;
}
if (mbSeedDisplayAllLocations != source.DisplayAllLocations)
{
mbSeedDisplayAllLocations = source.DisplayAllLocations;
changed = true;
}
if (mbSeedAlwaysAllowClearing != source.AlwaysAllowClearing)
{
mbSeedAlwaysAllowClearing = source.AlwaysAllowClearing;
changed = true;
}
if (mbSeedAutoUnpinLocationsOnClear != source.AutoUnpinLocationsOnClear)
{
mbSeedAutoUnpinLocationsOnClear = source.AutoUnpinLocationsOnClear;
changed = true;
}
if (mbSeedPinLocationsOnItemCapture != source.PinLocationsOnItemCapture)
{
mbSeedPinLocationsOnItemCapture = source.PinLocationsOnItemCapture;
changed = true;
}

if (changed)
WriteSettings();
}

public bool IgnoreAllLogic
{
get
Expand Down
8 changes: 8 additions & 0 deletions EmoTracker.Data/Sessions/PackageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public PackageLoadEventArgs(TrackerState target, IGamePackage package, IGamePack
[ThreadStatic]
static bool mInProgress;

/// <summary>
/// True while <see cref="LoadInto"/> is executing on this thread.
/// Used by <see cref="ApplicationSettings.SyncSeedsFromSession"/> to
/// suppress seed-writes driven by pack-script (init.lua) changes,
/// so only explicit user UI changes update the saved defaults.
/// </summary>
internal static bool IsLoading => mInProgress;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This appears unused. If it is, it should be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is used — ApplicationSettings.SyncSeedsFromSession checks it at line 119 (if (Sessions.PackageLoader.IsLoading) return;). Easy to miss since it's a cross-file internal reference. Happy to leave as-is.


/// <summary>
/// Loads <paramref name="package"/> (with optional <paramref name="variant"/>)
/// into <paramref name="target"/>'s catalogs. Caller is responsible for
Expand Down
10 changes: 10 additions & 0 deletions EmoTracker.Data/Sessions/SessionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ public partial class SessionSettings : TransactableModelTypeBase
public partial bool IgnoreAllLogic { get; set; }

[KVMutable]
[OnChanged(nameof(SyncSeedsToApplicationSettings))]
public partial bool DisplayAllLocations { get; set; }

[KVMutable]
[OnChanged(nameof(SyncSeedsToApplicationSettings))]
public partial bool AlwaysAllowClearing { get; set; }

[KVMutable]
[OnChanged(nameof(SyncSeedsToApplicationSettings))]
public partial bool AutoUnpinLocationsOnClear { get; set; }

[KVMutable]
[OnChanged(nameof(SyncSeedsToApplicationSettings))]
public partial bool PinLocationsOnItemCapture { get; set; }

[KVMutable]
Expand Down Expand Up @@ -111,6 +115,12 @@ protected void OnIgnoreAllLogicChanged()
// ApplicationSettings.IgnoreAllLogic's setter.
var state = OwnerState as TrackerState;
state?.Locations.RefreshAccessibility();
SyncSeedsToApplicationSettings();
}

protected void SyncSeedsToApplicationSettings()
{
ApplicationSettings.Instance?.SyncSeedsFromSession(this);
}

// ----------- Fork support ---------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions EmoTracker.Data/Sessions/TrackerState.PackageOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public void ActivatePackage(IGamePackage package, IGamePackageVariant variant)
PackageManager.Instance.RefreshActiveState();
NotifyPropertyChanged(nameof(ActiveVariantUID));

// Reset tracking settings to the user's saved defaults before
// running init.lua, so pack scripts start from the user's
// preferences and may optionally override them (issue #83).
ApplicationSettings.Instance.SeedIntoSession(Settings);

PackageLoader.LoadInto(this, package, variant);
}
finally
Expand Down
Loading