"use strict"; cc._RF.push(module, '454adgphRpA6oq5lB6Cg1fK', 'Load'); // Script/Load.ts "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, requireComponent = _a.requireComponent; var GameData_1 = require("./GameData"); var Storage_1 = require("./Storage"); var NewClass = /** @class */ (function (_super) { __extends(NewClass, _super); function NewClass() { return _super !== null && _super.apply(this, arguments) || this; } NewClass.prototype.start = function () { this.Authentication(); }; //鉴权,判断有无缓存userid,有的话判断是否过期,没有的话重新获取userid 并且缓存上 NewClass.prototype.Authentication = function () { var userId = Storage_1.StorageMessage.getStorage("user"); if (userId == "undifend" || userId == null || userId == "") { this.setUserId(); } else { var data = Storage_1.StorageMessage.getStorage("user"); data = this.getUserId(data); var timestamp = parseInt(new Date().getTime() / 1000 + ""); if ((timestamp - data[2]) > 86400) { this.setUserId(); return; } GameData_1.default._instance.GM_INFO.userId = parseInt(data[1]); } }; //设置userId,链接有获取,没有跳转授权 NewClass.prototype.setUserId = function () { GameData_1.default._instance.GM_INFO.userId = this.getUserId(null); if (GameData_1.default._instance.GM_INFO.userId == null) { var url = "http://api.sparkus.cn/api/user/auth/login?domain=hui32579WdYPsgYq&callback=" + location.href; window.location.href = url; } else { var timestamp = parseInt(new Date().getTime() / 1000 + ""); var idTemp = "gameId=" + GameData_1.default._instance.GM_INFO.gameId + "?userId= " + GameData_1.default._instance.GM_INFO.userId + "?time=" + timestamp; Storage_1.StorageMessage.setStorage("user", idTemp); GameData_1.default._instance.GM_INFO.userId = parseInt(GameData_1.default._instance.GM_INFO.userId); } }; //获取user id 有参数为获取gameid userid 时间戳, 无参数为只获取链接尾缀上的userId NewClass.prototype.getUserId = function (str) { var pathStr = window.location.search; var arr = pathStr.split("&"); if (str != null) arr = pathStr.split("?"); if (pathStr.length >= 0 && arr.length > 0) { var arr2_1 = []; arr.map(function (item) { arr2_1.push(item.split("=")[1]); }); return str == null ? arr2_1[0] : arr2_1; } else { return null; } }; //开始游戏,跳转至引导页面 NewClass.prototype.startGame = function () { cc.director.loadScene("GuideScene"); }; //备用,用来测试跳转 指定关卡 NewClass.prototype.clickBtn = function (event, data) { GameData_1.default._instance.GM_INFO.custom = parseInt(data); cc.director.loadScene("GameScene"); }; //打开排行榜 NewClass.prototype.openRank = function () { cc.director.loadScene("RankScene"); }; NewClass = __decorate([ ccclass ], NewClass); return NewClass; }(cc.Component)); exports.default = NewClass; cc._RF.pop();