| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- const { ccclass, property } = cc._decorator;
- @ccclass
- export class FarmGrowProcess extends cc.Component {
- @property({ type: [cc.Node], tooltip: "阶段集合" }) states: Array<cc.Node> = [];
- @property({ type: cc.Sprite, tooltip: "种子图标" }) seedIcon: cc.Sprite = null;
- @property({ type: [cc.Sprite], tooltip: "发芽精灵集合" }) fayas: Array<cc.Sprite> = [];
- @property({ type: [cc.Sprite], tooltip: "成长精灵集合" }) grows: Array<cc.Sprite> = [];
- @property({ type: [cc.Sprite], tooltip: "成熟精灵集合" }) ripes: Array<cc.Sprite> = [];
- /**成熟时间戳 */
- private ripeTime = 0;
- /**总时长 */
- private totleTime = 0;
- /**当前成长阶段 */
- private nowState = -1;
- private isDataed = false;
- private data = null;
- public async setData(data) {
- if (!this.isDataed) {
- this.data = data;
- this.isDataed = true;
- let producting = gData.gameData.getProductMap(data.productID);
- this.ripeTime = data.growSpan;
- this.totleTime = producting.time;
- this.seedIcon.node.active = true;
- this.seedIcon.spriteFrame = await mk.loader.load("game/coregame/texture/plant_icons/seed/seedIcon_" + data.productID, cc.SpriteFrame);
- for (let i = 0; i < this.fayas.length; i++) {
- this.fayas[i].spriteFrame = await mk.loader.load("game/coregame/texture/plant_icons/faya/faya_" + data.productID, cc.SpriteFrame);
- this.grows[i].spriteFrame = await mk.loader.load("game/coregame/texture/plant_icons/chengzhang/cz_" + data.productID, cc.SpriteFrame);
- this.ripes[i].spriteFrame = await mk.loader.load("game/coregame/texture/plant_icons/ripe/ripe_" + data.productID, cc.SpriteFrame);
- }
- this.changeState(0);
- }
- }
- update() {
- if (this.nowState >= 0 && this.nowState < 3) {
- let now = Date.now();
- let process = 1 - ((this.ripeTime - now) / (this.totleTime * 1000));
- if (process < 0.3) {
- this.changeState(0);
- } else if (process < 0.65) {
- this.changeState(1);
- } else if (process < 0.99) {
- this.changeState(2);
- } else {
- this.changeState(3);
- }
- }
- }
- private changeState(value: number): void {
- if (this.nowState != value) {
- for (let i = 0; i < this.states.length; i++) {
- this.states[i].active = false;
- }
- this.states[value] && (this.states[value].active = true);
- this.nowState = value;
- }
- }
- public onSpeed(): void {
- this.changeState(3);
- }
- public cleanProcess(): void {
- this.isDataed = false;
- this.changeState(-1);
- }
- }
|