bootloader.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. var svgNS = "http://www.w3.org/2000/svg";
  2. var color = ['#DE3F26','#606060','#48AF5E','#FFC800'];
  3. function parseTransformAttribute(aa) {
  4. var a = aa.split(' ').join('');
  5. var b={};
  6. for (var i in a = a.match(/(\w+\((\-?\d+\.?\d*,?)+\))+/g)) { var c = a[i].match(/[\w\.\-]+/g); b[c.shift()] = c; }
  7. return b; }
  8. function svg(html) { return new DOMParser().parseFromString(html, "text/xml").firstChild; }
  9. function removeChilds(e) { var last; while (last = e.lastChild) e.removeChild(last); };
  10. function setPlayerName(e, playerName) {
  11. var dx = 15;
  12. document.getElementById(e+"-Name").setAttribute("y",27);
  13. document.getElementById(e+"-Name").setAttribute("x",dx);
  14. document.getElementById(e+"-Name").textContent = playerName;
  15. document.getElementById(e+"-Pad").setAttribute('width', document.getElementById(e+"-Name").getBBox().width + 25); }
  16. function template_engine(html, data) {
  17. var re = /{([^}]+)?}/g, code = 'var r=[];', cursor = 0;
  18. var add = function(line,js) {
  19. js? (code += 'r.push(' + line + ');') :
  20. (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");' : ''); // "
  21. return add; }
  22. while(match = re.exec(html)) {
  23. add(html.slice(cursor, match.index))(match[1],true);
  24. cursor = match.index + match[0].length; }
  25. add(html.substr(cursor, html.length - cursor));
  26. code += 'return r.join("");';
  27. return new Function(code.replace(/[\r\t\n]/g, '')).apply(data); }
  28. function discarder(name) { return template_engine(localStorage.getItem("svg/Discarder.svg?q=" + $.timestamp), { name: name }); }
  29. function initDiscards() {
  30. [ {name:"Gabrielo-Discard", hand:"Player-Left-Hand"},
  31. {name:"Alina-Discard", hand:"Player-Right-Hand"},
  32. {name:"Mustafa-Discard", hand:"Player-Center-Hand"},
  33. {name:"You-Discard", hand:"Player-Me-Hand"} ].map(function(e) {
  34. // document.getElementById(e.name).firstElementChild.remove();
  35. document.getElementById(e.name).appendChild(svg(discarder(e.hand)));
  36. });
  37. }
  38. function PatchSVG()
  39. {
  40. // document.getElementById('Page-1').addEventListener("mousewheel", mouseWheelHandler, false);
  41. // Setup Clipping ViewPorts
  42. var clipPath1 = svg('<clipPath id="myClip1"><rect xmlns="http://www.w3.org/2000/svg" id="Clip-Path-Left" x="0" y="0" width="216" height="400"/></clipPath>');
  43. var clipPath2 = svg('<clipPath id="myClip2"><rect xmlns="http://www.w3.org/2000/svg" id="Clip-Path-Right" x="0" y="0" width="216" height="400"/></clipPath>');
  44. var clipPath3 = svg('<clipPath id="myClip3"><rect xmlns="http://www.w3.org/2000/svg" id="Clip-Path-Left-Chat" x="0" y="0" width="216" height="400"/></clipPath>');
  45. document.getElementsByTagName('defs').item(0).appendChild(clipPath1);
  46. document.getElementsByTagName('defs').item(0).appendChild(clipPath2);
  47. document.getElementsByTagName('defs').item(0).appendChild(clipPath3);
  48. // document.getElementById("Online-List").setAttribute("clip-path","url(#myClip1)");
  49. // document.getElementById("Chat").setAttribute("clip-path","url(#myClip2)");
  50. // document.getElementById("Online-Chat").setAttribute("clip-path","url(#myClip1)");
  51. document.getElementById("Clip-Path-Left").setAttribute("transform", "translate(0,0)");
  52. document.getElementById("Clip-Path-Right").setAttribute("transform", "translate(0,0)");
  53. document.getElementById("Clip-Path-Left-Chat").setAttribute("transform", "translate(0,0)");
  54. // document.getElementById('Player-Statistics').style.display = 'none';
  55. document.getElementById("Right-Bar").setAttribute("fill","lightblue");
  56. document.getElementById("Left-Bar").setAttribute("fill","lightblue");
  57. document.getElementById("Right-Bar").setAttribute("xmlns:data","Right-Bar");
  58. document.getElementById("Left-Bar").setAttribute("xmlns:data","Left-Bar");
  59. document.getElementById("Right-Bar").onmouseover = barHover;
  60. document.getElementById("Right-Bar").onmouseout = barHoverOut;
  61. document.getElementById("Left-Bar").onmouseover = onlineHover;
  62. document.getElementById("Left-Bar").onmouseout = onlineHoverOut;
  63. document.getElementById("Player-Left").style.display = 'block';
  64. // HTML editors
  65. /*
  66. document.getElementById('onlineChatEdit').setAttribute("contentEditable","true");
  67. document.getElementById('onlineChatEdit').onkeydown = chatEditor;
  68. document.getElementById("onlineChatEdit").style.display = 'none';
  69. document.getElementById('edit').setAttribute("contentEditable","true");
  70. document.getElementById('edit').onkeydown = chatEditor;
  71. document.getElementById('edit').setAttribute("xmlns:data","Chat");
  72. document.getElementById("edit").style.display = '';
  73. */
  74. // showOnlineList ctor
  75. var onlineListOnClick = [
  76. "Online-Users",
  77. "Online-Users-Pad",
  78. "Online-Logo",
  79. "Users-Online-Message",
  80. "Users-Online-Number" ];
  81. // onlineListOnClick.map(function(x) {
  82. // console.log(x);
  83. // document.getElementById(x).onclick = showOnlineList; });
  84. initDiscards();
  85. Core(ControllerScope);
  86. Core(DragScope);
  87. Core(DropScope);
  88. Core(TimerScope);
  89. Core(PlayerScope);
  90. Core(OkeyApiProviderScope);
  91. Core(CardScope);
  92. Core(HandScope);
  93. Core(DeckScope);
  94. $svg.attr({preserveAspectRatio:"xMidYMin meet",class:"svg"});
  95. }
  96. function onPlayerInfo(evt) {
  97. ws.send(enc(tuple(atom('client'),
  98. tuple(atom('stats_action'),bin(document.user),atom('game_okey'))))); }
  99. function onPlayerInfoClose(evt) { document.getElementById('Player-Statistics').style.display = 'none'; }
  100. // Run
  101. $.load('Kakaranet-Scene.svg', function(x) {
  102. var name = "Refined";
  103. var slot = document.getElementById(name);
  104. if (slot == null) return;
  105. slot.parentNode.replaceChild(svg(x),slot);
  106. $.load("svg/Discarder.svg", function(h) {
  107. PatchSVG();
  108. StartApp();
  109. });
  110. });