From de2a95c48ca02a22d57586fdb69cbdd31dbc291f Mon Sep 17 00:00:00 2001 From: dgflash Date: Tue, 1 Nov 2022 15:29:01 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=95=B0=E6=8D=AE=E8=AE=BF=E9=97=AE=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/libs/camera/OrbitCamera.ts | 4 ++-- assets/module/config/GameConfig.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/assets/libs/camera/OrbitCamera.ts b/assets/libs/camera/OrbitCamera.ts index a8fb8da..0b4b637 100644 --- a/assets/libs/camera/OrbitCamera.ts +++ b/assets/libs/camera/OrbitCamera.ts @@ -144,7 +144,7 @@ export class OrbitCamera extends Component { input.on(Input.EventType.MOUSE_WHEEL, this.onMouseWheel, this); } - this.resetTargetRotation(); + if (this.target) this.resetTargetRotation(); // 根据欧拉角信息计算摄像机四元数,旋转顺序为 YZX Quat.fromEuler(this._rotation, this._targetRotation.x, this._targetRotation.y, this._targetRotation.z); @@ -164,7 +164,7 @@ export class OrbitCamera extends Component { let targetRotation: Vec3 = this._targetRotation.set(this._startRotation); if (this.followTargetRotationY) { targetRotation = tempVec3_2.set(targetRotation); - Quat.toEuler(tempVec3, this.target!.worldRotation); + Quat.toEuler(tempVec3, this.target.worldRotation); targetRotation.add(tempVec3); } } diff --git a/assets/module/config/GameConfig.ts b/assets/module/config/GameConfig.ts index 41ecf5a..9d7e145 100644 --- a/assets/module/config/GameConfig.ts +++ b/assets/module/config/GameConfig.ts @@ -2,7 +2,7 @@ * @Author: dgflash * @Date: 2021-07-03 16:13:17 * @LastEditors: dgflash - * @LastEditTime: 2022-09-06 17:29:04 + * @LastEditTime: 2022-11-01 15:26:26 */ import { oops } from "../../core/Oops"; @@ -52,6 +52,11 @@ export class GameConfig { } private _data: any = null; + /** 游戏配置数据 */ + public get data(): any { + return this._data; + } + constructor(config: any) { let data = config.json; this._data = Object.freeze(data); From 589eb6d59d3c4035308ccdd0250ef56d8076b815 Mon Sep 17 00:00:00 2001 From: dgflash Date: Tue, 1 Nov 2022 15:50:04 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=BA=9F=E5=BC=83config=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BAoops.config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/Oops.ts | 6 ++++-- assets/core/Root.ts | 9 ++------- assets/module/config/Config.ts | 6 +++++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/assets/core/Oops.ts b/assets/core/Oops.ts index c651a65..b5b32af 100644 --- a/assets/core/Oops.ts +++ b/assets/core/Oops.ts @@ -2,12 +2,13 @@ * @Author: dgflash * @Date: 2022-02-11 09:32:47 * @LastEditors: dgflash - * @LastEditTime: 2022-09-02 15:29:45 + * @LastEditTime: 2022-11-01 15:47:42 */ import { ecs } from "../libs/ecs/ECS"; import { ECSRootSystem } from "../libs/ecs/ECSSystem"; import { LanguageManager } from "../libs/gui/language/Language"; import { HttpRequest } from "../libs/network/HttpRequest"; +import { config } from "../module/config/Config"; import { AudioManager } from "./common/audio/AudioManager"; import { MessageManager } from "./common/event/MessageManager"; import { ResLoader } from "./common/loader/ResLoader"; @@ -23,7 +24,8 @@ export var version: string = "1.1.2"; /** 框架核心模块访问入口 */ export class oops { /** ----------核心模块---------- */ - + /** 游戏配置 */ + static config = config; /** 日志管理 */ static log = Logger; /** 全局消息 */ diff --git a/assets/core/Root.ts b/assets/core/Root.ts index 2564e3f..983b219 100644 --- a/assets/core/Root.ts +++ b/assets/core/Root.ts @@ -2,18 +2,13 @@ * @Author: dgflash * @Date: 2021-07-03 16:13:17 * @LastEditors: dgflash - * @LastEditTime: 2022-09-23 15:20:46 + * @LastEditTime: 2022-11-01 15:44:57 */ import { Component, director, game, Game, log, Node, sys, view, _decorator } from "cc"; -import { ecs } from "../libs/ecs/ECS"; import { LanguageManager } from "../libs/gui/language/Language"; -import { HttpRequest } from "../libs/network/HttpRequest"; -import { config } from "../module/config/Config"; import { AudioManager } from "./common/audio/AudioManager"; import { EventMessage } from "./common/event/EventMessage"; -import { MessageManager } from "./common/event/MessageManager"; import { TimerManager } from "./common/manager/TimerManager"; -import { StorageManager } from "./common/storage/StorageManager"; import { GameManager } from "./game/GameManager"; import { GUI } from "./gui/GUI"; import { LayerManager } from "./gui/layer/LayerManager"; @@ -40,7 +35,7 @@ export class Root extends Component { onLoad() { console.log(`Oops Framework v${version}`); this.enabled = false; - config.init(() => { + oops.config.init(() => { this.enabled = true; this.init(); this.run(); diff --git a/assets/module/config/Config.ts b/assets/module/config/Config.ts index 64acccd..bab94d6 100644 --- a/assets/module/config/Config.ts +++ b/assets/module/config/Config.ts @@ -2,7 +2,7 @@ * @Author: dgflash * @Date: 2021-07-03 16:13:17 * @LastEditors: dgflash - * @LastEditTime: 2022-09-06 17:28:01 + * @LastEditTime: 2022-11-01 15:47:16 */ import { game, JsonAsset } from "cc"; @@ -45,4 +45,8 @@ export class Config { } } +/** + * 游戏配置静态访问类 + * @deprecated 下个版本废弃,请使用 oops.config + */ export const config = new Config() \ No newline at end of file From f7fc1ba8e77b14549b518d52f666bc7761645f14 Mon Sep 17 00:00:00 2001 From: dgflash Date: Sat, 5 Nov 2022 10:43:22 +0800 Subject: [PATCH 3/4] =?UTF-8?q?MVVM=E6=A1=86=E6=9E=B6=E5=85=BC=E5=AE=B93.6?= =?UTF-8?q?.2=E7=BC=96=E8=BE=91=E5=99=A8=E9=A2=84=E8=A7=88=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/Oops.ts | 2 +- assets/libs/model-view/JsonOb.ts | 2 +- assets/libs/model-view/VMBase.ts | 19 +++++---- assets/libs/model-view/VMCompsEdit.ts | 22 +++++----- assets/libs/model-view/VMCustom.ts | 45 +++++++++++---------- assets/libs/model-view/VMEnv.ts | 10 +++++ assets/libs/model-view/VMEnv.ts.meta | 9 +++++ assets/libs/model-view/VMEvent.ts | 4 +- assets/libs/model-view/VMLabel.ts | 22 +++++----- assets/libs/model-view/VMModify.ts | 4 +- assets/libs/model-view/VMParent.ts | 2 +- assets/libs/model-view/VMProgress.ts | 12 +++--- assets/libs/model-view/VMState.ts | 2 +- assets/libs/model-view/ui/BhvButtonGroup.ts | 2 +- assets/libs/model-view/ui/BhvFrameIndex.ts | 2 +- assets/libs/model-view/ui/BhvRollNumber.ts | 2 +- assets/libs/model-view/ui/BhvSwitchPage.ts | 9 +++-- 17 files changed, 100 insertions(+), 70 deletions(-) create mode 100644 assets/libs/model-view/VMEnv.ts create mode 100644 assets/libs/model-view/VMEnv.ts.meta diff --git a/assets/core/Oops.ts b/assets/core/Oops.ts index b5b32af..cc0e2c3 100644 --- a/assets/core/Oops.ts +++ b/assets/core/Oops.ts @@ -19,7 +19,7 @@ import { GameManager } from "./game/GameManager"; import { LayerManager } from "./gui/layer/LayerManager"; /** 框架版本号 */ -export var version: string = "1.1.2"; +export var version: string = "1.1.3"; /** 框架核心模块访问入口 */ export class oops { diff --git a/assets/libs/model-view/JsonOb.ts b/assets/libs/model-view/JsonOb.ts index d0ec78c..b1c0f84 100644 --- a/assets/libs/model-view/JsonOb.ts +++ b/assets/libs/model-view/JsonOb.ts @@ -4,11 +4,11 @@ * @LastEditors: dgflash * @LastEditTime: 2022-09-06 17:18:05 */ + /** * 实现动态绑定的核心部分, * 每次修改属性值,都会调用对应函数,并且获取值的路径 */ - const OP = Object.prototype; const types = { obj: '[object Object]', diff --git a/assets/libs/model-view/VMBase.ts b/assets/libs/model-view/VMBase.ts index 2b1f7a3..4838728 100644 --- a/assets/libs/model-view/VMBase.ts +++ b/assets/libs/model-view/VMBase.ts @@ -1,6 +1,7 @@ import { Component, log, _decorator } from 'cc'; -import { DEBUG, EDITOR } from 'cc/env'; +import { DEBUG } from 'cc/env'; import { VM } from './ViewModel'; +import { VMEnv } from './VMEnv'; // 用来处理通知数据的层级 // 控制旗下子节点的数据 @@ -9,13 +10,14 @@ import { VM } from './ViewModel'; const DEBUG_WATCH_PATH: boolean = false; -const { ccclass, property } = _decorator; +const { ccclass, help } = _decorator; /** * watchPath 的基础,只提供绑定功能 和 对应的数据更新函数 */ @ccclass -export default class VMBase extends Component { +@help('https://gitee.com/dgflash/oops-framework/blob/master/doc/mvvm/VMBase.md') +export class VMBase extends Component { /**VM管理 */ VM = VM; @@ -35,7 +37,7 @@ export default class VMBase extends Component { * 如果需要重写onLoad 方法,请根据顺序调用 super.onLoad(),执行默认方法 */ onLoad() { - if (EDITOR) return; + if (VMEnv.editor) return; // 提前拆分、并且解析路径 let paths = this.watchPath.split('.'); @@ -86,7 +88,8 @@ export default class VMBase extends Component { } onEnable() { - if (EDITOR) return; // 编辑器模式不能判断 + if (VMEnv.editor) return; + if (this.templateMode) { this.setMultPathEvent(true); } @@ -98,7 +101,8 @@ export default class VMBase extends Component { } onDisable() { - if (EDITOR) return;//编辑器模式不能判断 + if (VMEnv.editor) return; + if (this.templateMode) { this.setMultPathEvent(false); } @@ -109,7 +113,8 @@ export default class VMBase extends Component { // 多路径监听方式 private setMultPathEvent(enabled: boolean = true) { - if (EDITOR) return; + if (VMEnv.editor) return; + let arr = this.watchPathArr; for (let i = 0; i < arr.length; i++) { const path = arr[i]; diff --git a/assets/libs/model-view/VMCompsEdit.ts b/assets/libs/model-view/VMCompsEdit.ts index 004c7fc..05a6cc6 100644 --- a/assets/libs/model-view/VMCompsEdit.ts +++ b/assets/libs/model-view/VMCompsEdit.ts @@ -1,5 +1,5 @@ import { CCString, Component, Enum, log, Node, _decorator } from "cc"; -import { EDITOR } from "cc/env"; +import { VMEnv } from "./VMEnv"; const { ccclass, property, executeInEditMode, menu, help } = _decorator; @@ -17,7 +17,7 @@ enum ACTION_MODE { @ccclass @executeInEditMode @menu('ModelViewer/Edit-Comps (快速组件操作)') -@help('https://github.com/wsssheep/cocos_creator_mvvm_tools/blob/master/docs/VMCompsEdit.md') +@help('https://gitee.com/dgflash/oops-framework/blob/master/doc/mvvm/VMCompsEdit.md') export default class MVCompsEdit extends Component { @property({ type: [CCString] @@ -149,11 +149,10 @@ export default class MVCompsEdit extends Component { collectNodes: Node[] = []; onLoad() { - //不要把脚本挂载运行时的提示 - if (!EDITOR) { - let path = this.getNodePath(this.node); - console.error('you forget delete MVEditFinder,[path]', path); - } + if (VMEnv.editor) return; + + let path = this.getNodePath(this.node); + console.error('you forget delete MVEditFinder,[path]', path); } setComponents(state: number) { @@ -213,17 +212,16 @@ export default class MVCompsEdit extends Component { } } break; - case 1://激活组件 + case 1: // 激活组件 v.enabled = true; break; - case 2://关闭组件 + case 2: // 关闭组件 v.enabled = false; break; - case 3://删除组件 + case 3: // 删除组件 v.node.removeComponent(v); break; - case 4://替换指定路径 - + case 4: // 替换指定路径 let targetPath = this.targetPath; let replacePath = this.replacePath; if (v.templateMode === true) { diff --git a/assets/libs/model-view/VMCustom.ts b/assets/libs/model-view/VMCustom.ts index a110137..b3c1582 100644 --- a/assets/libs/model-view/VMCustom.ts +++ b/assets/libs/model-view/VMCustom.ts @@ -1,6 +1,6 @@ import { Toggle, _decorator } from 'cc'; -import { EDITOR } from 'cc/env'; -import VMBase from './VMBase'; +import { VMBase } from './VMBase'; +import { VMEnv } from './VMEnv'; const { ccclass, property, executeInEditMode, menu, help } = _decorator; @@ -26,8 +26,8 @@ const COMP_ARRAY_CHECK = [ @ccclass @executeInEditMode @menu('ModelViewer/VM-Custom (自定义VM)') -@help('https://github.com/wsssheep/cocos_creator_mvvm_tools/blob/master/docs/VMCustom.md') -export default class VMCustom extends VMBase { +@help('https://gitee.com/dgflash/oops-framework/blob/master/doc/mvvm/VMCustom.md') +export class VMCustom extends VMBase { @property({ tooltip: '激活controller,以开启双向绑定,否则只能接收消息', }) @@ -76,10 +76,11 @@ export default class VMCustom extends VMBase { // 只在运行时检查组件是否缺失可用 this.checkEditorComponent();//编辑器检查 - if (!EDITOR) { - this._watchComponent = this.node.getComponent(this.componentName); - this.checkComponentState(); - } + + if (VMEnv.editor) return; + + this._watchComponent = this.node.getComponent(this.componentName); + this.checkComponentState(); } onRestore() { @@ -93,18 +94,18 @@ export default class VMCustom extends VMBase { // 挂在对应节点后,自动获取组件属性和名字 checkEditorComponent() { - if (EDITOR) { - let checkArray = COMP_ARRAY_CHECK; - for (let i = 0; i < checkArray.length; i++) { - const params = checkArray[i]; - let comp = this.node.getComponent(params[0] as string); - if (comp) { - if (this.componentName == '') this.componentName = params[0] as string; - if (this.componentProperty == '') this.componentProperty = params[1] as string; - if (params[2] !== null) this.controller = params[2] as boolean; + if (VMEnv.editor) return; - break; - } + let checkArray = COMP_ARRAY_CHECK; + for (let i = 0; i < checkArray.length; i++) { + const params = checkArray[i]; + let comp = this.node.getComponent(params[0] as string); + if (comp) { + if (this.componentName == '') this.componentName = params[0] as string; + if (this.componentProperty == '') this.componentProperty = params[1] as string; + if (params[2] !== null) this.controller = params[2] as boolean; + + break; } } } @@ -133,7 +134,8 @@ export default class VMCustom extends VMBase { /** 初始化获取数据 */ onValueInit() { - if (EDITOR) return; //编辑器模式不初始化 + if (VMEnv.editor) return; + //更新信息 this.setComponentValue(this.VM.getValue(this.watchPath)); } @@ -150,7 +152,8 @@ export default class VMCustom extends VMBase { update(dt: number) { // 脏检查(组件是否存在,是否被激活) - if (EDITOR == true) return; + if (VMEnv.editor) return; + //if (this.templateMode == true) return; //todo 模板模式下不能计算 if (!this.controller) return; if (!this._canWatchComponent || this._watchComponent['enabled'] === false) return; diff --git a/assets/libs/model-view/VMEnv.ts b/assets/libs/model-view/VMEnv.ts new file mode 100644 index 0000000..addb3e8 --- /dev/null +++ b/assets/libs/model-view/VMEnv.ts @@ -0,0 +1,10 @@ +import { EDITOR } from "cc/env"; + +/** VM组件环境验证 */ +export class VMEnv { + /** 编辑状态 */ + static get editor() { + // @ts-ignore + return EDITOR && !cc.GAME_VIEW; + } +} \ No newline at end of file diff --git a/assets/libs/model-view/VMEnv.ts.meta b/assets/libs/model-view/VMEnv.ts.meta new file mode 100644 index 0000000..ce18e09 --- /dev/null +++ b/assets/libs/model-view/VMEnv.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "fdf7243d-d4f7-425e-93d0-fbadacd6e7e2", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/libs/model-view/VMEvent.ts b/assets/libs/model-view/VMEvent.ts index 5be438c..fa7c25f 100644 --- a/assets/libs/model-view/VMEvent.ts +++ b/assets/libs/model-view/VMEvent.ts @@ -1,5 +1,5 @@ import { CCString, Enum, EventHandler, _decorator } from 'cc'; -import VMBase from './VMBase'; +import { VMBase } from './VMBase'; // +普通 label 更新数据的情况,label.string = xxx; // +frameIndex 插件,通过number 数值设置 BhvFrameIndex 来切换当前贴图 @@ -30,7 +30,7 @@ enum FILTER_MODE { @ccclass @executeInEditMode @menu('ModelViewer/VM-EventCall(调用函数)') -@help('https://github.com/wsssheep/cocos_creator_mvvm_tools/blob/master/docs/VMEvent.md') +@help('https://gitee.com/dgflash/oops-framework/blob/master/doc/mvvm/VMEvent.md') export default class VMEvent extends VMBase { @property({ tooltip: '使用模板模式,可以使用多路径监听' diff --git a/assets/libs/model-view/VMLabel.ts b/assets/libs/model-view/VMLabel.ts index fe43b58..74f1101 100644 --- a/assets/libs/model-view/VMLabel.ts +++ b/assets/libs/model-view/VMLabel.ts @@ -1,7 +1,7 @@ import { CCString, error, _decorator } from 'cc'; -import { EDITOR } from 'cc/env'; import { StringFormatFunction } from './StringFormat'; -import VMBase from './VMBase'; +import { VMBase } from './VMBase'; +import { VMEnv } from './VMEnv'; const { ccclass, property, menu, executeInEditMode, help } = _decorator; @@ -20,7 +20,7 @@ const LABEL_TYPE = { @ccclass @executeInEditMode @menu('ModelViewer/VM-Label(文本VM)') -@help('https://github.com/wsssheep/cocos_creator_mvvm_tools/blob/master/docs/VMLabel.md') +@help('https://gitee.com/dgflash/oops-framework/blob/master/doc/mvvm/VMLabel.md') export default class VMLabel extends VMBase { @property({ tooltip: '是否启用模板代码,只能在运行时之前设置,\n将会动态解析模板语法 {{0}},并且自动设置监听的路径' @@ -29,6 +29,7 @@ export default class VMLabel extends VMBase { @property({ visible() { + // @ts-ignore return this.templateMode === false; } }) @@ -42,6 +43,7 @@ export default class VMLabel extends VMBase { @property({ type: [CCString], visible() { + // @ts-ignore return this.templateMode === true; } }) @@ -64,16 +66,18 @@ export default class VMLabel extends VMBase { onLoad() { super.onLoad(); this.checkLabel(); - if (!EDITOR) { - if (this.templateMode) { - this.originText = this.getLabelValue(); - this.parseTemplate(); - } + + if (VMEnv.editor) return; + + if (this.templateMode) { + this.originText = this.getLabelValue(); + this.parseTemplate(); } } start() { - if (EDITOR) return; + if (VMEnv.editor) return; + this.onValueInit(); } diff --git a/assets/libs/model-view/VMModify.ts b/assets/libs/model-view/VMModify.ts index d45d7a2..00d7b13 100644 --- a/assets/libs/model-view/VMModify.ts +++ b/assets/libs/model-view/VMModify.ts @@ -1,5 +1,5 @@ import { Enum, _decorator } from 'cc'; -import VMBase from './VMBase'; +import { VMBase } from './VMBase'; const { ccclass, property, menu, help } = _decorator; @@ -17,7 +17,7 @@ enum CLAMP_MODE { */ @ccclass @menu('ModelViewer/VM-Modify(修改Model)') -@help('https://github.com/wsssheep/cocos_creator_mvvm_tools/blob/master/docs/VMModify.md') +@help('https://gitee.com/dgflash/oops-framework/blob/master/doc/mvvm/VMModify.md') export default class VMModify extends VMBase { @property({ tooltip: "监视对象路径" diff --git a/assets/libs/model-view/VMParent.ts b/assets/libs/model-view/VMParent.ts index 4aa272e..f245eab 100644 --- a/assets/libs/model-view/VMParent.ts +++ b/assets/libs/model-view/VMParent.ts @@ -13,7 +13,7 @@ const { ccclass, help, executionOrder } = _decorator; */ @ccclass @executionOrder(-1) -@help('https://github.com/wsssheep/cocos_creator_mvvm_tools/blob/master/docs/VMParent.md') +@help('https://gitee.com/dgflash/oops-framework/blob/master/doc/mvvm/VMParent.md') export default class VMParent extends GameComponent { /** 绑定的标签,可以通过这个tag 获取 当前的 vm 实例 */ protected tag: string = '_temp'; diff --git a/assets/libs/model-view/VMProgress.ts b/assets/libs/model-view/VMProgress.ts index bd6cf5a..b57970f 100644 --- a/assets/libs/model-view/VMProgress.ts +++ b/assets/libs/model-view/VMProgress.ts @@ -5,15 +5,15 @@ * @LastEditTime: 2022-08-11 15:43:34 */ import { CCString, _decorator } from "cc"; -import { EDITOR } from "cc/env"; import { StringFormatFunction } from "./StringFormat"; -import VMCustom from "./VMCustom"; +import { VMCustom } from "./VMCustom"; +import { VMEnv } from "./VMEnv"; const { ccclass, property, menu, help } = _decorator; @ccclass @menu('ModelViewer/VM-Progress (VM-进度条)') -@help('https://github.com/wsssheep/cocos_creator_mvvm_tools/blob/master/docs/VMProgress.md') +@help('https://gitee.com/dgflash/oops-framework/blob/master/doc/mvvm/VMProgress.md') export default class VMProgress extends VMCustom { @property({ visible: false, @@ -46,9 +46,9 @@ export default class VMProgress extends VMCustom { } start() { - if (!EDITOR) { - this.onValueInit(); - } + if (VMEnv.editor) return; + + this.onValueInit(); } onValueInit() { diff --git a/assets/libs/model-view/VMState.ts b/assets/libs/model-view/VMState.ts index 18900c9..08d17dc 100644 --- a/assets/libs/model-view/VMState.ts +++ b/assets/libs/model-view/VMState.ts @@ -1,6 +1,6 @@ import { Button, CCInteger, color, Color, Enum, Node, UIRenderer, Sprite, UIOpacity, _decorator } from 'cc'; import { VM } from './ViewModel'; -import VMBase from './VMBase'; +import { VMBase } from './VMBase'; const { ccclass, property, menu, help } = _decorator; diff --git a/assets/libs/model-view/ui/BhvButtonGroup.ts b/assets/libs/model-view/ui/BhvButtonGroup.ts index 040daf1..ee8b9d5 100644 --- a/assets/libs/model-view/ui/BhvButtonGroup.ts +++ b/assets/libs/model-view/ui/BhvButtonGroup.ts @@ -13,7 +13,7 @@ enum PARAM_TYPE { */ @ccclass @menu("添加特殊行为/UI/Button Group(一组按钮控制)") -export default class BhvButtonGroup extends Component { +export class BhvButtonGroup extends Component { @property({ type: Enum(Button.Transition) }) diff --git a/assets/libs/model-view/ui/BhvFrameIndex.ts b/assets/libs/model-view/ui/BhvFrameIndex.ts index e535fef..168b6db 100644 --- a/assets/libs/model-view/ui/BhvFrameIndex.ts +++ b/assets/libs/model-view/ui/BhvFrameIndex.ts @@ -6,7 +6,7 @@ const { ccclass, property, executeInEditMode, requireComponent, menu } = _decora @executeInEditMode @requireComponent(Sprite) @menu("添加特殊行为/UI/Frame Index(帧图改变)") -export default class BhvFrameIndex extends Component { +export class BhvFrameIndex extends Component { @property({ type: [SpriteFrame], tooltip: 'sprite将会用到帧图片' diff --git a/assets/libs/model-view/ui/BhvRollNumber.ts b/assets/libs/model-view/ui/BhvRollNumber.ts index b49aebe..99882ab 100644 --- a/assets/libs/model-view/ui/BhvRollNumber.ts +++ b/assets/libs/model-view/ui/BhvRollNumber.ts @@ -25,7 +25,7 @@ type CustomCallback = (curValue: number, targetValue: number) => string; */ @ccclass @menu("添加特殊行为/UI/Roll Number (滚动数字)") -export default class BhvRollNumber extends Component { +export class BhvRollNumber extends Component { @property({ type: Label, tooltip: '需要滚动的 Label 组件,如果不进行设置,就会从自己的节点自动查找' diff --git a/assets/libs/model-view/ui/BhvSwitchPage.ts b/assets/libs/model-view/ui/BhvSwitchPage.ts index 1d0c3af..e13bdda 100644 --- a/assets/libs/model-view/ui/BhvSwitchPage.ts +++ b/assets/libs/model-view/ui/BhvSwitchPage.ts @@ -1,12 +1,12 @@ import { CCInteger, Component, Node, _decorator } from "cc"; -import { EDITOR } from "cc/env"; +import { VMEnv } from "../VMEnv"; const { ccclass, property, executeInEditMode, menu } = _decorator; @ccclass @executeInEditMode @menu("添加特殊行为/UI/Switch Page (切换页面)") -export default class BhvSwitchPage extends Component { +export class BhvSwitchPage extends Component { @property isLoopPage: boolean = false; @@ -34,7 +34,7 @@ export default class BhvSwitchPage extends Component { this.preIndex = this._index;//标记之前的页面 this._index = v; - if (EDITOR) { + if (VMEnv.editor) { this._updateEditorPage(v); } else { @@ -57,7 +57,8 @@ export default class BhvSwitchPage extends Component { } private _updateEditorPage(page: number) { - if (!EDITOR) return; + if (!VMEnv.editor) return; + let children = this.node.children; for (let i = 0; i < children.length; i++) { const node = children[i]; From aac0bf064a4d30d7ec0bfa9fd506e3c2c80c7c61 Mon Sep 17 00:00:00 2001 From: dgflash Date: Sat, 5 Nov 2022 12:11:14 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/Oops.ts | 4 +-- assets/core/Root.ts | 18 +++++++++-- assets/core/common/loader/ResLoader.ts | 8 +---- .../2d/SpineFinishedRelease.ts | 4 +-- assets/libs/gui/button/ButtonEffect.ts | 6 ++-- assets/module/config/Config.ts | 32 +------------------ 6 files changed, 25 insertions(+), 47 deletions(-) diff --git a/assets/core/Oops.ts b/assets/core/Oops.ts index cc0e2c3..3daed27 100644 --- a/assets/core/Oops.ts +++ b/assets/core/Oops.ts @@ -8,7 +8,7 @@ import { ecs } from "../libs/ecs/ECS"; import { ECSRootSystem } from "../libs/ecs/ECSSystem"; import { LanguageManager } from "../libs/gui/language/Language"; import { HttpRequest } from "../libs/network/HttpRequest"; -import { config } from "../module/config/Config"; +import { Config } from "../module/config/Config"; import { AudioManager } from "./common/audio/AudioManager"; import { MessageManager } from "./common/event/MessageManager"; import { ResLoader } from "./common/loader/ResLoader"; @@ -25,7 +25,7 @@ export var version: string = "1.1.3"; export class oops { /** ----------核心模块---------- */ /** 游戏配置 */ - static config = config; + static config = new Config(); /** 日志管理 */ static log = Logger; /** 全局消息 */ diff --git a/assets/core/Root.ts b/assets/core/Root.ts index 983b219..327440e 100644 --- a/assets/core/Root.ts +++ b/assets/core/Root.ts @@ -4,8 +4,11 @@ * @LastEditors: dgflash * @LastEditTime: 2022-11-01 15:44:57 */ -import { Component, director, game, Game, log, Node, sys, view, _decorator } from "cc"; +import { Component, director, game, Game, JsonAsset, log, Node, sys, view, _decorator } from "cc"; import { LanguageManager } from "../libs/gui/language/Language"; +import { BuildTimeConstants } from "../module/config/BuildTimeConstants"; +import { GameConfig } from "../module/config/GameConfig"; +import { GameQueryConfig } from "../module/config/GameQueryConfig"; import { AudioManager } from "./common/audio/AudioManager"; import { EventMessage } from "./common/event/EventMessage"; import { TimerManager } from "./common/manager/TimerManager"; @@ -35,7 +38,18 @@ export class Root extends Component { onLoad() { console.log(`Oops Framework v${version}`); this.enabled = false; - oops.config.init(() => { + + let config_name = "config/config"; + oops.res.load(config_name, JsonAsset, () => { + var config = oops.res.get(config_name); + oops.config.btc = new BuildTimeConstants(); + oops.config.query = new GameQueryConfig(); + oops.config.game = new GameConfig(config); + oops.http.server = oops.config.game.httpServer; // Http 服务器地址 + oops.http.timeout = oops.config.game.httpTimeout; // Http 请求超时时间 + oops.storage.init(oops.config.game.localDataKey, oops.config.game.localDataIv); // 初始化本地存储加密 + game.frameRate = oops.config.game.frameRate; // 初始化每秒传输帧数 + this.enabled = true; this.init(); this.run(); diff --git a/assets/core/common/loader/ResLoader.ts b/assets/core/common/loader/ResLoader.ts index 09f8306..e9d9a8a 100644 --- a/assets/core/common/loader/ResLoader.ts +++ b/assets/core/common/loader/ResLoader.ts @@ -284,10 +284,4 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback); }); } } -} - -/** - * 资源管理模块 - * @deprecated 下个版本废弃,请使用 oops.res - */ -export var resLoader = new ResLoader(); \ No newline at end of file +} \ No newline at end of file diff --git a/assets/libs/animator-effect/2d/SpineFinishedRelease.ts b/assets/libs/animator-effect/2d/SpineFinishedRelease.ts index 1340cfd..5f71a21 100644 --- a/assets/libs/animator-effect/2d/SpineFinishedRelease.ts +++ b/assets/libs/animator-effect/2d/SpineFinishedRelease.ts @@ -6,7 +6,7 @@ */ import { Component, sp, _decorator } from 'cc'; -import { resLoader } from '../../../core/common/loader/ResLoader'; +import { oops } from '../../../core/Oops'; const { ccclass, property } = _decorator; /** 动画播放完隐藏特效 */ @@ -28,7 +28,7 @@ export class SpineFinishedRelease extends Component { this.spine.setCompleteListener(this.onSpineComplete.bind(this)); if (this.resPath) { - resLoader.load(this.resPath, sp.SkeletonData, (err: Error | null, sd: sp.SkeletonData) => { + oops.res.load(this.resPath, sp.SkeletonData, (err: Error | null, sd: sp.SkeletonData) => { if (err) { console.error(`加载【${this.resPath}】的 SPINE 资源不存在`); return; diff --git a/assets/libs/gui/button/ButtonEffect.ts b/assets/libs/gui/button/ButtonEffect.ts index a45943d..162c895 100644 --- a/assets/libs/gui/button/ButtonEffect.ts +++ b/assets/libs/gui/button/ButtonEffect.ts @@ -1,5 +1,5 @@ import { Animation, AnimationClip, EventTouch, _decorator } from "cc"; -import { resLoader } from "../../../core/common/loader/ResLoader"; +import { oops } from "../../../core/Oops"; import ButtonSimple from "./ButtonSimple"; const { ccclass, property, menu } = _decorator; @@ -17,8 +17,8 @@ export default class ButtonEffect extends ButtonSimple { onLoad() { this.anim = this.node.addComponent(Animation); - var ac_start = resLoader.get("common/anim/button_scale_start", AnimationClip)!; - var ac_end = resLoader.get("common/anim/button_scale_end", AnimationClip)!; + var ac_start = oops.res.get("common/anim/button_scale_start", AnimationClip)!; + var ac_end = oops.res.get("common/anim/button_scale_end", AnimationClip)!; this.anim.defaultClip = ac_start; this.anim.createState(ac_start, ac_start?.name); this.anim.createState(ac_end, ac_end?.name); diff --git a/assets/module/config/Config.ts b/assets/module/config/Config.ts index bab94d6..366d962 100644 --- a/assets/module/config/Config.ts +++ b/assets/module/config/Config.ts @@ -5,8 +5,6 @@ * @LastEditTime: 2022-11-01 15:47:16 */ -import { game, JsonAsset } from "cc"; -import { oops } from "../../core/Oops"; import { BuildTimeConstants } from "./BuildTimeConstants"; import { GameConfig } from "./GameConfig"; import { GameQueryConfig } from "./GameQueryConfig"; @@ -21,32 +19,4 @@ export class Config { /** 浏览器查询参数 */ public query!: GameQueryConfig; - - /** 初始化游戏配置 */ - public init(callback: Function) { - let config_name = "config/config"; - oops.res.load(config_name, JsonAsset, () => { - var config = oops.res.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); - - callback(); - }); - } -} - -/** - * 游戏配置静态访问类 - * @deprecated 下个版本废弃,请使用 oops.config - */ -export const config = new Config() \ No newline at end of file +} \ No newline at end of file