refactor: 按键系统

This commit is contained in:
AncTe committed 2026-10-22 22:25:59 +08:00
1 parent d5b2a820d8
commit 564f53d82a
15 files changed
+569 -419

No files matched your search

+5 -1
View File
@@ -293,9 +293,13 @@
"200": "Cannot buy or sell item since target item '$1' does not exist.",
"201": "Cannot set hotkey condition or implement command since no scope is active.",
"202": "Cannot implement nonexistent hotkey command '$1'.",
"203": "Hotkey command '$1' has an invalid KeyUp combination: at most one non-auxiliary key is allowed.",
"203": "Hotkey command '$1' has an invalid KeyUp combination: at most one non-auxiliary key is allowed. This command will be never emitted by invalid command.",
"204": "Duplicate hotkey command '$1', the existing command will be used.",
"205": "Cannot leave nonexistent hotkey scope.",
"206": "Cannot set command key combination since delivered index is invalid: expected positive integer, found $1.",
"207": "Key combination count needs to be a positive integer, but got $1.",
"208": "Duplicate hotkey command group name: $1, old one will be overwritten.",
"209": "Cannot load key combinations for hotkey command $1 since no command named it.",
"1001": "Event(setBlock): Unknown tile '$1' when setting block."
}
}
+24
View File
@@ -20,3 +20,27 @@ export function cumsum(seq: Iterable<number>): number[] {
}
return result;
}
/**
* 判断一个数组的所有项,符合的项组成 `match`,不符合的组成 `unmatch`,返回 `[match, unmatch]`
* @param array 要判断的数组
* @param filter 判断函数
* @example matchArray([1, 2, 3, 4], v => v < 2); // [[1], [2, 3, 4]]
*/
export function matchArray<T>(
array: readonly T[],
filter: (v: T, i: number, a: readonly T[]) => boolean
): [match: T[], unmatch: T[]] {
const match: T[] = [];
const unmatch: T[] = [];
array.forEach((v, i, a) => {
if (filter(v, i, a)) {
match.push(v);
} else {
unmatch.push(v);
}
});
return [match, unmatch];
}