Move BLANK_PRESET_DATA to Table class

This commit is contained in:
redphx 2024-12-24 06:43:08 +07:00
parent c1786d3fba
commit 907e595b1e
12 changed files with 103 additions and 78 deletions

View File

@ -1246,6 +1246,15 @@ class MkbMappingPresetsTable extends BasePresetsTable {
} }
} }
}; };
BLANK_PRESET_DATA = {
mapping: {},
mouse: {
mapTo: 2,
sensitivityX: 100,
sensitivityY: 100,
deadzoneCounterweight: 20
}
};
DEFAULT_PRESET_ID = -1; DEFAULT_PRESET_ID = -1;
constructor() { constructor() {
super(LocalDb.TABLE_VIRTUAL_CONTROLLERS); super(LocalDb.TABLE_VIRTUAL_CONTROLLERS);
@ -1273,6 +1282,9 @@ class KeyboardShortcutsTable extends BasePresetsTable {
} }
} }
}; };
BLANK_PRESET_DATA = {
mapping: {}
};
DEFAULT_PRESET_ID = -1; DEFAULT_PRESET_ID = -1;
constructor() { constructor() {
super(LocalDb.TABLE_KEYBOARD_SHORTCUTS); super(LocalDb.TABLE_KEYBOARD_SHORTCUTS);
@ -2617,6 +2629,9 @@ class ControllerShortcutsTable extends BasePresetsTable {
} }
} }
}; };
BLANK_PRESET_DATA = {
mapping: {}
};
DEFAULT_PRESET_ID = -1; DEFAULT_PRESET_ID = -1;
constructor() { constructor() {
super(LocalDb.TABLE_CONTROLLER_SHORTCUTS); super(LocalDb.TABLE_CONTROLLER_SHORTCUTS);
@ -2648,6 +2663,16 @@ class ControllerCustomizationsTable extends BasePresetsTable {
} }
} }
}; };
BLANK_PRESET_DATA = {
mapping: {},
settings: {
leftTriggerRange: [0, 100],
rightTriggerRange: [0, 100],
leftStickDeadzone: [0, 100],
rightStickDeadzone: [0, 100],
vibrationIntensity: 100
}
};
DEFAULT_PRESET_ID = 0; DEFAULT_PRESET_ID = 0;
} }
class ControllerSettingsTable extends BaseLocalTable { class ControllerSettingsTable extends BaseLocalTable {

View File

@ -1318,6 +1318,15 @@ class MkbMappingPresetsTable extends BasePresetsTable {
} }
} }
}; };
BLANK_PRESET_DATA = {
mapping: {},
mouse: {
mapTo: 2,
sensitivityX: 100,
sensitivityY: 100,
deadzoneCounterweight: 20
}
};
DEFAULT_PRESET_ID = -1; DEFAULT_PRESET_ID = -1;
constructor() { constructor() {
super(LocalDb.TABLE_VIRTUAL_CONTROLLERS); super(LocalDb.TABLE_VIRTUAL_CONTROLLERS);
@ -1345,6 +1354,9 @@ class KeyboardShortcutsTable extends BasePresetsTable {
} }
} }
}; };
BLANK_PRESET_DATA = {
mapping: {}
};
DEFAULT_PRESET_ID = -1; DEFAULT_PRESET_ID = -1;
constructor() { constructor() {
super(LocalDb.TABLE_KEYBOARD_SHORTCUTS); super(LocalDb.TABLE_KEYBOARD_SHORTCUTS);
@ -2727,6 +2739,9 @@ class ControllerShortcutsTable extends BasePresetsTable {
} }
} }
}; };
BLANK_PRESET_DATA = {
mapping: {}
};
DEFAULT_PRESET_ID = -1; DEFAULT_PRESET_ID = -1;
constructor() { constructor() {
super(LocalDb.TABLE_CONTROLLER_SHORTCUTS); super(LocalDb.TABLE_CONTROLLER_SHORTCUTS);
@ -2758,6 +2773,16 @@ class ControllerCustomizationsTable extends BasePresetsTable {
} }
} }
}; };
BLANK_PRESET_DATA = {
mapping: {},
settings: {
leftTriggerRange: [0, 100],
rightTriggerRange: [0, 100],
leftStickDeadzone: [0, 100],
rightStickDeadzone: [0, 100],
vibrationIntensity: 100
}
};
DEFAULT_PRESET_ID = 0; DEFAULT_PRESET_ID = 0;
} }
class ControllerSettingsTable extends BaseLocalTable { class ControllerSettingsTable extends BaseLocalTable {
@ -5134,7 +5159,7 @@ class BaseProfileManagerDialog extends NavigationDialog {
onClick: async (e) => { onClick: async (e) => {
let newName = this.promptNewName(t("new")); let newName = this.promptNewName(t("new"));
if (!newName) return; if (!newName) return;
let newId = await this.presetsDb.newPreset(newName, this.BLANK_PRESET_DATA); let newId = await this.presetsDb.newPreset(newName, this.presetsDb.BLANK_PRESET_DATA);
this.currentPresetId = newId, await this.refresh(); this.currentPresetId = newId, await this.refresh();
} }
}), createButton({ }), createButton({
@ -5219,9 +5244,6 @@ class ControllerShortcutsManagerDialog extends BaseProfileManagerDialog {
static getInstance = () => ControllerShortcutsManagerDialog.instance ?? (ControllerShortcutsManagerDialog.instance = new ControllerShortcutsManagerDialog(t("controller-shortcuts"))); static getInstance = () => ControllerShortcutsManagerDialog.instance ?? (ControllerShortcutsManagerDialog.instance = new ControllerShortcutsManagerDialog(t("controller-shortcuts")));
$content; $content;
selectActions = {}; selectActions = {};
BLANK_PRESET_DATA = {
mapping: {}
};
BUTTONS_ORDER = [ BUTTONS_ORDER = [
3, 3,
0, 0,
@ -5295,7 +5317,7 @@ class ControllerShortcutsManagerDialog extends BaseProfileManagerDialog {
super.updateButtonStates(); super.updateButtonStates();
} }
updatePreset() { updatePreset() {
let newData = deepClone(this.BLANK_PRESET_DATA), button; let newData = deepClone(this.presetsDb.BLANK_PRESET_DATA), button;
for (button in this.selectActions) { for (button in this.selectActions) {
let action = this.selectActions[button].value; let action = this.selectActions[button].value;
if (!action) continue; if (!action) continue;
@ -5402,16 +5424,6 @@ class ControllerCustomizationsManagerDialog extends BaseProfileManagerDialog {
$leftStickDeadzone; $leftStickDeadzone;
$rightStickDeadzone; $rightStickDeadzone;
$btnDetect; $btnDetect;
BLANK_PRESET_DATA = {
mapping: {},
settings: {
leftTriggerRange: [0, 100],
rightTriggerRange: [0, 100],
leftStickDeadzone: [0, 100],
rightStickDeadzone: [0, 100],
vibrationIntensity: 100
}
};
selectsMap = {}; selectsMap = {};
selectsOrder = []; selectsOrder = [];
isDetectingButton = !1; isDetectingButton = !1;
@ -5480,7 +5492,7 @@ class ControllerCustomizationsManagerDialog extends BaseProfileManagerDialog {
}); });
} }
} }
let params = { let blankSettings = this.presetsDb.BLANK_PRESET_DATA.settings, params = {
min: 0, min: 0,
minDiff: 1, minDiff: 1,
max: 100, max: 100,
@ -5500,7 +5512,7 @@ class ControllerCustomizationsManagerDialog extends BaseProfileManagerDialog {
customTextValue: (value) => { customTextValue: (value) => {
return value = parseInt(value), value === 0 ? t("off") : value + "%"; return value = parseInt(value), value === 0 ? t("off") : value + "%";
} }
}, boundUpdatePreset)), createSettingRow(t("left-trigger-range"), this.$leftTriggerRange = BxDualNumberStepper.create("left-trigger-range", this.BLANK_PRESET_DATA.settings.leftTriggerRange, params, boundUpdatePreset)), createSettingRow(t("right-trigger-range"), this.$rightTriggerRange = BxDualNumberStepper.create("right-trigger-range", this.BLANK_PRESET_DATA.settings.rightTriggerRange, params, boundUpdatePreset)), createSettingRow(t("left-stick-deadzone"), this.$leftStickDeadzone = BxDualNumberStepper.create("left-stick-deadzone", this.BLANK_PRESET_DATA.settings.leftStickDeadzone, params, boundUpdatePreset)), createSettingRow(t("right-stick-deadzone"), this.$rightStickDeadzone = BxDualNumberStepper.create("right-stick-deadzone", this.BLANK_PRESET_DATA.settings.rightStickDeadzone, params, boundUpdatePreset))); }, boundUpdatePreset)), createSettingRow(t("left-trigger-range"), this.$leftTriggerRange = BxDualNumberStepper.create("left-trigger-range", blankSettings.leftTriggerRange, params, boundUpdatePreset)), createSettingRow(t("right-trigger-range"), this.$rightTriggerRange = BxDualNumberStepper.create("right-trigger-range", blankSettings.rightTriggerRange, params, boundUpdatePreset)), createSettingRow(t("left-stick-deadzone"), this.$leftStickDeadzone = BxDualNumberStepper.create("left-stick-deadzone", blankSettings.leftStickDeadzone, params, boundUpdatePreset)), createSettingRow(t("right-stick-deadzone"), this.$rightStickDeadzone = BxDualNumberStepper.create("right-stick-deadzone", blankSettings.rightStickDeadzone, params, boundUpdatePreset)));
} }
startDetectingButton() { startDetectingButton() {
this.isDetectingButton = !0; this.isDetectingButton = !0;
@ -5566,10 +5578,10 @@ class ControllerCustomizationsManagerDialog extends BaseProfileManagerDialog {
manualTrigger: !0 manualTrigger: !0
}); });
} }
presetData.settings = Object.assign({}, this.BLANK_PRESET_DATA.settings, presetData.settings), $vibrationIntensity.value = presetData.settings.vibrationIntensity.toString(), $vibrationIntensity.dataset.disabled = isDefaultPreset.toString(), $leftStickDeadzone.dataset.disabled = $rightStickDeadzone.dataset.disabled = $leftTriggerRange.dataset.disabled = $rightTriggerRange.dataset.disabled = isDefaultPreset.toString(), $leftStickDeadzone.setValue(presetData.settings.leftStickDeadzone), $rightStickDeadzone.setValue(presetData.settings.rightStickDeadzone), $leftTriggerRange.setValue(presetData.settings.leftTriggerRange), $rightTriggerRange.setValue(presetData.settings.rightTriggerRange); presetData.settings = Object.assign({}, this.presetsDb.BLANK_PRESET_DATA.settings, presetData.settings), $vibrationIntensity.value = presetData.settings.vibrationIntensity.toString(), $vibrationIntensity.dataset.disabled = isDefaultPreset.toString(), $leftStickDeadzone.dataset.disabled = $rightStickDeadzone.dataset.disabled = $leftTriggerRange.dataset.disabled = $rightTriggerRange.dataset.disabled = isDefaultPreset.toString(), $leftStickDeadzone.setValue(presetData.settings.leftStickDeadzone), $rightStickDeadzone.setValue(presetData.settings.rightStickDeadzone), $leftTriggerRange.setValue(presetData.settings.leftTriggerRange), $rightTriggerRange.setValue(presetData.settings.rightTriggerRange);
} }
updatePreset() { updatePreset() {
let newData = deepClone(this.BLANK_PRESET_DATA), gamepadKey; let newData = deepClone(this.presetsDb.BLANK_PRESET_DATA), gamepadKey;
for (gamepadKey in this.selectsMap) { for (gamepadKey in this.selectsMap) {
let value = this.selectsMap[gamepadKey].value; let value = this.selectsMap[gamepadKey].value;
if (!value) continue; if (!value) continue;
@ -6016,15 +6028,6 @@ class MkbMappingManagerDialog extends BaseProfileManagerDialog {
202, 202,
203 203
]; ];
BLANK_PRESET_DATA = {
mapping: {},
mouse: {
mapTo: 2,
sensitivityX: 100,
sensitivityY: 100,
deadzoneCounterweight: 20
}
};
allKeyElements = []; allKeyElements = [];
$mouseMapTo; $mouseMapTo;
$mouseSensitivityX; $mouseSensitivityX;
@ -6105,7 +6108,7 @@ class MkbMappingManagerDialog extends BaseProfileManagerDialog {
this.$mouseMapTo.value = mouse.mapTo.toString(), this.$mouseSensitivityX.value = mouse.sensitivityX.toString(), this.$mouseSensitivityY.value = mouse.sensitivityY.toString(), this.$mouseDeadzone.value = mouse.deadzoneCounterweight.toString(), this.$mouseMapTo.disabled = isDefaultPreset, this.$mouseSensitivityX.dataset.disabled = isDefaultPreset.toString(), this.$mouseSensitivityY.dataset.disabled = isDefaultPreset.toString(), this.$mouseDeadzone.dataset.disabled = isDefaultPreset.toString(); this.$mouseMapTo.value = mouse.mapTo.toString(), this.$mouseSensitivityX.value = mouse.sensitivityX.toString(), this.$mouseSensitivityY.value = mouse.sensitivityY.toString(), this.$mouseDeadzone.value = mouse.deadzoneCounterweight.toString(), this.$mouseMapTo.disabled = isDefaultPreset, this.$mouseSensitivityX.dataset.disabled = isDefaultPreset.toString(), this.$mouseSensitivityY.dataset.disabled = isDefaultPreset.toString(), this.$mouseDeadzone.dataset.disabled = isDefaultPreset.toString();
} }
savePreset() { savePreset() {
let presetData = deepClone(this.BLANK_PRESET_DATA); let presetData = deepClone(this.presetsDb.BLANK_PRESET_DATA);
for (let $elm of this.allKeyElements) { for (let $elm of this.allKeyElements) {
let { buttonIndex, keySlot } = this.parseDataset($elm), mapping = presetData.mapping; let { buttonIndex, keySlot } = this.parseDataset($elm), mapping = presetData.mapping;
if (!mapping[buttonIndex]) mapping[buttonIndex] = []; if (!mapping[buttonIndex]) mapping[buttonIndex] = [];
@ -6131,9 +6134,6 @@ class KeyboardShortcutsManagerDialog extends BaseProfileManagerDialog {
$content; $content;
$unbindNote; $unbindNote;
allKeyElements = []; allKeyElements = [];
BLANK_PRESET_DATA = {
mapping: {}
};
constructor(title) { constructor(title) {
super(title, KeyboardShortcutsTable.getInstance()); super(title, KeyboardShortcutsTable.getInstance());
let $rows = CE("div", { class: "bx-keyboard-shortcuts-manager-container" }); let $rows = CE("div", { class: "bx-keyboard-shortcuts-manager-container" });
@ -6189,7 +6189,7 @@ class KeyboardShortcutsManagerDialog extends BaseProfileManagerDialog {
} }
} }
savePreset() { savePreset() {
let presetData = deepClone(this.BLANK_PRESET_DATA); let presetData = deepClone(this.presetsDb.BLANK_PRESET_DATA);
for (let $elm of this.allKeyElements) { for (let $elm of this.allKeyElements) {
let { action } = this.parseDataset($elm), mapping = presetData.mapping; let { action } = this.parseDataset($elm), mapping = presetData.mapping;
if ($elm.keyInfo) mapping[action] = $elm.keyInfo; if ($elm.keyInfo) mapping[action] = $elm.keyInfo;

View File

@ -24,8 +24,6 @@ export abstract class BaseProfileManagerDialog<T extends PresetRecord> extends N
private $btnRename!: HTMLButtonElement; private $btnRename!: HTMLButtonElement;
private $btnDelete!: HTMLButtonElement; private $btnDelete!: HTMLButtonElement;
protected abstract readonly BLANK_PRESET_DATA: T['data'];
constructor(title: string, presetsDb: BasePresetsTable<T>) { constructor(title: string, presetsDb: BasePresetsTable<T>) {
super(); super();
@ -138,7 +136,7 @@ export abstract class BaseProfileManagerDialog<T extends PresetRecord> extends N
} }
// Create new preset selected name // Create new preset selected name
const newId = await this.presetsDb.newPreset(newName, this.BLANK_PRESET_DATA); const newId = await this.presetsDb.newPreset(newName, this.presetsDb.BLANK_PRESET_DATA);
this.currentPresetId = newId; this.currentPresetId = newId;
await this.refresh(); await this.refresh();

View File

@ -29,18 +29,6 @@ export class ControllerCustomizationsManagerDialog extends BaseProfileManagerDia
private $rightStickDeadzone!: BxDualNumberStepper; private $rightStickDeadzone!: BxDualNumberStepper;
private $btnDetect!: HTMLButtonElement; private $btnDetect!: HTMLButtonElement;
protected readonly BLANK_PRESET_DATA = {
mapping: {},
settings: {
leftTriggerRange: [0, 100],
rightTriggerRange: [0, 100],
leftStickDeadzone: [0, 100],
rightStickDeadzone: [0, 100],
vibrationIntensity: 100,
},
} satisfies ControllerCustomizationPresetData;
private selectsMap: PartialRecord<GamepadKey, HTMLSelectElement> = {}; private selectsMap: PartialRecord<GamepadKey, HTMLSelectElement> = {};
private selectsOrder: GamepadKey[] = []; private selectsOrder: GamepadKey[] = [];
@ -153,6 +141,7 @@ export class ControllerCustomizationsManagerDialog extends BaseProfileManagerDia
} }
} }
const blankSettings = this.presetsDb.BLANK_PRESET_DATA.settings;
const params: DualNumberStepperParams = { const params: DualNumberStepperParams = {
min: 0, min: 0,
minDiff: 1, minDiff: 1,
@ -189,19 +178,19 @@ export class ControllerCustomizationsManagerDialog extends BaseProfileManagerDia
// Range settings // Range settings
createSettingRow(t('left-trigger-range'), createSettingRow(t('left-trigger-range'),
this.$leftTriggerRange = BxDualNumberStepper.create('left-trigger-range', this.BLANK_PRESET_DATA.settings.leftTriggerRange, params, boundUpdatePreset), this.$leftTriggerRange = BxDualNumberStepper.create('left-trigger-range', blankSettings.leftTriggerRange!, params, boundUpdatePreset),
), ),
createSettingRow(t('right-trigger-range'), createSettingRow(t('right-trigger-range'),
this.$rightTriggerRange = BxDualNumberStepper.create('right-trigger-range', this.BLANK_PRESET_DATA.settings.rightTriggerRange, params, boundUpdatePreset), this.$rightTriggerRange = BxDualNumberStepper.create('right-trigger-range', blankSettings.rightTriggerRange!, params, boundUpdatePreset),
), ),
createSettingRow(t('left-stick-deadzone'), createSettingRow(t('left-stick-deadzone'),
this.$leftStickDeadzone = BxDualNumberStepper.create('left-stick-deadzone', this.BLANK_PRESET_DATA.settings.leftStickDeadzone, params, boundUpdatePreset), this.$leftStickDeadzone = BxDualNumberStepper.create('left-stick-deadzone', blankSettings.leftStickDeadzone!, params, boundUpdatePreset),
), ),
createSettingRow(t('right-stick-deadzone'), createSettingRow(t('right-stick-deadzone'),
this.$rightStickDeadzone = BxDualNumberStepper.create('right-stick-deadzone', this.BLANK_PRESET_DATA.settings.rightStickDeadzone, params, boundUpdatePreset), this.$rightStickDeadzone = BxDualNumberStepper.create('right-stick-deadzone', blankSettings.rightStickDeadzone!, params, boundUpdatePreset),
), ),
); );
} }
@ -323,7 +312,7 @@ export class ControllerCustomizationsManagerDialog extends BaseProfileManagerDia
} }
// Add missing settings // Add missing settings
presetData.settings = Object.assign({}, this.BLANK_PRESET_DATA.settings, presetData.settings); presetData.settings = Object.assign({}, this.presetsDb.BLANK_PRESET_DATA.settings, presetData.settings);
// Vibration intensity // Vibration intensity
$vibrationIntensity.value = presetData.settings.vibrationIntensity.toString(); $vibrationIntensity.value = presetData.settings.vibrationIntensity.toString();
@ -338,7 +327,7 @@ export class ControllerCustomizationsManagerDialog extends BaseProfileManagerDia
} }
private updatePreset() { private updatePreset() {
const newData: ControllerCustomizationPresetData = deepClone(this.BLANK_PRESET_DATA); const newData: ControllerCustomizationPresetData = deepClone(this.presetsDb.BLANK_PRESET_DATA);
// Set mappings // Set mappings
let gamepadKey: unknown; let gamepadKey: unknown;

View File

@ -21,10 +21,6 @@ export class ControllerShortcutsManagerDialog extends BaseProfileManagerDialog<C
protected $content: HTMLElement; protected $content: HTMLElement;
private selectActions: PartialRecord<GamepadKey, HTMLSelectElement> = {}; private selectActions: PartialRecord<GamepadKey, HTMLSelectElement> = {};
protected readonly BLANK_PRESET_DATA = {
mapping: {},
};
private readonly BUTTONS_ORDER = [ private readonly BUTTONS_ORDER = [
GamepadKey.Y, GamepadKey.A, GamepadKey.X, GamepadKey.B, GamepadKey.Y, GamepadKey.A, GamepadKey.X, GamepadKey.B,
GamepadKey.UP, GamepadKey.DOWN, GamepadKey.LEFT, GamepadKey.RIGHT, GamepadKey.UP, GamepadKey.DOWN, GamepadKey.LEFT, GamepadKey.RIGHT,
@ -138,7 +134,7 @@ export class ControllerShortcutsManagerDialog extends BaseProfileManagerDialog<C
} }
private updatePreset() { private updatePreset() {
const newData: ControllerShortcutPresetData = deepClone(this.BLANK_PRESET_DATA); const newData: ControllerShortcutPresetData = deepClone(this.presetsDb.BLANK_PRESET_DATA);
let button: unknown; let button: unknown;
for (button in this.selectActions) { for (button in this.selectActions) {

View File

@ -22,10 +22,6 @@ export class KeyboardShortcutsManagerDialog extends BaseProfileManagerDialog<Key
private $unbindNote: HTMLElement; private $unbindNote: HTMLElement;
private readonly allKeyElements: BxKeyBindingButton[] = []; private readonly allKeyElements: BxKeyBindingButton[] = [];
protected readonly BLANK_PRESET_DATA: KeyboardShortcutPresetData = {
mapping: {},
};
constructor(title: string) { constructor(title: string) {
super(title, KeyboardShortcutsTable.getInstance()); super(title, KeyboardShortcutsTable.getInstance());
@ -132,7 +128,7 @@ export class KeyboardShortcutsManagerDialog extends BaseProfileManagerDialog<Key
} }
private savePreset() { private savePreset() {
const presetData = deepClone(this.BLANK_PRESET_DATA) as KeyboardShortcutPresetData; const presetData = deepClone(this.presetsDb.BLANK_PRESET_DATA) as KeyboardShortcutPresetData;
// Get mapping // Get mapping
for (const $elm of this.allKeyElements) { for (const $elm of this.allKeyElements) {

View File

@ -4,7 +4,7 @@ import { t } from "@/utils/translation";
import { MkbMappingPresetsTable } from "@/utils/local-db/mkb-mapping-presets-table"; import { MkbMappingPresetsTable } from "@/utils/local-db/mkb-mapping-presets-table";
import { GamepadKey, GamepadKeyName } from "@/enums/gamepad"; import { GamepadKey, GamepadKeyName } from "@/enums/gamepad";
import { CE, createSettingRow } from "@/utils/html"; import { CE, createSettingRow } from "@/utils/html";
import { MouseMapTo, MkbPresetKey, type KeyCode } from "@/enums/mkb"; import { MouseMapTo, type KeyCode } from "@/enums/mkb";
import { BxKeyBindingButton, BxKeyBindingButtonFlag } from "@/web-components/bx-key-binding-button"; import { BxKeyBindingButton, BxKeyBindingButtonFlag } from "@/web-components/bx-key-binding-button";
import { StreamSettings } from "@/utils/stream-settings"; import { StreamSettings } from "@/utils/stream-settings";
import { BxNumberStepper } from "@/web-components/bx-number-stepper"; import { BxNumberStepper } from "@/web-components/bx-number-stepper";
@ -33,16 +33,6 @@ export class MkbMappingManagerDialog extends BaseProfileManagerDialog<MkbPresetR
GamepadKey.R3, GamepadKey.RS_UP, GamepadKey.RS_DOWN, GamepadKey.RS_LEFT, GamepadKey.RS_RIGHT, GamepadKey.R3, GamepadKey.RS_UP, GamepadKey.RS_DOWN, GamepadKey.RS_LEFT, GamepadKey.RS_RIGHT,
]; ];
protected readonly BLANK_PRESET_DATA: MkbPresetData = {
mapping: {},
mouse: {
[MkbPresetKey.MOUSE_MAP_TO]: MouseMapTo.RS,
[MkbPresetKey.MOUSE_SENSITIVITY_X]: 100,
[MkbPresetKey.MOUSE_SENSITIVITY_Y]: 100,
[MkbPresetKey.MOUSE_DEADZONE_COUNTERWEIGHT]: 20,
},
};
private readonly allKeyElements: BxKeyBindingButton[] = []; private readonly allKeyElements: BxKeyBindingButton[] = [];
private $mouseMapTo!: BxSelectElement; private $mouseMapTo!: BxSelectElement;
private $mouseSensitivityX!: BxNumberStepper; private $mouseSensitivityX!: BxNumberStepper;
@ -217,7 +207,7 @@ export class MkbMappingManagerDialog extends BaseProfileManagerDialog<MkbPresetR
} }
private savePreset() { private savePreset() {
const presetData = deepClone(this.BLANK_PRESET_DATA) as MkbPresetData; const presetData = deepClone(this.presetsDb.BLANK_PRESET_DATA) as MkbPresetData;
// Get mapping // Get mapping
for (const $elm of this.allKeyElements) { for (const $elm of this.allKeyElements) {

View File

@ -6,6 +6,7 @@ export abstract class BasePresetsTable<T extends PresetRecord> extends BaseLocal
protected abstract TABLE_PRESETS: string; protected abstract TABLE_PRESETS: string;
protected abstract DEFAULT_PRESETS: PresetRecords<T>; protected abstract DEFAULT_PRESETS: PresetRecords<T>;
protected abstract readonly DEFAULT_PRESET_ID: number; protected abstract readonly DEFAULT_PRESET_ID: number;
abstract readonly BLANK_PRESET_DATA: T['data'];
async newPreset(name: string, data: T['data']) { async newPreset(name: string, data: T['data']) {
const newRecord = { name, data } as T; const newRecord = { name, data } as T;

View File

@ -1,4 +1,4 @@
import type { ControllerCustomizationPresetRecord, PresetRecords } from "@/types/presets"; import type { ControllerCustomizationPresetData, ControllerCustomizationPresetRecord, PresetRecords } from "@/types/presets";
import { LocalDb } from "./local-db"; import { LocalDb } from "./local-db";
import { BasePresetsTable } from "./base-presets-table"; import { BasePresetsTable } from "./base-presets-table";
import { GamepadKey } from "@/enums/gamepad"; import { GamepadKey } from "@/enums/gamepad";
@ -40,6 +40,17 @@ export class ControllerCustomizationsTable extends BasePresetsTable<ControllerCu
}, },
}; };
protected DEFAULT_PRESET_ID = ControllerCustomizationDefaultPresetId.DEFAULT; readonly BLANK_PRESET_DATA = {
mapping: {},
settings: {
leftTriggerRange: [0, 100],
rightTriggerRange: [0, 100],
leftStickDeadzone: [0, 100],
rightStickDeadzone: [0, 100],
vibrationIntensity: 100,
},
} satisfies ControllerCustomizationPresetData;
protected DEFAULT_PRESET_ID = ControllerCustomizationDefaultPresetId.DEFAULT;
} }

View File

@ -52,6 +52,10 @@ export class ControllerShortcutsTable extends BasePresetsTable<ControllerShortcu
}, },
}; };
readonly BLANK_PRESET_DATA = {
mapping: {},
};
protected readonly DEFAULT_PRESET_ID = ControllerShortcutDefaultId.DEFAULT; protected readonly DEFAULT_PRESET_ID = ControllerShortcutDefaultId.DEFAULT;
private constructor() { private constructor() {

View File

@ -36,6 +36,10 @@ export class KeyboardShortcutsTable extends BasePresetsTable<KeyboardShortcutPre
}, },
}; };
readonly BLANK_PRESET_DATA = {
mapping: {},
};
protected readonly DEFAULT_PRESET_ID = KeyboardShortcutDefaultId.DEFAULT; protected readonly DEFAULT_PRESET_ID = KeyboardShortcutDefaultId.DEFAULT;
private constructor() { private constructor() {

View File

@ -117,6 +117,17 @@ export class MkbMappingPresetsTable extends BasePresetsTable<MkbPresetRecord> {
}, },
}, },
}; };
readonly BLANK_PRESET_DATA = {
mapping: {},
mouse: {
[MkbPresetKey.MOUSE_MAP_TO]: MouseMapTo.RS,
[MkbPresetKey.MOUSE_SENSITIVITY_X]: 100,
[MkbPresetKey.MOUSE_SENSITIVITY_Y]: 100,
[MkbPresetKey.MOUSE_DEADZONE_COUNTERWEIGHT]: 20,
},
};
protected readonly DEFAULT_PRESET_ID = MkbMappingDefaultPresetId.DEFAULT; protected readonly DEFAULT_PRESET_ID = MkbMappingDefaultPresetId.DEFAULT;
private constructor() { private constructor() {