UNPKG

gamelet-pixui-frame

Version:

pixui开发者框架

214 lines 9.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PresetDataMgr = void 0; var utilities_1 = require("../../../utilities/utilities"); var PresetDataMgrImpl = /** @class */ (function () { function PresetDataMgrImpl() { this.userdata = undefined; this.gamelet = undefined; this.env = undefined; this.searchParams = new Map(); this.openArgs = ""; this.init(); } PresetDataMgrImpl.prototype.init = function () { this.parseSearch(); this.initUserdata(); this.initGamelet(); this.initEnv(); this.initMisc(); }; PresetDataMgrImpl.prototype.getUserdata = function () { return this.userdata; }; PresetDataMgrImpl.prototype.getGamelet = function () { return this.gamelet; }; PresetDataMgrImpl.prototype.getEnv = function () { return this.env; }; PresetDataMgrImpl.prototype.getOpenArgs = function () { return this.openArgs; }; PresetDataMgrImpl.prototype.getValueFromMapAsString = function (map, key) { var val = map.get(key); if (typeof (val) != 'string') { return ""; } return val; }; PresetDataMgrImpl.prototype.getValueFromMapAsStringOrUndefined = function (map, key) { var val = map.get(key); if (typeof (val) != 'string') { return undefined; } return val; }; PresetDataMgrImpl.prototype.getValueFromMapAsNumber = function (map, key) { var val = map.get(key); if (typeof (val) == 'number') { return val; } else if (typeof (val) == 'string') { try { var parsedVal = parseInt(val); return parsedVal; } catch (err) { return 0; } } return 0; }; PresetDataMgrImpl.prototype.getValueFromMapAsBool = function (map, key) { var val = map.get(key); if (typeof (val) == 'number' || typeof (val) == 'boolean') { return Boolean(val); } // 字符串 'true' 和 '1' 翻译为 true , 其他翻译为 false if (typeof (val) == 'string') { if (val == 'true' || val == '1') { return true; } } return false; }; PresetDataMgrImpl.prototype.isValueExistInMap = function (map, key) { var val = map.get(key); if (val) { return true; } return false; }; PresetDataMgrImpl.prototype.parseSearch = function () { // this.searchParams = new Map<string, string>(); var params = window.location.search.split("&"); for (var i = 0; i < params.length; ++i) { var kvpair = params[i].split("="); if (kvpair.length < 2) { continue; } else if (kvpair.length == 2) { this.searchParams.set(kvpair[0], kvpair[1]); } else if (kvpair.length > 2) { //连接数组中1+ var valuestr = ''; for (var idx = 1; idx < kvpair.length; idx++) { valuestr = valuestr + '=' + kvpair[idx]; } this.searchParams.set(kvpair[0], valuestr); } } }; PresetDataMgrImpl.prototype.initUserdata = function () { // let argOpenID = this.getValueFromMapAsString(this.searchParams, "ud_openID"); // let argServiceType = this.getValueFromMapAsString(this.searchParams, "ud_serviceType"); // let argAppID = this.getValueFromMapAsString(this.searchParams, "ud_appID"); // let argRoleID = this.getValueFromMapAsString(this.searchParams, "ud_roleID"); // let argPlatID = this.getValueFromMapAsString(this.searchParams, "ud_platID"); // let argAccountType = this.getValueFromMapAsString(this.searchParams, "ud_accountType"); // let argArea = this.getValueFromMapAsString(this.searchParams, "ud_area"); // let argPartition = this.getValueFromMapAsString(this.searchParams, "ud_partition"); // let argAccessToken = this.getValueFromMapAsString(this.searchParams, "ud_accessToken"); // let argGameVer = this.getValueFromMapAsString(this.searchParams, "ud_gameVer"); // let argPayToken = this.getValueFromMapAsString(this.searchParams, "ud_payToken"); // let argChannelID = this.getValueFromMapAsString(this.searchParams, "ud_channelID"); // let argSDKVersion = this.getValueFromMapAsString(this.searchParams, "ud_sdkVersion"); // let argSign = this.getValueFromMapAsString(this.searchParams, "ud_sign"); // let argCountry = this.getValueFromMapAsString(this.searchParams, "ud_country"); // let argLoginChannel = this.getValueFromMapAsString(this.searchParams, "ud_loginChannel"); // let argIntlSdkParam = this.getValueFromMapAsString(this.searchParams, "ud_intlSdkParam"); // let argLanguage = this.getValueFromMapAsString(this.searchParams, "ud_language"); // this.userdata = { // openID: argOpenID, // serviceType: argServiceType, // appID: argAppID, // roleID: argRoleID, // platID: argPlatID, // accountType: argAccountType, // area: argArea, // partition: argPartition, // accessToken: argAccessToken, // gameVer: argGameVer, // payToken: argPayToken, // channelID: argChannelID, // sdkVersion: argSDKVersion, // sign: argSign, // country: argCountry, // loginChannel: argLoginChannel, // intlSdkParam: argIntlSdkParam, // language: argLanguage, // sOpenId: argOpenID, // sServiceType: argServiceType, // sAppId: argAppID, // sRoleId: argRoleID, // sPlatID: argPlatID, // sAcountType: argAccountType, // sArea: argArea, // sPartition: argPartition, // sAccessToken: argAccessToken, // sGameVer: argGameVer, // sPayToken: argPayToken, // sChannelID: argChannelID, // sSdkVersion: argSDKVersion, // sSign: argSign, // sCountry: argCountry, // sLoginChannel: argLoginChannel, // sIntlSdkParam: argIntlSdkParam, // sLanguage: argLanguage, // }; }; PresetDataMgrImpl.prototype.initGamelet = function () { var config = {}; var configSrc = this.getValueFromMapAsStringOrUndefined(this.searchParams, "gl_entranceConfig"); if (configSrc != undefined) { if ((0, utilities_1.checkVersionToNumber)((0, utilities_1.getGameletInnerVersion)()) > (0, utilities_1.checkVersionToNumber)('1.0.0')) { config = JSON.parse(decodeURIComponent(configSrc)); } else { config = JSON.parse(decodeURI(configSrc)); } } var faasAddrStr = ""; var faasAddrSrc = this.getValueFromMapAsStringOrUndefined(this.searchParams, "gl_faasAddr"); if (faasAddrSrc != undefined) { faasAddrStr = decodeURIComponent(faasAddrSrc); } this.gamelet = { openMessage: this.getValueFromMapAsStringOrUndefined(this.searchParams, "gl_openMessage"), entranceConfig: config, appId: this.getValueFromMapAsNumber(this.searchParams, "gl_appId"), appKey: this.getValueFromMapAsString(this.searchParams, "gl_appKey"), appName: this.getValueFromMapAsString(this.searchParams, "gl_appName"), appVersion: this.getValueFromMapAsString(this.searchParams, "gl_appVersion"), env: this.getValueFromMapAsString(this.searchParams, "gl_env"), mainpage: this.getValueFromMapAsString(this.searchParams, "gl_mainpage"), parentPath: this.getValueFromMapAsString(this.searchParams, "gl_parentPath"), windowStartTimestamp: this.getValueFromMapAsString(this.searchParams, "gl_windowStartTimestamp"), totalLogSwitch: this.isValueExistInMap(this.searchParams, "gl_totalLogSwitch") ? this.getValueFromMapAsNumber(this.searchParams, "gl_totalLogSwitch") : -1, appLogSwitch: this.isValueExistInMap(this.searchParams, "gl_appLogSwitch") ? this.getValueFromMapAsNumber(this.searchParams, "gl_appLogSwitch") : -1, isHitBackendWhitelist: this.isValueExistInMap(this.searchParams, "gl_isHitBackendWhitelist") ? this.getValueFromMapAsNumber(this.searchParams, "gl_isHitBackendWhitelist") : 0, faasAddr: faasAddrStr }; }; PresetDataMgrImpl.prototype.initEnv = function () { this.env = { isNano: this.getValueFromMapAsNumber(this.searchParams, "env_isNano"), platform: this.getValueFromMapAsNumber(this.searchParams, "env_platform"), isProduct: this.getValueFromMapAsNumber(this.searchParams, "env_isProduct"), entryInfo: decodeURIComponent(this.getValueFromMapAsString(this.searchParams, "env_entryInfo")), }; }; PresetDataMgrImpl.prototype.initMisc = function () { if ((0, utilities_1.checkVersionToNumber)((0, utilities_1.getGameletInnerVersion)()) > (0, utilities_1.checkVersionToNumber)('1.0.0')) { this.openArgs = decodeURIComponent(this.getValueFromMapAsString(this.searchParams, "open_args")); } else { this.openArgs = decodeURI(this.getValueFromMapAsString(this.searchParams, "open_args")); } }; return PresetDataMgrImpl; }()); exports.PresetDataMgr = (0, utilities_1.singleton)(PresetDataMgrImpl); //# sourceMappingURL=presetdata_mgr.js.map