svg.htm 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <html>
  3. <head>
  4. <link href="synrc.css" type="text/css" rel="stylesheet">
  5. </head>
  6. <body>
  7. <div class="threecol">
  8. <div class="left">
  9. <div class="hints"></div>
  10. <div class="main">
  11. <h1>Full SVG Application</h1>
  12. <br>
  13. <svg id="Refined" width="900px">Placeholder for SVG Game Scene</svg>
  14. <code>Refined and Distilled File to download: <a href="Kakaranet-7-Refined.svg">Kakaranet-7-Refined.svg</a></code>
  15. <p><font color=red style="font-weight:bold;">Please make sure your Vector Editor correctly opens this file!</font></p>
  16. <div style="display: none;" id="history">
  17. <button id="pluslogin" type="button" data-gapiattached="true">Login</button>
  18. <label id="nothing"> Google</label></div><label id="gosterge">Gosterge: 1 5</label><br>
  19. <label id="player1"> Albert Einstein </label><select id="h1"></select>
  20. <label id="player2"> Marie Curie </label><select id="h2"></select>
  21. <label id="player3"> Ilya Prigogine </label><select id="h3"></select>
  22. <label id="player4" style="font-weight: bold; color: red;"> Asena Simsek </label><select id="h4"></select><br>
  23. <button id="attach" type="button">Attach</button>
  24. <button id="join" type="button">Join</button>
  25. <select id="games_ids"></select>
  26. <select id="take_src"><option label="Table" value="0">Table</option><option label="Left" value="1">Left</option></select>
  27. <button id="take" type="button">Take</button>
  28. <select id="istaka"></select>
  29. <button id="discard" type="button">Discard</button>
  30. <button id="reveal" type="button">Reveal</button>
  31. <button id="saw_okey" type="button">I Saw Okey</button>
  32. <button id="have_8" type="button">8 Tashes</button>
  33. <button id="pause" type="button">Pause</button>
  34. <button id="info" type="button">PlayerInfo</button>
  35. <div id="n2ostatus"></div>
  36. <h1>Refined Object Names</h1>
  37. <code>
  38. Mustafa-Persona Facebook-Login Have-8-Tashes
  39. Gabrielo-Persona Online-Users Settings
  40. Alina-Person Kakaranet-Logo Pause
  41. Gabrielo-Deck Point-Table
  42. Alina-Deck Table Create
  43. Mustafa-Deck Gosterge Play
  44. Gabrielo-Discard Slot-1,1..15 Promos
  45. You-Discard Slot-2,1..15 Tournaments
  46. Alina-Discard Place-Card Okey
  47. Mustafa-Discard Center-Cards
  48. You-Deck Detailed-Houses
  49. Stupid-Cards Sky
  50. Mustafa-+-Timer Deck-Cards Sun
  51. You-+-Timer City
  52. Gabrielo
  53. Alina
  54. Right-Menu
  55. Left-Menu
  56. </code>
  57. <h1>SVG Templates and DOM Manipulation</h1>
  58. Here we using Simple Template Engine in 12 LOC.<br>
  59. SVG loader with localStorage caching in 9 LOC.<br>
  60. SVG DOM storing in 3 LOC<br>
  61. <code>
  62. function template_engine(html, data) {
  63. var re = /{([^}]+)?}/g, code = 'var r=[];', cursor = 0;
  64. var add = function(line,js) {
  65. js? (code += 'r.push(' + line + ');') :
  66. (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");' : '');
  67. return add; }
  68. while(match = re.exec(html)) {
  69. add(html.slice(cursor, match.index))(match[1],true);
  70. cursor = match.index + match[0].length; }
  71. add(html.substr(cursor, html.length - cursor));
  72. code += 'return r.join("");';
  73. return new Function(code.replace(/[\r\t\n]/g, '')).apply(data); }
  74. function reload_cont(cont,name,element) { if (null != cont) (cont)() else reload(name,element); }
  75. function reload(file, name) { var slot = document.getElementById(name);
  76. slot.parentNode.replaceChild(svg(localStorage.getItem(file)),slot);}
  77. function loadFile(name,cont,element) {
  78. if (localStorage.getItem(name) == null) {
  79. var client = new XMLHttpRequest();
  80. client.open('GET', name, true);
  81. client.onload = function() {
  82. localStorage.setItem(name,client.responseText);
  83. reload_cont(cont,name,element); }
  84. client.send(); }
  85. else reload_cont(cont,name,element); }
  86. function svg(html) { return new DOMParser().parseFromString(html, "text/xml").firstChild; }
  87. </code>
  88. <h1>The Card</h1>
  89. <code>
  90. templates/Card.svg:
  91. &lt;g xmlns="http://www.w3.org/2000/svg" id="<font color=yellow>{this.name}</font>"
  92. transform="translate(<font color=yellow>{this.x}</font>,<font color=yellow>{this.y}</font>)"&gt;mbership,
  93. &lt;rect fill="#FFFFFF" x="0" y="0" width="40" height="60" rx="4"/&gt;
  94. &lt;circle fill="<font color=yellow>{this.suit}</font>" cx="20" cy="43" r="7"&gt;
  95. &lt;animate begin="0" fill="freeze" attributeName="r"
  96. values="4;5;6;7;8;6;5;4" dur="1s"
  97. calcMode="linear" repeatCount="indefinite"/&gt;&lt;/circle&gt;
  98. &lt;text dx="20" x="0" y="26.4873125"
  99. font-family="Lucida Grande" font-size="24"
  100. font-weight="bold" letter-spacing="-2" text-anchor="middle"
  101. fill="<font color=yellow>{this.suit}</font>"&gt;<font color=yellow>{this.value}</font>&lt;/text&gt;
  102. &lt;/g&gt;
  103. function card(line,pos,col,v) {
  104. return template_engine(
  105. localStorage.getItem("templates/Card.svg"),
  106. { name: slotName(pos,line),
  107. suit: color[col-1],
  108. value: v,
  109. y: (line-1)*69,
  110. x: (pos-1)*42 }); }
  111. <svg id="Scene" width="200px" height="200px" viewBox="0 0 40 60">
  112. <g xmlns="http://www.w3.org/2000/svg" id="Slot"
  113. transform="translate(0,0)">
  114. <rect fill="#FFFFFF" x="0" y="0"
  115. width="40" height="60" rx="4"/>
  116. <text dx="20" x="0" y="26.4873125"
  117. font-family="Lucida Grande" font-size="24"
  118. font-weight="bold" letter-spacing="-2" text-anchor="middle"
  119. fill="#CE290F">12</text>
  120. <circle id="Color-{this.pos}" fill="#CE290F" cx="20" cy="43" r="7">
  121. <animate begin="0" fill="freeze" attributeName="r"
  122. values="4;5;6;7;8;6;5;4" dur="1s"
  123. calcMode="linear" repeatCount="indefinite"/></circle></g></svg>
  124. </code>
  125. <h1>Draw Deck</h1>
  126. <code>
  127. var color = ['#CE290F','#3B5998','#48AF5E','#FFEC00'];
  128. var slotName = slotNameDef;
  129. function slotNameDef(x,y) { return "Slot-"+y+","+x; }
  130. function place_card(x,y,c,v) {
  131. var slot = document.getElementById(slotName(x,y));
  132. slot.parentNode.replaceChild(svg(card(y,x,c,v)),slot); }
  133. function rand(lo,hi) { return Math.floor((Math.random()*hi)+lo); }
  134. function slotName1(x,y) { return "1Slot-"+y+","+x; }
  135. function drawSampleCards() {
  136. slotName = slotName1;
  137. for (var i=1;i<15;i++) { place_card(i,rand(1,2),rand(1,4),rand(1,13)); }
  138. slotName = slotNameDef; }
  139. loadFile('templates/Card.svg', drawSampleCards);
  140. <svg id="Scene" width="630px" height="200px" viewBox="-3 0 634 130">
  141. <rect id="Deck" fill="#AF7B58" x=-5 y=-2 width=635 height=133></rect>
  142. <rect id="Deck" fill="#BC8864" x=-5 y=62 width=635 height=5></rect>
  143. <g id="1Slot-1,1"/> <g id="1Slot-1,2"/> <g id="1Slot-1,3"/>
  144. <g id="1Slot-1,4"/> <g id="1Slot-1,5"/> <g id="1Slot-1,6"/>
  145. <g id="1Slot-1,7"/> <g id="1Slot-1,8"/> <g id="1Slot-1,9"/>
  146. <g id="1Slot-1,10"/><g id="1Slot-1,11"/><g id="1Slot-1,12"/>
  147. <g id="1Slot-1,13"/><g id="1Slot-1,14"/><g id="1Slot-1,15"/>
  148. <g id="1Slot-2,1"/> <g id="1Slot-2,2"/> <g id="1Slot-2,3"/>
  149. <g id="1Slot-2,4"/> <g id="1Slot-2,5"/> <g id="1Slot-2,6"/>
  150. <g id="1Slot-2,7"/> <g id="1Slot-2,8"/> <g id="1Slot-2,9"/>
  151. <g id="1Slot-2,10"/><g id="1Slot-2,11"/><g id="1Slot-2,12"/>
  152. <g id="1Slot-2,13"/><g id="1Slot-2,14"/><g id="1Slot-2,15"/>
  153. </svg>
  154. </code>
  155. <h1>Mustafa</h1>
  156. <code>
  157. > document.getElementById("Mustafa-Persona");
  158. <svg width="400px" height="400px" viewBox="450 120 150 200">
  159. <g id="Mustafa-Selection-Sample"/>
  160. <g id="Mustafa-Persona-Sample"/>
  161. </svg>
  162. > document.getElementById("Mustafa-Selection").style.display = "none";
  163. </code>
  164. <button id="MustafaSelection" style="font-size:28pt;">Toggle Mustafa Selection</button>
  165. <script src='svg.js' type='text/javascript' charset='utf-8'></script>
  166. <code style="font-size: 6pt;">
  167. &lt;g id="Mustafa-Persona" sketch:type="MSLayerGroup" transform="translate(467.000000, 150.000000)"&gt;
  168. &lt;path d="M135.729,120.296 C118.005,95.269 108.839,85.517 85.519,85.517 L45.641,85.517 C22.321,85.517 11.022,103.055 0.272,120.296
  169. L135.729,120.296 L135.729,120.296 Z" id="Mustafa-Body" fill="#8DCED7"&gt;&lt;/path&gt;
  170. &lt;path d="M52.283,65.674 L48.134,81.099 L62.961,92.715 C62.961,92.715 68.155,92.749 68.329,92.691 C68.505,92.63 82.401,82.215
  171. 82.401,82.215 L78.093,65.59 L52.283,65.674 L52.283,65.674 Z" id="Mestafa-Neck" fill="#FFD191"&gt;&lt;/path&gt;
  172. &lt;path d="M56.035,1.351 C55.251,1.787 55.519,2.374 56.04,2.389 C57.252,2.419 58.102,2.639 58.81,3.7 C59.027,4.136 60.433,8.259 53.572,9.985
  173. C44.985,11.985 31.101,25.204 40.796,45.629 C41.402,46.905 42.03,48.031 42.676,49.019 C65.907,47.218 68.327,47.042
  174. 89.399,45.259 C106.855,15.955 69.488,-5.38 56.035,1.351 L56.035,1.351 Z" id="Mustafa-Hair" fill="#3F372E"&gt;&lt;/path&gt;
  175. &lt;path d="M88.417,44.449 C88.417,44.312 88.394,44.178 88.365,44.053 C88.288,43.666 88.116,43.387 87.864,43.196 C87.553,42.909 87.148,42.73 86.69,42.73
  176. L85.381,42.73 C85.263,42.73 85.152,42.752 85.039,42.764 L85.039,40.178 C85.039,29.368 76.272,20.604 65.456,20.604 C54.639,20.604 45.871,29.369
  177. 45.871,40.178 L45.871,42.739 C45.838,42.739 45.808,42.73 45.772,42.73 C44.099,42.73 42.742,42.844 42.742,44.518 L42.742,53.114 C42.742,54.788
  178. 44.099,56.141 45.772,56.141 C45.807,56.141 45.837,56.132 45.871,56.132 L45.871,62.719 C45.871,72.543 52.695,79.145 61.763,82.679 C62.161,84.207
  179. 63.533,85.34 65.189,85.34 C66.759,85.34 68.081,84.313 68.547,82.897 C78.753,79.063 85.038,72.831 85.038,62.719 L85.038,56.108 C85.15,56.118
  180. 85.262,56.141 85.38,56.141 C87.054,56.141 88.415,54.787 88.415,53.114 L88.415,44.518 C88.415,44.502 88.408,44.498 88.408,44.488 C88.41,44.474
  181. 88.417,44.462 88.417,44.449 L88.417,44.449 Z" id="Mustafa-Face" fill="#FFE0A5"&gt;&lt;/path&gt;
  182. &lt;path d="M62.358,88.807 C62.251,88.775 51.594,85.661 47.004,79.336 C46.652,78.854 46.035,78.639 45.46,78.799 C42.924,79.506 42.006,84.223 42.402,86.014
  183. C44.687,96.295 58.986,102.323 59.593,102.574 C59.772,102.644 59.957,102.686 60.144,102.686 C60.384,102.686 60.624,102.624 60.839,102.503 C61.22,102.289
  184. 61.486,101.916 61.557,101.484 L63.378,90.417 C63.496,89.699 63.059,89.006 62.358,88.807 L62.358,88.807 Z" id="Mustafa-Left-Collar" fill="#EFEFEF"&gt;&lt;/path&gt;
  185. &lt;path d="M85.984,78.799 C85.408,78.639 84.79,78.854 84.439,79.336 C79.851,85.66 69.2,88.774 69.088,88.807 C68.393,89.006 67.953,89.7 68.067,90.417
  186. L69.888,101.484 C69.96,101.916 70.223,102.289 70.606,102.503 C70.822,102.624 71.065,102.686 71.308,102.686 C71.492,102.686
  187. 71.677,102.644 71.854,102.574 C72.458,102.323 86.754,96.296 89.039,86.014 C89.441,84.223 88.521,79.506 85.984,78.799
  188. L85.984,78.799 Z" id="Mustafa-Right-Collar" fill="#EFEFEF"&gt;&lt;/path&gt;
  189. &lt;path d="M45.821,47.087 C45.821,47.087 48.215,47.551 48.588,44.092 C49.207,39.158 47.304,25.716 54.907,27.976 C62.513,30.241 67.131,31.426 72.271,28.758
  190. C77.406,26.085 80.23,30.547 81.311,33.531 C82.352,36.408 80.573,46.199 85.095,45.786 C85.121,44.68 85.073,43.809 85.116,42.687 C87.802,41.369
  191. 87.042,36.324 87.118,28.9 C86.626,22.662 83.987,16.503 69.765,16.263 C68.323,16.263 52.084,15.646 48.18,21.195 C44.276,26.742 45.621,35.719
  192. 45.621,35.719 L45.821,47.087 L45.821,47.087 Z" id="Mustafa-Hair-2" fill="#3F372E"&gt;&lt;/path&gt;
  193. &lt;path d="M60.429,52.326 C59.764,52.326 59.226,51.787 59.226,51.122 C59.226,50.295 58.551,49.619 57.72,49.619 C56.89,49.619 56.217,50.295 56.217,51.122
  194. C56.217,51.787 55.676,52.326 55.014,52.326 C54.347,52.326 53.81,51.787 53.81,51.122 C53.81,48.967 55.563,47.213 57.72,47.213 C59.88,47.213
  195. 61.634,48.967 61.634,51.122 C61.634,51.787 61.094,52.326 60.429,52.326 L60.429,52.326 Z" id="Mustafa-Left-Eye" fill="#3F372E"&gt;&lt;/path&gt;
  196. &lt;path d="M75.899,52.326 C75.231,52.326 74.695,51.787 74.695,51.122 C74.695,50.295 74.021,49.619 73.188,49.619 C72.361,49.619 71.688,50.295 71.688,51.122
  197. C71.688,51.787 71.146,52.326 70.484,52.326 C69.818,52.326 69.278,51.787 69.278,51.122 C69.278,48.967 71.037,47.213 73.188,47.213 C75.346,47.213
  198. 77.101,48.967 77.101,51.122 C77.102,51.787 76.559,52.326 75.899,52.326 L75.899,52.326 Z" id="Mustafa-Right-Eye" fill="#3F372E"&gt;&lt;/path&gt;
  199. &lt;path d="M76.4456778,62.3565674 C78.1319071,63.7008727 74.4204926,66.9530814 72.7733273,68.0499695 C71.126162,69.1468575 68.0660971,70.5763405
  200. 65.8852394,70.5763405 C63.7043817,70.5763405 59.6097044,68.9318757 58.3813209,68.0499693 C57.1529374,67.1680629 53.4953577,63.8108791
  201. 54.8127441,62.3565674 C56.1301305,60.9022556 58.2236035,63.1233233 59.4535298,63.9693678 C60.6834562,64.8154119 63.4038036,66.1736356
  202. 65.6591608,66.1736357 C67.2722666,66.1736358 69.8272118,65.4283507 71.0461488,64.5069182 C72.2650857,63.5854857 74.7594486,61.012262
  203. 76.4456778,62.3565674 Z" id="Mustafa-Mouth" fill="#E6BE7C"&gt;&lt;/path&gt;&lt;/g&gt;
  204. </code>
  205. <h2>Abstract</h2>
  206. <p>Основна ідея мати чистий SVG фреймворк що усі елементи були однотипними,
  207. і підхід був уніфікований, кнопки будь якого розміру, форми і які легко
  208. було би змінити в майбутньому. HTML/CSS підхід в подальшому не даcть
  209. змогу легко замінити контрольні елементи, карти і таке інше, доведеть
  210. повністью розбирати CSS елементи і верску. Уявіть що ми захочемо в
  211. майбутньому просто відкрити SVG у векторному редакторі, перемалювати
  212. і зберегти з тими самими element ID. У випадку з CSS при зміні дизайну ми
  213. постійно будемо змушені пестворювати верстку, знову наймати одноразову ручну роботу.
  214. У випадку з SVG нам доведеться тільки замінити елементи SVG.</P>
  215. <h2>SVG Integration Process</h2>
  216. <p>Підхід який пропонується нагадуеє уніфіковану роботу з векторними
  217. XML елементами, як це є в WPF наприклад. Тут справа не в байтах, в
  218. інтеграції процессу між дизайнерами, розробниками, верстальниками і
  219. серверними програмістами. Як наприклад Expression Blend у Microsoft для WPF.
  220. Саме з цих міркувань була вибрана технологія SVG.</p>
  221. <h2>SVG DOM Control</h2>
  222. <p>Інша частина це інтеграція SVG DOM і управління ним на сервері.
  223. Ми хочемо мати можливість модифікувати SVG DOM з сервера. Для цього
  224. нам потрібно прозорий та уніфікований підхід до усіх елементів.
  225. Це дасть нам змогу використовувати підхід як товстого (гра повністю в браузері),
  226. так і тонкого клієнту (коли стан гри повнітю контролюється сервером).</p>
  227. <h2>Sample Client</h2>
  228. <p>Прототип тонкого клієнту на елементах HTML/CSS викладений тут:<p>
  229. <code><a href="http://srv5.kakaranet.com:8080">http://srv5.kakaranet.com:8080</a></code>
  230. </div>
  231. <div class="contents">
  232. <iframe src="contents.htm" frameborder=0 width=340 height=2190></iframe>
  233. </div>
  234. </div>
  235. <script src='../nitrogen/bullet.js' type='text/javascript' charset='utf-8'></script>
  236. <script src='../nitrogen/n2o.js' type='text/javascript' charset='utf-8'></script>
  237. <script src='../nitrogen/bert.js' type='text/javascript' charset='utf-8'></script>
  238. </body>
  239. </html>