FactorySystem.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /** 工厂数据类 */
  2. import { FactroyState } from "../../game/data/GameData";
  3. import { FactoryIcon } from "./FactoryIcon";
  4. const { ccclass } = cc._decorator;
  5. @ccclass
  6. export default class FactorySystem {
  7. private _currSelectFactory: FactoryIcon = null;
  8. public factoryIcons: Array<FactoryIcon> = [];
  9. public set currSelectFactory(factory: FactoryIcon) {
  10. this._currSelectFactory = factory;
  11. }
  12. public get currSelectFactory(): FactoryIcon {
  13. return this._currSelectFactory;
  14. }
  15. public make(id: number): void {
  16. this._currSelectFactory && this._currSelectFactory.make(id);
  17. }
  18. public addFactory(factory) {
  19. this.factoryIcons.push(factory);
  20. }
  21. public nextFactory() {
  22. let len = this.factoryIcons.length;
  23. for (var i = 0; i < len; i++) {
  24. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  25. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  26. gData.gameData.nextMake = this.factoryIcons[i];
  27. return this.factoryIcons[i];
  28. }
  29. }
  30. }
  31. public btnMake() {
  32. gData.gameData.nextMake.make(gData.gameData.nextCanProduct.picture);
  33. }
  34. }