diff --git a/public/main.js b/public/main.js index b29017d..0758cc0 100644 --- a/public/main.js +++ b/public/main.js @@ -411,7 +411,7 @@ main.prototype.loadAsync = async function (mode, callback) { main.core = core; // 自动放缩最大化 - let auto = core.getLocalStorage('autoScale'); + let auto = Mota.require('var', 'mainSetting').getValue('autoSclae'); if (auto && !core.domStyle.isVertical) { try { @@ -801,74 +801,74 @@ main.prototype.listen = function () { }; ////// 手机端的按钮1-7 ////// - main.statusBar.image.btn1.onclick = function (e) { - e.stopPropagation(); - core.onkeyUp({ - keyCode: 49, - altKey: core.getLocalStorage('altKey') - }); - }; + // main.statusBar.image.btn1.onclick = function (e) { + // e.stopPropagation(); + // core.onkeyUp({ + // keyCode: 49, + // altKey: core.getLocalStorage('altKey') + // }); + // }; - main.statusBar.image.btn2.onclick = function (e) { - e.stopPropagation(); - core.onkeyUp({ - keyCode: 50, - altKey: core.getLocalStorage('altKey') - }); - }; + // main.statusBar.image.btn2.onclick = function (e) { + // e.stopPropagation(); + // core.onkeyUp({ + // keyCode: 50, + // altKey: core.getLocalStorage('altKey') + // }); + // }; - main.statusBar.image.btn3.onclick = function (e) { - e.stopPropagation(); - core.onkeyUp({ - keyCode: 51, - altKey: core.getLocalStorage('altKey') - }); - }; + // main.statusBar.image.btn3.onclick = function (e) { + // e.stopPropagation(); + // core.onkeyUp({ + // keyCode: 51, + // altKey: core.getLocalStorage('altKey') + // }); + // }; - main.statusBar.image.btn4.onclick = function (e) { - e.stopPropagation(); - core.onkeyUp({ - keyCode: 52, - altKey: core.getLocalStorage('altKey') - }); - }; + // main.statusBar.image.btn4.onclick = function (e) { + // e.stopPropagation(); + // core.onkeyUp({ + // keyCode: 52, + // altKey: core.getLocalStorage('altKey') + // }); + // }; - main.statusBar.image.btn5.onclick = function (e) { - e.stopPropagation(); - core.onkeyUp({ - keyCode: 53, - altKey: core.getLocalStorage('altKey') - }); - }; + // main.statusBar.image.btn5.onclick = function (e) { + // e.stopPropagation(); + // core.onkeyUp({ + // keyCode: 53, + // altKey: core.getLocalStorage('altKey') + // }); + // }; - main.statusBar.image.btn6.onclick = function (e) { - e.stopPropagation(); - core.onkeyUp({ - keyCode: 54, - altKey: core.getLocalStorage('altKey') - }); - }; + // main.statusBar.image.btn6.onclick = function (e) { + // e.stopPropagation(); + // core.onkeyUp({ + // keyCode: 54, + // altKey: core.getLocalStorage('altKey') + // }); + // }; - main.statusBar.image.btn7.onclick = function (e) { - e.stopPropagation(); - core.onkeyUp({ - keyCode: 55, - altKey: core.getLocalStorage('altKey') - }); - }; + // main.statusBar.image.btn7.onclick = function (e) { + // e.stopPropagation(); + // core.onkeyUp({ + // keyCode: 55, + // altKey: core.getLocalStorage('altKey') + // }); + // }; - main.statusBar.image.btn8.onclick = function (e) { - e.stopPropagation(); - if (core.getLocalStorage('altKey')) { - core.removeLocalStorage('altKey'); - core.drawTip('Alt模式已关闭。'); - main.statusBar.image.btn8.style.filter = ''; - } else { - core.setLocalStorage('altKey', true); - core.drawTip('Alt模式已开启;此模式下1~7按钮视为Alt+1~7。'); - main.statusBar.image.btn8.style.filter = 'sepia(1) contrast(1.5)'; - } - }; + // main.statusBar.image.btn8.onclick = function (e) { + // e.stopPropagation(); + // if (core.getLocalStorage('altKey')) { + // core.removeLocalStorage('altKey'); + // core.drawTip('Alt模式已关闭。'); + // main.statusBar.image.btn8.style.filter = ''; + // } else { + // core.setLocalStorage('altKey', true); + // core.drawTip('Alt模式已开启;此模式下1~7按钮视为Alt+1~7。'); + // main.statusBar.image.btn8.style.filter = 'sepia(1) contrast(1.5)'; + // } + // }; window.onblur = function () { if (core && core.control) { diff --git a/src/core/index.ts b/src/core/index.ts index 570a6c2..9133297 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -29,41 +29,8 @@ import { CustomToolbar } from './main/custom/toolbar'; import { Hotkey } from './main/custom/hotkey'; import { Keyboard } from './main/custom/keyboard'; -// export interface Mota { -// sound: SoundController; -// /** 游戏资源 */ -// resource: ResourceStore>; -// zipResource: ResourceStore<'zip'>; -// bgm: BgmController; -// plugin: AncTePlugin; -// hook: EventEmitter; -// classes: { -// storage: typeof GameStorage; -// }; -// ui: { -// main: UiController; -// fixed: UiController; -// }; -// } - function ready() { - // window.mota = { - // bgm: new BgmController(), - // resource: new ResourceStore(), - // zipResource: new ResourceStore(), - // sound: new SoundController(), - // // @ts-ignore - // plugin: {}, - // hook, - // storage: GameStorage, - // ui: { - // main: mainUi, - // fixed: fixedUi - // } - // }; - readyAllResource(); - // loading.once('coreInit', resolvePlugin); } // ----- 类注册 @@ -99,4 +66,5 @@ Mota.register('var', 'settingStorage', settingStorage); Mota.register('var', 'status', status); // ----- 模块注册 + ready(); diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index 7f9d0a8..30f21dd 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -480,19 +480,19 @@ const loading = Mota.require('var', 'loading'); loading.once('coreInit', () => { mainSetting.reset({ 'screen.fullscreen': !!document.fullscreenElement, - 'screen.halo': !!storage.getValue('showHalo', true), - 'screen.itemDetail': !!storage.getValue('itemDetail', true), - 'screen.heroDetail': !!storage.getValue('heroDetail', false), - 'screen.transition': !!storage.getValue('transition', false), - 'screen.antiAlias': !!storage.getValue('antiAlias', false), - 'screen.fontSize': storage.getValue('fontSize', 16), - 'screen.smoothView': !!storage.getValue('smoothView', true), - 'screen.criticalGem': !!storage.getValue('criticalGem', false), - 'action.fixed': !!storage.getValue('fixed', true), - 'utils.betterLoad': !!storage.getValue('betterLoad', true), - 'utils.autoScale': !!storage.getValue('autoScale', true), - 'fx.paraLight': !!storage.getValue('paraLight', true), - 'fx.frag': !!storage.getValue('frag', true) + 'screen.halo': !!storage.getValue('screen.showHalo', true), + 'screen.itemDetail': !!storage.getValue('screen.itemDetail', true), + 'screen.heroDetail': !!storage.getValue('screen.heroDetail', false), + 'screen.transition': !!storage.getValue('screen.transition', false), + 'screen.antiAlias': !!storage.getValue('screen.antiAlias', false), + 'screen.fontSize': storage.getValue('screen.fontSize', 16), + 'screen.smoothView': !!storage.getValue('screen.smoothView', true), + 'screen.criticalGem': !!storage.getValue('screen.criticalGem', false), + 'action.fixed': !!storage.getValue('action.fixed', true), + 'utils.betterLoad': !!storage.getValue('utils.betterLoad', true), + 'utils.autoScale': !!storage.getValue('utils.autoScale', true), + 'fx.paraLight': !!storage.getValue('fx.paraLight', true), + 'fx.frag': !!storage.getValue('fx.frag', true) }); }); diff --git a/src/game/enemy/battle.ts b/src/game/enemy/battle.ts index dddee71..84a6020 100644 --- a/src/game/enemy/battle.ts +++ b/src/game/enemy/battle.ts @@ -1,5 +1,6 @@ import { DamageEnemy, ensureFloorDamage, getSingleEnemy } from './damage'; import { findDir, has } from '../../plugin/game/utils'; +import { loading } from '../game'; export interface CurrentEnemy { enemy: DamageEnemy; @@ -41,7 +42,7 @@ export function battle( core.saveAndStopAutomaticRoute(); const enemy = getEnemy(x, y); // 非强制战斗 - if (!core.enemys.canBattle(x, y) && !force && !core.status.event.id) { + if (!canBattle(x, y) && !force && !core.status.event.id) { core.stopSound(); core.playSound('操作失败'); core.drawTip('你打不过此怪物!', enemy.id); @@ -189,7 +190,7 @@ export function getCurrentEnemys(floorId = core.status.floorId) { }); } -export function init() { +function init() { core.events._sys_battle = function (data: Block, callback?: () => void) { // 检查战前事件 const floor = core.floors[core.status.floorId]; @@ -214,7 +215,7 @@ export function init() { core.insertAction(beforeBattle, data.x, data.y, callback); } } else { - this.battle(data.x, data.y, false, callback); + battle(data.x, data.y, false, callback); } }; @@ -233,7 +234,8 @@ export function init() { y, prefix ) as LocArr; - this.battle(ex, ey, true, core.doAction); + battle(ex, ey, true, core.doAction); } }; } +loading.once('coreInit', init); diff --git a/src/game/enemy/damage.ts b/src/game/enemy/damage.ts index 06b0cec..01ad1b8 100644 --- a/src/game/enemy/damage.ts +++ b/src/game/enemy/damage.ts @@ -203,7 +203,8 @@ export class EnemyCollection implements RangeCollection { py: 32 * (v.y! + 1) - 1, color: color }); - const criGem = core.getLocalStorage('criticalGem', false); + const setting = Mota.require('var', 'mainSetting'); + const criGem = setting.getValue('screen.criticalGem', false); const n = critical?.atkDelta ?? Infinity; const ratio = core.status.maps[this.floorId].ratio; const cri = criGem ? Math.ceil(n / ratio) : n; diff --git a/src/game/index.ts b/src/game/index.ts index 870bd75..23ce7f0 100644 --- a/src/game/index.ts +++ b/src/game/index.ts @@ -1,14 +1,11 @@ import './system'; import '../plugin/game/index'; import { DamageEnemy, EnemyCollection } from './enemy/damage'; -import { - EmitableEvent, - EventEmitter, - IndexedEventEmitter -} from '@/core/common/eventEmitter'; +import { EventEmitter, IndexedEventEmitter } from '@/core/common/eventEmitter'; import { Range } from '@/plugin/game/range'; import { specials } from './enemy/special'; import { gameListener, hook, loading } from './game'; +import * as battle from './enemy/battle'; // ----- 类注册 Mota.register('class', 'DamageEnemy', DamageEnemy); @@ -17,7 +14,11 @@ Mota.register('class', 'EventEmitter', EventEmitter); Mota.register('class', 'IndexedEventEmitter', IndexedEventEmitter); Mota.register('class', 'Range', Range); // ----- 函数注册 - +Mota.register('fn', 'battle', battle.battle); +Mota.register('fn', 'getEnemy', battle.getEnemy); +Mota.register('fn', 'afterBattle', battle.afterBattle); +Mota.register('fn', 'canBattle', battle.canBattle); +Mota.register('fn', 'getCurrentEnemys', battle.getCurrentEnemys); // ----- 变量注册 Mota.register('var', 'enemySpecials', specials); Mota.register('var', 'hook', hook); diff --git a/src/game/system.ts b/src/game/system.ts index 67d7d95..b124f7a 100644 --- a/src/game/system.ts +++ b/src/game/system.ts @@ -29,6 +29,7 @@ import type { specials } from './enemy/special'; import type { Range } from '@/plugin/game/range'; import type { KeyCode } from '@/plugin/keyCodes'; import type { Ref } from 'vue'; +import * as battle from './enemy/battle'; interface ClassInterface { // 渲染进程与游戏进程通用 @@ -59,7 +60,9 @@ interface ClassInterface { DamageEnemy: typeof DamageEnemy; } -interface FunctionInterface { +type _IBattle = typeof battle; + +interface FunctionInterface extends _IBattle { // 定义于渲染进程,录像中会进行polyfill,但是不执行任何内容 readyAllResource(): void; // 定义于游戏进程,渲染进程依然可用 diff --git a/src/plugin/fx/frag.ts b/src/plugin/fx/frag.ts index cc38c0f..77cf0c5 100644 --- a/src/plugin/fx/frag.ts +++ b/src/plugin/fx/frag.ts @@ -25,9 +25,11 @@ const MAX_ROTATE = 0.5; const FRAG_TIMING = linear(); export function init() { - Mota.rewrite(core.events, 'afterBattle', 'add', (_, enemy, x, y) => { + const fn = Mota.requireAll('fn'); + Mota.rewrite(fn, 'afterBattle', 'add', (_, enemy, x, y) => { // 打怪特效 - if (core.getLocalStorage('frag') && has(x) && has(y)) { + const setting = Mota.require('var', 'mainSetting'); + if (setting.getValue('screen.frag') && has(x) && has(y)) { const frame = core.status.globalAnimateStatus % 2; const canvas = document.createElement('canvas'); canvas.width = 32; diff --git a/src/plugin/game/fx/halo.ts b/src/plugin/game/fx/halo.ts index 7507b1f..9bc397e 100644 --- a/src/plugin/game/fx/halo.ts +++ b/src/plugin/game/fx/halo.ts @@ -11,7 +11,8 @@ export function drawHalo( floorId: FloorIds ) { if (main.replayChecking) return; - if (!core.getLocalStorage('showHalo', true)) return; + const setting = Mota.require('var', 'mainSetting'); + if (!setting.getValue('screen.showHalo', true)) return; const list = core.status.maps[floorId].enemy.haloList.concat( Object.keys(flags[`melt_${floorId}`] ?? {}).map(v => { const [x, y] = v.split(',').map(v => parseInt(v)); diff --git a/src/plugin/game/fx/heroDetail.ts b/src/plugin/game/fx/heroDetail.ts index ccc870d..2a854c5 100644 --- a/src/plugin/game/fx/heroDetail.ts +++ b/src/plugin/game/fx/heroDetail.ts @@ -1,5 +1,6 @@ function drawHeroDetail(px: number, py: number) { - if (!core.getLocalStorage('heroDetail', false)) return; + const setting = Mota.require('var', 'mainSetting'); + if (!setting.getValue('screen.heroDetail', false)) return; const { hp, atk, def } = core.status.hero; const toDraw = { atk: { diff --git a/src/plugin/game/fx/itemDetail.ts b/src/plugin/game/fx/itemDetail.ts index 1b7c9f6..0fcec27 100644 --- a/src/plugin/game/fx/itemDetail.ts +++ b/src/plugin/game/fx/itemDetail.ts @@ -33,7 +33,8 @@ export function init() { // 获取宝石信息 并绘制 function getItemDetail(floorId: FloorIds, onMap: boolean) { - if (!core.getLocalStorage('itemDetail')) return; + const setting = Mota.require('var', 'mainSetting'); + if (!setting.getValue('screen.itemDetail')) return; floorId ??= core.status.thisMap.floorId; let diff: Record = {}; const before = core.status.hero;