mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-02 17:44:31 +08:00
refactor: 插件注册初步处理
This commit is contained in:
1 parent
483df57fdf
commit
ef9a3d6537
19 files changed
+123
-152
No files matched your search
@@ -2,14 +2,9 @@ import { Animation, circle, hyper, sleep, TimingFn } from 'mutate-animate';
|
||||
import { completeAchievement } from '../ui/achievement';
|
||||
import { has } from '../utils';
|
||||
import { ChaseCameraData, ChasePath, getChaseDataByIndex } from './data';
|
||||
import { init1 } from './chase1';
|
||||
|
||||
// todo: 优化,可以继承自EventEmitter
|
||||
|
||||
export default function init() {
|
||||
return { startChase, chaseInit1: init1 };
|
||||
}
|
||||
|
||||
export function shake2(power: number, timing: TimingFn): TimingFn {
|
||||
let r = 0;
|
||||
return t => {
|
||||
|
||||
@@ -6,10 +6,6 @@ import {
|
||||
import { changeLocalStorage } from './utils';
|
||||
import list from '../data/achievement.json';
|
||||
|
||||
export default function init() {
|
||||
return { getChapterCompletion, checkVisitedFloor };
|
||||
}
|
||||
|
||||
export const floors: Record<number, FloorIds[]> = {
|
||||
1: ['MT0', 'tower7']
|
||||
};
|
||||
|
||||
+33
-3
@@ -1,4 +1,5 @@
|
||||
import { Animation, linear, sleep } from 'mutate-animate';
|
||||
import { has } from '../utils';
|
||||
|
||||
interface SplittedImage {
|
||||
canvas: HTMLCanvasElement;
|
||||
@@ -23,15 +24,44 @@ const MAX_ROTATE = 0.5;
|
||||
/** 碎裂动画的速率曲线函数 */
|
||||
const FRAG_TIMING = linear();
|
||||
|
||||
export default function init() {
|
||||
return { applyFragWith };
|
||||
export function init() {
|
||||
Mota.rewrite(core.events, 'afterBattle', 'add', (_, enemy, x, y) => {
|
||||
// 打怪特效
|
||||
if (core.getLocalStorage('frag') && has(x) && has(y)) {
|
||||
const frame = core.status.globalAnimateStatus % 2;
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 32;
|
||||
canvas.height = 32;
|
||||
core.drawIcon(canvas, enemy.id, 0, 0, 32, 32, frame);
|
||||
const manager = applyFragWith(canvas);
|
||||
const frag = manager.canvas;
|
||||
frag.style.imageRendering = 'pixelated';
|
||||
frag.style.width = `${frag.width * core.domStyle.scale}px`;
|
||||
frag.style.height = `${frag.height * core.domStyle.scale}px`;
|
||||
const left =
|
||||
(x * 32 + 16 - frag.width / 2 - core.bigmap.offsetX) *
|
||||
core.domStyle.scale;
|
||||
const top =
|
||||
(y * 32 + 16 - frag.height / 2 - core.bigmap.offsetY) *
|
||||
core.domStyle.scale;
|
||||
frag.style.left = `${left}px`;
|
||||
frag.style.top = `${top}px`;
|
||||
frag.style.zIndex = '45';
|
||||
frag.style.position = 'absolute';
|
||||
frag.style.filter = 'sepia(20%)brightness(120%)';
|
||||
core.dom.gameDraw.appendChild(frag);
|
||||
manager.onEnd.then(() => {
|
||||
frag.remove();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function applyFragWith(
|
||||
canvas: HTMLCanvasElement,
|
||||
length: number = 4,
|
||||
time: number = 1000,
|
||||
config: any = {}
|
||||
config: any = {} // todo: 类型标注
|
||||
) {
|
||||
// 先切分图片
|
||||
const imgs = splitCanvas(canvas, length);
|
||||
|
||||
@@ -167,35 +167,6 @@ core.events.afterBattle = function (
|
||||
// 如果已有事件正在处理中
|
||||
if (core.status.event.id == null) core.continueAutomaticRoute();
|
||||
else core.clearContinueAutomaticRoute();
|
||||
|
||||
// 打怪特效
|
||||
if (core.getLocalStorage('frag') && has(x) && has(y)) {
|
||||
const frame = core.status.globalAnimateStatus % 2;
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 32;
|
||||
canvas.height = 32;
|
||||
core.drawIcon(canvas, enemy.id, 0, 0, 32, 32, frame);
|
||||
const manager = mota.plugin.frag.applyFragWith(canvas);
|
||||
const frag = manager.canvas;
|
||||
frag.style.imageRendering = 'pixelated';
|
||||
frag.style.width = `${frag.width * core.domStyle.scale}px`;
|
||||
frag.style.height = `${frag.height * core.domStyle.scale}px`;
|
||||
const left =
|
||||
(x * 32 + 16 - frag.width / 2 - core.bigmap.offsetX) *
|
||||
core.domStyle.scale;
|
||||
const top =
|
||||
(y * 32 + 16 - frag.height / 2 - core.bigmap.offsetY) *
|
||||
core.domStyle.scale;
|
||||
frag.style.left = `${left}px`;
|
||||
frag.style.top = `${top}px`;
|
||||
frag.style.zIndex = '45';
|
||||
frag.style.position = 'absolute';
|
||||
frag.style.filter = 'sepia(20%)brightness(120%)';
|
||||
core.dom.gameDraw.appendChild(frag);
|
||||
manager.onEnd.then(() => {
|
||||
frag.remove();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
core.events._sys_battle = function (data: Block, callback?: () => void) {
|
||||
|
||||
@@ -10,7 +10,7 @@ control.prototype.checkBlock = function (forceMockery: boolean = false) {
|
||||
const damage = info?.damage;
|
||||
if (damage) {
|
||||
if (!main.replayChecking) {
|
||||
mota.plugin.pop.addPop(
|
||||
Mota.Plugin.require('pop').addPop(
|
||||
(x - core.bigmap.offsetX / 32) * 32 + 12,
|
||||
(y - core.bigmap.offsetY / 32) * 32 + 20,
|
||||
(-damage).toString()
|
||||
|
||||
@@ -36,7 +36,7 @@ export function removeMaps(fromId, toId, force) {
|
||||
deleted = true;
|
||||
}
|
||||
if (deleted && !main.replayChecking) {
|
||||
mota.plugin.fly.splitArea();
|
||||
Mota.Plugin.require('fly').splitArea();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -496,7 +496,11 @@ function intelligentArrow(fromSelf) {
|
||||
damaged[loc + direction] = true;
|
||||
core.drawHeroAnimate('hand');
|
||||
core.status.hero.hp -= 1000;
|
||||
mota.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -1000);
|
||||
Mota.Plugin.require('pop').addPop(
|
||||
x * 32 + 16,
|
||||
y * 32 + 16,
|
||||
-1000
|
||||
);
|
||||
core.updateStatusBar();
|
||||
if (core.status.hero.hp < 0) {
|
||||
clearInterval(skill1);
|
||||
@@ -511,7 +515,11 @@ function intelligentArrow(fromSelf) {
|
||||
damaged[loc + direction] = true;
|
||||
core.drawHeroAnimate('hand');
|
||||
core.status.hero.hp -= 1000;
|
||||
mota.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -1000);
|
||||
Mota.Plugin.require('pop').addPop(
|
||||
x * 32 + 16,
|
||||
y * 32 + 16,
|
||||
-1000
|
||||
);
|
||||
core.updateStatusBar();
|
||||
if (core.status.hero.hp < 0) {
|
||||
clearInterval(skill1);
|
||||
@@ -637,7 +645,11 @@ function icyMomentem() {
|
||||
if (x == locs[index][0] && y == locs[index][1]) {
|
||||
core.drawHeroAnimate('hand');
|
||||
core.status.hero.hp -= 5000;
|
||||
mota.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -5000);
|
||||
Mota.Plugin.require('pop').addPop(
|
||||
x * 32 + 16,
|
||||
y * 32 + 16,
|
||||
-5000
|
||||
);
|
||||
core.updateStatusBar();
|
||||
if (core.status.hero.hp < 0) {
|
||||
core.status.hero.hp = 0;
|
||||
@@ -812,7 +824,11 @@ function getThunderDamage(x, y, power) {
|
||||
hy = core.status.hero.loc.y;
|
||||
if (Math.abs(hx - x) <= 1 && Math.abs(hy - y) <= 1) {
|
||||
core.status.hero.hp -= 3000 * power;
|
||||
mota.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -3000 * power);
|
||||
Mota.Plugin.require('pop').addPop(
|
||||
x * 32 + 16,
|
||||
y * 32 + 16,
|
||||
-3000 * power
|
||||
);
|
||||
core.updateStatusBar();
|
||||
if (core.status.hero.hp < 0) {
|
||||
core.status.hero.hp = 0;
|
||||
@@ -976,7 +992,7 @@ function ballThunder() {
|
||||
) {
|
||||
damaged[i] = true;
|
||||
core.status.hero.hp -= 3000;
|
||||
mota.plugin.pop.addPop(
|
||||
Mota.Plugin.require('pop').addPop(
|
||||
x * 32 + 16,
|
||||
y * 32 + 16,
|
||||
-3000
|
||||
@@ -1486,7 +1502,11 @@ function boomingAnimate() {
|
||||
hy = core.status.hero.loc.y;
|
||||
if (loc[0] == hx && loc[1] == hy) {
|
||||
core.status.hero.hp -= 3000;
|
||||
mota.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -3000);
|
||||
Mota.Plugin.require('pop').addPop(
|
||||
x * 32 + 16,
|
||||
y * 32 + 16,
|
||||
-3000
|
||||
);
|
||||
core.updateStatusBar();
|
||||
if (core.status.hero.hp < 0) {
|
||||
core.status.hero.hp = 0;
|
||||
@@ -1525,7 +1545,11 @@ function lineDamage(x1, y1, x2, y2, damage) {
|
||||
n2 = ((y2 - y1) / (x2 - x1)) * (loc2[0] - x1) + y1 - loc2[1];
|
||||
if (n1 * n2 <= 0) {
|
||||
core.status.hero.hp -= damage;
|
||||
mota.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -damage);
|
||||
Mota.Plugin.require('pop').addPop(
|
||||
x * 32 + 16,
|
||||
y * 32 + 16,
|
||||
-damage
|
||||
);
|
||||
core.updateStatusBar();
|
||||
core.playSound('electron.mp3');
|
||||
if (core.status.hero.hp < 0) {
|
||||
@@ -1545,7 +1569,11 @@ function lineDamage(x1, y1, x2, y2, damage) {
|
||||
n2 = ((y2 - y1) / (x2 - x1)) * (loc2[0] - x1) + y1 - loc2[1];
|
||||
if (n1 * n2 <= 0) {
|
||||
core.status.hero.hp -= damage;
|
||||
mota.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -damage);
|
||||
Mota.Plugin.require('pop').addPop(
|
||||
x * 32 + 16,
|
||||
y * 32 + 16,
|
||||
-damage
|
||||
);
|
||||
core.updateStatusBar();
|
||||
core.playSound('electron.mp3');
|
||||
if (core.status.hero.hp < 0) {
|
||||
|
||||
@@ -20,8 +20,8 @@ export {};
|
||||
|
||||
function updateVueStatusBar() {
|
||||
if (main.replayChecking) return;
|
||||
mota.plugin.status.statusBarStatus.value =
|
||||
!mota.plugin.status.statusBarStatus.value;
|
||||
const status = Mota.Plugin.require('status');
|
||||
status.statusBarStatus.value = !status.statusBarStatus.value;
|
||||
}
|
||||
|
||||
ui.prototype.drawBook = function () {
|
||||
|
||||
+2
-6
@@ -5,12 +5,8 @@ let pop: any[] = [];
|
||||
|
||||
let time = 0;
|
||||
|
||||
// 插件必须有默认导出,并返回所有外部会用到的函数,所有返回的函数会被转发到core上
|
||||
// 并且在这里面完成所有的初始化,函数外部也可以进行初始化,但完全不能涉及到样板相关内容
|
||||
export default function init() {
|
||||
export function init() {
|
||||
core.registerAnimationFrame('pop', true, popValue);
|
||||
// 返回值是所有外部可见内容
|
||||
return { addPop, pop };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +49,7 @@ function popValue(t: number) {
|
||||
* @param py 弹出的纵坐标
|
||||
* @param value 弹出的文字
|
||||
*/
|
||||
function addPop(px: number, py: number, value: string) {
|
||||
export function addPop(px: number, py: number, value: string) {
|
||||
var data = {
|
||||
px: px,
|
||||
py: py,
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { hyper, power } from 'mutate-animate';
|
||||
import { Polygon } from './polygon';
|
||||
import {
|
||||
Light,
|
||||
animateLight,
|
||||
getAllLights,
|
||||
moveLight,
|
||||
initShadowCanvas,
|
||||
refreshLight,
|
||||
removeAllLights,
|
||||
setBackground,
|
||||
@@ -13,17 +11,11 @@ import {
|
||||
setShadowNodes
|
||||
} from './shadow';
|
||||
import { pColor } from '../utils';
|
||||
import { drawHeroDetail } from '../game/fx/heroDetail';
|
||||
|
||||
export default function init() {
|
||||
const origin4 = control.prototype.drawHero;
|
||||
control.prototype.drawHero = function () {
|
||||
origin4.apply(core.control, arguments);
|
||||
drawHeroDetail(
|
||||
core.status.heroCenter.px - 16,
|
||||
core.status.heroCenter.py + 20
|
||||
);
|
||||
import { setCanvasFilterByFloorId } from '../fx/gameCanvas';
|
||||
|
||||
export function init() {
|
||||
// 勇士身上的光源
|
||||
Mota.rewrite(core.control, 'drawHero', 'add', () => {
|
||||
if (core.getFlag('__heroOpacity__') !== 0) {
|
||||
getAllLights().forEach(v => {
|
||||
if (!v.followHero) return;
|
||||
@@ -33,9 +25,25 @@ export default function init() {
|
||||
refreshLight();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return { updateShadow, clearShadowCache, setCalShadow };
|
||||
});
|
||||
// 更新地形数据
|
||||
Mota.rewrite(core.maps, 'removeBlock', 'add', success => {
|
||||
if (success && main.replayChecking) updateShadow(true);
|
||||
return success;
|
||||
});
|
||||
Mota.rewrite(core.maps, 'setBlock', 'add', () => {
|
||||
if (main.replayChecking) updateShadow(true);
|
||||
});
|
||||
Mota.rewrite(core.events, 'changingFloor', 'add', (_, floorId) => {
|
||||
if (!main.replayChecking) {
|
||||
updateShadow();
|
||||
setCanvasFilterByFloorId(floorId);
|
||||
}
|
||||
});
|
||||
// 初始化画布信息
|
||||
Mota.rewrite(core.ui, 'deleteAllCanvas', 'add', () => {
|
||||
if (main.mode === 'play' && !main.replayChecking) initShadowCanvas();
|
||||
});
|
||||
}
|
||||
|
||||
const shadowInfo: Partial<Record<FloorIds, Light[]>> = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CurrentEnemy } from '../game/enemy/battle';
|
||||
import type { CurrentEnemy } from '../game/enemy/battle';
|
||||
import { has } from '../utils';
|
||||
|
||||
export interface ToShowEnemy extends CurrentEnemy {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getDamageColor } from '../utils';
|
||||
import { ToShowEnemy } from './book';
|
||||
import { DamageEnemy } from '../game/enemy/damage';
|
||||
import type { DamageEnemy } from '../game/enemy/damage';
|
||||
import { isMobile } from '../use';
|
||||
|
||||
export function getLocFromMouseLoc(x: number, y: number): LocArr {
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { has } from '../utils';
|
||||
|
||||
export default function init() {
|
||||
return { splitArea, getMapDrawData };
|
||||
}
|
||||
|
||||
type BFSFromString = `${FloorIds},${number},${number},${Dir}`;
|
||||
type BFSToString = `${FloorIds},${number},${number}`;
|
||||
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
const status = ref(false);
|
||||
|
||||
export default function init() {
|
||||
return { statusBarStatus: status };
|
||||
}
|
||||
|
||||
export { status };
|
||||
export const status = ref(false);
|
||||
Reference in new issue
Block a user