OptionsManager.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {RDPlatformParam} from "./RDPlatformParam";
  2. import HttpManager from "../net/HttpManager";
  3. import {AdsManager} from "./AdsManager";
  4. import {BenzAssetManager} from "../asset/BenzAssetManager";
  5. import {AssetsHelper} from "../asset/AssetsHelper";
  6. export class OpCommand {
  7. public static readonly CMD_OPTION_BANNER_MOVE = 101; //banner位移误触开关
  8. public static readonly CMD_OPTION_VIDEO_SELECT = 102; //默认勾选激励广告开关
  9. public static readonly CMD_OPTION_VIDEO_ICON = 103; //激励视频广告按键图标开关
  10. public static readonly CMD_OPTION_ALL_SCREEN = 104;//全屏导出界面开关
  11. public static readonly CMD_OPTION_EXIT = 105;//假退出打开互推界面开关
  12. public static readonly CMD_OPTION_INTERTITAL = 106;//插屏广告误触-延迟出广告:游戏结算和暂停时1500毫秒后突然弹出
  13. }
  14. export default class OptionsManager {
  15. private static _instance: OptionsManager = new OptionsManager();
  16. public static getInstance(): OptionsManager {
  17. return this._instance;
  18. }
  19. private switchData = {};
  20. public init(): void {
  21. let self = this;
  22. this.initCity();
  23. }
  24. changeData(data) {
  25. let newData = {};
  26. let ary1 = data.split("#");
  27. for (let i = 0; i < ary1.length; i++) {
  28. let ary2 = ary1[i].split("|");
  29. newData[ary2[0]] = {
  30. 'switch': ary2[1],
  31. 'prob': ary2[2],
  32. };
  33. }
  34. return newData;
  35. }
  36. getOptionData(cityId) {
  37. var gameId = RDPlatformParam.ADPARAM[RDPlatformParam.platFromId]["gameId"];
  38. if (!gameId) return;
  39. HttpManager.getInstance().get("https://hcrsstzb-sst.emptygame.com.cn:8443", "/ReadGameConfig11", "id=" + gameId + "&" + "cid=" + cityId, function (err, res) {
  40. console.log("开关数据成功" + res);
  41. if(!res) return;
  42. this.switchData = this.changeData(res);
  43. console.log("开关数据成功" + JSON.stringify(this.switchData));
  44. // this.initCity();
  45. }.bind(this));
  46. }
  47. initCity() {
  48. HttpManager.getInstance().get("https://pv.sohu.com", "/cityjson", "", function (err, res) {
  49. console.log("城市数据" + res);
  50. if (!err) {
  51. let cityId = res.split('"')[7];
  52. console.log("城市行政id" + cityId);
  53. this.getOptionData(cityId);
  54. }
  55. }.bind(this));
  56. }
  57. getOptionSwitch(cmd: number): boolean {
  58. var eventId = RDPlatformParam.ADPARAM[RDPlatformParam.platFromId]["eventId"];
  59. if (!eventId) return false;
  60. let id = eventId[cmd.toString()];
  61. if (!id) return false;
  62. let data = this.switchData[id];
  63. if (!data) return false;
  64. console.log("开关数据" + JSON.stringify(data));
  65. return data.switch == "true";
  66. }
  67. /**
  68. * 退出按钮添加
  69. */
  70. // addExit(node: cc.Node) {
  71. // if (OptionsManager.getInstance().getOptionSwitch(OpCommand.CMD_OPTION_EXIT)) {
  72. // //Todo 给对应界面添加虚拟退出按钮 位置自动转到世界坐标的右上角(距离上面130 , 右边15)
  73. // let btn: cc.Node = cc.instantiate(<cc.Prefab>BenzAssetManager.getInstance().getAsset(AssetsHelper.SHOW_ADSCREEN_BUTTON));
  74. // btn.on(cc.Node.EventType.TOUCH_END, function () {
  75. // AdsManager.getInstance().showADScreen();
  76. // }, this);
  77. // btn.setPosition(node.convertToNodeSpaceAR(cc.v2(cc.winSize.width - 15, cc.winSize.height - 130)));
  78. // node.addChild(btn);
  79. // }
  80. // }
  81. /**
  82. * 界面切换是否跳出全屏推广
  83. */
  84. // addADScreen() {
  85. // if (OptionsManager.getInstance().getOptionSwitch(OpCommand.CMD_OPTION_ALL_SCREEN)) {
  86. // AdsManager.getInstance().showADScreen();
  87. // }
  88. // }
  89. }