2023-02-28 18:21:29 +08:00
|
|
|
///<reference path="../../../src/types/core.d.ts" />
|
2023-02-28 17:49:34 +08:00
|
|
|
|
2023-04-16 17:05:47 +08:00
|
|
|
/**
|
|
|
|
* 滑动数组
|
|
|
|
* @param {any[]} arr
|
|
|
|
* @param {number} delta
|
|
|
|
*/
|
|
|
|
export 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;
|
2023-02-27 20:39:59 +08:00
|
|
|
}
|
2023-04-16 17:05:47 +08:00
|
|
|
if (delta < 0) {
|
|
|
|
arr.push(...arr.splice(0, -delta));
|
|
|
|
return arr;
|
2023-02-28 17:49:34 +08:00
|
|
|
}
|
2023-04-16 17:05:47 +08:00
|
|
|
}
|
2023-02-27 20:39:59 +08:00
|
|
|
|
2023-04-16 17:05:47 +08:00
|
|
|
export function backDir(dir) {
|
|
|
|
return {
|
|
|
|
up: 'down',
|
|
|
|
down: 'up',
|
|
|
|
left: 'right',
|
|
|
|
right: 'left'
|
|
|
|
}[dir];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function has(v) {
|
|
|
|
return v !== null && v !== void 0;
|
|
|
|
}
|
2023-02-27 20:39:59 +08:00
|
|
|
|
2023-04-16 17:05:47 +08:00
|
|
|
export 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
|
2023-02-27 20:39:59 +08:00
|
|
|
);
|
2023-04-16 17:05:47 +08:00
|
|
|
core.resize();
|
2023-02-27 20:39:59 +08:00
|
|
|
}
|
2023-04-16 17:05:47 +08:00
|
|
|
}
|
2023-02-27 20:39:59 +08:00
|
|
|
|
2023-04-16 17:05:47 +08:00
|
|
|
core.plugin.utils = {
|
|
|
|
slide,
|
|
|
|
backDir,
|
|
|
|
has,
|
|
|
|
maxGameScale
|
|
|
|
};
|
2023-04-25 20:50:23 +08:00
|
|
|
core.has = has;
|