This commit is contained in:
walkpan
2024-07-18 08:38:58 +08:00
parent 2ef3bcf322
commit 55542871ef
18 changed files with 409 additions and 78 deletions

View File

@@ -0,0 +1,35 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { dataModelComp } from "./dataModelComp";
import { dataViewComp } from "./dataViewComp";
/** data 模块 */
@ecs.register(`data`)
export class data extends ecs.Entity {
/** ---------- 数据层 ---------- */
dataModel!: dataModelComp;
/** ---------- 业务层 ---------- */
// dataBll!: dataBllComp;
/** ---------- 视图层 ---------- */
dataView!: dataViewComp;
/** 实始添加的数据层组件 */
protected init() {
this.addComponents<ecs.Comp>(dataViewComp,dataModelComp);
}
/** 模块资源释放 */
destroy() {
// 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放
super.destroy();
}
}
/** data 模块业务逻辑系统组件,如无业务逻辑处理可删除此对象 */
export class EcsdataSystem extends ecs.System {
constructor() {
super();
// this.add(new ecs.ComblockSystem());
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "cb9afa42-2112-471e-b86c-79407ba6abd4",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,46 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { VM } from "../../../../extensions/oops-plugin-framework/assets/libs/model-view/ViewModel";
/** 数据层对象 */
@ecs.register('dataModel')
export class dataModelComp extends ecs.Comp {
/** 提供 MVVM 组件使用的数据 */
private vm: dataVM = new dataVM();
/** 显示数据添加到 MVVM 框架中监视 */
vmAdd() {
console.log("dataModelComp vmAdd");
VM.add(this.vm, "data");
}
/** 显示数据从 MVVM 框架中移除 */
vmRemove() {
VM.remove("data");
}
/** 数据层组件移除时,重置所有数据为默认值 */
reset() {
for (var key in this.vm) {
delete this.vm[key];
}
}
}
class dataVM {
/** 英雄名称 */
name: string = "数据测试";
/** 当前等级 */
porwer: number = 0;
/** 当前经验 */
def: number = 0;
/** 下级经验 */
speed: number = 0;
reset() {
this.name = "";
this.porwer = 0;
this.def = 0;
this.speed = 0;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "0aefc30a-9392-4ada-b3d0-8c15625e8cfc",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,26 @@
import { _decorator } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('dataViewComp')
@ecs.register('dataView', true)
export class dataViewComp extends CCComp {
/** 视图层逻辑代码分离演示 */
start() {
var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
// this.on(ModuleEvent.Cmd, this.onHandler, this);
}
/** 全局消息逻辑处理 */
private onHandler(event: string, args: any) {
console.log(event, args);
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "8ae6d033-ff0f-44d5-9ff7-c57751bd4ea1",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,23 @@
import { _decorator } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCVMParentComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCVMParentComp";
const { ccclass, property } = _decorator;
/** 视图层对象 - 支持 MVVM 框架的数据绑定 */
@ccclass('dataViewVMComp')
@ecs.register('dataViewVM', false)
export class dataViewVMComp extends CCVMParentComp {
/** 脚本控制的界面 MVVM 框架绑定数据 */
data: any = {};
/** 视图层逻辑代码分离演示 */
start() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "4209bcee-3867-4c0b-83c9-a4eeee989328",
"files": [],
"subMetas": {},
"userData": {}
}