74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
import { _decorator,v3 } from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { HeroCard } from "../monster/HeroCard";
|
|
import { HeroCardViewComp } from "../monster/HeroCardViewComp";
|
|
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
|
import { CardList } from "../common/config/CardSet";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('CardControllerComp')
|
|
@ecs.register('CardController', false)
|
|
export class CardControllerComp extends CCComp {
|
|
card_level = 1;
|
|
start() {
|
|
this.load_cards()
|
|
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
|
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
|
}
|
|
|
|
/** 全局消息逻辑处理 */
|
|
// private onHandler(event: string, args: any) {
|
|
// switch (event) {
|
|
// case ModuleEvent.Cmd:
|
|
// break;
|
|
// }
|
|
// }
|
|
shuaxin(dt: number) {
|
|
smc.vm_data.shuaxin.min += smc.vm_data.shuaxin.speed*dt;
|
|
if (smc.vm_data.shuaxin.min >= smc.vm_data.shuaxin.max) {
|
|
smc.vm_data.shuaxin.min = 0;
|
|
this.load_cards()
|
|
}
|
|
}
|
|
load_cards() {
|
|
let old_cards = ecs.query(ecs.allOf(HeroCardViewComp))
|
|
if (old_cards.length > 0) {
|
|
old_cards.forEach(element => {
|
|
element.destroy();
|
|
});
|
|
}
|
|
// console.log(old_cards)
|
|
let cards_node= this.node.getChildByName("cards")
|
|
let x=0
|
|
let y=0
|
|
let lists = this.get_card_list()
|
|
lists.forEach(element => {
|
|
let card = ecs.getEntity<HeroCard>(HeroCard);
|
|
let pos = v3(x,y)
|
|
card.load(pos,element[0],cards_node);
|
|
x=x+100
|
|
});
|
|
this.node.getChildByName("cards").getChildByName("active").active = false
|
|
}
|
|
/** 转场 */
|
|
protected update(dt: number): void {
|
|
this.shuaxin(dt)
|
|
}
|
|
|
|
get_card_list(){
|
|
let lists:any = []
|
|
for (let index = 0; index < 5; index++) {
|
|
let list = RandomManager.instance.getRandomByObjectList(CardList[this.card_level], 1);
|
|
lists.push(list)
|
|
}
|
|
return lists
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ControllerComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |