mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-19 12:49:25 +08:00
存储管理系统
This commit is contained in:
parent
bf828bcacf
commit
05ed15c0a6
1
idea.md
1
idea.md
@ -85,3 +85,4 @@ dam4.png ---- 存档 59
|
||||
[] 优化 ui 控制系统
|
||||
[] 优化游戏进程与渲染进程间的通讯
|
||||
[] 优化资源分离,音乐放到 bgm 目录下
|
||||
[] 一次性道具拾取与清怪
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
////// 获得勇士实际属性(增幅后的) //////
|
||||
|
@ -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<SettingStorage>(
|
||||
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)
|
||||
});
|
||||
});
|
||||
|
||||
|
65
src/core/main/storage.ts
Normal file
65
src/core/main/storage.ts
Normal file
@ -0,0 +1,65 @@
|
||||
export class GameStorage<T> {
|
||||
static list: GameStorage<any>[] = [];
|
||||
|
||||
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<K extends keyof T>(key: K, value: T[K]) {
|
||||
this.data[key] = value;
|
||||
}
|
||||
|
||||
getValue<K extends keyof T>(key: K): T[K] | null;
|
||||
getValue<K extends keyof T>(key: K, defaults?: T[K]): T[K];
|
||||
getValue<K extends keyof T>(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());
|
||||
});
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -263,3 +263,10 @@ export function pColor(color: string) {
|
||||
arr[3] ??= 1;
|
||||
return `rgba(${arr.join(',')})` as Color;
|
||||
}
|
||||
|
||||
export function deleteWith<T>(arr: T[], ele: T): T[] {
|
||||
const index = arr.indexOf(ele);
|
||||
if (index === -1) return arr;
|
||||
arr.splice(index, 1);
|
||||
return arr;
|
||||
}
|
||||
|
2
src/types/core.d.ts
vendored
2
src/types/core.d.ts
vendored
@ -997,6 +997,8 @@ interface Core extends Pick<Main, CoreDataFromMain> {
|
||||
*/
|
||||
readonly flags: CoreFlags;
|
||||
|
||||
readonly firstData: FirstData;
|
||||
|
||||
/**
|
||||
* 获得所有楼层的信息
|
||||
* @example core.floors[core.status.floorId].events // 获得本楼层的所有自定义事件
|
||||
|
Loading…
Reference in New Issue
Block a user