mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-02-28 17:37:07 +08:00
feat: logger
This commit is contained in:
parent
2528a36864
commit
3f195fdc72
2
idea.md
2
idea.md
@ -83,7 +83,7 @@ dam4.png ---- 存档 59
|
|||||||
[] 重写技能控制系统
|
[] 重写技能控制系统
|
||||||
[x] 自定义快捷键
|
[x] 自定义快捷键
|
||||||
[x] 优化 ui 控制系统
|
[x] 优化 ui 控制系统
|
||||||
[] 优化游戏进程与渲染进程间的通讯
|
[x] 优化游戏进程与渲染进程间的通讯
|
||||||
[] 优化资源分离,音乐放到 bgm 目录下
|
[] 优化资源分离,音乐放到 bgm 目录下
|
||||||
[] 一次性道具拾取与清怪
|
[] 一次性道具拾取与清怪
|
||||||
[] 重构数据统计
|
[] 重构数据统计
|
||||||
|
71
src/core/common/logger.ts
Normal file
71
src/core/common/logger.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
export const enum LogLevel {
|
||||||
|
/** 输出所有,包括日志 */
|
||||||
|
LOG,
|
||||||
|
/** 报错、严重警告和警告 */
|
||||||
|
WARNING,
|
||||||
|
/** 报错和严重警告 */
|
||||||
|
SEVERE_WARNING,
|
||||||
|
/** 仅报错 */
|
||||||
|
ERROR
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Logger {
|
||||||
|
level: LogLevel = LogLevel.LOG;
|
||||||
|
|
||||||
|
constructor(logLevel: LogLevel) {
|
||||||
|
this.level = logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置该日志类的输出等级
|
||||||
|
* @param level 要设置为的输出等级
|
||||||
|
*/
|
||||||
|
setLogLevel(level: LogLevel) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输出报错信息
|
||||||
|
* @param code 错误代码,每个错误都应当使用唯一的错误代码
|
||||||
|
* @param text 错误信息
|
||||||
|
*/
|
||||||
|
error(code: number, text: string) {
|
||||||
|
if (this.level <= LogLevel.ERROR) {
|
||||||
|
console.error(`[ERROR Code ${code}] ${text}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输出严重警告信息
|
||||||
|
* @param code 警告代码
|
||||||
|
* @param text 警告信息
|
||||||
|
*/
|
||||||
|
severe(code: number, text: string) {
|
||||||
|
if (this.level <= LogLevel.SEVERE_WARNING) {
|
||||||
|
console.warn(`[SEVERE WARNING Code ${code}] ${text}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输出警告信息
|
||||||
|
* @param code 警告代码
|
||||||
|
* @param text 警告信息
|
||||||
|
*/
|
||||||
|
warn(code: number, text: string) {
|
||||||
|
if (this.level <= LogLevel.WARNING) {
|
||||||
|
console.warn(`[WARNING Code ${code}] ${text}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输出日志
|
||||||
|
* @param text 日志信息
|
||||||
|
*/
|
||||||
|
log(text: string) {
|
||||||
|
if (this.level <= LogLevel.LOG) {
|
||||||
|
console.log(`[LOG] ${text}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const logger = new Logger(LogLevel.LOG);
|
@ -58,6 +58,7 @@ import KeyboardPanel from '@/panel/keyboard.vue';
|
|||||||
import { MCGenerator } from './main/layout';
|
import { MCGenerator } from './main/layout';
|
||||||
import { ResourceController } from './loader/controller';
|
import { ResourceController } from './loader/controller';
|
||||||
import { readyAllResource } from './loader/load';
|
import { readyAllResource } from './loader/load';
|
||||||
|
import { logger } from './common/logger';
|
||||||
|
|
||||||
// ----- 类注册
|
// ----- 类注册
|
||||||
Mota.register('class', 'AudioPlayer', AudioPlayer);
|
Mota.register('class', 'AudioPlayer', AudioPlayer);
|
||||||
@ -93,6 +94,7 @@ Mota.register('var', 'mainSetting', mainSetting);
|
|||||||
Mota.register('var', 'KeyCode', KeyCode);
|
Mota.register('var', 'KeyCode', KeyCode);
|
||||||
Mota.register('var', 'settingStorage', settingStorage);
|
Mota.register('var', 'settingStorage', settingStorage);
|
||||||
Mota.register('var', 'status', status);
|
Mota.register('var', 'status', status);
|
||||||
|
Mota.register('var', 'logger', logger);
|
||||||
// ----- 模块注册
|
// ----- 模块注册
|
||||||
Mota.register('module', 'CustomComponents', {
|
Mota.register('module', 'CustomComponents', {
|
||||||
createSettingComponents,
|
createSettingComponents,
|
||||||
|
@ -27,6 +27,7 @@ import type { KeyCode } from '@/plugin/keyCodes';
|
|||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import type * as battle from './enemy/battle';
|
import type * as battle from './enemy/battle';
|
||||||
import type * as hero from './hero';
|
import type * as hero from './hero';
|
||||||
|
import type { Logger } from '@/core/common/logger';
|
||||||
|
|
||||||
interface ClassInterface {
|
interface ClassInterface {
|
||||||
// 渲染进程与游戏进程通用
|
// 渲染进程与游戏进程通用
|
||||||
@ -88,6 +89,7 @@ interface VariableInterface {
|
|||||||
// 定义于游戏进程,渲染进程依然可用
|
// 定义于游戏进程,渲染进程依然可用
|
||||||
haloSpecials: number[];
|
haloSpecials: number[];
|
||||||
enemySpecials: typeof specials;
|
enemySpecials: typeof specials;
|
||||||
|
logger: Logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ModuleInterface {}
|
interface ModuleInterface {}
|
||||||
|
@ -22,3 +22,4 @@ export { default as Toolbox } from './toolbox.vue';
|
|||||||
export { default as Hotkey } from './hotkey.vue';
|
export { default as Hotkey } from './hotkey.vue';
|
||||||
export { default as Toolbar } from './toolbar.vue';
|
export { default as Toolbar } from './toolbar.vue';
|
||||||
export { default as ToolEditor } from './toolEditor.vue';
|
export { default as ToolEditor } from './toolEditor.vue';
|
||||||
|
export { default as Load } from './load.vue';
|
||||||
|
13
src/ui/load.vue
Normal file
13
src/ui/load.vue
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<template>
|
||||||
|
<div id="load"></div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup></script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
#load {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Reference in New Issue
Block a user