| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- var reGameStates = require('GameStates');
- cc.Class({
- extends: cc.Component,
- properties: {
- stateArray: {
- default: [],
- type: cc.SpriteFrame,
- serializable: true,
- },
- workArray: {
- default: [],
- type: cc.SpriteFrame,
- serializable: true,
- },
- changeSprite: {
- default: null,
- type: cc.Sprite,
- serializable: true,
- },
- //工作状态
- workingStatus: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- workPlace: {
- default: reGameStates.BuildType.Farmland,
- type: cc.Enum(reGameStates.BuildType),
- serializable: true,
- },
- },
- start() {
- if (this.workPlace == reGameStates.BuildType.TimberYard) {
- // this.onChangeSpriteFromGrow();
- }
- },
- onChangeFromAIWorker(_workPlace, _consume) {
- // cc.log('this.workPlace',_workPlace,_consume);
- if (_workPlace == reGameStates.BuildType.Farmland) {
- this.onChangeSpriteFromWork(_consume);
- } else if (_workPlace == reGameStates.BuildType.TimberYard) {
- this.onChangeSpriteFromTimberYardWork(_consume);
- } else if (_workPlace == reGameStates.BuildType.MiningPit) {
- this.onChangeSpriteFromWork(_consume);
- }
- },
- // 工作时候
- onChangeSpriteFromWork(consume) {
- if (consume <= 0 || consume >= 50) {
- this.workingStatus.active = false;
- } else if (!this.workingStatus.active) {
- this.workingStatus.active = true
- }
- let index = 50 - consume;
- /*
- //这部分是旧的代码
- if (index < 20 && index > 10)
- // this.changeSprite.spriteFrame = this.workArray[0];
- this.changeSprite.spriteFrame = this.workArray[0];
- else if (index >= 20 && index <= 35)
- this.changeSprite.spriteFrame = this.workArray[1];
- else if (index > 35)
- this.changeSprite.spriteFrame = this.workArray[2];
- */
- if (index < 20 && index > 10) {
- this.changeSprite.spriteFrame = this.workArray[0];
- // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
- // this.changeSprite.node.width = this.workArray[0].getRect().width;
- // this.changeSprite.node.height = this.workArray[0].getRect().height;
- }
- else if (index >= 20 && index <= 35) {
- this.changeSprite.spriteFrame = this.workArray[1];
- // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
- // this.changeSprite.node.width = this.workArray[1].getRect().width;
- // this.changeSprite.node.height = this.workArray[1].getRect().height;
- }
- else if (index > 35) {
- this.changeSprite.spriteFrame = this.workArray[2];
- // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
- // this.changeSprite.node.width = this.workArray[2].getRect().width;
- // this.changeSprite.node.height = this.workArray[2].getRect().height;
- }
- },
- onChangeSpriteFromTimberYardWork(consume) {
- if (consume <= 0 || consume >= 50) {
- this.workingStatus.active = false;
- } else if (!this.workingStatus.active) {
- this.workingStatus.active = true
- }
- let index = 50 - consume;
- /*
- //这部分是旧的代码
- if (index < 25 && index > 10)
- this.changeSprite.spriteFrame = this.workArray[0];
- else if (index >= 25 && index <= 40)
- this.changeSprite.spriteFrame = this.workArray[1];
- else if (index > 40)
- this.changeSprite.spriteFrame = this.workArray[2];
- */
- if (index < 25 && index > 10) {
- this.changeSprite.spriteFrame = this.workArray[0];
- // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
- // this.changeSprite.node.width = this.workArray[0].getRect().width;
- // this.changeSprite.node.height = this.workArray[0].getRect().height;
- // cc.log(this.workArray[0].getRect().width);
- }
- else if (index >= 25 && index <= 40) {
- this.changeSprite.spriteFrame = this.workArray[1];
- // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
- // this.changeSprite.node.width = this.workArray[1].getRect().width;
- // this.changeSprite.node.height = this.workArray[1].getRect().height;
- }
- else if (index > 40) {
- this.changeSprite.spriteFrame = this.workArray[2];
- // this.changeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
- // this.changeSprite.node.width = this.workArray[2].getRect().width;
- // this.changeSprite.node.height = this.workArray[2].getRect().height;
- }
- },
- // 运输时候调用
- onChangeSpriteFromGrow() {
- this.count = 0;
- this.callback = function () {
- if (this.count === this.stateArray.length - 1) {
- // 在第六次执行回调时取消这个计时器
- this.unschedule(this.callback);
- }
- this.onTreeGrowth(this.count);
- this.count++;
- }
- this.schedule(this.callback, 0.5);
- },
- /**
- * 神龙田地的直接生长
- */
- onHolyFarmlandSeedFromGrow() {
- this.count = 0;
- this.callback = function () {
- if (this.count === this.stateArray.length - 1) {
- // 在第六次执行回调时取消这个计时器
- this.unschedule(this.callback);
- }
- this.onTreeGrowth(this.count);
- this.count++;
- }
- this.schedule(this.callback, 0.5);
- },
- // 生长
- onTreeGrowth(count) {
- this.changeSprite.spriteFrame = this.stateArray[count];
- },
- /**
- * 神龙田地的直接 生长图片设置
- */
- onSetGrow(growStage, harvestSpriteFrame) {
- // console.log(growStage,harvestSpriteFrame);
- if (growStage === 0) {
- this.changeSprite.spriteFrame = null;
- } else if (growStage === 1 || growStage === 2) {
- this.changeSprite.spriteFrame = this.stateArray[growStage - 1];
- } else {
- this.changeSprite.spriteFrame = harvestSpriteFrame;
- }
- },
- onResetSprite(_workPlace) {
- if (_workPlace == reGameStates.BuildType.Farmland) {
- // this.changeSprite.spriteFrame = this.stateArray[0];
- this.changeSprite.spriteFrame = this.stateArray[0];
- this.onChangeSpriteFromGrow();
- } else if (_workPlace == reGameStates.BuildType.TimberYard) {
- //运输时候木材清空
- this.changeSprite.spriteFrame = this.workArray[3];
- this.onChangeSpriteFromGrow();
- } else if (_workPlace == reGameStates.BuildType.MiningPit) {
- this.changeSprite.spriteFrame = this.stateArray[0];
- }
- },
- //设置当前的完成状态
- //读取数据时候设置
- //todo....
- onSetWorkStateFormReadingData(_Index) {
- this.changeSprite.spriteFrame = this.workArray[_Index];
- },
- });
|