ddd
This commit is contained in:
@@ -9,7 +9,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
|
||||
import { Initialize } from "../initialize/Initialize";
|
||||
import { GameMap } from "../map/GameMap";
|
||||
import { Role } from "../role/Role";
|
||||
|
||||
import { data } from "../data/data";
|
||||
/** 游戏模块 */
|
||||
@ecs.register('SingletonModule')
|
||||
export class SingletonModuleComp extends ecs.Comp {
|
||||
@@ -19,6 +19,8 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
map: GameMap = null!;
|
||||
/** 游戏主角 */
|
||||
own: Role = null;
|
||||
/** 游戏数据 */
|
||||
data:data = null!;
|
||||
|
||||
reset() { }
|
||||
}
|
||||
|
||||
9
assets/script/game/data.meta
Normal file
9
assets/script/game/data.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "7d9b27df-701e-44ee-8732-b53f9d22cca2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
35
assets/script/game/data/data.ts
Normal file
35
assets/script/game/data/data.ts
Normal 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());
|
||||
}
|
||||
}
|
||||
9
assets/script/game/data/data.ts.meta
Normal file
9
assets/script/game/data/data.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "cb9afa42-2112-471e-b86c-79407ba6abd4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
46
assets/script/game/data/dataModelComp.ts
Normal file
46
assets/script/game/data/dataModelComp.ts
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
9
assets/script/game/data/dataModelComp.ts.meta
Normal file
9
assets/script/game/data/dataModelComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0aefc30a-9392-4ada-b3d0-8c15625e8cfc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
26
assets/script/game/data/dataViewComp.ts
Normal file
26
assets/script/game/data/dataViewComp.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/data/dataViewComp.ts.meta
Normal file
9
assets/script/game/data/dataViewComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8ae6d033-ff0f-44d5-9ff7-c57751bd4ea1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
23
assets/script/game/data/dataViewVM.ts
Normal file
23
assets/script/game/data/dataViewVM.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/data/dataViewVM.ts.meta
Normal file
9
assets/script/game/data/dataViewVM.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4209bcee-3867-4c0b-83c9-a4eeee989328",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import { AsyncQueue, NextFunction } from "../../../../extensions/oops-plugin-fra
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { LoadingViewComp } from "./view/LoadingViewComp";
|
||||
|
||||
import {data} from "../data/data";
|
||||
/**
|
||||
* 游戏进入初始化模块
|
||||
* 1、热更新
|
||||
@@ -20,10 +20,12 @@ import { LoadingViewComp } from "./view/LoadingViewComp";
|
||||
@ecs.register(`Initialize`)
|
||||
export class Initialize extends ecs.Entity {
|
||||
LoadingView!: LoadingViewComp;
|
||||
|
||||
data:data=null!;
|
||||
protected init() {
|
||||
var queue: AsyncQueue = new AsyncQueue();
|
||||
|
||||
this.data=ecs.getEntity<data>(data);
|
||||
this.data.dataModel.vmAdd();
|
||||
var queue: AsyncQueue = new AsyncQueue();
|
||||
// 加载自定义资源
|
||||
this.loadCustom(queue);
|
||||
// 加载多语言包
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-17 13:46:25
|
||||
*/
|
||||
import { _decorator } from "cc";
|
||||
import { _decorator ,v3,Vec3} from "cc";
|
||||
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 { smc } from "../../common/SingletonModuleComp";
|
||||
import { GameMap } from "../../map/GameMap";
|
||||
|
||||
import { Role } from "../../role/Role";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 游戏资源加载 */
|
||||
@@ -51,7 +51,6 @@ export class LoadingViewComp extends CCVMParentComp {
|
||||
start() {
|
||||
this.loadRes();
|
||||
}
|
||||
|
||||
/** 加载资源 */
|
||||
private async loadRes() {
|
||||
this.data.progress = 0;
|
||||
|
||||
@@ -28,7 +28,6 @@ export class MapViewComp extends CCComp {
|
||||
|
||||
start() {
|
||||
this.scene = this.getComponent(MapViewScene);
|
||||
|
||||
this.addHero();
|
||||
}
|
||||
|
||||
@@ -36,7 +35,7 @@ export class MapViewComp extends CCComp {
|
||||
|
||||
|
||||
private mapLoaded() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/** 添加玩家 */
|
||||
|
||||
@@ -15,7 +15,6 @@ import Charactor from "../map/view/map/charactor/Charactor";
|
||||
import { RoleModelComp } from "./model/RoleModelComp";
|
||||
import { RoleSpine } from "./view/RoleSpine";
|
||||
import { RoleViewComp } from "./view/RoleViewComp";
|
||||
import { RoleViewUIControllerComp } from "./view/RoleViewUIControllerComp";
|
||||
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Role`)
|
||||
@@ -24,7 +23,6 @@ export class Role extends ecs.Entity {
|
||||
RoleModel!: RoleModelComp;
|
||||
// 视图层
|
||||
RoleView!: RoleViewComp;
|
||||
RoleViewUIController!: RoleViewUIControllerComp;
|
||||
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(
|
||||
@@ -57,17 +55,5 @@ export class Role extends ecs.Entity {
|
||||
}
|
||||
}
|
||||
|
||||
/** 摇撼控制 */
|
||||
loadJoystick() {
|
||||
var uic: UICallbacks = {
|
||||
onAdded: (node: Node, params: any) => {
|
||||
var comp = node.getComponent(RoleViewUIControllerComp) as ecs.Comp;
|
||||
this.add(comp);
|
||||
}
|
||||
};
|
||||
oops.gui.open(UIID.Role_Controller, null, uic);
|
||||
}
|
||||
removeJoystick() {
|
||||
oops.gui.remove(UIID.Role_Controller);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,13 +28,7 @@ export class RoleViewComp extends CCComp {
|
||||
this.charactor = this.getComponent(Charactor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 摇杆移动
|
||||
* @param dir 移动方向
|
||||
*/
|
||||
runJoystick(dir: Vec3) {
|
||||
this.charactor.joystick(dir);
|
||||
}
|
||||
|
||||
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
|
||||
@@ -10,31 +10,17 @@ import { ecs } from '../../../../../extensions/oops-plugin-framework/assets/libs
|
||||
import { CCComp } from '../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp';
|
||||
import { smc } from '../../common/SingletonModuleComp';
|
||||
import { Role } from '../Role';
|
||||
import { JoystickDataType, RoleViewUIJoystick, SpeedType } from './RoleViewUIJoystick';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("RoleViewUIControllerComp")
|
||||
@ecs.register('RoleViewUIController', false)
|
||||
export class RoleViewUIControllerComp extends CCComp {
|
||||
@property({ type: RoleViewUIJoystick })
|
||||
joystick: RoleViewUIJoystick = null!;
|
||||
|
||||
private target: Role = null!;
|
||||
|
||||
start() {
|
||||
this.target = smc.own;
|
||||
this.joystick.onController = (event: EventTouch, data: JoystickDataType) => {
|
||||
switch (data.type) {
|
||||
case SpeedType.NORMAL:
|
||||
case SpeedType.FAST:
|
||||
this.target.RoleView.runJoystick(data.vector);
|
||||
break;
|
||||
case SpeedType.STOP:
|
||||
this.target.RoleView.runJoystick(Vec3.ZERO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
|
||||
Reference in New Issue
Block a user