Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/hotkeys.js
/** | /** | ||||
* Holds a map of scancode name -> user keyboard name | * Holds a map of scancode name -> user keyboard name | ||||
*/ | */ | ||||
var g_ScancodesMap; | var g_ScancodesMap; | ||||
var g_HotkeyNames = new Map(); | |||||
wraitii: This seems to be used as a dictionary, maybe you could make it a `new Map();` ? | |||||
function hotkeySort(a, b) | function hotkeySort(a, b) | ||||
{ | { | ||||
const specialKeys = ["Shift", "Alt", "Ctrl", "Super"]; | const specialKeys = ["Shift", "Alt", "Ctrl", "Super"]; | ||||
// Quick hack to put those first. | // Quick hack to put those first. | ||||
if (specialKeys.indexOf(a) !== -1) | if (specialKeys.indexOf(a) !== -1) | ||||
a = ' ' + a; | a = ' ' + a; | ||||
if (specialKeys.indexOf(b) !== -1) | if (specialKeys.indexOf(b) !== -1) | ||||
b = ' ' + b; | b = ' ' + b; | ||||
Show All 18 Lines | |||||
{ | { | ||||
if (!combinations || !combinations.length) | if (!combinations || !combinations.length) | ||||
return translateScancodes ? "" : []; | return translateScancodes ? "" : []; | ||||
let combs = combinations.map(x => formatHotkeyCombination(x, translateScancodes)); | let combs = combinations.map(x => formatHotkeyCombination(x, translateScancodes)); | ||||
combs.sort((a, b) => a.length - b.length || a - b); | combs.sort((a, b) => a.length - b.length || a - b); | ||||
return translateScancodes ? combs.join(", ") : combs; | return translateScancodes ? combs.join(", ") : combs; | ||||
} | } | ||||
function getHotkeyFiles() | |||||
{ | |||||
return Engine.ListDirectoryFiles("gui/hotkeys/spec/", "*.json"); | |||||
} | |||||
function getReadableHotkeyName(key) | |||||
Not Done Inline ActionsGetReadableHotkeyName? wraitii: `GetReadableHotkeyName`? | |||||
{ | |||||
if (!g_HotkeyNames.size) | |||||
for (let file of getHotkeyFiles()) | |||||
{ | |||||
let data = Engine.ReadJSONFile(file); | |||||
if (data.mapped_hotkeys) | |||||
for (let cat in data.mapped_hotkeys) | |||||
for (let hotkey in data.mapped_hotkeys[cat]) | |||||
g_HotkeyNames.set(hotkey, data.mapped_hotkeys[cat][hotkey].name); | |||||
} | |||||
return g_HotkeyNames.get(key); | |||||
} |
Wildfire Games · Phabricator
This seems to be used as a dictionary, maybe you could make it a new Map(); ?