From 05ed15c0a62a8fc41be1a9c22204ac6d6d2ffd16 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Tue, 8 Aug 2023 13:29:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=98=E5=82=A8=E7=AE=A1=E7=90=86=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- idea.md | 1 + public/libs/control.js | 3 +- src/core/main/setting.ts | 44 +++++++++++++++++++-------- src/core/main/storage.ts | 65 ++++++++++++++++++++++++++++++++++++++++ src/plugin/use.ts | 6 ++-- src/plugin/utils.ts | 7 +++++ src/types/core.d.ts | 2 ++ 7 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 src/core/main/storage.ts diff --git a/idea.md b/idea.md index f7cc87f..38f5a30 100644 --- a/idea.md +++ b/idea.md @@ -85,3 +85,4 @@ dam4.png ---- 存档 59 [] 优化 ui 控制系统 [] 优化游戏进程与渲染进程间的通讯 [] 优化资源分离,音乐放到 bgm 目录下 +[] 一次性道具拾取与清怪 diff --git a/public/libs/control.js b/public/libs/control.js index 71f0e9f..e21a0ce 100644 --- a/public/libs/control.js +++ b/public/libs/control.js @@ -2811,8 +2811,7 @@ control.prototype.getStatus = function (name) { ////// 从status中获得属性,如果不存在则从勇士属性中获取 ////// control.prototype.getStatusOrDefault = function (status, name) { - if (status && name in status) return Math.floor(status[name]); - return Math.floor(this.getStatus(name)); + // Deprecated. See src/plugin/game/hero.ts }; ////// 获得勇士实际属性(增幅后的) ////// diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index 40f5491..a03fbd0 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -4,6 +4,7 @@ import { transition } from '../../plugin/uiController'; import { loading } from '../loader/load'; import { hook } from './game'; import { isMobile } from '../../plugin/use'; +import { GameStorage } from './storage'; type MotaSettingType = boolean | number | MotaSetting; @@ -396,21 +397,38 @@ mainSetting .register('autoScale', '自动放缩', true) ); +interface SettingStorage { + showHalo: boolean; + frag: boolean; + itemDetail: boolean; + transition: boolean; + antiAlias: boolean; + fontSize: number; + smoothView: boolean; + criticalGem: boolean; + fixed: boolean; + betterLoad: boolean; + autoScale: boolean; +} + +const storage = new GameStorage( + GameStorage.fromAncTe('setting') +); + loading.once('coreInit', () => { - const get = core.getLocalStorage; mainSetting.reset({ - 'screen.fullscreen': false, - 'screen.halo': !!get('showHalo', true), - 'screen.frag': !!get('frag', true), - 'screen.itemDetail': !!get('itemDetail', true), - 'screen.transition': !!get('transition', false), - 'screen.antiAlias': !!get('antiAlias', false), - 'screen.fontSize': get('fontSize', 16), - 'screen.smoothView': !!get('smoothView', true), - 'screen.criticalGem': !!get('criticalGem', false), - 'action.fixed': !!get('fixed', true), - 'utils.betterLoad': !!get('betterLoad', true), - 'utils.autoScale': !!get('autoScale', true) + 'screen.fullscreen': !!document.fullscreenElement, + 'screen.halo': !!storage.getValue('showHalo', true), + 'screen.frag': !!storage.getValue('frag', true), + 'screen.itemDetail': !!storage.getValue('itemDetail', true), + '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) }); }); diff --git a/src/core/main/storage.ts b/src/core/main/storage.ts new file mode 100644 index 0000000..df06c04 --- /dev/null +++ b/src/core/main/storage.ts @@ -0,0 +1,65 @@ +export class GameStorage { + static list: GameStorage[] = []; + + key: string; + data!: T; + + constructor(key: string) { + this.key = key; + this.read(); + GameStorage.list.push(this); + } + + /** + * 从本地存储读取 + */ + read(): T { + const data = localStorage.getItem(this.key) ?? '{}'; + return (this.data = JSON.parse(data)); + } + + /** + * 写入本地存储 + */ + write() { + localStorage.setItem(this.key, JSON.stringify(this.data)); + } + + /** + * 设置存储的值 + * @param key 存储的名称 + * @param value 存储的值 + */ + setValue(key: K, value: T[K]) { + this.data[key] = value; + } + + getValue(key: K): T[K] | null; + getValue(key: K, defaults?: T[K]): T[K]; + getValue(key: K, defaults?: T[K]) { + if (this.data[key]) return this.data[key]; + else { + if (defaults !== void 0) { + this.data[key] = defaults; + return defaults; + } + return null; + } + } + + /** + * 获取本游戏的存储键 + * @param key 存储名称 + */ + static fromGame(key: string) { + return `HumanBreak_${key}`; + } + + static fromAncTe(key: string) { + return `AncTe@${key}`; + } +} + +window.addEventListener('unload', () => { + GameStorage.list.forEach(v => v.write()); +}); diff --git a/src/plugin/use.ts b/src/plugin/use.ts index 99367ac..eaf8677 100644 --- a/src/plugin/use.ts +++ b/src/plugin/use.ts @@ -1,5 +1,3 @@ -import { debounce } from 'lodash-es'; - export default function init() { return { useDrag, useWheel, useUp, isMobile }; } @@ -31,7 +29,9 @@ checkMobile(); function checkMobile() { if (isMobile && !alerted) { - alert('手机端建议使用自带的浏览器进行游玩,并在进入游戏后开启全屏游玩'); + alert( + '手机端建议使用自带的浏览器进行游玩,并在进入游戏后开启游戏内的全屏设置游玩' + ); alerted = true; } } diff --git a/src/plugin/utils.ts b/src/plugin/utils.ts index 5fc4b1b..105eed0 100644 --- a/src/plugin/utils.ts +++ b/src/plugin/utils.ts @@ -263,3 +263,10 @@ export function pColor(color: string) { arr[3] ??= 1; return `rgba(${arr.join(',')})` as Color; } + +export function deleteWith(arr: T[], ele: T): T[] { + const index = arr.indexOf(ele); + if (index === -1) return arr; + arr.splice(index, 1); + return arr; +} diff --git a/src/types/core.d.ts b/src/types/core.d.ts index 9e15159..8d8265c 100644 --- a/src/types/core.d.ts +++ b/src/types/core.d.ts @@ -997,6 +997,8 @@ interface Core extends Pick { */ readonly flags: CoreFlags; + readonly firstData: FirstData; + /** * 获得所有楼层的信息 * @example core.floors[core.status.floorId].events // 获得本楼层的所有自定义事件