怪物手册初步

This commit is contained in:
AncTe committed 2022-11-16 23:01:23 +08:00
1 parent da771dae91
commit 8517dbdabf
34 files changed
+5179 -1858

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
const animation: ((time: number) => void)[] = [];
let animateTime = 0;
export default function init() {
core.registerAnimationFrame('animate', true, time => {
if (time - animateTime <= core.values.animateSpeed) return;
for (const fn of animation) {
fn(time);
}
animateTime = core.animateFrame.animateTime;
});
return { addAnimate, removeAnimate };
}
/**
* 添加一个动画
* @param fn 要添加的函数
*/
export function addAnimate(fn: (time: number) => void) {
animation.push(fn);
}
/**
* 移除一个动画
* @param fn 要移除的函数
*/
export function removeAnimate(fn: (time: number) => void) {
const index = animation.findIndex(v => v === fn);
if (index === -1)
throw new ReferenceError('No such function in animation.');
}
+6 -1
View File
@@ -1,5 +1,5 @@
export default function init() {
return { useDrag, useWheel };
return { useDrag, useWheel, isMobile };
}
/**
@@ -55,3 +55,8 @@ export function useWheel(
fn(e.deltaX, e.deltaY, e.deltaZ, e);
});
}
/**
* 是否是移动设备
*/
export const isMobile = matchMedia('(max-width: 600px)').matches;
+27
View File
@@ -0,0 +1,27 @@
import { isNil } from 'lodash';
export default function init() {
return { has, getDamageColor };
}
/**
* 判定一个值是否不是undefined或null
* @param value 要判断的值
*/
export function has<T>(value: T): value is NonNullable<T> {
return !isNil(value);
}
/**
* 根据伤害大小获取颜色
* @param damage 伤害大小
*/
export function getDamageColor(damage: number): string {
if (typeof damage !== 'number') return '#f00';
if (damage === 0) return '#2f2';
if (damage < 0) return '#7f7';
if (damage < core.status.hero.hp / 3) return '#fff';
if (damage < (core.status.hero.hp * 2) / 3) return '#ff4';
if (damage < core.status.hero.hp) return '#f22';
return '#f00';
}