mirror of
https://gitee.com/dgflash/oops-framework.git
synced 2026-06-03 19:09:36 +08:00
优化日志模块与本地存储模块的注释
This commit is contained in:
@@ -227,7 +227,7 @@
|
||||
"_priority": 1073741824,
|
||||
"_fov": 45,
|
||||
"_fovAxis": 0,
|
||||
"_orthoHeight": 456.3597430406852,
|
||||
"_orthoHeight": 471.4346895074946,
|
||||
"_near": 1,
|
||||
"_far": 2000,
|
||||
"_color": {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-07-03 16:13:17
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-07-15 17:02:40
|
||||
* @LastEditTime: 2022-07-19 11:38:55
|
||||
*/
|
||||
import { dynamicAtlasManager, macro, profiler, _decorator } from 'cc';
|
||||
import { DEBUG, JSB } from 'cc/env';
|
||||
@@ -25,8 +25,7 @@ export class Main extends CommonEnter {
|
||||
}
|
||||
|
||||
protected async run() {
|
||||
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
||||
|
||||
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
||||
if (JSB) {
|
||||
oops.gui.toast("热更新后新程序的提示");
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
* @Author: dgflash
|
||||
* @Date: 2022-02-11 09:32:47
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-06-17 11:20:20
|
||||
* @LastEditTime: 2022-07-19 11:02:08
|
||||
*/
|
||||
import { ECSRootSystem } from "../libs/ecs/ECSSystem";
|
||||
import { AudioManager } from "./common/audio/AudioManager";
|
||||
import { Logger } from "./common/log/Logger";
|
||||
import { TimerManager } from "./common/manager/TimerManager";
|
||||
import { storage } from "./common/storage/StorageManager";
|
||||
import { GameManager } from "./game/GameManager";
|
||||
@@ -17,6 +18,10 @@ import { HttpRequest } from "./network/HttpRequest";
|
||||
export var version: string = "1.0.7";
|
||||
|
||||
export class oops {
|
||||
/** 日志管理 */
|
||||
static log = Logger;
|
||||
/** 本地存储 */
|
||||
static storage = storage;
|
||||
/** ECS */
|
||||
static ecs: ECSRootSystem;
|
||||
/** 多语言模块 */
|
||||
@@ -31,6 +36,4 @@ export class oops {
|
||||
static game: GameManager;
|
||||
/** HTTP */
|
||||
static http: HttpRequest;
|
||||
/** 本地存储 */
|
||||
static storage = storage;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { error, log, warn } from "cc";
|
||||
import { log } from "cc";
|
||||
|
||||
export enum LogType {
|
||||
/** 网络层日志 */
|
||||
@@ -9,17 +9,26 @@ export enum LogType {
|
||||
Business = 4,
|
||||
/** 视图层日志 */
|
||||
View = 8,
|
||||
/** 配置数据 */
|
||||
/** 配置日志 */
|
||||
Config = 16,
|
||||
/** 登录日志 */
|
||||
/** 标准日志 */
|
||||
Trace = 32,
|
||||
}
|
||||
|
||||
var names = {
|
||||
"1": "网络日志",
|
||||
"2": "数据日志",
|
||||
"4": "业务日志",
|
||||
"8": "视图日志",
|
||||
"16": "配置日志",
|
||||
"32": "标准日志",
|
||||
}
|
||||
|
||||
/** 日志管理 */
|
||||
export class Logger {
|
||||
private static tags: number = 0;
|
||||
|
||||
public static init(): void {
|
||||
private static init(): void {
|
||||
this.tags =
|
||||
LogType.Net |
|
||||
LogType.Model |
|
||||
@@ -29,84 +38,82 @@ export class Logger {
|
||||
LogType.Trace;
|
||||
}
|
||||
|
||||
/** 开始计时 */
|
||||
public static start(): void {
|
||||
console.time("Time");
|
||||
/**
|
||||
* 记录开始计时
|
||||
* @param describe 标题描述
|
||||
*/
|
||||
static start(describe: string = "Time"): void {
|
||||
console.time(describe);
|
||||
}
|
||||
|
||||
/** 打印范围内时间消耗 */
|
||||
public static end(): void {
|
||||
console.timeEnd("Time");
|
||||
/**
|
||||
* 打印范围内时间消耗
|
||||
* @param describe 标题描述
|
||||
*/
|
||||
static end(describe: string = "Time"): void {
|
||||
console.timeEnd(describe);
|
||||
}
|
||||
|
||||
/** 打印表格 */
|
||||
public static table(msg: any, describe?: string): void {
|
||||
static table(msg: any, describe?: string): void {
|
||||
if (!this.isOpen(LogType.Trace)) {
|
||||
return;
|
||||
}
|
||||
console.table(msg);
|
||||
}
|
||||
|
||||
/** 无颜色日志 */
|
||||
public static trace(msg: any, describe?: string) {
|
||||
/** 打印标准日志 */
|
||||
static trace(msg: any, describe?: string) {
|
||||
this.print(LogType.Trace, msg, "", describe)
|
||||
}
|
||||
|
||||
/** 网络层数据日志 */
|
||||
public static logNet(msg: any, describe?: string) {
|
||||
/** 打印网络层日志 */
|
||||
static logNet(msg: any, describe?: string) {
|
||||
this.orange(LogType.Net, msg, describe);
|
||||
}
|
||||
|
||||
/** 客户端数据结构层日志 */
|
||||
public static logModel(msg: any, describe?: string) {
|
||||
/** 打印数据层日志 */
|
||||
static logModel(msg: any, describe?: string) {
|
||||
this.violet(LogType.Model, msg, describe);
|
||||
}
|
||||
|
||||
/** 客户端数据结构层日志 */
|
||||
public static logBusiness(msg: any, describe?: string) {
|
||||
/** 打印业务层日志 */
|
||||
static logBusiness(msg: any, describe?: string) {
|
||||
this.blue(LogType.Business, msg, describe);
|
||||
}
|
||||
|
||||
/** 客户端数据结构层日志 */
|
||||
public static logView(msg: any, describe?: string) {
|
||||
/** 打印视图日志 */
|
||||
static logView(msg: any, describe?: string) {
|
||||
this.green(LogType.View, msg, describe);
|
||||
}
|
||||
|
||||
/** 客户端配置数据 */
|
||||
public static logConfig(msg: any, describe?: string) {
|
||||
/** 打印配置日志 */
|
||||
static logConfig(msg: any, describe?: string) {
|
||||
this.gray(LogType.Config, msg, describe);
|
||||
}
|
||||
|
||||
public static erroring(msg: string) {
|
||||
error('[ERROR]' + msg);
|
||||
}
|
||||
|
||||
public static warning(msg: string) {
|
||||
warn('[WARN]:' + msg);
|
||||
}
|
||||
|
||||
// 橙色
|
||||
public static orange(tag: LogType, msg: any, describe?: string) {
|
||||
private static orange(tag: LogType, msg: any, describe?: string) {
|
||||
this.print(tag, msg, "color:#ee7700;", describe)
|
||||
}
|
||||
|
||||
// 紫色
|
||||
public static violet(tag: LogType, msg: any, describe?: string) {
|
||||
private static violet(tag: LogType, msg: any, describe?: string) {
|
||||
this.print(tag, msg, "color:Violet;", describe)
|
||||
}
|
||||
|
||||
// 蓝色
|
||||
public static blue(tag: LogType, msg: any, describe?: string) {
|
||||
private static blue(tag: LogType, msg: any, describe?: string) {
|
||||
this.print(tag, msg, "color:#3a5fcd;", describe)
|
||||
}
|
||||
|
||||
// 绿色
|
||||
public static green(tag: LogType, msg: any, describe?: string) {
|
||||
private static green(tag: LogType, msg: any, describe?: string) {
|
||||
this.print(tag, msg, "color:green;", describe)
|
||||
}
|
||||
|
||||
// 灰色
|
||||
public static gray(tag: LogType, msg: any, describe?: string) {
|
||||
private static gray(tag: LogType, msg: any, describe?: string) {
|
||||
this.print(tag, msg, "color:gray;", describe)
|
||||
}
|
||||
|
||||
@@ -114,17 +121,27 @@ export class Logger {
|
||||
return (this.tags & tag) != 0;
|
||||
}
|
||||
|
||||
public static print(tag: LogType, msg: any, color: string, describe?: string) {
|
||||
/**
|
||||
* 输出日志
|
||||
* @param tag 日志类型
|
||||
* @param msg 日志内容
|
||||
* @param color 日志文本颜色
|
||||
* @param describe 日志标题描述
|
||||
* @returns
|
||||
*/
|
||||
private static print(tag: LogType, msg: any, color: string, describe?: string) {
|
||||
// 标记没有打开,不打印该日志
|
||||
if (!this.isOpen(tag)) {
|
||||
return;
|
||||
|
||||
}
|
||||
var backLog = console.log || log;
|
||||
var type = names[tag];
|
||||
if (describe) {
|
||||
backLog.call(null, "%c%s%s%s:%s%o", color, this.getDateString(), '[' + tag + ']', this.stack(5), describe, msg);
|
||||
backLog.call(null, "%c%s%s%s:%s%o", color, this.getDateString(), '[' + type + ']', this.stack(5), describe, msg);
|
||||
}
|
||||
else {
|
||||
backLog.call(null, "%c%s%s%s:%o", color, this.getDateString(), '[' + tag + ']', this.stack(5), msg);
|
||||
backLog.call(null, "%c%s%s%s:%o", color, this.getDateString(), '[' + type + ']', this.stack(5), msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +194,7 @@ export class Logger {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static getDateString(): string {
|
||||
private static getDateString(): string {
|
||||
let d = new Date();
|
||||
let str = d.getHours().toString();
|
||||
let timeStr = "";
|
||||
@@ -196,4 +213,5 @@ export class Logger {
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
Logger.init();
|
||||
@@ -21,6 +21,7 @@ interface AsyncTask {
|
||||
params: any
|
||||
}
|
||||
|
||||
/** 异步队列处理 */
|
||||
export class AsyncQueue {
|
||||
// 正在运行的任务
|
||||
private _runningAsyncTask: AsyncTask | null = null;
|
||||
|
||||
@@ -27,7 +27,7 @@ export module storage {
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储
|
||||
* 存储本地数据
|
||||
* @param key 存储key
|
||||
* @param value 存储值
|
||||
* @returns
|
||||
@@ -75,7 +75,7 @@ export module storage {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取
|
||||
* 获取本地数据
|
||||
* @param key 获取的key
|
||||
* @param defaultValue 获取的默认值
|
||||
* @returns
|
||||
@@ -127,8 +127,8 @@ export module storage {
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除某个值
|
||||
* @param key 需要移除的key
|
||||
* 删除指定关键字的数据
|
||||
* @param key 需要移除的关键字
|
||||
* @returns
|
||||
*/
|
||||
export function remove(key: string) {
|
||||
@@ -145,9 +145,7 @@ export module storage {
|
||||
sys.localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空整个本地存储
|
||||
*/
|
||||
/** 清空整个本地存储 */
|
||||
export function clear() {
|
||||
sys.localStorage.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user