UserInfoJS.js 7.3 KB

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