// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property, requireComponent} = cc._decorator; import GameData from "./GameData"; import { StorageMessage } from "./Storage"; import HttpUtil from "./crypto/serverAPI"; import Rq from "./crypto/serverAPI"; // import {StorageMessage} from "./StorageMessage"; // import { apiSign } from "./crypto/sign"; @ccclass export default class NewClass extends cc.Component { @property(cc.Label) label: cc.Label = null; @property text: string = 'hello'; start () { let userId = StorageMessage.getStorage("user"); if(userId == "undifend" || userId==null){ this.setId(); } else{ let data = StorageMessage.getStorage("user"); data = this.getId(data); let timestamp = parseInt(new Date().getTime()/1000 + ""); if((timestamp - data[2]) > 86400){ this.setId(); return; } GameData._instance.GM_INFO.userId = data[1]; GameData._instance.GM_INFO.userId = parseInt(GameData._instance.GM_INFO.userId); } } setId(){ GameData._instance.GM_INFO.userId = this.getUserId(); if(GameData._instance.GM_INFO.userId == null){ let url = "http://api.sparkus.cn/api/user/auth/login?domain=hui32579WdYPsgYq&callback="+location.href; window.location.href = url; } else{ let timestamp = parseInt(new Date().getTime()/1000 + ""); let idTemp = "gameId=" + GameData._instance.GM_INFO.gameId + "?userId= " + GameData._instance.GM_INFO.userId + "?time=" + timestamp; StorageMessage.setStorage("user",idTemp); GameData._instance.GM_INFO.userId = parseInt(GameData._instance.GM_INFO.userId); } } createTexture(){ let url = "http://static.sparkus.cn/shoot-sun/assets/resources/native/7a/7a8b41ad-9425-44e2-8f55-7740f12b0e0a.jpg"; cc.assetManager.loadRemote(url, (err, texture:cc.Texture2D) => { console.log(err,texture) if(texture){ var sprite = this.node.getChildByName("icon").getComponent(cc.Sprite); sprite.spriteFrame = new cc.SpriteFrame(texture); } }) } private getUserId() { let pathStr = window.location.search; let arr=pathStr.split("&"); if (pathStr.length>= 0&&arr.length>0) { let arr2=[]; arr.map(item=>{ arr2.push(item.split("=")[1]) }) // GameData._instance.GM_INFO.userId = arr2[0] + ""; return arr2[0]; } else { return null } } private getId(str) { let pathStr = str; let arr=pathStr.split("?"); if (pathStr.length>= 0&&arr.length>0) { let arr2=[]; arr.map(item=>{ arr2.push(item.split("=")[1]) }) // GameData._instance.GM_INFO.userId = arr2[1] + ""; return arr2; } else { return null } } startGame(){ GameData._instance.GM_INFO.custom = 0; cc.director.loadScene("GuideScene"); } clickBtn(event,data){ GameData._instance.GM_INFO.custom = parseInt(data); cc.director.loadScene("GameScene"); } openLevel(){ this.node.getChildByName("Level").active = true; } closeBtn(){ this.node.getChildByName("Level").active = false; } back(data){ // debugger; } openBtn(){ GameData._instance.GM_INFO.custom = 0; cc.director.loadScene("GuideScene"); } openRank(){ cc.director.loadScene("RankScene"); } // update (dt) {} }