UserInfoJS.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. Global UserInfo
  3. */
  4. window.UserInfo = {
  5. /*
  6. 积分
  7. */
  8. shield: {
  9. count: 1
  10. }, //护盾信息
  11. shareLimit: 3, //分享次数限制
  12. shareAddGold: 10, //分享增加金币数
  13. platform: CC_WECHATGAME ? 1 : 0, //1为微信小游戏模式
  14. shareUrl: 'https://pub.dwstatic.com/wxgame/budingGame/share/shareImage.jpg',//分享图片地址
  15. shareDesc: '超级可爱的布丁,快来跟我一起玩吧',
  16. shareDescChanllenge: '顽强的布丁',
  17. wxversion: '6.6.3',
  18. localversion: '1.0.1',
  19. ewmurl: 'https://pub.dwstatic.com/wxgame/escape/share/2weima.jpg',//公众号二维码
  20. GameCount: 2,
  21. getScore: function () {
  22. let score = cc.sys.localStorage.getItem(this.getCurWeekScoreValue());
  23. return score ? parseInt(score) : 0;
  24. },
  25. setScore: function (value) {
  26. cc.sys.localStorage.setItem(this.getCurWeekScoreValue(), "" + value);
  27. },
  28. getCurrLocalversion: function () {
  29. if (this.IsEmpty(this.localversion))
  30. return "";
  31. return this.localversion;
  32. },
  33. setLocalversion: function (version) {
  34. cc.sys.localStorage.setItem("localversion", "" + version);
  35. },
  36. getLocalversion: function () {
  37. let version = cc.sys.localStorage.getItem('localversion');
  38. if (this.IsEmpty(version)) {
  39. cc.sys.localStorage.setItem('localversion', '');
  40. version = '';
  41. }
  42. return version;
  43. },
  44. addScore: function (value) {
  45. let score = cc.sys.localStorage.getItem(this.getCurWeekScoreValue());
  46. let inputScore = (score ? parseInt(score) : 0) + parseInt(value) + "";
  47. cc.sys.localStorage.setItem(this.getCurWeekScoreValue(), inputScore);
  48. },
  49. /*
  50. 金币
  51. */
  52. getGold: function () {
  53. let gold = cc.sys.localStorage.getItem('gold');
  54. return gold ? parseInt(gold) : 0;
  55. },
  56. setGold: function (value) {
  57. cc.sys.localStorage.setItem('gold', "" + value);
  58. },
  59. addGold: function (value) {
  60. let gold = cc.sys.localStorage.getItem('gold');
  61. let inputGold = (gold ? parseInt(gold) : 0) + parseInt(value) + "";
  62. cc.sys.localStorage.setItem('gold', inputGold);
  63. this.addTotalGold(value);
  64. },
  65. addTotalGold: function (value) {
  66. let goldTotal = cc.sys.localStorage.getItem('goldTotal');
  67. let inputGold = (goldTotal ? parseInt(goldTotal) : 0) + parseInt(value) + "";
  68. cc.sys.localStorage.setItem('goldTotal', inputGold);
  69. },
  70. getTotalGold: function () {
  71. let goldTotal = cc.sys.localStorage.getItem('goldTotal');
  72. return goldTotal ? parseInt(goldTotal) : 0;
  73. },
  74. addStageProp: function (value) {//累计道具数
  75. let propcnt = cc.sys.localStorage.getItem('propcnt');
  76. let inputCnt = (propcnt ? parseInt(propcnt) : 0) + parseInt(value) + "";
  77. cc.sys.localStorage.setItem('propcnt', inputCnt);
  78. },
  79. setStageProp: function (value) {//累计道具数
  80. let inputCnt = parseInt(value) + "";
  81. cc.sys.localStorage.setItem('propcnt', inputCnt);
  82. },
  83. getStageProp: function () {
  84. let propcnt = cc.sys.localStorage.getItem('propcnt');
  85. return propcnt ? parseInt(propcnt) : 0;
  86. },
  87. getCurrentLevel: function () {
  88. let level = cc.sys.localStorage.getItem('levelSign');
  89. if (this.IsEmpty(level)) {
  90. cc.sys.localStorage.setItem('levelSign', '0');
  91. level = '0';
  92. }
  93. return parseInt(level);
  94. },
  95. setCurrentLevel: function (value) {
  96. cc.sys.localStorage.setItem('levelSign', value + "");
  97. },
  98. setFlyCnt: function (cnt) {
  99. cc.sys.localStorage.setItem('flycnt', cnt + "");
  100. },
  101. getFlyCnt: function () {
  102. let level = cc.sys.localStorage.getItem('flycnt');
  103. if (this.IsEmpty(level)) {
  104. cc.sys.localStorage.setItem('flycnt', '0');
  105. level = '0';
  106. }
  107. return parseInt(level);
  108. },
  109. setSkinIndex: function (skinIndex) {
  110. cc.sys.localStorage.setItem('skinIndex', skinIndex + "");
  111. },
  112. getSkinIndex: function () {
  113. let skinIndex = cc.sys.localStorage.getItem('skinIndex');
  114. if (this.IsEmpty(skinIndex)) {
  115. cc.sys.localStorage.setItem('skinIndex', '0');
  116. skinIndex = '0';
  117. }
  118. return parseInt(skinIndex);
  119. },
  120. /*
  121. 当前等级
  122. */
  123. getCurrentPlane: function () {
  124. let level = cc.sys.localStorage.getItem('level');
  125. if (this.IsEmpty(level)) {
  126. cc.sys.localStorage.setItem('level', '1');
  127. level = '1';
  128. }
  129. var intLevel = parseInt(level);
  130. if (intLevel <= 0) {
  131. intLevel = 1;
  132. }
  133. return intLevel;
  134. },
  135. setCurrentPlane: function (value) {
  136. cc.sys.localStorage.setItem('level', value + "");
  137. },
  138. getLevelStage: function () {
  139. let level = cc.sys.localStorage.getItem('levelStage');
  140. if (this.IsEmpty(level)) {
  141. cc.sys.localStorage.setItem('levelStage', '');
  142. level = '';
  143. }
  144. return level;
  145. },
  146. setLevelStage: function (value) {
  147. cc.sys.localStorage.setItem('levelStage', value + "");
  148. },
  149. /*
  150. 设置自定义数据
  151. */
  152. setString: function (str, value) {
  153. cc.sys.localStorage.setItem(str, value);
  154. },
  155. getString: function (str) {
  156. return cc.sys.localStorage.getItem(str);
  157. },
  158. addString: function (str, value) {
  159. let data = cc.sys.localStorage.getItem(str);
  160. let inputData = (data ? parseInt(data) : 0) + parseInt(value) + "";
  161. cc.sys.localStorage.setItem(str, inputData);
  162. },
  163. removeString: function (str) {
  164. cc.sys.localStorage.removeItem(str);
  165. },
  166. IsEmpty(obj) {//判断是否为空
  167. if (obj == "undefined" || obj == null || obj == "") {
  168. return true;
  169. } else {
  170. return false;
  171. }
  172. },
  173. getMaxTime() {//历史最长时间
  174. var score = this.getString('maxtime');
  175. if (this.IsEmpty(score)) {
  176. cc.sys.localStorage.setItem('maxtime', "0");
  177. score = "0";
  178. }
  179. return parseInt(score);
  180. },
  181. setMaxTime: function (value) {
  182. cc.sys.localStorage.setItem('maxtime', value + "");
  183. },
  184. getHistoryScore() {//历史最高分
  185. var score = this.getString('historyScore');
  186. if (this.IsEmpty(score)) {
  187. cc.sys.localStorage.setItem('historyScore', "0");
  188. score = "0";
  189. }
  190. return parseInt(score);
  191. },
  192. getCurWeekScoreValue() {
  193. return this.getNowFormatDate();
  194. },
  195. getNowFormatDate() {
  196. var date = new Date();
  197. var seperator1 = "-";
  198. var year = date.getFullYear();
  199. // var month = date.getMonth() + 1;
  200. // if (month >= 1 && month <= 9) {
  201. // month = "0" + month;
  202. // }
  203. var week = this.Getweek();
  204. var currentdate = year + seperator1 + week;
  205. return currentdate;
  206. },
  207. getMonthWeek() {
  208. var date = new Date(),
  209. w = date.getDay(),
  210. d = date.getDate();
  211. return Math.ceil(
  212. (d + 7 - w) / 7
  213. );
  214. },
  215. Getweek(dateString) {
  216. var da = '';
  217. if (dateString == undefined) {
  218. var now = new Date();
  219. var now_m = now.getMonth() + 1;
  220. now_m = (now_m < 10) ? '0' + now_m : now_m;
  221. var now_d = now.getDate();
  222. now_d = (now_d < 10) ? '0' + now_d : now_d;
  223. da = now.getFullYear() + '-' + now_m + '-' + now_d;
  224. } else {
  225. da = dateString; //日期格式2015-12-30
  226. }
  227. var date1 = new Date(da.substring(0, 4), parseInt(da.substring(5, 7)) - 1, da.substring(8, 10)); //当前日期
  228. var date2 = new Date(da.substring(0, 4), 0, 1); //1月1号
  229. //获取1月1号星期(以周一为第一天,0周一~6周日)
  230. var dateWeekNum = date2.getDay() - 1;
  231. if (dateWeekNum < 0) {
  232. dateWeekNum = 6;
  233. }
  234. if (dateWeekNum < 4) {
  235. //前移日期
  236. date2.setDate(date2.getDate() - dateWeekNum);
  237. } else {
  238. //后移日期
  239. date2.setDate(date2.getDate() + 7 - dateWeekNum);
  240. }
  241. var d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);
  242. var year = date1.getFullYear();
  243. var week = Math.ceil((d + 1) / 7);
  244. return week;
  245. }
  246. };