bootloader.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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).appendChild(svg(discarder(e.hand)));
  35. });
  36. }
  37. function PatchSVG()
  38. {
  39. $('Player-Statistics').hide();
  40. var onlineListOnClick = [
  41. "Online-Users",
  42. "Online-Users-Pad",
  43. "Online-Logo",
  44. "Users-Online-Message",
  45. "Users-Online-Number" ];
  46. onlineListOnClick.map(function(x) {
  47. document.getElementById(x).onclick = showOnlineList; });
  48. Core(ControllerScope);
  49. Core(DragScope);
  50. Core(DropScope);
  51. Core(TimerScope);
  52. Core(PlayerScope);
  53. Core(OkeyApiProviderScope);
  54. Core(CardScope);
  55. Core(HandScope);
  56. Core(DeckScope);
  57. Core(RosterScope);
  58. initDiscards();
  59. initChat();
  60. initChatSample();
  61. //document.addEventListener('touchmove',function(e) {e.preventDefault();},false);
  62. $svg.attr({preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%"});
  63. }
  64. function initChatSample() {
  65. chatMessage("Chat","1","Maxim2","Joe:\nHello There!".encodeHTML());
  66. chatMessage("Chat","2","Maxim2","Alice:\nYou got new Design. Eh?".encodeHTML());
  67. chatMessage("Chat","3","Maxim","Maxim So:\nThis was made with pure SVG".encodeHTML());
  68. barHover();
  69. mouseWheelHandler({'detail':-100000,'wheelDelta':-100000});
  70. barHoverOut();
  71. }
  72. function onPlayerInfo(evt) {
  73. ws.send(enc(tuple(atom('client'),
  74. tuple(atom('stats_action'),bin(document.user),atom('game_okey'))))); }
  75. function onPlayerInfoClose(evt) { document.getElementById('Player-Statistics').style.display = 'none'; }
  76. // Run
  77. $.load('Kakaranet-Scene.svg', function(x) {
  78. var name = "Refined";
  79. var slot = document.getElementById(name);
  80. if (slot == null) return;
  81. slot.parentNode.replaceChild(svg(x),slot);
  82. $.load("svg/Discarder.svg", function(h) {
  83. PatchSVG();
  84. StartApp();
  85. });
  86. });