refactor: 设置获取

This commit is contained in:
AncTe committed 2024-02-02 17:59:38 +08:00
1 parent fa73b47d02
commit a825b268bc
11 files changed
+105 -125

No files matched your search

+1 -33
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();
+13 -13
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)
});
});
+6 -4
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);
+2 -1
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;
+7 -6
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);
+4 -1
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;
// 定义于游戏进程,渲染进程依然可用
+4 -2
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;
+2 -1
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));
+2 -1
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: {
+2 -1
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;