CompanyMapDecoder.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. var CompanyData = require("CompanyData");
  2. var ProData = require("ProData");
  3. var CompanyMapDecoder = cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. jsonName:"company",
  7. companyList:{
  8. default:[],
  9. type:[CompanyData],
  10. },
  11. },
  12. //解析数据
  13. DecodeJson:function (event) {
  14. //cc.log("===解析公司数据===");
  15. var self = this;
  16. self.reCb = event;
  17. cc.loader.loadRes("json/"+self.jsonName, function (error, obj) {
  18. if(error)
  19. {
  20. //cc.log("+++解析出错,查下json+++" + error);
  21. self.reCb(false);
  22. return;
  23. }
  24. var jsonRoot = obj.json.company;
  25. //cc.log("===数据长度===" + jsonRoot.length);
  26. for (var i = 0; i < jsonRoot.length; i++) {
  27. var comData = new CompanyData();
  28. comData.Id = jsonRoot[i].Id;
  29. comData.icon = jsonRoot[i].icon;
  30. comData.name = jsonRoot[i].name;
  31. comData.inPrice = jsonRoot[i].inPrice;
  32. comData.outPrice = jsonRoot[i].outPrice; //破产点
  33. comData.LimitYear = jsonRoot[i].LimitYear;
  34. comData.bonusRatio = jsonRoot[i].bonusRatio;
  35. //买到后刷这个比例
  36. for (var j = 0; j < jsonRoot[i].proList.length; j++) {
  37. var proD = new ProData();
  38. proD.lowRatio = jsonRoot[i].proList[j][0];
  39. proD.upRatio = jsonRoot[i].proList[j][1];
  40. proD.weight = jsonRoot[i].proList[j][2];
  41. comData.proList[j] = proD;
  42. }
  43. //没有买时候刷这个比例
  44. for (var j = 0; j < jsonRoot[i].unList.length; j++) {
  45. var proD = new ProData();
  46. proD.lowRatio = jsonRoot[i].unList[j][0];
  47. proD.upRatio = jsonRoot[i].unList[j][1];
  48. proD.weight = jsonRoot[i].unList[j][2];
  49. comData.unList[j] = proD;
  50. }
  51. self.companyList[i] = comData;
  52. }
  53. self.reCb(true);
  54. });
  55. },
  56. //通过名字拿到当前的数据 不建议用,你要用我也没办法
  57. getDataByName:function (name) {
  58. var data = null;
  59. for (var i = this.companyList.length - 1; i >= 0; i--) {
  60. if(name == this.companyList[i].name)
  61. {
  62. data = this.companyList[i];
  63. break;
  64. }
  65. }
  66. return data;
  67. },
  68. //通过itemid获取数据
  69. getDataByItemId:function(itemId){
  70. var data = null;
  71. for (var i = this.companyList.length - 1; i >= 0; i--) {
  72. if(itemId == this.companyList[i].Id)
  73. {
  74. data = this.companyList[i];
  75. break;
  76. }
  77. }
  78. return data;
  79. },
  80. getJsonLength:function(){
  81. return this.companyList.length
  82. },
  83. getDataList:function(){
  84. return this.companyList;
  85. },
  86. });
  87. module.exports = CompanyMapDecoder;