bootloader.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. function isSafari() {
  2. var ua = navigator.userAgent.toLowerCase();
  3. return ua.indexOf('safari') != -1 && ua.indexOf('chrome') == -1;
  4. }
  5. var svgNS = "http://www.w3.org/2000/svg";
  6. var color = ['#DE3F26','#606060','#48AF5E','#FFC800'];
  7. function parseTransformAttribute(aa) {
  8. var a = aa.split(' ').join('');
  9. var b={};
  10. for (var i in a = a.match(/(\w+\((\-?\d+\.?\d*,?)+\))+/g)) { var c = a[i].match(/[\w\.\-]+/g); b[c.shift()] = c; }
  11. return b; }
  12. function svg(html) { return new DOMParser().parseFromString(html, "text/xml").firstChild; }
  13. function removeChilds(e) { var last; while (last = e.lastChild) e.removeChild(last); };
  14. function setPlayerName(e, playerName) {
  15. var dx = 15;
  16. document.getElementById(e+"-Name").setAttribute("y",27);
  17. document.getElementById(e+"-Name").setAttribute("x",dx);
  18. document.getElementById(e+"-Name").textContent = playerName;
  19. document.getElementById(e+"-Pad").setAttribute('width', document.getElementById(e+"-Name").getBBox().width + 25); }
  20. function template_engine(html, data) {
  21. var re = /{([^}]+)?}/g, code = 'var r=[];', cursor = 0;
  22. var add = function(line,js) {
  23. js? (code += 'r.push(' + line + ');') :
  24. (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");' : ''); // "
  25. return add; }
  26. while(match = re.exec(html)) {
  27. add(html.slice(cursor, match.index))(match[1],true);
  28. cursor = match.index + match[0].length; }
  29. add(html.substr(cursor, html.length - cursor));
  30. code += 'return r.join("");';
  31. return new Function(code.replace(/[\r\t\n]/g, '')).apply(data); }
  32. function discarder(name) { return template_engine(localStorage.getItem("svg/Discarder.svg?q=" + $.timestamp), { name: name }); }
  33. function initDiscards() {
  34. [ {name:"Gabrielo-Discard", hand:"Player-Left-Hand"},
  35. {name:"Alina-Discard", hand:"Player-Right-Hand"},
  36. {name:"Mustafa-Discard", hand:"Player-Center-Hand"},
  37. {name:"You-Discard", hand:"Player-Me-Hand"} ].map(function(e) {
  38. document.getElementById(e.name).appendChild(svg(discarder(e.hand)));
  39. });
  40. }
  41. function PatchSVG()
  42. {
  43. $('Player-Statistics').hide();
  44. var onlineListOnClick = [
  45. "Online-Users",
  46. "Online-Users-Pad",
  47. "Online-Logo",
  48. "Users-Online-Message",
  49. "Users-Online-Number" ];
  50. onlineListOnClick.map(function(x) {
  51. document.getElementById(x).style.cursor = "pointer";
  52. document.getElementById(x).onclick = showOnlineList; });
  53. Core(ControllerScope);
  54. Core(DragScope);
  55. Core(DropScope);
  56. Core(TimerScope);
  57. Core(PlayerScope);
  58. Core(OkeyApiProviderScope);
  59. Core(CardScope);
  60. Core(HandScope);
  61. Core(DeckScope);
  62. Core(RosterScope);
  63. initDiscards();
  64. initChat();
  65. initChatSample();
  66. initEditorsSafari()
  67. // document.addEventListener('touchmove',function(e) {e.preventDefault();},false);
  68. $svg.attr({preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%"});
  69. }
  70. function initChatSample() {
  71. chatMessage("Chat","1","Maxim2","Joe:\nHello There!".encodeHTML());
  72. chatMessage("Chat","2","Maxim2","Alice:\nYou got new Design. Eh?".encodeHTML());
  73. chatMessage("Chat","3","Maxim","Maxim So:\nThis was made with pure SVG".encodeHTML());
  74. barHover();
  75. mouseWheelHandler({'detail':-100000,'wheelDelta':-100000});
  76. barHoverOut();
  77. }
  78. function onPlayerInfo(evt) {
  79. ws.send(enc(tuple(atom('client'),
  80. tuple(atom('stats_action'),bin(document.user),atom('game_okey'))))); }
  81. function onPlayerInfoClose(evt) { document.getElementById('Player-Statistics').style.display = 'none'; }
  82. // Run
  83. $.load('Kakaranet-Scene.svg', function(x) {
  84. var name = "Refined";
  85. var slot = document.getElementById(name);
  86. if (slot == null) return;
  87. slot.parentNode.replaceChild(svg(x),slot);
  88. $.load("svg/Discarder.svg", function(h) {
  89. PatchSVG();
  90. StartApp();
  91. });
  92. });
  93. function initEditorsSafari()
  94. {
  95. if (isSafari()) {
  96. $("#edit").css({position:"relative"});
  97. $("#onlineChatEdit").css({position:"relative"});
  98. $(window).on("resize", manualForeignObjectPositioning);
  99. $(window).on("orientationchange", manualForeignObjectPositioning);
  100. manualForeignObjectPositioning();
  101. }
  102. }
  103. function manualForeignObjectPositioning()
  104. {
  105. var svgWidth = $svg[0].viewBox.baseVal.width,
  106. svgHeight = $svg[0].viewBox.baseVal.height;
  107. var sizeX = svgWidth / innerWidth,
  108. sizeY = svgHeight / innerHeight,
  109. size = Math.max(sizeX, sizeY) || 1;
  110. var realX, realY, scale, shiftX, shiftY;
  111. realX = 1/size * svgWidth;
  112. realY = 1/size * svgHeight;
  113. if (sizeX < sizeY) {
  114. // console.log("Left and Right White Spaces. Do stretch the Width ");
  115. shiftY = 0;
  116. shiftX = (innerWidth - realX) / 2;
  117. } else {
  118. // console.log("Top and Bottom White Spaces. Do reorient, or adopt the Height.");
  119. shiftX = 0;
  120. shiftY = (innerHeight - realY) / 2;
  121. }
  122. $("#GameChatEditor").attr({x: 864 * realX / svgWidth + shiftX,
  123. y: 504 * realY / svgHeight + shiftY,
  124. width: 198 * realX / svgWidth,
  125. height: 120 * realY / svgHeight});
  126. $("#OnlineChatEditor").attr({x: 10 * realX / svgWidth + shiftX,
  127. y: 504 * realY / svgHeight + shiftY,
  128. width: 198 * realX / svgWidth,
  129. height: 120 * realY / svgHeight});
  130. }