bootloader.js 6.3 KB

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