Browse Source

游戏通用配置模块提到框架中成为复用功能模块

dgflash 3 years ago
parent
commit
b632fc2c9e

+ 1 - 1
.gitignore

@@ -11,7 +11,7 @@ native
 #//////////////////////////
 # NPM
 #//////////////////////////
-node_modules/
+# node_modules/
 
 #//////////////////////////
 # VSCode

+ 15 - 5
assets/script/Main.ts

@@ -2,24 +2,34 @@
  * @Author: dgflash
  * @Date: 2021-07-03 16:13:17
  * @LastEditors: dgflash
- * @LastEditTime: 2022-08-03 10:18:56
+ * @LastEditTime: 2022-08-05 17:27:25
  */
 import { profiler, _decorator } from 'cc';
 import { DEBUG } from 'cc/env';
+import { oops } from '../../extensions/oops-plugin-framework/assets/core/Oops';
+import { Root } from '../../extensions/oops-plugin-framework/assets/core/Root';
 import { ecs } from '../../extensions/oops-plugin-framework/assets/libs/ecs/ECS';
-import { CommonEnter } from './game/common/ecs/CommonEnter';
+import { UIConfigData } from './game/common/config/GameUIConfig';
 import { smc } from './game/common/ecs/SingletonModuleComp';
-import { Initialize } from './game/initialize/Initialize';
+import { EcsInitializeSystem, Initialize } from './game/initialize/Initialize';
 
 const { ccclass, property } = _decorator;
 
 @ccclass('Main')
-export class Main extends CommonEnter {
+export class Main extends Root {
     start() {
         if (DEBUG) profiler.showStats();
     }
 
-    protected async run() {
+    protected run() {
         smc.initialize = ecs.getEntity<Initialize>(Initialize);
     }
+
+    protected initGui() {
+        oops.gui.init(UIConfigData);
+    }
+
+    protected initEcsSystem() {
+        oops.ecs.add(new EcsInitializeSystem());
+    }
 }

+ 0 - 23
assets/script/game/common/config/BuildTimeConstants.ts

@@ -1,23 +0,0 @@
-/*
- * @Author: dgflash
- * @Date: 2021-07-03 16:13:17
- * @LastEditors: dgflash
- * @LastEditTime: 2022-08-02 14:25:27
- */
-import * as buildTimeConstants from 'cc/env';
-
-const keys = (Object.keys(buildTimeConstants) as (keyof typeof buildTimeConstants)[]).sort();
-
-/* 游戏运行环境 */
-export class BuildTimeConstants {
-    constructor() {
-        const keyNameMaxLen = keys.reduce((len, key) => Math.max(len, key.length), 0);
-        var enviroment = `${keys.map((key) => {
-            const value = buildTimeConstants[key];
-            const valueRep = typeof value === 'boolean' ? (value ? 'true' : 'false') : value;
-            return `\n${key.padStart(keyNameMaxLen, ' ')} : ${valueRep}`;
-        })}`;
-
-        console.log(enviroment);
-    }
-}

+ 0 - 11
assets/script/game/common/config/BuildTimeConstants.ts.meta

@@ -1,11 +0,0 @@
-{
-  "ver": "4.0.23",
-  "importer": "typescript",
-  "imported": true,
-  "uuid": "8be0e62f-c2cf-4149-a508-120f952d97e3",
-  "files": [],
-  "subMetas": {},
-  "userData": {
-    "simulateGlobals": []
-  }
-}

+ 0 - 51
assets/script/game/common/config/Config.ts

@@ -1,51 +0,0 @@
-/*
- * @Author: dgflash
- * @Date: 2021-07-03 16:13:17
- * @LastEditors: dgflash
- * @LastEditTime: 2022-06-14 18:43:22
- */
-
-import { game, JsonAsset } from "cc";
-import { resLoader } from "../../../../../extensions/oops-plugin-framework/assets/core/common/loader/ResLoader";
-import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
-import { BuildTimeConstants } from "./BuildTimeConstants";
-import { GameConfig } from "./GameConfig";
-import { GameQueryConfig } from "./GameQueryConfig";
-import { UIConfigData } from "./GameUIConfig";
-
-/** 游戏配置静态访问类 */
-export class Config {
-    /** 构建时环境常量 */
-    public btc!: BuildTimeConstants;
-
-    /** 配置数据,版本号、支持语种等数据 */
-    public game!: GameConfig;
-
-    /** 处理浏览器地址栏参数,包括服务器ip、端口等数据 */
-    public query!: GameQueryConfig;
-
-    public init(callback: Function) {
-        let config_name = "config/config";
-        resLoader.load(config_name, JsonAsset, () => {
-            var config = resLoader.get(config_name);
-            this.btc = new BuildTimeConstants();
-            this.query = new GameQueryConfig();
-            this.game = new GameConfig(config);
-
-            // 初始化每秒传输帧数
-            game.frameRate = this.game.frameRate;
-            // Http 服务器地址
-            oops.http.server = this.game.httpServer;
-            //  Http 请求超时时间
-            oops.http.timeout = this.game.httpTimeout;
-            // 初始化本地存储加密
-            oops.storage.init(this.game.localDataKey, this.game.localDataIv);
-            // 初始化界面窗口配置
-            oops.gui.init(UIConfigData);
-
-            callback();
-        })
-    }
-}
-
-export const config = new Config()

+ 0 - 13
assets/script/game/common/config/Config.ts.meta

@@ -1,13 +0,0 @@
-{
-  "ver": "4.0.23",
-  "importer": "typescript",
-  "imported": true,
-  "uuid": "2f2089e5-ec4b-46fc-a087-6f6c19ec2f4f",
-  "files": [],
-  "subMetas": {},
-  "userData": {
-    "moduleId": "project:///assets/script/game/config/Config.js",
-    "importerSettings": 4,
-    "simulateGlobals": []
-  }
-}

+ 0 - 69
assets/script/game/common/config/GameConfig.ts

@@ -1,69 +0,0 @@
-/*
- * @Author: dgflash
- * @Date: 2021-07-03 16:13:17
- * @LastEditors: dgflash
- * @LastEditTime: 2022-08-02 14:25:50
- */
-
-import { Logger } from "../../../../../extensions/oops-plugin-framework/assets/core/common/log/Logger";
-
-/* 游戏配置解析,对应 resources/config/config.json 配置 */
-export class GameConfig {
-    /** 游戏配置路径 */
-    getConfigPath(relative_path: string) {
-        return "config/game/" + relative_path;
-    }
-    /** 角色资源路径 */
-    getRolePath(name: string) {
-        return `content/role/${name}`;
-    }
-
-    /** 客户端版本号配置 */
-    get version(): string {
-        return this._data["config"]["version"];
-    }
-    /** 包名 */
-    get package(): string {
-        return this._data["config"]["package"];
-    }
-    /** 游戏每秒传输帧数 */
-    get frameRate(): number {
-        return this._data.config.frameRate;
-    }
-    /** 本地存储内容加密 key */
-    get localDataKey(): string {
-        return this._data.config.localDataKey;
-    }
-    /** 本地存储内容加密 iv */
-    get localDataIv(): string {
-        return this._data.config.localDataIv;
-    }
-    /** Http 服务器地址 */
-    get httpServer(): string {
-        return this._data.config.httpServer;
-    }
-    /** Http 请求超时时间 */
-    get httpTimeout(): number {
-        return this._data.config.httpTimeout;
-    }
-
-    /** 获取当前客户端支持的语言类型 */
-    get language(): Array<string> {
-        return this._data.language.type || ["zh"];
-    }
-    get languagePathJson(): string {
-        return this._data.language.path.json || "language/json";
-    }
-    get languagePathTexture(): string {
-        return this._data.language.path.texture || "language/texture";
-    }
-
-
-    private _data: any = null;
-    constructor(config: any) {
-        let data = config.json;
-        this._data = Object.freeze(data);
-
-        Logger.logConfig(this._data, "游戏配置");
-    }
-}

+ 0 - 13
assets/script/game/common/config/GameConfig.ts.meta

@@ -1,13 +0,0 @@
-{
-  "ver": "4.0.23",
-  "importer": "typescript",
-  "imported": true,
-  "uuid": "00d52e1d-c361-4c75-a0e4-98cee46921fc",
-  "files": [],
-  "subMetas": {},
-  "userData": {
-    "moduleId": "project:///assets/script/game/config/GameConfig.js",
-    "importerSettings": 4,
-    "simulateGlobals": []
-  }
-}

+ 0 - 76
assets/script/game/common/config/GameQueryConfig.ts

@@ -1,76 +0,0 @@
-/*
- * @Author: dgflash
- * @Date: 2022-04-14 17:08:01
- * @LastEditors: dgflash
- * @LastEditTime: 2022-08-02 14:25:37
- */
-import { warn } from "cc";
-import { Logger } from "../../../../../extensions/oops-plugin-framework/assets/core/common/log/Logger";
-import { guid } from "../../../../../extensions/oops-plugin-framework/assets/core/common/manager/TimerManager";
-import { UrlParse } from "./UrlParse";
-
-/* 获取和处理浏览器地址栏参数 */
-export class GameQueryConfig {
-    /** 玩家帐号名 */
-    public get username(): string {
-        return this._data["username"];
-    }
-
-    /** 语言 */
-    public get lang(): string {
-        return this._data["lang"] || "zh";
-    }
-
-    /** 客户端ip */
-    public get ip(): string {
-        return this._data["ip"] || "";
-    }
-
-    /** 游戏服务器端口 */
-    public get port(): string {
-        return this._data["port"];
-    }
-
-    /** 测试模式开关 */
-    public get debug(): string {
-        return this._data["debug"];
-    }
-
-    /** 处理动态传递给游戏的服务器地址 */
-    public getConfigServerInfo(): { ips: Array<string>, ssl: boolean, port: number } {
-        let ret = {
-            ips: [],
-            ssl: false,
-            port: 0
-        }
-
-        if (this.port) {
-            ret.port = parseInt(this.port)
-        }
-        if (ret.ips.length < 1) {
-            warn("请在地址栏输入游戏服务器ip");
-        }
-        if (ret.port < 1) {
-            warn("请在地址栏输入端口号")
-        }
-        return ret;
-    }
-
-    // 浏览器地址栏原始参数,不可修改!
-    private _data: any = null;
-    public get data() {
-        return this._data;
-    }
-    constructor() {
-        let data: any = (new UrlParse()).query;
-        if (!data) {
-            return;
-        }
-        if (!data["username"]) {
-            data["username"] = guid();
-        }
-        this._data = Object.freeze(data);
-
-        Logger.logConfig(this._data, "查询参数");
-    }
-}

+ 0 - 9
assets/script/game/common/config/GameQueryConfig.ts.meta

@@ -1,9 +0,0 @@
-{
-  "ver": "4.0.23",
-  "importer": "typescript",
-  "imported": true,
-  "uuid": "966ca790-d312-45e8-a4ce-f4f639b34e4c",
-  "files": [],
-  "subMetas": {},
-  "userData": {}
-}

+ 0 - 48
assets/script/game/common/config/UrlParse.ts

@@ -1,48 +0,0 @@
-/*
- * @Author: dgflash
- * @Date: 2022-07-26 15:27:57
- * @LastEditors: dgflash
- * @LastEditTime: 2022-08-02 14:26:06
- */
-import { sys } from "cc";
-
-/* 地址栏参数处理 */
-export class UrlParse {
-    private _data: any = null;
-
-    /** URL search参数对象 */
-    public get query(): any {
-        return this._data;
-    }
-
-    constructor() {
-        if (!sys.isBrowser) {
-            this._data = {};
-            return;
-        }
-        this._data = this.parseUrl();
-    }
-
-    private parseUrl() {
-        if (typeof window !== "object") {
-            return {};
-        }
-        if (!window.document) {
-            return {};
-        }
-        let url = window.document.location.href.toString();
-        let u = url.split("?");
-        if (typeof (u[1]) == "string") {
-            u = u[1].split("&");
-            let get: any = {};
-            for (let i = 0, l = u.length; i < l; ++i) {
-                let j = u[i].split("=");
-                get[j[0]] = j[1];
-            }
-            return get;
-        }
-        else {
-            return {};
-        }
-    }
-}

+ 0 - 9
assets/script/game/common/config/UrlParse.ts.meta

@@ -1,9 +0,0 @@
-{
-  "ver": "4.0.23",
-  "importer": "typescript",
-  "imported": true,
-  "uuid": "78fce88e-bf53-426f-bb96-19f90cf5d95d",
-  "files": [],
-  "subMetas": {},
-  "userData": {}
-}

+ 0 - 31
assets/script/game/common/ecs/CCComp.ts

@@ -1,31 +0,0 @@
-/*
- * @Author: dgflash
- * @Date: 2021-11-11 19:05:32
- * @LastEditors: dgflash
- * @LastEditTime: 2022-07-25 17:05:19
- */
-
-import { _decorator } from 'cc';
-import { GameComponent } from '../../../../../extensions/oops-plugin-framework/assets/core/game/GameComponent';
-import { ecs } from '../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS';
-
-const { ccclass, property } = _decorator;
-
-/** 
- * ECS结合Cocos Creator组件
- * 使用方法:
- * 1、对象拥有Cocos引擎组件功能、ECS 组件全局访问功能
- * 2、网络游戏,优先有数据对象,在才创建视图组件的流程,在释放视图组件时,不释放数据对象
- * 3、对象自带监听、释放、发送全局消息功能
- * 4、对象管理的所有节点摊平,直接通过节点名获取cc.Node对象(节点名不能有重名)
- */
-@ccclass('CCComp')
-export abstract class CCComp extends GameComponent implements ecs.IComp {
-    static tid: number = -1;
-    static compName: string;
-
-    canRecycle!: boolean;
-    ent!: ecs.Entity;
-
-    abstract reset(): void;
-}

+ 0 - 9
assets/script/game/common/ecs/CCComp.ts.meta

@@ -1,9 +0,0 @@
-{
-  "ver": "4.0.23",
-  "importer": "typescript",
-  "imported": true,
-  "uuid": "c979c0a1-f763-4a06-8b20-a67b2313ff3f",
-  "files": [],
-  "subMetas": {},
-  "userData": {}
-}

+ 0 - 31
assets/script/game/common/ecs/CCVMParentComp.ts

@@ -1,31 +0,0 @@
-/*
- * @Author: dgflash
- * @Date: 2021-11-11 19:05:32
- * @LastEditors: dgflash
- * @LastEditTime: 2022-07-25 17:05:53
- */
-
-import { _decorator } from 'cc';
-import { ecs } from '../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS';
-import VMParent from '../../../../../extensions/oops-plugin-framework/assets/libs/model-view/VMParent';
-
-const { ccclass, property } = _decorator;
-
-/** 
- * Cocos Creator Component + ECS Comp + VM VMParent
- * 使用方法:
- * 1、对象拥有Cocos引擎组件功能、ECS 组件全局访问功能、显示对象与数据结构绑定功能
- * 2、网络游戏,优先有数据对象,然后才创建视图组件,在释放视图组件时,不释放数据对象
- * 3、对象自带监听、释放、发送全局消息功能
- * 4、对象管理的所有节点摊平,直接通过节点名获取cc.Node对象(节点名不能有重名)
- */
-@ccclass('CCVMParentComp')
-export abstract class CCVMParentComp extends VMParent implements ecs.IComp {
-    static tid: number = -1;
-    static compName: string;
-
-    canRecycle!: boolean;
-    ent!: ecs.Entity;
-
-    abstract reset(): void;
-}

+ 0 - 9
assets/script/game/common/ecs/CCVMParentComp.ts.meta

@@ -1,9 +0,0 @@
-{
-  "ver": "4.0.23",
-  "importer": "typescript",
-  "imported": true,
-  "uuid": "79aa43cf-725e-4373-a353-e518f7f15b2f",
-  "files": [],
-  "subMetas": {},
-  "userData": {}
-}

+ 0 - 34
assets/script/game/common/ecs/CommonEnter.ts

@@ -1,34 +0,0 @@
-/*
- * @Author: dgflash
- * @Date: 2021-07-03 16:13:17
- * @LastEditors: dgflash
- * @LastEditTime: 2022-07-25 17:06:01
- */
-import { oops } from '../../../../../extensions/oops-plugin-framework/assets/core/Oops';
-import { Root } from '../../../../../extensions/oops-plugin-framework/assets/core/Root';
-import { ECSRootSystem } from '../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECSSystem';
-import { config } from '../config/Config';
-import { CommonSystem } from './CommonSystem';
-
-/** 游戏业务入口 */
-export class CommonEnter extends Root {
-    onLoad() {
-        super.onLoad();
-
-        oops.ecs = new ECSRootSystem();
-        oops.ecs.add(new CommonSystem())
-        oops.ecs.init();
-
-        // 加载游戏配置
-        config.init(this.run.bind(this));
-    }
-
-    /** 加载完引擎配置文件后执行 */
-    protected run() {
-
-    }
-
-    update(dt: number) {
-        oops.ecs.execute(dt);
-    }
-}

+ 0 - 9
assets/script/game/common/ecs/CommonEnter.ts.meta

@@ -1,9 +0,0 @@
-{
-  "ver": "4.0.23",
-  "importer": "typescript",
-  "imported": true,
-  "uuid": "3164466b-c780-4812-ab04-1a932aac3204",
-  "files": [],
-  "subMetas": {},
-  "userData": {}
-}

+ 0 - 4
assets/script/game/common/ecs/CommonEvent.ts

@@ -1,4 +0,0 @@
-/** 角色模块全局事件 */
-export enum CommonEvent {
-
-}

+ 0 - 9
assets/script/game/common/ecs/CommonEvent.ts.meta

@@ -1,9 +0,0 @@
-{
-  "ver": "4.0.23",
-  "importer": "typescript",
-  "imported": true,
-  "uuid": "cf5d6e27-6466-4df7-a2d6-f416648784a0",
-  "files": [],
-  "subMetas": {},
-  "userData": {}
-}

+ 0 - 18
assets/script/game/common/ecs/CommonSystem.ts

@@ -1,18 +0,0 @@
-/*
- * @Author: dgflash
- * @Date: 2021-07-03 16:13:17
- * @LastEditors: dgflash
- * @LastEditTime: 2022-08-03 10:19:49
- */
-import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
-import { EcsInitializeSystem } from "../../initialize/Initialize";
-
-/** 多模块系统组件注册 */
-export class CommonSystem extends ecs.System {
-    constructor() {
-        super();
-
-        // 添加自定义游戏模块
-        this.add(new EcsInitializeSystem());
-    }
-}

+ 0 - 9
assets/script/game/common/ecs/CommonSystem.ts.meta

@@ -1,9 +0,0 @@
-{
-  "ver": "4.0.23",
-  "importer": "typescript",
-  "imported": true,
-  "uuid": "17cf37fe-121f-4b39-a79d-19716b8c4bc3",
-  "files": [],
-  "subMetas": {},
-  "userData": {}
-}

+ 2 - 2
assets/script/game/initialize/bll/InitRes.ts

@@ -2,13 +2,13 @@
  * @Author: dgflash
  * @Date: 2022-07-22 17:06:22
  * @LastEditors: dgflash
- * @LastEditTime: 2022-07-22 17:09:30
+ * @LastEditTime: 2022-08-05 17:27:40
  */
 import { resLoader } from "../../../../../extensions/oops-plugin-framework/assets/core/common/loader/ResLoader";
 import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
 import { AsyncQueue, NextFunction } from "../../../../../extensions/oops-plugin-framework/assets/libs/collection/AsyncQueue";
 import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
-import { config } from "../../common/config/Config";
+import { config } from "../../../../../extensions/oops-plugin-framework/assets/module/config/Config";
 import { UIID } from "../../common/config/GameUIConfig";
 import { Initialize } from "../Initialize";
 import { LoadingViewComp } from "../view/LoadingViewComp";

+ 2 - 2
assets/script/game/initialize/view/LoadingViewComp.ts

@@ -2,14 +2,14 @@
  * @Author: dgflash
  * @Date: 2021-07-03 16:13:17
  * @LastEditors: dgflash
- * @LastEditTime: 2022-08-03 10:20:31
+ * @LastEditTime: 2022-08-05 17:27:50
  */
 import { _decorator } from "cc";
 import { resLoader } from "../../../../../extensions/oops-plugin-framework/assets/core/common/loader/ResLoader";
 import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
 import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
+import { CCVMParentComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCVMParentComp";
 import { UIID } from "../../common/config/GameUIConfig";
-import { CCVMParentComp } from "../../common/ecs/CCVMParentComp";
 
 const { ccclass, property } = _decorator;
 

+ 1 - 1
extensions/oops-plugin-framework

@@ -1 +1 @@
-Subproject commit 657b7d160edfcb9b6522d91ba88a47793e00e4a4
+Subproject commit 27138767c60ace4a58bcf81abb6dbe83507becc5