-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmodifier.js
More file actions
53 lines (49 loc) · 1.51 KB
/
Copy pathmodifier.js
File metadata and controls
53 lines (49 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
export const SEND = 'Ctrl';
export const BRING = 'Shift';
export const STASHCOPY = 'Shift';
const EVENT_KEYS = {
ctrlKey: SEND,
shiftKey: BRING,
}
const MODIFIABLE_ACTIONS_TABLE = {
switch: { [SEND]: 'send', [BRING]: 'bring' },
new: { [SEND]: 'kick', [BRING]: 'pop' },
newnormal: { [SEND]: 'kicknormal', [BRING]: 'popnormal' },
newprivate: { [SEND]: 'kickprivate', [BRING]: 'popprivate' },
bring: { [SEND]: 'send' },
pop: { [SEND]: 'kick' },
popnormal: { [SEND]: 'kicknormal' },
popprivate: { [SEND]: 'kickprivate' },
send: { [BRING]: 'bring' },
kick: { [BRING]: 'pop' },
kicknormal: { [BRING]: 'popnormal' },
kickprivate: { [BRING]: 'popprivate' },
}
/**
* @param {Event} event
* @returns {string[]}
*/
export function get(event) {
const modifiers = [];
for (const key in EVENT_KEYS)
if (event[key])
modifiers.push(EVENT_KEYS[key]);
return modifiers;
}
/**
* Change an action to another based on given event or array of modifiers.
* @param {string} action
* @param {string[]} modifiers
* @returns {string}
*/
export function modify(action, modifiers) {
if (!modifiers.length)
return action;
const modifiedActionDict = MODIFIABLE_ACTIONS_TABLE[action];
if (!modifiedActionDict)
return action;
for (const modifier in modifiedActionDict)
if (modifiers.includes(modifier))
return modifiedActionDict[modifier];
return action;
}