
                (function() {
                    var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
                    var __module = nodeEnv ? module : {exports:{}};
                    var __filename = 'preview-scripts/assets/Script/tool/GameTool.js';
                    var __require = nodeEnv ? function (request) {
                        return cc.require(request);
                    } : function (request) {
                        return __quick_compile_project__.require(request, __filename);
                    };
                    function __define (exports, require, module) {
                        if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}"use strict";
cc._RF.push(module, '35a73aTEIBAZoXKp/xutwzU', 'GameTool');
// Script/tool/GameTool.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameTool = void 0;
var GameData_1 = require("../GameData");
var HttpUtil_1 = require("../crypto/HttpUtil");
var Storage_1 = require("./Storage");
//最大工具类
var GameTool = {
    _startTime: 0,
    _endTime: 0,
    _totalTime: 0,
    getSeedRandom: function (min, max) {
        max = max || 1;
        min = min || 0;
        GameData_1.default._instance.GM_INFO.currSeed = (GameData_1.default._instance.GM_INFO.currSeed * 9301 + 49297) % 233280;
        var rnd = GameData_1.default._instance.GM_INFO.currSeed / 233280.0;
        var tmp = min + rnd * (max - min);
        return Math.floor(tmp);
    },
    //获取userId
    Authentication: function () {
        var name = "user_" + GameData_1.default._instance.GM_INFO.gameId;
        var data = JSON.parse(localStorage.getItem(name));
        if (data == "undifend" || data == null || data == "") {
            var url = "https://api.sparkus.cn/api/user/auth/login?domain=hui32579WdYPsgYq&callback=" + location.href;
            window.location.href = url;
        }
        else {
            Storage_1.StorageMessage.setStorage(name, data);
            GameData_1.default._instance.GM_INFO.userId = parseInt(data.userId);
        }
    },
    //埋点上传
    setGameData: function () {
        //GAME_DATA 初始化 每次清零
        GameData_1.default._instance.GAME_DATA = [];
        GameData_1.default._instance.GAME_DATA.push(GameData_1.default._instance.CLICK_DATA);
        //GAME_DATA 赋值后 CLICK_DATA清零 
        GameData_1.default._instance.CLICK_init();
        var matchId = this.getMatchId(GameData_1.default._instance.GAME_DATA[0].round);
        var postData = {
            "matchId": matchId,
            "data": GameData_1.default._instance.GAME_DATA
        };
        // console.log("上传数据:",postData);
        HttpUtil_1.default.uploadUserLogData(postData, function () { });
    },
    setRank: function () {
        //GAME_DATA 初始化 每次清零
        var postData = {
            "type": 1,
            "round": "1",
            "score": GameData_1.default._instance.GM_INFO.score,
            "success": GameData_1.default._instance.GM_INFO.success
        };
        HttpUtil_1.default.rankData(1, function () { }, postData);
    },
    //获取matchId  用于上传每次点击数据里面记录id方便查询
    getMatchId: function (level) {
        var matchId = cc.sys.localStorage.getItem("matchId");
        if (matchId == "undifend" || matchId == null) {
            matchId = this.setMatchId();
        }
        else {
            if (this.containsNanana(matchId) == true) {
                matchId = this.setMatchId();
            }
            else {
                var char = parseInt(cc.sys.localStorage.getItem("matchNumber"));
                if (level == 1) {
                    char += 1;
                    cc.sys.localStorage.setItem("matchNumber", char);
                }
                matchId = matchId.slice(0, 10) + char + "";
                GameData_1.default._instance.GM_INFO.matchId = matchId;
                cc.sys.localStorage.setItem("matchId", matchId);
            }
        }
        return matchId;
    },
    //检测matchId 如果有缓存以前的nanana数据清除
    containsNanana: function (str) {
        return /na/i.test(str);
    },
    //重新设置MatchId
    setMatchId: function () {
        // 定义包含可用字符的字符集
        var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        // 创建一个数组以保存随机字符
        var uuidArray = [];
        // 循环10次 生成10位的UUID
        for (var i = 0; i < 10; i++) {
            // 生成随机索引，范围是字符集的长度
            var randomIndex = Math.floor(Math.random() * characters.length);
            // 从字符集中获取随机字符
            var randomChar = characters.charAt(randomIndex);
            // 将字符添加到数组中
            uuidArray.push(randomChar);
        }
        var data = uuidArray.join('') + 1 + "";
        cc.sys.localStorage.setItem("matchNumber", 1);
        cc.sys.localStorage.setItem("matchId", data);
        GameData_1.default._instance.GM_INFO.matchId = data;
        return data;
    },
    getSetScreenResolutionFlag: function () {
        var size = cc.winSize;
        var width = size.width;
        var height = size.height;
        if ((height / width) > (16.2 / 9))
            return false;
        return true;
    },
    //判断全面屏适配
    setFit: function (canvas) {
        var flag = GameTool.getSetScreenResolutionFlag();
        if (flag) {
            // console.log("不是全面屏");
        }
        else {
            // console.log("是全面屏");
        }
        return flag;
    },
    getTip: function () {
        var index = Math.floor(Math.random() * 4) + 1;
        switch (index) {
            case 1: {
                return "根据小球的位置，合理晃动手机，确保小球不掉出木板。";
            }
            case 2: {
                return "根据小球位置控制晃动幅度，过大或过小都不是个好选择。";
            }
            case 3: {
                return "不要被天上掉落的障碍吓到，有时候它反而会帮你保持平衡。";
            }
            case 4: {
                return "尝试着顶开掉落的障碍，是个很酷的玩法。";
            }
        }
    },
    beginTiming: function () {
        this._startTime = new Date().getTime();
    },
    endTiming: function () {
        this._endTime = new Date().getTime();
        // this._totalTime = endTime - this._startTime;
    },
    //如果是判断时常的游戏 调用此方法
    updateScoreTime: function () {
        var endTime = new Date().getTime();
        var tempTime = endTime - this._startTime;
        if (tempTime < 0 || tempTime > 500) {
            tempTime = Math.round(cc.director.getAnimationInterval() * 1000);
        }
        this._endTime += tempTime / 1000;
        this._totalTime = this._endTime.toFixed(2);
        GameData_1.default._instance.GM_INFO.currScore = this._totalTime;
        this._startTime = endTime;
    },
    //倒计时调用此方法
    countDown: function () {
        this._endTime = new Date().getTime();
        this._totalTime = Math.floor((this._endTime - this._startTime) / 1000);
        GameData_1.default._instance.GM_INFO.remainingTime = GameData_1.default._instance.GM_INFO.totalTime - this._totalTime;
    },
    getGameInfo: function (node) {
        var jg = false;
        return jg;
    },
    //根据服务器数据重置所需要所有数据
    reset: function () {
        // console.log("本地数据丢失,重新启动游戏");
        cc.director.loadScene('LoadScene');
    },
    setGameInfo: function (pd) {
    },
    //输入秒,返回需要展示时间格式
    getTimeMargin: function (second) {
        var total = second;
        var hour = Math.floor(total / (60 * 60)); //计算整数小时数
        var afterHour = total - hour * 60 * 60; //取得算出小时数后剩余的秒数
        var min = Math.floor(afterHour / 60); //计算整数分
        var afterMin = total - hour * 60 * 60 - min * 60; //取得算出分后剩余的秒数
        return '剩余:' + hour + ':' + min + ':' + afterMin;
    },
    getTimeMargin2: function (second) {
        var total = second;
        var min = null;
        var afterMin = null;
        var hour = Math.floor(total / (60 * 60)); //计算整数小时数
        var afterHour = total - hour * 60 * 60; //取得算出小时数后剩余的秒数
        min = Math.floor(afterHour / 60); //计算整数分
        if (min < 10)
            min = "0" + min;
        afterMin = total - hour * 60 * 60 - min * 60; //取得算出分后剩余的秒数
        if (afterMin < 10)
            afterMin = "0" + afterMin;
        return '剩余:' + min + ':' + afterMin;
    },
    //将时间转换为59:23
    getTime: function (time) {
        var label = "";
        var number_1 = null;
        var number_2 = null;
        number_1 = Math.floor(time / 60);
        number_2 = time - number_1 * 60;
        if (number_1 < 10) {
            number_1 = "0" + number_1;
        }
        if (number_2 < 10) {
            number_2 = "0" + number_2;
        }
        label = number_1 + ":" + number_2;
        return label;
    },
    //number 为传进来的数值,type为最多显示几位数
    getNumber: function (number, type) {
        // console.log(type,"需要转换的数字为:",number);
        var count = 1000;
        var place = type - 3;
        if (number > Math.pow(count, 8) * Math.pow(10, place)) {
            if (number / Math.pow(count, 8) < 100)
                number = Math.floor(number / Math.pow(count, 8) * 10) / 10 + "S";
            else
                number = Math.floor(number / Math.pow(count, 8)) + "S";
        }
        else if (number > Math.pow(count, 7) * Math.pow(10, place)) {
            if (number / Math.pow(count, 7) < 100)
                number = Math.floor(number / Math.pow(count, 7) * 10) / 10 + "s";
            else
                number = Math.floor(number / Math.pow(count, 7)) + "s";
        }
        else if (number > Math.pow(count, 6) * Math.pow(10, place)) {
            if (number / Math.pow(count, 6) < 100)
                number = Math.floor(number / Math.pow(count, 6) * 10) / 10 + "Q";
            else
                number = Math.floor(number / Math.pow(count, 6)) + "Q";
        }
        else if (number > Math.pow(count, 5) * Math.pow(10, place)) {
            if (number / Math.pow(count, 5) < 100)
                number = Math.floor(number / Math.pow(count, 5) * 10) / 10 + "q";
            else
                number = Math.floor(number / Math.pow(count, 5)) + "q";
        }
        else if (number > Math.pow(count, 4) * Math.pow(10, place)) {
            if (number / Math.pow(count, 4) < 100)
                number = Math.floor(number / Math.pow(count, 4) * 10) / 10 + "t";
            else
                number = Math.floor(number / Math.pow(count, 4)) + "t";
        }
        else if (number > Math.pow(count, 3) * Math.pow(10, place)) {
            if (number / Math.pow(count, 3) < 100)
                number = Math.floor(number / Math.pow(count, 3) * 10) / 10 + "b";
            else
                number = Math.floor(number / Math.pow(count, 3)) + "b";
        }
        else if (number > Math.pow(count, 2) * Math.pow(10, place)) {
            if (number / Math.pow(count, 2) < 100)
                number = Math.floor(number / Math.pow(count, 2) * 10) / 10 + "m";
            else
                number = Math.floor(number / Math.pow(count, 2)) + "m";
        }
        else if (number > Math.pow(count, 1) * Math.pow(10, place)) {
            if (number / Math.pow(count, 1) < 100) {
                number = Math.floor(number / Math.pow(count, 1) * 10) / 10 + "k";
            }
            else
                number = Math.floor(number / Math.pow(count, 1)) + "k";
        }
        else {
            number = Math.floor(number / Math.pow(count, 0)) + "";
        }
        // console.log("结果为"+type+"位数",number);
        return number;
    },
    begainTiming: function () {
        this._startTime = new Date().getTime();
    },
    endTiming2: function () {
        var endTime = new Date().getTime();
        this._endTime = endTime;
        this._totalTime = endTime - this._startTime;
    },
    getScoreTime: function () {
        var endTime = new Date().getTime();
        var tempTime = endTime - this._startTime;
        if (tempTime < 0 || tempTime > 500) {
            tempTime = Math.round(cc.director.getAnimationInterval() * 1000);
        }
        GameData_1.default._instance.GM_INFO.currScore += tempTime;
        this._startTime = endTime;
    },
    getFormatTime: function (time) {
        var date = new Date();
        date.setTime(time);
        var ms = date.getMilliseconds();
        // let msString = date.getMilliseconds();
        var msString = null;
        var secondString = null;
        var minString = null;
        msString = Math.floor(ms / 10) % 100;
        secondString = date.getSeconds();
        minString = date.getMinutes();
        if (msString < 10) {
            msString = "0" + msString;
        }
        if (secondString < 10) {
            secondString = "0" + secondString;
        }
        secondString = secondString + ":";
        if (minString < 10) {
            minString = "0" + minString;
        }
        minString = minString + ":";
        return minString + secondString + msString;
    },
    pushLister: function () {
    },
    removeAllLister: function () {
    },
};
exports.GameTool = GameTool;

cc._RF.pop();
                    }
                    if (nodeEnv) {
                        __define(__module.exports, __require, __module);
                    }
                    else {
                        __quick_compile_project__.registerModuleFunc(__filename, function () {
                            __define(__module.exports, __require, __module);
                        });
                    }
                })();
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 34188 characters]