mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-10 07:07:46 +02:00
Automatically reset game setting's value if it has the same value as global's
This commit is contained in:
@@ -63,7 +63,7 @@ export class BaseSettingsStorage<T extends AnyPref> {
|
||||
return this.definitions[key];
|
||||
}
|
||||
|
||||
hasSetting<K extends keyof PrefTypeMap<K>>(key: K): boolean {
|
||||
hasSetting(key: T): boolean {
|
||||
return key in this.settings;
|
||||
}
|
||||
|
||||
@@ -196,4 +196,15 @@ export class BaseSettingsStorage<T extends AnyPref> {
|
||||
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
deleteSetting(pref: T) {
|
||||
if (this.hasSetting(pref)) {
|
||||
delete this.settings[pref];
|
||||
this.saveSettings();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -10,15 +10,4 @@ export class GameSettingsStorage extends BaseSettingsStorage<StreamPref> {
|
||||
isEmpty() {
|
||||
return Object.keys(this.settings).length === 0;
|
||||
}
|
||||
|
||||
deleteSetting(pref: StreamPref) {
|
||||
if (this.hasSetting(pref)) {
|
||||
delete this.settings[pref];
|
||||
this.saveSettings();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -398,7 +398,13 @@ export class StreamSettingsStorage extends BaseSettingsStorage<StreamPref> {
|
||||
getGameSettings(id: number) {
|
||||
if (id > -1) {
|
||||
if (!this.gameSettings[id]) {
|
||||
this.gameSettings[id] = new GameSettingsStorage(id);
|
||||
const gameStorage = new GameSettingsStorage(id);
|
||||
this.gameSettings[id] = gameStorage;
|
||||
|
||||
// Remove values same as global's
|
||||
for (const key in gameStorage.settings) {
|
||||
this.getSettingByGame(id, key);
|
||||
}
|
||||
}
|
||||
|
||||
return this.gameSettings[id];
|
||||
@@ -408,20 +414,25 @@ export class StreamSettingsStorage extends BaseSettingsStorage<StreamPref> {
|
||||
}
|
||||
|
||||
getSetting<K extends keyof PrefTypeMap<K>>(key: K, checkUnsupported?: boolean): PrefTypeMap<K>[K] {
|
||||
return this.getSettingByGame(this.xboxTitleId, key, true, checkUnsupported)!;
|
||||
return this.getSettingByGame(this.xboxTitleId, key, checkUnsupported)!;
|
||||
}
|
||||
|
||||
getSettingByGame<K extends keyof PrefTypeMap<K>>(id: number, key: K, returnBaseValue: boolean=true, checkUnsupported?: boolean): PrefTypeMap<K>[K] | undefined {
|
||||
getSettingByGame<K extends keyof PrefTypeMap<K>>(id: number, key: K, checkUnsupported?: boolean): PrefTypeMap<K>[K] | undefined {
|
||||
const gameSettings = this.getGameSettings(id);
|
||||
if (gameSettings?.hasSetting(key)) {
|
||||
return gameSettings.getSetting(key, checkUnsupported);
|
||||
if (gameSettings?.hasSetting(key as StreamPref)) {
|
||||
let gameValue = gameSettings.getSetting(key, checkUnsupported);
|
||||
const globalValue = super.getSetting(key, checkUnsupported);
|
||||
|
||||
// Remove value if it's the same as global's
|
||||
if (globalValue === gameValue) {
|
||||
this.deleteSettingByGame(id, key as StreamPref);
|
||||
gameValue = globalValue;
|
||||
}
|
||||
|
||||
return gameValue;
|
||||
}
|
||||
|
||||
if (returnBaseValue) {
|
||||
return super.getSetting(key, checkUnsupported);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return super.getSetting(key, checkUnsupported);
|
||||
}
|
||||
|
||||
setSetting<V = any>(key: StreamPref, value: V, origin: SettingActionOrigin): V {
|
||||
@@ -439,6 +450,15 @@ export class StreamSettingsStorage extends BaseSettingsStorage<StreamPref> {
|
||||
return super.setSetting(key, value, origin);
|
||||
}
|
||||
|
||||
deleteSettingByGame(id: number, key: StreamPref): boolean {
|
||||
const gameSettings = this.getGameSettings(id);
|
||||
if (gameSettings) {
|
||||
return gameSettings.deleteSetting(key);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
hasGameSetting(id: number, key: StreamPref): boolean {
|
||||
const gameSettings = this.getGameSettings(id);
|
||||
return !!(gameSettings && gameSettings.hasSetting(key));
|
||||
|
Reference in New Issue
Block a user