bootloader.js 7.2 KB

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