GC.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /**
  2. * Created by juho on 2016-03-28.
  3. */
  4. import GD from './human.min'
  5. import { TweenMax } from './TweenMax.min'
  6. import { pixelRatioX, pixelRatioY, windowWidth, windowHeight } from './fitConfig';
  7. var gWidth = windowWidth * pixelRatioX
  8. var gHeight = windowHeight * pixelRatioY
  9. var gc = {
  10. width: gWidth,
  11. height: gHeight,
  12. soundFlag: true,
  13. bgmFlag: true,
  14. soundPopup: null,
  15. isPaused: false,
  16. gameOver: false,
  17. intro: 0,
  18. state: "intro",
  19. introPage: null,
  20. localTest: false,
  21. flag: 0,
  22. isLowPhone: false,
  23. game: null,
  24. sessionId: null,
  25. playSeq: null,
  26. phoneType: "ad",
  27. deviceStopFlag: false,
  28. GAME_ID: "NAVER-PUZZLETRIP",
  29. storagebgm: "naverpuzzletripbgm",
  30. storagesound: "naverpuzzletripsound",
  31. gameType: 0,
  32. gameId: 2,
  33. startDatetime: null,
  34. game_idx: null,
  35. arrays: {}
  36. };
  37. function getSessionId() {
  38. if (gc.localTest) {
  39. return "test";
  40. }
  41. else {
  42. return gc.sessionId;
  43. //var obj = OcbApplicationJS.getAuthInfo();
  44. //var alertMsg = '';
  45. //for( var k in obj)
  46. //{
  47. // alertMsg += ("send data => " + k + " : " + obj[k] + "\n");
  48. //}
  49. ////alert(alertMsg);
  50. //if(obj.auth == '0') return '';
  51. //else return obj.session;
  52. }
  53. };
  54. function setAuthInfo(authObj) {
  55. var isAuth = false;
  56. if (authObj) {
  57. var obj = JSON.parse(authObj);
  58. if (obj.auth == '0') {
  59. gc.sessionId = '';
  60. } else {
  61. gc.sessionId = obj.session;
  62. }
  63. isAuth = isValidAuth(obj);
  64. } else {
  65. gc.sessionId = null;
  66. }
  67. if (isAuth) {
  68. gc.onGame();
  69. } else {
  70. try {
  71. var msg = "본인 인증이 필요한 서비스입니다.\n본인 인증을 하시겠습니까?\n\n※휴대폰 인증으로만 참여가능한 서비스입니다. 다른 인증 상태일 경우 재인증이 필요합니다.";
  72. OcbApplicationJS.showPopupT3("OK CASHBAG", msg, "startAuth", "stopAuth");
  73. } catch (e) {
  74. gc.log('authPopup cancel');
  75. }
  76. }
  77. };
  78. function isValidAuth(authInfo) {
  79. try {
  80. if (authInfo.session == 'undefined' || authInfo.session == "") {
  81. return false;
  82. } else if (authInfo.type == 'undefined') {
  83. return false;
  84. } else if (authInfo.type == "01" || authInfo.type == "62") {
  85. return true;
  86. }
  87. } catch (e) {
  88. }
  89. return false;
  90. };
  91. function startAuth() {
  92. //schemeJS.authIntegration('KMC');
  93. };
  94. function stopAuth() {
  95. //OcbApplicationJS.requestCloseWindow();
  96. };
  97. gc.pauseMusic = function () {
  98. Howler.mute(true);
  99. };
  100. gc.resumeMusic = function () {
  101. Howler.mute(false);
  102. };
  103. // 로컬스토리지에 게임정보 반환
  104. gc.getStorage = function (item) {
  105. return false;
  106. // var value = wx.getStorageSync('#' + gc.GAME_ID + '@' + item);
  107. // console.log(value)
  108. // if (value == undefined) return null;
  109. // return value;
  110. };
  111. // 로컬스토리지에 게임정보 저장
  112. gc.setStorage = function (item, value) {
  113. wx.setStorageSync('#' + gc.GAME_ID + '@' + item, value);
  114. };
  115. gc.onBackKey = function () {
  116. GD.soundAllStop();
  117. };
  118. gc.deviceResume = function () {
  119. gc.deviceStopFlag = false;
  120. if (gc.bgmFlag && GD.AGENT != "ios") {
  121. GD.bgmStop();
  122. if (!gc.gameOver)
  123. GD.bgmPlay(1);
  124. }
  125. };
  126. gc.deviceStop = function () {
  127. gc.deviceStopFlag = true;
  128. GD.soundAllStop();
  129. };
  130. gc.stopAllEffectSound = function () {
  131. for (var i in GD.sound) {
  132. if (i != "sound_bgm")
  133. GD.sound[i].stop();
  134. }
  135. };
  136. // 화면크기변경
  137. GD.resize = function () {
  138. if (GD.renderer) {
  139. var widthToHeight = gc.width / gc.height;
  140. var newWidth = window.innerWidth;
  141. var newHeight = window.innerHeight;
  142. //if(gc.phoneType == "io")newHeight -= 20;
  143. var newWidthToHeight = newWidth / newHeight;
  144. if (newWidthToHeight > widthToHeight) {
  145. newWidth = newHeight * widthToHeight;
  146. } else {
  147. newHeight = newWidth / widthToHeight;
  148. }
  149. if ($('#gamecontainer')[0]) {
  150. var gameContainer = document.getElementById('gamecontainer');
  151. gameContainer.style.color = "#FF0000";
  152. if (newWidthToHeight > widthToHeight) {
  153. newWidth = newHeight * widthToHeight;
  154. gameContainer.style.width = newWidth + 'px';
  155. gameContainer.style.height = newHeight + 'px';
  156. GD.renderer.view.style.width = newWidth + 'px';
  157. GD.renderer.view.style.height = newHeight + 'px';
  158. } else {
  159. newHeight = newWidth / widthToHeight;
  160. gameContainer.style.width = newWidth + 'px';
  161. gameContainer.style.height = newHeight + 'px';
  162. GD.renderer.view.style.width = newWidth + 'px';
  163. GD.renderer.view.style.height = newHeight + 'px';
  164. }
  165. } else {
  166. GD.renderer.view.style.position = "absolute";
  167. GD.renderer.view.style.width = window.innerWidth + "px";
  168. GD.renderer.view.style.height = window.innerHeight + "px";
  169. GD.renderer.view.style.display = "block";
  170. }
  171. }
  172. setTimeout(function () {
  173. GD.setOrientationGuide();
  174. }, 500);
  175. //TweenMax.delayedCall(0.5, function () {
  176. // GD.setOrientationGuide();
  177. //});
  178. //GD.setOrientationGuide();
  179. };
  180. GD.setOrientationGuide = function () {
  181. var rank_layout = document.getElementById('rank_layout');
  182. if (rank_layout && rank_layout.style.display != 'none' && com) {
  183. GD.renderer.view.style.display = 'none';
  184. GD.showOrientation(false);
  185. return;
  186. }
  187. var p1 = window.innerWidth / window.innerHeight;
  188. var p2 = GD.width / GD.height;
  189. if (p2 > 1) {
  190. GD.orientationType = 'phone rotate_x';
  191. } else {
  192. GD.orientationType = 'phone rotate_y';
  193. }
  194. if (p1 > 1 && p2 < 1 || p1 < 1 && p2 > 1) {
  195. GD.showOrientation(true);
  196. } else {
  197. GD.showOrientation(false);
  198. }
  199. if (GD.renderer) {
  200. var widthToHeight = gc.width / gc.height;
  201. var newWidth = window.innerWidth;
  202. var newHeight = window.innerHeight;
  203. //if(gc.phoneType == "io")newHeight -= 20;
  204. var newWidthToHeight = newWidth / newHeight;
  205. if (newWidthToHeight > widthToHeight) {
  206. newWidth = newHeight * widthToHeight;
  207. } else {
  208. newHeight = newWidth / widthToHeight;
  209. }
  210. if ($('#gamecontainer')[0]) {
  211. var gameContainer = document.getElementById('gamecontainer');
  212. gameContainer.style.color = "#FF0000";
  213. if (newWidthToHeight > widthToHeight) {
  214. newWidth = newHeight * widthToHeight;
  215. gameContainer.style.width = newWidth + 'px';
  216. gameContainer.style.height = newHeight + 'px';
  217. GD.renderer.view.style.width = newWidth + 'px';
  218. GD.renderer.view.style.height = newHeight + 'px';
  219. } else {
  220. newHeight = newWidth / widthToHeight;
  221. gameContainer.style.width = newWidth + 'px';
  222. gameContainer.style.height = newHeight + 'px';
  223. GD.renderer.view.style.width = newWidth + 'px';
  224. GD.renderer.view.style.height = newHeight + 'px';
  225. }
  226. } else {
  227. GD.renderer.view.style.position = "absolute";
  228. GD.renderer.view.style.width = window.innerWidth + "px";
  229. GD.renderer.view.style.height = window.innerHeight + "px";
  230. GD.renderer.view.style.display = "block";
  231. }
  232. }
  233. };
  234. // 방향가이드 설정
  235. GD.showOrientation = function ($bool) {
  236. // 화면사이즈에 따라 회전문구 삭제
  237. var list = [
  238. "Z300C", "TF701T", "TF700T", "TF103C", "TF101-1B251A", "TA2506 10BK", "SM-T805", "SM-T800", "SM-T677", "SM-T670", "SM-P900",
  239. "SMP-605", "SMP-600", "SMART-TV", "SmartTV", "SM-905", "SHW-M480W", "SHW-M380", "SHV-E230", "SGP771", "SGP311", "QM0101",
  240. "Q109", "MZ68", "MZ601", "MX1080", "MID 1065-8", "MID 1042-8", "ME102A", "LGV940", "LGV700N", "GT-P5110", "FZ-A1", "AT105", "A10-70",
  241. "10QS", "10ES"
  242. ];
  243. var i = list.length;
  244. while (i--) {
  245. if (navigator.userAgent.match(list[i])) return;
  246. }
  247. var orientationGuide;
  248. var arrowDiv;
  249. var textDiv;
  250. var yesText;
  251. var noText;
  252. var guideText;
  253. if (GD.isMobile) {
  254. var len = document.getElementsByClassName('xy_wrap').length;
  255. if ($bool) {
  256. gc.isPaused = true;
  257. TweenMax.pauseAll();
  258. orientationGuide = GD.orientationGuide;
  259. if (orientationGuide == null) {
  260. // 배경
  261. orientationGuide = document.createElement('div');
  262. orientationGuide.style.backgroundColor = '#ff7e17';
  263. orientationGuide.style.position = "absolute";
  264. orientationGuide.style.left = 0;
  265. orientationGuide.style.top = 0;
  266. orientationGuide.style.right = 0;
  267. orientationGuide.style.bottom = 0;
  268. orientationGuide.style.margin = 'auto';
  269. orientationGuide.setAttribute("class", 'xy_wrap');
  270. GD.orientationGuide = orientationGuide;
  271. // 화살표
  272. arrowDiv = document.createElement('div');
  273. arrowDiv.setAttribute("class", 'xy_info');
  274. // 폰이미지
  275. textDiv = document.createElement('div');
  276. textDiv.setAttribute("class", GD.orientationType);
  277. // yes text
  278. yesText = document.createElement('span');
  279. yesText.setAttribute("class", 'yes');
  280. // no text
  281. noText = document.createElement('span');
  282. noText.setAttribute("class", 'no');
  283. orientationGuide.appendChild(arrowDiv);
  284. arrowDiv.appendChild(textDiv);
  285. arrowDiv.appendChild(yesText);
  286. arrowDiv.appendChild(noText);
  287. // 가이드 내용
  288. guideText = document.createElement('p');
  289. guideText.style.left = "0px";
  290. guideText.style.right = "0px";
  291. guideText.style.padding = '15px';
  292. guideText.style.lineHeight = '130%';
  293. guideText.style.color = '#FFFFFF';
  294. guideText.style.position = 'absolute';
  295. if (GD.lang == "en") {
  296. guideText.style.fontSize = "18px";
  297. guideText.innerHTML = 'Please rotate your device.';
  298. } else {
  299. var message;
  300. switch (GD.lang) {
  301. case 'jp':
  302. message = 'お使いの携帯電話を 回転させて 下ください。';
  303. break;
  304. case 'en':
  305. message = 'ROTATE YOUR PHONE';
  306. break;
  307. case 'cn':
  308. message = '请关闭屏幕自动旋转功能。';
  309. break;
  310. default:
  311. if (window.innerWidth > 480) {
  312. message = '화면 전환이 되지 않는다면, 자동회전 기능을 꺼 주세요.';
  313. } else {
  314. message = '화면 전환이 되지 않는다면,<br>자동회전 기능을 꺼 주세요.';
  315. }
  316. break;
  317. }
  318. guideText.innerHTML = message;
  319. }
  320. arrowDiv.appendChild(guideText);
  321. }
  322. if (len == 0) {
  323. document.body.appendChild(orientationGuide);
  324. GD.orientationChange(true);
  325. GD.renderer.view.style.visibility = 'hidden';
  326. }
  327. } else {
  328. if (len > 0) {
  329. gc.isPaused = false;
  330. TweenMax.resumeAll();
  331. document.body.removeChild(GD.orientationGuide);
  332. GD.orientationChange(false);
  333. GD.renderer.view.style.visibility = 'visible';
  334. }
  335. }
  336. }
  337. };
  338. module.exports = gc