MateMapDecoder.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. var LovePointCost = require("LovePointCost");
  2. var MateData = require("MateData");
  3. var MateBonus = require("MateBonus");
  4. var MateGetCond = require("MateGetCond");
  5. var MateMapDecoder = cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. jsonName:"mate",
  9. mateList:{
  10. default:[],
  11. type:[MateData],
  12. },
  13. },
  14. //解析数据
  15. DecodeJson:function (event) {
  16. //cc.log("===解析伴侣数据===");
  17. var self = this;
  18. self.reCb = event;
  19. cc.loader.loadRes("json/"+self.jsonName, function (error, obj) {
  20. if(error)
  21. {
  22. //cc.log("+++解析出错,查下json+++" + error);
  23. self.reCb(false);
  24. return;
  25. }
  26. var jsonRoot = obj.json.mate;
  27. //cc.log("===数据长度===" + jsonRoot.length);
  28. for (var i = 0; i < jsonRoot.length; i++) {
  29. var mateData = new MateData();
  30. mateData.Id = jsonRoot[i].Id;
  31. mateData.icon = jsonRoot[i].icon;
  32. mateData.sex = jsonRoot[i].sex;
  33. mateData.name = jsonRoot[i].name;
  34. mateData.unlockCond = jsonRoot[i].unlockCond;//可以约会条件
  35. ////cc.log(jsonRoot[i].name + " 是否可以直接约会的" + mateData.unlockCond);
  36. for (var j = 0; j < jsonRoot[i].getCond.length; j++) {
  37. var getCond = new MateGetCond();
  38. getCond.unlockType = jsonRoot[i].getCond[j][0];
  39. getCond.value = jsonRoot[i].getCond[j][1];
  40. mateData.getCondList[j] = getCond;
  41. }
  42. for (var j = 0; j < jsonRoot[i].lovePointList.length; j++) {
  43. var lpCost = new LovePointCost();
  44. lpCost.cost = jsonRoot[i].lovePointList[j][2];
  45. lpCost.LovePoint = jsonRoot[i].lovePointList[j][1];
  46. lpCost.curLevel = jsonRoot[i].lovePointList[j][0];
  47. mateData.lovePointList[j] = lpCost;
  48. }
  49. for (var j = 0; j < jsonRoot[i].bonusList.length; j++) {
  50. var lpCost = new MateBonus();
  51. lpCost.bonusType = jsonRoot[i].bonusList[j][0];
  52. lpCost.bonusNum = jsonRoot[i].bonusList[j][1];
  53. mateData.bonusList[j] = lpCost;
  54. }
  55. self.mateList[i] = mateData;
  56. }
  57. self.reCb(true);
  58. });
  59. },
  60. //通过名字拿到当前的数据 不建议用,你要用我也没办法
  61. getDataByName:function (name) {
  62. var data = null;
  63. for (var i = this.mateListmateList.length - 1; i >= 0; i--) {
  64. if(name == this.mateList[i].name)
  65. {
  66. data = this.mateList[i];
  67. break;
  68. }
  69. }
  70. return data;
  71. },
  72. //通过itemid获取数据
  73. getDataByItemId:function(itemId){
  74. var data = null;
  75. for (var i = this.mateList.length - 1; i >= 0; i--) {
  76. if(itemId == this.mateList[i].Id)
  77. {
  78. data = this.mateList[i];
  79. break;
  80. }
  81. }
  82. return data;
  83. },
  84. getJsonLength:function(){
  85. return this.mateList.length
  86. },
  87. getDataList:function(){
  88. return this.mateList;
  89. },
  90. });
  91. module.exports = MateMapDecoder;