GoodsData.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { Framework } from "../../framework/Framework";
  2. import { BaseItem, ItemEnum } from "../common/InterfaceAddEnum";
  3. import { MaterialConf } from "../config/MaterialConf";
  4. import { GameEvent } from "./GameEvent";
  5. class Data {
  6. private _goodsData: { [id: string]: BaseItem } = {};
  7. init(): void {
  8. this.reset();
  9. }
  10. reset(): void {
  11. this._goodsData = {};
  12. }
  13. purge(): void {
  14. this.reset();
  15. }
  16. setAllGoods(data) {
  17. this._goodsData = {};
  18. let conf = MaterialConf.data;
  19. for (const key in data) {
  20. if (Object.prototype.hasOwnProperty.call(data, key)) {
  21. const element = data[key];
  22. let mConf = conf[key];
  23. if (mConf) {
  24. let item = {
  25. id: key,
  26. count: Number(element),
  27. type: ItemEnum.material,
  28. conf: mConf,
  29. }
  30. this._goodsData[key] = item;
  31. }
  32. }
  33. }
  34. }
  35. getAllGoods() {
  36. return this._goodsData;
  37. }
  38. }
  39. export let GoodsData = new Data;