GameEnvironmentProxy.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local GameEnvironmentProxy = class("GameEnvironmentProxy", RemoteProxy)
  3. GameEnvironmentProxy.NAME = global.ProxyTable.GameEnvironment
  4. function GameEnvironmentProxy:ctor()
  5. GameEnvironmentProxy.super.ctor(self)
  6. --
  7. self._totalMemoryType = global.MMO.MEMORY_TYPE_X
  8. self:Init()
  9. end
  10. function GameEnvironmentProxy:Init()
  11. -- 内存警告
  12. if global.Platform ~= cc.PLATFORM_OS_WINDOWS then
  13. local totalMemSize = self:GetTotalMemSize()
  14. if totalMemSize <= 1.2 then
  15. self._totalMemoryType = global.MMO.MEMORY_TYPE_L
  16. elseif totalMemSize <= 2.2 then
  17. self._totalMemoryType = global.MMO.MEMORY_TYPE_M
  18. elseif totalMemSize <= 4.2 then
  19. self._totalMemoryType = global.MMO.MEMORY_TYPE_H
  20. else
  21. self._totalMemoryType = global.MMO.MEMORY_TYPE_X
  22. end
  23. end
  24. end
  25. function GameEnvironmentProxy:getBoxuid()
  26. local boxuid = nil
  27. if boxuid == nil or boxuid == "" then
  28. boxuid = global.L_GameEnvManager:GetEnvDataByKey("uid")
  29. end
  30. return boxuid
  31. end
  32. function GameEnvironmentProxy:getBoxtoken()
  33. local boxtoken = nil
  34. if boxtoken == nil or boxtoken == "" then
  35. boxtoken = global.L_GameEnvManager:GetEnvDataByKey("new_boxtoken")
  36. end
  37. if boxtoken == nil or boxtoken == "" then
  38. boxtoken = global.L_GameEnvManager:GetEnvDataByKey("token")
  39. end
  40. return boxtoken
  41. end
  42. function GameEnvironmentProxy:IsNeedExitGame()
  43. if not global.isWindows then
  44. return false
  45. end
  46. -- PC联运
  47. local PCPlatform = global.L_GameEnvManager:GetEnvDataByKey("PCPlatform")
  48. local user_id = global.L_GameEnvManager:GetEnvDataByKey("user_id")
  49. local token = global.L_GameEnvManager:GetEnvDataByKey("token")
  50. if tonumber(PCPlatform) == 1 and user_id and token then
  51. return true
  52. end
  53. -- -- 盒子
  54. -- local envProxy = global.Facade:retrieveProxy(global.ProxyTable.GameEnvironment)
  55. -- local bokuid = envProxy:getBoxuid()
  56. -- local boxtoken = envProxy:getBoxtoken()
  57. -- if bokuid and boxtoken then
  58. -- return true
  59. -- end
  60. return false
  61. end
  62. function GameEnvironmentProxy:IsReviewServer()
  63. return global.L_GameEnvManager:IsReview()
  64. end
  65. function GameEnvironmentProxy:GetCustomDataByKey(key)
  66. local currentModule = global.L_ModuleManager:GetCurrentModule()
  67. local moduleGameEnv = currentModule:GetGameEnv()
  68. local customData = moduleGameEnv:GetCustomData()
  69. if not customData then
  70. return nil
  71. end
  72. return customData[key]
  73. end
  74. function GameEnvironmentProxy:GetBatteryLevel()
  75. return global.L_GameEnvManager:GetBattery()
  76. end
  77. function GameEnvironmentProxy:SetBatteryLevel(batterLevel)
  78. global.L_GameEnvManager:SetBattery(batterLevel)
  79. global.Facade:sendNotification(global.NoticeTable.BattreyChange, self:GetBatteryLevel())
  80. ssr.ssrBridge:OnBatteryValueChange(self:GetBatteryLevel())
  81. SLBridge:onLUAEvent(LUA_EVENT_BATTERYCHANGE, self:GetBatteryLevel())
  82. end
  83. function GameEnvironmentProxy:GetNetType()
  84. return global.L_GameEnvManager:GetNetType()
  85. end
  86. function GameEnvironmentProxy:SetNetType(t)
  87. -- -1:未识别 0:wifi 1:2g 2:3g 3:4g
  88. global.L_GameEnvManager:SetNetType(t)
  89. global.Facade:sendNotification(global.NoticeTable.NetStateChange, self:GetNetType())
  90. ssr.ssrBridge:OnNetStateChange(self:GetNetType())
  91. SLBridge:onLUAEvent(LUA_EVENT_NETCHANGE, self:GetNetType())
  92. end
  93. -- 设备物理地址
  94. function GameEnvironmentProxy:GetMacAddress()
  95. return global.L_GameEnvManager:GetMacAddress()
  96. end
  97. -- apk info
  98. function GameEnvironmentProxy:GetAPKVersionName()
  99. return global.L_GameEnvManager:GetAPKVersionName()
  100. end
  101. function GameEnvironmentProxy:GetAPKVersionCode()
  102. return global.L_GameEnvManager:GetAPKVersionCode()
  103. end
  104. function GameEnvironmentProxy:GetAPKPackageName()
  105. return global.L_GameEnvManager:GetAPKPackageName()
  106. end
  107. function GameEnvironmentProxy:GetChannelID()
  108. return global.L_GameEnvManager:GetChannelID()
  109. end
  110. function GameEnvironmentProxy:GetTotalMemSize()
  111. return global.L_GameEnvManager:GetTotalMemSize()
  112. end
  113. function GameEnvironmentProxy:GetTotalMemSize()
  114. return global.L_GameEnvManager:GetTotalMemSize()
  115. end
  116. function GameEnvironmentProxy:GetTotalMemoryType()
  117. return self._totalMemoryType
  118. end
  119. function GameEnvironmentProxy:GetUDID()
  120. return global.L_GameEnvManager:GetUDID()
  121. end
  122. function GameEnvironmentProxy:GetPUID()
  123. return global.L_GameEnvManager:GetPUID()
  124. end
  125. return GameEnvironmentProxy