Skip to content

Clean up AppPreferences - #4986

Merged
cwisniew merged 3 commits into
RPTools:developfrom
kwvanderlinde:refactor/4985-app-preferences
Oct 9, 2024
Merged

Clean up AppPreferences#4986
cwisniew merged 3 commits into
RPTools:developfrom
kwvanderlinde:refactor/4985-app-preferences

Conversation

@kwvanderlinde

@kwvanderlinde kwvanderlinde commented Oct 8, 2024

Copy link
Copy Markdown
Collaborator

Identify the Bug or Feature request

Resolves #4985

Description of the Change

This add a new AppPreferences.Preference<T> type to represent user preferences. Preferences are defined by instantiatng this class and assigning to a static field of AppPreferences.

A new AppStatePersisted captures those parts of AppPReferences that are not related to user preference but are actually about tracking application state across runs of MT. These have more specialized logic as well, so they do not use the new preference types.

That sums up the bulk of the changes, but a couple tweaks were made beyond that:

  • The default value for the typingNotificationDuration preference was reduced from 5000 seconds to 5 seconds.
  • ChatAutoSave is no longer a single with a static interface. Instead, we just choose to create only one in MapTool and interact with it normally.

Possible Drawbacks

Assuming no typos in the new preference spellings, should be none.

Documentation Notes

N/A

Release Notes

  • Refactored AppPreferences to be more declarative.

This change is Reviewable

@kwvanderlinde kwvanderlinde self-assigned this Oct 8, 2024
This new class is for app state that needs to be maintained between runs of MT. It is not for user preferences despite
being built on `Preferences` as well.
All `AppPreferences` preferences will be made instances of this type in the next change. For now, we are just adding the
new classes:
- `Type<T>` defines how to store the preference.
- `Preference<T>` defines the preference itself by its key, type, default value, and validation.
- Implementations of `Preference` specialize the storage characteristics, i.e., which methods on the `Preference` object
  to use when loading and storing a value.
All preferences are now instances of `Preference<T>`. The few types that had additional update logic not use the change
listener to notify observers about it.

In order to really make this change effective, we no longer store any colors component-wise since they can easily be
stored as a single integer. For those preferences that once had component-wise storage, the static initializer ensures
backwards compatibility by detecting whether a new value is present and loading the old values if not.
@kwvanderlinde
kwvanderlinde force-pushed the refactor/4985-app-preferences branch from 0131f67 to 110e1e6 Compare October 8, 2024 04:25
@cwisniew
cwisniew added this pull request to the merge queue Oct 9, 2024
Merged via the queue into RPTools:develop with commit e095cf1 Oct 9, 2024
@kwvanderlinde
kwvanderlinde deleted the refactor/4985-app-preferences branch November 26, 2024 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

No open projects
Status: Merged

Development

Successfully merging this pull request may close these issues.

[Refactoring]: Clean up AppPreferences

2 participants