mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-19 20:59:37 +08:00
52 lines
1.0 KiB
JavaScript
52 lines
1.0 KiB
JavaScript
|
/**
|
||
|
* 滑动数组
|
||
|
* @param {any[]} arr
|
||
|
* @param {number} delta
|
||
|
*/
|
||
|
function slide(arr, delta) {
|
||
|
if (delta === 0) return arr;
|
||
|
delta %= arr.length;
|
||
|
if (delta > 0) {
|
||
|
arr.unshift(...arr.splice(arr.length - delta, delta));
|
||
|
return arr;
|
||
|
}
|
||
|
if (delta < 0) {
|
||
|
arr.push(...arr.splice(0, -delta));
|
||
|
return arr;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function backDir(dir) {
|
||
|
return {
|
||
|
up: 'down',
|
||
|
down: 'up',
|
||
|
left: 'right',
|
||
|
right: 'left'
|
||
|
}[dir];
|
||
|
}
|
||
|
|
||
|
function has(v) {
|
||
|
return v !== null && v !== void 0;
|
||
|
}
|
||
|
|
||
|
function maxGameScale(n = 0) {
|
||
|
const index = core.domStyle.availableScale.indexOf(core.domStyle.scale);
|
||
|
core.control.setDisplayScale(
|
||
|
core.domStyle.availableScale.length - 1 - index - n
|
||
|
);
|
||
|
if (!core.isPlaying() && core.flags.enableHDCanvas) {
|
||
|
core.domStyle.ratio = Math.max(
|
||
|
window.devicePixelRatio || 1,
|
||
|
core.domStyle.scale
|
||
|
);
|
||
|
core.resize();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
core.plugin.utils = {
|
||
|
slide,
|
||
|
backDir,
|
||
|
has,
|
||
|
maxGameScale
|
||
|
};
|