修改插件加载机制

This commit is contained in:
AncTe committed 2023-08-01 12:22:05 +08:00
1 parent 0604c56e98
commit d2746c4dc5
43 files changed
+527 -490

No files matched your search

+1 -1
View File
@@ -68,7 +68,7 @@ onMounted(async () => {
resize();
await sleep(50);
if (core.plugin.transition.value) await sleep(600);
if (ancTe.plugin.ui.transition.value) await sleep(600);
document.addEventListener('keyup', key);
});
onUpdated(resize);
+40 -14
View File
@@ -1,20 +1,43 @@
import { BgmController } from './audio/bgm';
import { SoundController } from './audio/sound';
import { readyAllResource } from './loader/load';
import { loading, readyAllResource } from './loader/load';
import { ResourceStore, ResourceType } from './loader/resource';
import { resolvePlugin } from './plugin';
declare global {
interface AncTe {
sound: SoundController;
/** 游戏资源 */
resource: ResourceStore<Exclude<ResourceType, 'zip'>>;
zipResource: ResourceStore<'zip'>;
bgm: BgmController;
}
interface Window {
ancTe: AncTe;
}
const ancTe: AncTe;
interface AncTePlugin {
pop: ReturnType<typeof import('../plugin/pop').default>;
ui: ReturnType<typeof import('../plugin/uiController').default>;
use: ReturnType<typeof import('../plugin/use').default>;
animate: ReturnType<typeof import('../plugin/animateController').default>;
utils: ReturnType<typeof import('../plugin/utils').default>;
status: ReturnType<typeof import('../plugin/ui/statusBar').default>;
mark: ReturnType<typeof import('../plugin/mark').default>;
setting: ReturnType<typeof import('../plugin/settings').default>;
chapter: ReturnType<typeof import('../plugin/ui/chapter').default>;
fly: ReturnType<typeof import('../plugin/ui/fly').default>;
chase: ReturnType<typeof import('../plugin/chase/chase').default>;
fixed: ReturnType<typeof import('../plugin/ui/fixed').default>;
webglUtils: ReturnType<typeof import('../plugin/webgl/utils').default>;
shadow: ReturnType<typeof import('../plugin/shadow/shadow').default>;
gameShadow: ReturnType<
typeof import('../plugin/shadow/gameShadow').default
>;
achievement: ReturnType<typeof import('../plugin/ui/achievement').default>;
completion: ReturnType<typeof import('../plugin/completion').default>;
path: ReturnType<typeof import('../plugin/fx/path').default>;
gameCanvas: ReturnType<typeof import('../plugin/fx/gameCanvas').default>;
noise: ReturnType<typeof import('../plugin/fx/noise').default>;
smooth: ReturnType<typeof import('../plugin/fx/smoothView').default>;
frag: ReturnType<typeof import('../plugin/fx/frag').default>;
}
export interface AncTe {
sound: SoundController;
/** 游戏资源 */
resource: ResourceStore<Exclude<ResourceType, 'zip'>>;
zipResource: ResourceStore<'zip'>;
bgm: BgmController;
plugin: AncTePlugin;
}
function ready() {
@@ -22,9 +45,12 @@ function ready() {
bgm: new BgmController(),
resource: new ResourceStore(),
zipResource: new ResourceStore(),
sound: new SoundController()
sound: new SoundController(),
// @ts-ignore
plugin: {}
};
readyAllResource();
loading.once('coreInit', resolvePlugin);
}
ready();
+1 -2
View File
@@ -1,5 +1,4 @@
import resource from '../../data/resource.json';
import { has } from '../../plugin/utils';
import { EmitableEvent, EventEmitter } from '../common/eventEmitter';
import { Resource, getTypeByResource } from './resource';
@@ -118,7 +117,7 @@ export const loading = new GameLoading();
declare global {
interface Main {
loading: EventEmitter<GameLoadEvent>;
loading: GameLoading;
}
}
main.loading = loading;
+62
View File
@@ -0,0 +1,62 @@
import pop from '../plugin/pop';
import ui from '../plugin/uiController';
import use from '../plugin/use';
import animate from '../plugin/animateController';
import utils from '../plugin/utils';
import status from '../plugin/ui/statusBar';
import mark from '../plugin/mark';
import setting from '../plugin/settings';
import chapter from '../plugin/ui/chapter';
import fly from '../plugin/ui/fly';
import chase from '../plugin/chase/chase';
import fixed from '../plugin/ui/fixed';
import webglUtils from '../plugin/webgl/utils';
import shadow from '../plugin/shadow/shadow';
import gameShadow from '../plugin/shadow/gameShadow';
import achievement from '../plugin/ui/achievement';
import completion, { floors } from '../plugin/completion';
import path from '../plugin/fx/path';
import gameCanvas from '../plugin/fx/gameCanvas';
import noise from '../plugin/fx/noise';
import smooth from '../plugin/fx/smoothView';
import frag from '../plugin/fx/frag';
import { AncTe } from '.';
export function resolvePlugin() {
const toForward: [keyof AncTe['plugin'], any][] = [
['pop', pop()],
['ui', ui()],
['use', use()],
['animate', animate()],
['utils', utils()],
['status', status()],
['mark', mark()],
['setting', setting()],
['chapter', chapter()],
['fly', fly()],
['chase', chase()],
['fixed', fixed()],
['webglUtils', webglUtils()],
['shadow', shadow()],
['gameShadow', gameShadow()],
['achievement', achievement()],
['completion', completion()],
['path', path()],
['gameCanvas', gameCanvas()],
['noise', noise()],
['smooth', smooth()],
['frag', frag()]
];
for (const [key, obj] of toForward) {
ancTe.plugin[key] = obj;
}
// 完成度相关
Object.values(floors).forEach((v, i) => {
const from = core.floorIds.indexOf(v[0]);
const to = core.floorIds.indexOf(v[1]);
const all = core.floorIds.slice(from, to + 1);
floors[i + 1] = all;
});
}
+2 -2
View File
@@ -37,7 +37,7 @@
"text": [
"第一章完成度达到100%"
],
"progress": "${core.getChapterCompletion(1)} / 100",
"progress": "${ancTe.plugin.completion.getChapterCompletion(1)} / 100",
"percent": true,
"point": 50
},
@@ -55,7 +55,7 @@
"text": [
"第二章完成度达到100%"
],
"progress": "${core.getChapterCompletion(2)} / 100",
"progress": "${ancTe.plugin.completion.getChapterCompletion(2)} / 100",
"percent": true,
"point": 50
},
-78
View File
@@ -1,78 +0,0 @@
import pop from './plugin/pop';
import ui from './plugin/uiController';
import use from './plugin/use';
import animate from './plugin/animateController';
import utils from './plugin/utils';
import status from './plugin/ui/statusBar';
import mark from './plugin/mark';
import setting from './plugin/settings';
import chapter from './plugin/ui/chapter';
import fly from './plugin/ui/fly';
import chase from './plugin/chase/chase';
import fixed from './plugin/ui/fixed';
import webglUtils from './plugin/webgl/utils';
import shadow from './plugin/shadow/shadow';
import gameShadow from './plugin/shadow/gameShadow';
import achievement from './plugin/ui/achievement';
import completion, { floors } from './plugin/completion';
import path from './plugin/fx/path';
import gameCanvas from './plugin/fx/gameCanvas';
import noise from './plugin/fx/noise';
import smooth from './plugin/fx/smoothView';
import frag from './plugin/fx/frag';
function forward() {
const toForward: any[] = [
pop(),
ui(),
use(),
animate(),
utils(),
status(),
mark(),
setting(),
chapter(),
fly(),
chase(),
fixed(),
webglUtils(),
shadow(),
gameShadow(),
achievement(),
completion(),
path(),
gameCanvas(),
noise(),
smooth(),
frag()
];
// 初始化所有插件,并转发到core上
for (const data of toForward) {
for (const name in data) {
const d = data[name as keyof typeof data];
if (!(name in core.plugin)) {
// @ts-ignore
core.plugin[name as keyof PluginDeclaration] = d;
}
if (!(d instanceof Function)) continue;
if (name in core) continue;
if (name.startsWith('_')) continue;
// @ts-ignore
core[name as ForwardKeys<PluginDeclaration>] = d;
}
}
console.log('插件转发完成!');
Object.values(floors).forEach((v, i) => {
const from = core.floorIds.indexOf(v[0]);
const to = core.floorIds.indexOf(v[1]);
const all = core.floorIds.slice(from, to + 1);
floors[i + 1] = all;
});
}
main.forward = forward;
main.init('play');
main.listen();
+3 -1
View File
@@ -3,8 +3,10 @@ import App from './App.vue';
import App2 from './App2.vue';
import './styles.less';
import 'ant-design-vue/dist/antd.dark.css';
import './initPlugin';
import './core/index';
createApp(App).mount('#root');
createApp(App2).mount('#root2');
main.init('play');
main.listen();
+1 -1
View File
@@ -191,7 +191,7 @@ core.events.afterBattle = function (
canvas.width = 32;
canvas.height = 32;
core.drawIcon(canvas, enemy.id, 0, 0, 32, 32, frame);
const manager = core.applyFragWith(canvas);
const manager = ancTe.plugin.frag.applyFragWith(canvas);
const frag = manager.canvas;
frag.style.imageRendering = 'pixelated';
frag.style.width = `${frag.width * core.domStyle.scale}px`;
+1 -1
View File
@@ -10,7 +10,7 @@ control.prototype.checkBlock = function (forceMockery: boolean = false) {
const damage = info?.damage;
if (damage) {
if (!main.replayChecking) {
core.addPop(
ancTe.plugin.pop.addPop(
(x - core.bigmap.offsetX / 32) * 32 + 12,
(y - core.bigmap.offsetY / 32) * 32 + 20,
(-damage).toString()
+1 -1
View File
@@ -36,7 +36,7 @@ export function removeMaps(fromId, toId, force) {
deleted = true;
}
if (deleted && !main.replayChecking) {
core.splitArea();
ancTe.plugin.fly.splitArea();
}
}
+1 -1
View File
@@ -227,7 +227,7 @@ export function getSkillConsume(skill) {
export function openTree() {
if (main.replayChecking) return;
core.plugin.skillTreeOpened.value = true;
ancTe.plugin.ui.skillTreeOpened.value = true;
}
/**
+1 -1
View File
@@ -27,7 +27,7 @@ export function studySkill(enemy: any, number: number) {
if (special instanceof Function) special = special(enemy);
if (!canStudySkill(number)) {
if (!main.replayChecking) {
core.tip('error', `无法学习${special}`);
ancTe.plugin.utils.tip('error', `无法学习${special}`);
}
return;
}
+20 -8
View File
@@ -496,7 +496,11 @@ function intelligentArrow(fromSelf) {
damaged[loc + direction] = true;
core.drawHeroAnimate('hand');
core.status.hero.hp -= 1000;
core.addPop(x * 32 + 16, y * 32 + 16, -1000);
ancTe.plugin.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;
core.addPop(x * 32 + 16, y * 32 + 16, -1000);
ancTe.plugin.pop.addPop(
x * 32 + 16,
y * 32 + 16,
-1000
);
core.updateStatusBar();
if (core.status.hero.hp < 0) {
clearInterval(skill1);
@@ -637,7 +645,7 @@ function icyMomentem() {
if (x == locs[index][0] && y == locs[index][1]) {
core.drawHeroAnimate('hand');
core.status.hero.hp -= 5000;
core.addPop(x * 32 + 16, y * 32 + 16, -5000);
ancTe.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -5000);
core.updateStatusBar();
if (core.status.hero.hp < 0) {
core.status.hero.hp = 0;
@@ -812,7 +820,7 @@ 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;
core.addPop(x * 32 + 16, y * 32 + 16, -3000 * power);
ancTe.plugin.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 +984,11 @@ function ballThunder() {
) {
damaged[i] = true;
core.status.hero.hp -= 3000;
core.addPop(x * 32 + 16, y * 32 + 16, -3000);
ancTe.plugin.pop.addPop(
x * 32 + 16,
y * 32 + 16,
-3000
);
core.updateStatusBar();
core.playSound('electron.mp3');
if (core.status.hero.hp < 0) {
@@ -1482,7 +1494,7 @@ function boomingAnimate() {
hy = core.status.hero.loc.y;
if (loc[0] == hx && loc[1] == hy) {
core.status.hero.hp -= 3000;
core.addPop(x * 32 + 16, y * 32 + 16, -3000);
ancTe.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -3000);
core.updateStatusBar();
if (core.status.hero.hp < 0) {
core.status.hero.hp = 0;
@@ -1521,7 +1533,7 @@ 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;
core.addPop(x * 32 + 16, y * 32 + 16, -damage);
ancTe.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -damage);
core.updateStatusBar();
core.playSound('electron.mp3');
if (core.status.hero.hp < 0) {
@@ -1541,7 +1553,7 @@ 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;
core.addPop(x * 32 + 16, y * 32 + 16, -damage);
ancTe.plugin.pop.addPop(x * 32 + 16, y * 32 + 16, -damage);
core.updateStatusBar();
core.playSound('electron.mp3');
if (core.status.hero.hp < 0) {
+15 -11
View File
@@ -12,30 +12,34 @@ export {};
function openItemShop(itemShopId) {
if (!core.isReplaying()) {
core.plugin.openedShopId = itemShopId;
core.plugin.shopOpened.value = true;
ancTe.plugin.ui.shopOpened.value = true;
}
}
function updateVueStatusBar() {
if (main.replayChecking) return;
core.plugin.statusBarStatus.value = !core.plugin.statusBarStatus.value;
core.checkMarkedEnemy();
ancTe.plugin.mark.checkMarkedEnemy();
}
ui.prototype.drawBook = function () {
if (!core.isReplaying()) return (core.plugin.bookOpened.value = true);
if (!core.isReplaying())
return (ancTe.plugin.ui.bookOpened.value = true);
};
ui.prototype._drawToolbox = function () {
if (!core.isReplaying()) return (core.plugin.toolOpened.value = true);
if (!core.isReplaying())
return (ancTe.plugin.ui.toolOpened.value = true);
};
ui.prototype._drawEquipbox = function () {
if (!core.isReplaying()) return (core.plugin.equipOpened.value = true);
if (!core.isReplaying())
return (ancTe.plugin.ui.equipOpened.value = true);
};
ui.prototype.drawFly = function () {
if (!core.isReplaying()) return (core.plugin.flyOpened.value = true);
if (!core.isReplaying())
return (ancTe.plugin.ui.flyOpened.value = true);
};
control.prototype.updateStatusBar_update = function () {
@@ -53,7 +57,7 @@ export {};
control.prototype.showStatusBar = function () {
if (main.mode == 'editor') return;
core.removeFlag('hideStatusBar');
core.plugin.showStatusBar.value = true;
ancTe.plugin.ui.showStatusBar.value = true;
core.dom.tools.hard.style.display = 'block';
core.dom.toolBar.style.display = 'block';
};
@@ -64,7 +68,7 @@ export {};
// 如果原本就是隐藏的,则先显示
if (!core.domStyle.showStatusBar) this.showStatusBar();
if (core.isReplaying()) showToolbox = true;
core.plugin.showStatusBar.value = false;
ancTe.plugin.ui.showStatusBar.value = false;
var toolItems = core.dom.tools;
core.setFlag('hideStatusBar', true);
@@ -83,13 +87,13 @@ export {};
function showChapter(chapter) {
if (core.isReplaying()) return;
core.plugin.chapterContent.value = chapter;
core.plugin.chapterShowed.value = true;
ancTe.plugin.chapter.chapterContent.value = chapter;
ancTe.plugin.chapter.chapterShowed.value = true;
}
function openSkill() {
if (core.isReplaying()) return;
core.plugin.skillOpened.value = true;
ancTe.plugin.ui.skillOpened.value = true;
}
core.plugin.gameUi = {
+2 -2
View File
@@ -33,7 +33,7 @@ export const antiAliasing = ref(true);
export const fullscreen = ref(false);
watch(transition, n => {
core.plugin.transition.value = n;
ancTe.plugin.ui.transition.value = n;
core.setLocalStorage('transition', n);
});
@@ -88,7 +88,7 @@ watch(antiAliasing, n => {
function reset() {
const t = core.getLocalStorage('transition', false);
transition.value = t;
core.plugin.transition.value = transition.value;
ancTe.plugin.ui.transition.value = transition.value;
autoScale.value = core.getLocalStorage('autoScale', true);
showStudied.value = core.getLocalStorage('showStudied', true);
showHalo.value = core.getLocalStorage('showHalo', true);
+3 -10
View File
@@ -13,6 +13,8 @@ import Shop from '../ui/shop.vue';
import Achievement from '../ui/achievement.vue';
import Bgm from '../ui/bgmList.vue';
// todo: 优化开启控制器
export const bookOpened = ref(false);
export const toolOpened = ref(false);
export const equipOpened = ref(false);
@@ -25,23 +27,15 @@ export const flyOpened = ref(false);
export const showStudiedSkill = ref(false);
export const fixedDetailOpened = ref(false);
export const shopOpened = ref(false);
export const startOpened = ref(false);
export const startOpened = ref(true);
export const achievementOpened = ref(false);
export const bgmOpened = ref(false);
export const transition = ref(true);
export const noClosePanel = ref(false);
export const loaded = ref(false);
export const startAnimationEnded = ref(false);
watch(loaded, n => {
if (n && startAnimationEnded.value) startOpened.value = true;
});
watch(startAnimationEnded, n => {
if (n && loaded.value) startOpened.value = true;
});
let app: HTMLDivElement;
/** ui声明列表 */
@@ -98,7 +92,6 @@ export default function init() {
shopOpened,
startOpened,
startAnimationEnded,
loaded,
achievementOpened,
bgmOpened
};
+5
View File
@@ -475,3 +475,8 @@ type Forward<T> = {
};
type ForwardKeys<T> = keyof Forward<T>;
declare const ancTe: import('../core/index').AncTe;
interface Window {
ancTe: import('../core/index').AncTe;
}
+1 -1
View File
@@ -51,7 +51,7 @@ const content = computed(() => {
const name = computed(() => list[selected.value]!.name);
function exit() {
core.plugin.bgmOpened.value = false;
ancTe.plugin.ui.bgmOpened.value = false;
}
function select(id: BgmIds) {
+3 -3
View File
@@ -166,8 +166,8 @@ async function show() {
*/
async function exit() {
noClosePanel.value = true;
core.plugin.bookOpened.value = false;
if (core.plugin.transition.value) await sleep(650);
ancTe.plugin.ui.bookOpened.value = false;
if (ancTe.plugin.ui.transition.value) await sleep(650);
else await sleep(100);
if (core.events.recoverEvents(core.status.event.interval)) {
return;
@@ -244,7 +244,7 @@ function keydown(e: KeyboardEvent) {
}
onMounted(async () => {
if (core.plugin.transition.value) await sleep(600);
if (ancTe.plugin.ui.transition.value) await sleep(600);
else await sleep(50);
document.addEventListener('keyup', keyup);
document.addEventListener('keydown', keydown);
+1 -1
View File
@@ -28,7 +28,7 @@ type DescKey = keyof typeof desc;
const selected = ref(Object.keys(desc)[0] as DescKey);
function exit() {
core.plugin.descOpened.value = false;
ancTe.plugin.ui.descOpened.value = false;
}
const content = computed(() => {
+6 -6
View File
@@ -311,7 +311,7 @@ function changeSort() {
}
function exit() {
core.plugin.equipOpened.value = false;
ancTe.plugin.ui.equipOpened.value = false;
}
function clickList(i: number) {
@@ -429,12 +429,12 @@ function dragout(e: Event) {
}
async function toTool() {
const before = core.plugin.transition.value;
core.plugin.transition.value = false;
const before = ancTe.plugin.ui.transition.value;
ancTe.plugin.ui.transition.value = false;
exit();
await sleep(50);
core.plugin.toolOpened.value = true;
core.plugin.transition.value = before;
ancTe.plugin.ui.toolOpened.value = true;
ancTe.plugin.ui.transition.value = before;
}
function keyup(e: KeyboardEvent) {
@@ -455,7 +455,7 @@ watch(toShow, n => {
onMounted(async () => {
bind();
if (core.plugin.transition.value) await sleep(600);
if (ancTe.plugin.ui.transition.value) await sleep(600);
else await sleep(50);
document.addEventListener('keyup', keyup);
});
+1 -1
View File
@@ -84,7 +84,7 @@ async function calHeight() {
vw = window.innerWidth;
width.value = vh * 0.28;
await new Promise(res => requestAnimationFrame(res));
if (core.plugin.fixedDetailOpened.value) {
if (ancTe.plugin.ui.fixedDetailOpened.value) {
showFixed.value = false;
}
updateMain();
+1 -1
View File
@@ -30,7 +30,7 @@ if (e && core.getClsFromId(e)?.startsWith('enemy')) {
}
function close() {
core.plugin.fixedDetailOpened.value = false;
ancTe.plugin.ui.fixedDetailOpened.value = false;
}
</script>
+2 -2
View File
@@ -147,7 +147,7 @@ let thumbCtx: CanvasRenderingContext2D;
let downloadMode = false;
function exit() {
core.plugin.flyOpened.value = false;
ancTe.plugin.ui.flyOpened.value = false;
}
const title = computed(() => {
@@ -610,7 +610,7 @@ onMounted(async () => {
});
await sleep(50);
if (core.plugin.transition.value) await sleep(600);
if (ancTe.plugin.ui.transition.value) await sleep(600);
document.addEventListener('keyup', keyup);
map.addEventListener('touchstart', touchdown);
+1 -1
View File
@@ -137,7 +137,7 @@ const settings: Record<keyof Settings, Ref<boolean>> = {
const ignore: (keyof Settings)[] = ['fullscreen'];
function exit() {
core.plugin.settingsOpened.value = false;
ancTe.plugin.ui.settingsOpened.value = false;
}
function click(id: keyof Settings) {
+2 -2
View File
@@ -303,12 +303,12 @@ function keydown(e: KeyboardEvent) {
function exit() {
if (bought) core.status.route.push('closeShop');
core.plugin.shopOpened.value = false;
ancTe.plugin.ui.shopOpened.value = false;
}
onMounted(async () => {
await sleep(50);
if (core.plugin.transition.value) await sleep(600);
if (ancTe.plugin.ui.transition.value) await sleep(600);
document.addEventListener('keyup', keyup);
document.addEventListener('keydown', keydown);
core.status.route.push(`openShop:${id}`);
+1 -1
View File
@@ -60,7 +60,7 @@ const content = computed(() => {
});
function exit() {
core.plugin.skillOpened.value = false;
ancTe.plugin.ui.skillOpened.value = false;
}
</script>
+2 -2
View File
@@ -173,7 +173,7 @@ const level = computed(() => {
});
function exit() {
core.plugin.skillTreeOpened.value = false;
ancTe.plugin.ui.skillTreeOpened.value = false;
}
function resize() {
@@ -274,7 +274,7 @@ onMounted(async () => {
draw();
await sleep(50);
if (core.plugin.transition.value) await sleep(600);
if (ancTe.plugin.ui.transition.value) await sleep(600);
canvas.addEventListener('click', click);
document.addEventListener('keyup', key);
});
+20 -18
View File
@@ -69,6 +69,7 @@ import { doByInterval, keycode } from '../plugin/utils';
import { KeyCode } from '../plugin/keyCodes';
import { achievementOpened } from '../plugin/uiController';
import { triggerFullscreen } from '../plugin/settings';
import { loading } from '../core/loader/load';
let startdiv: HTMLDivElement;
let start: HTMLDivElement;
@@ -96,6 +97,7 @@ const toshow = reactive<string[]>([]);
const selected = ref('start-game');
function resize() {
if (!window.core) return;
const scale = core.domStyle.scale;
const h = core._PY_;
const height = h * scale;
@@ -290,34 +292,34 @@ async function setButtonAnimate() {
onMounted(async () => {
cursor = document.getElementById('cursor')!;
played = core.getLocalStorage('oneweek1', false);
startdiv = document.getElementById('start-div') as HTMLDivElement;
main = document.getElementById('start-main') as HTMLDivElement;
start = document.getElementById('start') as HTMLDivElement;
background = document.getElementById('background') as HTMLImageElement;
core.registerResize('start', resize);
resize();
loading.once('coreInit', async () => {
window.addEventListener('resize', resize);
resize();
soundChecked.value = core.musicStatus.bgmStatus;
soundChecked.value = core.musicStatus.bgmStatus;
await sleep(50);
document.addEventListener('keydown', keydown);
document.addEventListener('keyup', keyup);
start.style.opacity = '1';
if (played) {
text.value = text2;
hard.splice(1, 0, '挑战');
}
setButtonAnimate().then(() => (showed.value = true));
await sleep(1000);
showCursor();
await sleep(1200);
core.dom.startPanel.style.display = 'none';
await sleep(50);
document.addEventListener('keydown', keydown);
document.addEventListener('keyup', keyup);
start.style.opacity = '1';
if (played) {
text.value = text2;
hard.splice(1, 0, '挑战');
}
setButtonAnimate().then(() => (showed.value = true));
await sleep(1000);
showCursor();
await sleep(1200);
});
});
onUnmounted(() => {
core.unregisterResize('start');
window.removeEventListener('resize', resize);
document.removeEventListener('keydown', keydown);
document.removeEventListener('keyup', keyup);
});
+9 -9
View File
@@ -165,19 +165,19 @@ async function select(id: ShowItemIds, nouse: boolean = false) {
}
function exit() {
core.plugin.toolOpened.value = false;
ancTe.plugin.ui.toolOpened.value = false;
}
async function use(id: ShowItemIds) {
if (id === 'none') return;
if (core.canUseItem(id)) {
// 应该暂时把动画去掉
const before = core.plugin.transition.value;
core.plugin.transition.value = false;
const before = ancTe.plugin.ui.transition.value;
ancTe.plugin.ui.transition.value = false;
exit();
await sleep(50);
core.useItem(id);
core.plugin.transition.value = before;
ancTe.plugin.ui.transition.value = before;
} else {
message.warn({
content: '当前无法使用该道具!',
@@ -187,12 +187,12 @@ async function use(id: ShowItemIds) {
}
async function toEquip() {
const before = core.plugin.transition.value;
core.plugin.transition.value = false;
const before = ancTe.plugin.ui.transition.value;
ancTe.plugin.ui.transition.value = false;
exit();
await sleep(50);
core.plugin.equipOpened.value = true;
core.plugin.transition.value = before;
ancTe.plugin.ui.equipOpened.value = true;
ancTe.plugin.ui.transition.value = before;
}
function keyup(e: KeyboardEvent) {
@@ -239,7 +239,7 @@ function keydown(e: KeyboardEvent) {
}
onMounted(async () => {
if (core.plugin.transition.value) await sleep(600);
if (ancTe.plugin.ui.transition.value) await sleep(600);
else await sleep(50);
document.addEventListener('keyup', keyup);
document.addEventListener('keydown', keydown);