refactor: 设置获取

This commit is contained in:
unanmed 2024-02-02 17:59:38 +08:00
parent fa73b47d02
commit a825b268bc
11 changed files with 105 additions and 125 deletions

View File

@ -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) {

View File

@ -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<Exclude<ResourceType, 'zip'>>;
// zipResource: ResourceStore<'zip'>;
// bgm: BgmController;
// plugin: AncTePlugin;
// hook: EventEmitter<GameEvent>;
// 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();

View File

@ -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)
});
});

View File

@ -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);

View File

@ -203,7 +203,8 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
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;

View File

@ -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);

View File

@ -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;
// 定义于游戏进程,渲染进程依然可用

View File

@ -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;

View File

@ -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));

View File

@ -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: {

View File

@ -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<string | symbol, number | undefined> = {};
const before = core.status.hero;