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; main.core = core;
// 自动放缩最大化 // 自动放缩最大化
let auto = core.getLocalStorage('autoScale'); let auto = Mota.require('var', 'mainSetting').getValue('autoSclae');
if (auto && !core.domStyle.isVertical) { if (auto && !core.domStyle.isVertical) {
try { try {
@ -801,74 +801,74 @@ main.prototype.listen = function () {
}; };
////// 手机端的按钮1-7 ////// ////// 手机端的按钮1-7 //////
main.statusBar.image.btn1.onclick = function (e) { // main.statusBar.image.btn1.onclick = function (e) {
e.stopPropagation(); // e.stopPropagation();
core.onkeyUp({ // core.onkeyUp({
keyCode: 49, // keyCode: 49,
altKey: core.getLocalStorage('altKey') // altKey: core.getLocalStorage('altKey')
}); // });
}; // };
main.statusBar.image.btn2.onclick = function (e) { // main.statusBar.image.btn2.onclick = function (e) {
e.stopPropagation(); // e.stopPropagation();
core.onkeyUp({ // core.onkeyUp({
keyCode: 50, // keyCode: 50,
altKey: core.getLocalStorage('altKey') // altKey: core.getLocalStorage('altKey')
}); // });
}; // };
main.statusBar.image.btn3.onclick = function (e) { // main.statusBar.image.btn3.onclick = function (e) {
e.stopPropagation(); // e.stopPropagation();
core.onkeyUp({ // core.onkeyUp({
keyCode: 51, // keyCode: 51,
altKey: core.getLocalStorage('altKey') // altKey: core.getLocalStorage('altKey')
}); // });
}; // };
main.statusBar.image.btn4.onclick = function (e) { // main.statusBar.image.btn4.onclick = function (e) {
e.stopPropagation(); // e.stopPropagation();
core.onkeyUp({ // core.onkeyUp({
keyCode: 52, // keyCode: 52,
altKey: core.getLocalStorage('altKey') // altKey: core.getLocalStorage('altKey')
}); // });
}; // };
main.statusBar.image.btn5.onclick = function (e) { // main.statusBar.image.btn5.onclick = function (e) {
e.stopPropagation(); // e.stopPropagation();
core.onkeyUp({ // core.onkeyUp({
keyCode: 53, // keyCode: 53,
altKey: core.getLocalStorage('altKey') // altKey: core.getLocalStorage('altKey')
}); // });
}; // };
main.statusBar.image.btn6.onclick = function (e) { // main.statusBar.image.btn6.onclick = function (e) {
e.stopPropagation(); // e.stopPropagation();
core.onkeyUp({ // core.onkeyUp({
keyCode: 54, // keyCode: 54,
altKey: core.getLocalStorage('altKey') // altKey: core.getLocalStorage('altKey')
}); // });
}; // };
main.statusBar.image.btn7.onclick = function (e) { // main.statusBar.image.btn7.onclick = function (e) {
e.stopPropagation(); // e.stopPropagation();
core.onkeyUp({ // core.onkeyUp({
keyCode: 55, // keyCode: 55,
altKey: core.getLocalStorage('altKey') // altKey: core.getLocalStorage('altKey')
}); // });
}; // };
main.statusBar.image.btn8.onclick = function (e) { // main.statusBar.image.btn8.onclick = function (e) {
e.stopPropagation(); // e.stopPropagation();
if (core.getLocalStorage('altKey')) { // if (core.getLocalStorage('altKey')) {
core.removeLocalStorage('altKey'); // core.removeLocalStorage('altKey');
core.drawTip('Alt模式已关闭。'); // core.drawTip('Alt模式已关闭。');
main.statusBar.image.btn8.style.filter = ''; // main.statusBar.image.btn8.style.filter = '';
} else { // } else {
core.setLocalStorage('altKey', true); // core.setLocalStorage('altKey', true);
core.drawTip('Alt模式已开启此模式下1~7按钮视为Alt+1~7。'); // core.drawTip('Alt模式已开启此模式下1~7按钮视为Alt+1~7。');
main.statusBar.image.btn8.style.filter = 'sepia(1) contrast(1.5)'; // main.statusBar.image.btn8.style.filter = 'sepia(1) contrast(1.5)';
} // }
}; // };
window.onblur = function () { window.onblur = function () {
if (core && core.control) { if (core && core.control) {

View File

@ -29,41 +29,8 @@ import { CustomToolbar } from './main/custom/toolbar';
import { Hotkey } from './main/custom/hotkey'; import { Hotkey } from './main/custom/hotkey';
import { Keyboard } from './main/custom/keyboard'; 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() { 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(); readyAllResource();
// loading.once('coreInit', resolvePlugin);
} }
// ----- 类注册 // ----- 类注册
@ -99,4 +66,5 @@ Mota.register('var', 'settingStorage', settingStorage);
Mota.register('var', 'status', status); Mota.register('var', 'status', status);
// ----- 模块注册 // ----- 模块注册
ready(); ready();

View File

@ -480,19 +480,19 @@ const loading = Mota.require('var', 'loading');
loading.once('coreInit', () => { loading.once('coreInit', () => {
mainSetting.reset({ mainSetting.reset({
'screen.fullscreen': !!document.fullscreenElement, 'screen.fullscreen': !!document.fullscreenElement,
'screen.halo': !!storage.getValue('showHalo', true), 'screen.halo': !!storage.getValue('screen.showHalo', true),
'screen.itemDetail': !!storage.getValue('itemDetail', true), 'screen.itemDetail': !!storage.getValue('screen.itemDetail', true),
'screen.heroDetail': !!storage.getValue('heroDetail', false), 'screen.heroDetail': !!storage.getValue('screen.heroDetail', false),
'screen.transition': !!storage.getValue('transition', false), 'screen.transition': !!storage.getValue('screen.transition', false),
'screen.antiAlias': !!storage.getValue('antiAlias', false), 'screen.antiAlias': !!storage.getValue('screen.antiAlias', false),
'screen.fontSize': storage.getValue('fontSize', 16), 'screen.fontSize': storage.getValue('screen.fontSize', 16),
'screen.smoothView': !!storage.getValue('smoothView', true), 'screen.smoothView': !!storage.getValue('screen.smoothView', true),
'screen.criticalGem': !!storage.getValue('criticalGem', false), 'screen.criticalGem': !!storage.getValue('screen.criticalGem', false),
'action.fixed': !!storage.getValue('fixed', true), 'action.fixed': !!storage.getValue('action.fixed', true),
'utils.betterLoad': !!storage.getValue('betterLoad', true), 'utils.betterLoad': !!storage.getValue('utils.betterLoad', true),
'utils.autoScale': !!storage.getValue('autoScale', true), 'utils.autoScale': !!storage.getValue('utils.autoScale', true),
'fx.paraLight': !!storage.getValue('paraLight', true), 'fx.paraLight': !!storage.getValue('fx.paraLight', true),
'fx.frag': !!storage.getValue('frag', true) 'fx.frag': !!storage.getValue('fx.frag', true)
}); });
}); });

View File

@ -1,5 +1,6 @@
import { DamageEnemy, ensureFloorDamage, getSingleEnemy } from './damage'; import { DamageEnemy, ensureFloorDamage, getSingleEnemy } from './damage';
import { findDir, has } from '../../plugin/game/utils'; import { findDir, has } from '../../plugin/game/utils';
import { loading } from '../game';
export interface CurrentEnemy { export interface CurrentEnemy {
enemy: DamageEnemy; enemy: DamageEnemy;
@ -41,7 +42,7 @@ export function battle(
core.saveAndStopAutomaticRoute(); core.saveAndStopAutomaticRoute();
const enemy = getEnemy(x, y); 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.stopSound();
core.playSound('操作失败'); core.playSound('操作失败');
core.drawTip('你打不过此怪物!', enemy.id); 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) { core.events._sys_battle = function (data: Block, callback?: () => void) {
// 检查战前事件 // 检查战前事件
const floor = core.floors[core.status.floorId]; const floor = core.floors[core.status.floorId];
@ -214,7 +215,7 @@ export function init() {
core.insertAction(beforeBattle, data.x, data.y, callback); core.insertAction(beforeBattle, data.x, data.y, callback);
} }
} else { } else {
this.battle(data.x, data.y, false, callback); battle(data.x, data.y, false, callback);
} }
}; };
@ -233,7 +234,8 @@ export function init() {
y, y,
prefix prefix
) as LocArr; ) 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, py: 32 * (v.y! + 1) - 1,
color: color 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 n = critical?.atkDelta ?? Infinity;
const ratio = core.status.maps[this.floorId].ratio; const ratio = core.status.maps[this.floorId].ratio;
const cri = criGem ? Math.ceil(n / ratio) : n; const cri = criGem ? Math.ceil(n / ratio) : n;

View File

@ -1,14 +1,11 @@
import './system'; import './system';
import '../plugin/game/index'; import '../plugin/game/index';
import { DamageEnemy, EnemyCollection } from './enemy/damage'; import { DamageEnemy, EnemyCollection } from './enemy/damage';
import { import { EventEmitter, IndexedEventEmitter } from '@/core/common/eventEmitter';
EmitableEvent,
EventEmitter,
IndexedEventEmitter
} from '@/core/common/eventEmitter';
import { Range } from '@/plugin/game/range'; import { Range } from '@/plugin/game/range';
import { specials } from './enemy/special'; import { specials } from './enemy/special';
import { gameListener, hook, loading } from './game'; import { gameListener, hook, loading } from './game';
import * as battle from './enemy/battle';
// ----- 类注册 // ----- 类注册
Mota.register('class', 'DamageEnemy', DamageEnemy); Mota.register('class', 'DamageEnemy', DamageEnemy);
@ -17,7 +14,11 @@ Mota.register('class', 'EventEmitter', EventEmitter);
Mota.register('class', 'IndexedEventEmitter', IndexedEventEmitter); Mota.register('class', 'IndexedEventEmitter', IndexedEventEmitter);
Mota.register('class', 'Range', Range); 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', 'enemySpecials', specials);
Mota.register('var', 'hook', hook); 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 { Range } from '@/plugin/game/range';
import type { KeyCode } from '@/plugin/keyCodes'; import type { KeyCode } from '@/plugin/keyCodes';
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import * as battle from './enemy/battle';
interface ClassInterface { interface ClassInterface {
// 渲染进程与游戏进程通用 // 渲染进程与游戏进程通用
@ -59,7 +60,9 @@ interface ClassInterface {
DamageEnemy: typeof DamageEnemy; DamageEnemy: typeof DamageEnemy;
} }
interface FunctionInterface { type _IBattle = typeof battle;
interface FunctionInterface extends _IBattle {
// 定义于渲染进程录像中会进行polyfill但是不执行任何内容 // 定义于渲染进程录像中会进行polyfill但是不执行任何内容
readyAllResource(): void; readyAllResource(): void;
// 定义于游戏进程,渲染进程依然可用 // 定义于游戏进程,渲染进程依然可用

View File

@ -25,9 +25,11 @@ const MAX_ROTATE = 0.5;
const FRAG_TIMING = linear(); const FRAG_TIMING = linear();
export function init() { 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 frame = core.status.globalAnimateStatus % 2;
const canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
canvas.width = 32; canvas.width = 32;

View File

@ -11,7 +11,8 @@ export function drawHalo(
floorId: FloorIds floorId: FloorIds
) { ) {
if (main.replayChecking) return; 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( const list = core.status.maps[floorId].enemy.haloList.concat(
Object.keys(flags[`melt_${floorId}`] ?? {}).map(v => { Object.keys(flags[`melt_${floorId}`] ?? {}).map(v => {
const [x, y] = v.split(',').map(v => parseInt(v)); const [x, y] = v.split(',').map(v => parseInt(v));

View File

@ -1,5 +1,6 @@
function drawHeroDetail(px: number, py: number) { 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 { hp, atk, def } = core.status.hero;
const toDraw = { const toDraw = {
atk: { atk: {

View File

@ -33,7 +33,8 @@ export function init() {
// 获取宝石信息 并绘制 // 获取宝石信息 并绘制
function getItemDetail(floorId: FloorIds, onMap: boolean) { 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; floorId ??= core.status.thisMap.floorId;
let diff: Record<string | symbol, number | undefined> = {}; let diff: Record<string | symbol, number | undefined> = {};
const before = core.status.hero; const before = core.status.hero;