mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-26 00:55:16 -07:00
fix(controller): save remaps per profile, gate modals on enabled (#69)
This commit is contained in:
@@ -1453,6 +1453,104 @@ test('parses descriptor-based controller bindings', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('parses controller profiles as per-gamepad binding overrides', () => {
|
||||
const dir = makeTempDir();
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'config.jsonc'),
|
||||
`{
|
||||
"controller": {
|
||||
"buttonIndices": {
|
||||
"buttonSouth": 0,
|
||||
"leftTrigger": 6
|
||||
},
|
||||
"bindings": {
|
||||
"toggleLookup": { "kind": "button", "buttonIndex": 0 },
|
||||
"quitMpv": "leftTrigger"
|
||||
},
|
||||
"profiles": {
|
||||
"8BitDo SN30": {
|
||||
"label": "8BitDo SN30",
|
||||
"bindings": {
|
||||
"toggleLookup": { "kind": "button", "buttonIndex": 11 },
|
||||
"leftStickVertical": { "kind": "axis", "axisIndex": 7, "dpadFallback": "none" }
|
||||
}
|
||||
},
|
||||
"Xbox Wireless Controller": {
|
||||
"buttonIndices": {
|
||||
"leftTrigger": 8
|
||||
},
|
||||
"bindings": {
|
||||
"quitMpv": "leftTrigger"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`,
|
||||
'utf-8',
|
||||
);
|
||||
|
||||
const service = new ConfigService(dir);
|
||||
const config = service.getConfig();
|
||||
|
||||
assert.deepEqual(config.controller.profiles['8BitDo SN30']?.bindings.toggleLookup, {
|
||||
kind: 'button',
|
||||
buttonIndex: 11,
|
||||
});
|
||||
assert.deepEqual(config.controller.profiles['8BitDo SN30']?.bindings.closeLookup, {
|
||||
kind: 'button',
|
||||
buttonIndex: 1,
|
||||
});
|
||||
assert.deepEqual(config.controller.profiles['8BitDo SN30']?.bindings.leftStickVertical, {
|
||||
kind: 'axis',
|
||||
axisIndex: 7,
|
||||
dpadFallback: 'none',
|
||||
});
|
||||
assert.deepEqual(config.controller.profiles['Xbox Wireless Controller']?.bindings.quitMpv, {
|
||||
kind: 'button',
|
||||
buttonIndex: 8,
|
||||
});
|
||||
assert.equal(
|
||||
config.controller.profiles['Xbox Wireless Controller']?.buttonIndices.leftTrigger,
|
||||
8,
|
||||
);
|
||||
assert.deepEqual(config.controller.bindings.quitMpv, { kind: 'button', buttonIndex: 6 });
|
||||
});
|
||||
|
||||
test('rejects reserved controller profile ids from config', () => {
|
||||
const dir = makeTempDir();
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'config.jsonc'),
|
||||
`{
|
||||
"controller": {
|
||||
"profiles": {
|
||||
"__proto__": { "label": "polluted" },
|
||||
"constructor": { "label": "ctor" },
|
||||
"prototype": { "label": "proto" },
|
||||
"pad-1": { "label": "Pad 1" }
|
||||
}
|
||||
}
|
||||
}`,
|
||||
'utf-8',
|
||||
);
|
||||
|
||||
const service = new ConfigService(dir);
|
||||
const config = service.getConfig();
|
||||
const warnings = service.getWarnings();
|
||||
|
||||
assert.equal(Object.hasOwn(config.controller.profiles, '__proto__'), false);
|
||||
assert.equal(Object.hasOwn(config.controller.profiles, 'constructor'), false);
|
||||
assert.equal(Object.hasOwn(config.controller.profiles, 'prototype'), false);
|
||||
assert.equal(config.controller.profiles['pad-1']?.label, 'Pad 1');
|
||||
assert.equal(
|
||||
warnings.some((warning) => warning.path === 'controller.profiles.constructor'),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
warnings.some((warning) => warning.path === 'controller.profiles.prototype'),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('controller descriptor config rejects malformed binding objects', () => {
|
||||
const dir = makeTempDir();
|
||||
fs.writeFileSync(
|
||||
|
||||
Reference in New Issue
Block a user