svg.htm 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <link href="synrc.css" type="text/css" rel="stylesheet">
  6. <link href='http://fonts.googleapis.com/css?family=Exo+2:600' rel='stylesheet' type='text/css'>
  7. <script type="text/javascript">
  8. function verticalFlow(evt, dx) {
  9. console.log("Vertical Flow: " + evt);
  10. }
  11. </script>
  12. </head>
  13. <body>
  14. <div class="threecol">
  15. <div class="left">
  16. <div class="hints"></div>
  17. <div class="main">
  18. <h1>Full SVG Application</h1>
  19. <br>
  20. <svg id="Refined" width="900px">Placeholder for SVG Game Scene</svg>
  21. <code>Refined and Distilled File to download: <a href="Kakaranet-Scene.svg">Kakaranet-Scene.svg</a></code>
  22. <p><font color=red style="font-weight:bold;">Please make sure your Vector Editor correctly opens this file!</font></p>
  23. <div style="display: none;" id="history">
  24. <button id="pluslogin" type="button" data-gapiattached="true">Login</button>
  25. <label id="nothing"> Google</label></div><label id="gosterge">Gosterge: 1 5</label><br>
  26. <label id="player1"> Albert Einstein </label><select id="h1"></select>
  27. <label id="player2"> Marie Curie </label><select id="h2"></select>
  28. <label id="player3"> Ilya Prigogine </label><select id="h3"></select>
  29. <label id="player4" style="font-weight: bold; color: red;"> Asena Simsek </label><select id="h4"></select><br>
  30. <button id="logout" type="button">Logout</button>
  31. <button id="attach" type="button">Attach</button>
  32. <button id="join" type="button">Join</button>
  33. <select id="games_ids"></select>
  34. <select id="take_src"><option label="Table" value="0">Table</option><option label="Left" value="1">Left</option></select>
  35. <button id="take" type="button">Take</button>
  36. <select id="istaka"></select>
  37. <button id="discard" type="button">Discard</button>
  38. <button id="reveal" type="button">Reveal</button>
  39. <button id="saw_okey" type="button">I Saw Okey</button>
  40. <button id="have_8" type="button">8 Tashes</button>
  41. <button id="pause" type="button">Pause</button>
  42. <button id="info" type="button">PlayerInfo</button>
  43. <div id="n2ostatus"></div>
  44. <h1>Refined Object Names</h1>
  45. <code>
  46. Mustafa-Persona Facebook-Login Have-8-Tashes
  47. Gabrielo-Persona Online-Users Settings
  48. Alina-Person Kakaranet-Logo Pause
  49. Gabrielo-Deck Point-Table
  50. Alina-Deck Table Create
  51. Mustafa-Deck Gosterge Play
  52. Gabrielo-Discard Slot-1,1..15 Promos
  53. You-Discard Slot-2,1..15 Tournaments
  54. Alina-Discard Place-Card Okey
  55. Mustafa-Discard Center-Cards
  56. You-Deck Detailed-Houses
  57. Stupid-Cards Sky
  58. Mustafa-+-Timer Deck-Cards Sun
  59. You-+-Timer City
  60. Gabrielo
  61. Alina
  62. Right-Menu
  63. Left-Menu
  64. </code>
  65. <h1>SVG Templates and DOM Manipulation</h1>
  66. Here we using Simple Template Engine in 12 LOC.<br>
  67. SVG loader with localStorage caching in 9 LOC.<br>
  68. SVG DOM storing in 3 LOC<br>
  69. <code>
  70. function template_engine(html, data) {
  71. var re = /{([^}]+)?}/g, code = 'var r=[];', cursor = 0;
  72. var add = function(line,js) {
  73. js? (code += 'r.push(' + line + ');') :
  74. (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");' : '');
  75. return add; }
  76. while(match = re.exec(html)) {
  77. add(html.slice(cursor, match.index))(match[1],true);
  78. cursor = match.index + match[0].length; }
  79. add(html.substr(cursor, html.length - cursor));
  80. code += 'return r.join("");';
  81. return new Function(code.replace(/[\r\t\n]/g, '')).apply(data); }
  82. function reload_cont(cont,name,element) { if (null != cont) (cont)() else reload(name,element); }
  83. function reload(file, name) { var slot = document.getElementById(name);
  84. slot.parentNode.replaceChild(svg(localStorage.getItem(file)),slot);}
  85. function loadFile(name,cont,element) {
  86. if (localStorage.getItem(name) == null) {
  87. var client = new XMLHttpRequest();
  88. client.open('GET', name, true);
  89. client.onload = function() {
  90. localStorage.setItem(name,client.responseText);
  91. reload_cont(cont,name,element); }
  92. client.send(); }
  93. else reload_cont(cont,name,element); }
  94. function svg(html) { return new DOMParser().parseFromString(html, "text/xml").firstChild; }
  95. </code>
  96. <h1>The Card</h1>
  97. <code>
  98. templates/Card.svg:
  99. &lt;g xmlns="http://www.w3.org/2000/svg" id="<font color=yellow>{this.name}</font>"
  100. transform="translate(<font color=yellow>{this.x}</font>,<font color=yellow>{this.y}</font>)"&gt;mbership,
  101. &lt;rect fill="#FFFFFF" x="0" y="0" width="40" height="60" rx="4"/&gt;
  102. &lt;circle fill="<font color=yellow>{this.suit}</font>" cx="20" cy="43" r="7"&gt;
  103. &lt;animate begin="0" fill="freeze" attributeName="r"
  104. values="4;5;6;7;8;6;5;4" dur="1s"
  105. calcMode="linear" repeatCount="indefinite"/&gt;&lt;/circle&gt;
  106. &lt;text dx="20" x="0" y="26.4873125"
  107. font-family="Lucida Grande" font-size="24"
  108. font-weight="bold" letter-spacing="-2" text-anchor="middle"
  109. fill="<font color=yellow>{this.suit}</font>"&gt;<font color=yellow>{this.value}</font>&lt;/text&gt;
  110. &lt;/g&gt;
  111. function card(line,pos,col,v) {
  112. return template_engine(
  113. localStorage.getItem("templates/Card.svg"),
  114. { name: slotName(pos,line),
  115. suit: color[col-1],
  116. value: v,
  117. y: (line-1)*69,
  118. x: (pos-1)*42 }); }
  119. <svg id="Scene" width="200px" height="200px" viewBox="0 0 40 60">
  120. <g xmlns="http://www.w3.org/2000/svg" id="Slot"
  121. transform="translate(0,0)">
  122. <rect fill="#FFFFFF" x="0" y="0"
  123. width="40" height="60" rx="4"/>
  124. <text dx="20" x="0" y="26.4873125"
  125. font-family="Lucida Grande" font-size="24"
  126. font-weight="bold" letter-spacing="-2" text-anchor="middle"
  127. fill="#CE290F">12</text>
  128. <circle id="Color-{this.pos}" fill="#CE290F" cx="20" cy="43" r="7">
  129. <animate begin="0" fill="freeze" attributeName="r"
  130. values="4;5;6;7;8;6;5;4" dur="1s"
  131. calcMode="linear" repeatCount="indefinite"/></circle></g></svg>
  132. </code>
  133. <h1>Draw Deck</h1>
  134. <code>
  135. var color = ['#CE290F','#3B5998','#48AF5E','#FFEC00'];
  136. var slotName = slotNameDef;
  137. function slotNameDef(x,y) { return "Slot-"+y+","+x; }
  138. function place_card(x,y,c,v) {
  139. var slot = document.getElementById(slotName(x,y));
  140. slot.parentNode.replaceChild(svg(card(y,x,c,v)),slot); }
  141. function rand(lo,hi) { return Math.floor((Math.random()*hi)+lo); }
  142. function slotName1(x,y) { return "1Slot-"+y+","+x; }
  143. function drawSampleCards() {
  144. slotName = slotName1;
  145. for (var i=1;i<15;i++) { place_card(i,rand(1,2),rand(1,4),rand(1,13)); }
  146. slotName = slotNameDef; }
  147. loadFile('templates/Card.svg', drawSampleCards);
  148. <svg id="Scene" width="630px" height="200px" viewBox="-3 0 634 130">
  149. <rect id="Deck" fill="#AF7B58" x=-5 y=-2 width=635 height=133></rect>
  150. <rect id="Deck" fill="#BC8864" x=-5 y=62 width=635 height=5></rect>
  151. <g id="1Slot-1,1"/> <g id="1Slot-1,2"/> <g id="1Slot-1,3"/>
  152. <g id="1Slot-1,4"/> <g id="1Slot-1,5"/> <g id="1Slot-1,6"/>
  153. <g id="1Slot-1,7"/> <g id="1Slot-1,8"/> <g id="1Slot-1,9"/>
  154. <g id="1Slot-1,10"/><g id="1Slot-1,11"/><g id="1Slot-1,12"/>
  155. <g id="1Slot-1,13"/><g id="1Slot-1,14"/><g id="1Slot-1,15"/>
  156. <g id="1Slot-2,1"/> <g id="1Slot-2,2"/> <g id="1Slot-2,3"/>
  157. <g id="1Slot-2,4"/> <g id="1Slot-2,5"/> <g id="1Slot-2,6"/>
  158. <g id="1Slot-2,7"/> <g id="1Slot-2,8"/> <g id="1Slot-2,9"/>
  159. <g id="1Slot-2,10"/><g id="1Slot-2,11"/><g id="1Slot-2,12"/>
  160. <g id="1Slot-2,13"/><g id="1Slot-2,14"/><g id="1Slot-2,15"/>
  161. </svg>
  162. </code>
  163. <h1>Mustafa</h1>
  164. <code>
  165. > document.getElementById("Mustafa-Persona");
  166. <svg width="400px" height="400px" viewBox="450 120 150 200">
  167. <g id="Mustafa-Selection-Sample"/>
  168. <g id="Mustafa-Persona-Sample"/>
  169. </svg>
  170. > document.getElementById("Mustafa-Selection").style.display = "none";
  171. </code>
  172. <button id="MustafaSelection" style="font-size:28pt;">Toggle Mustafa Selection</button>
  173. <script src='svg.js' type='text/javascript' charset='utf-8'></script>
  174. <code style="font-size: 6pt;">
  175. &lt;g id="Mustafa-Persona" sketch:type="MSLayerGroup" transform="translate(467.000000, 150.000000)"&gt;
  176. &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
  177. L135.729,120.296 L135.729,120.296 Z" id="Mustafa-Body" fill="#8DCED7"&gt;&lt;/path&gt;
  178. &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
  179. 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;
  180. &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
  181. 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
  182. 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;
  183. &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
  184. 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
  185. 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
  186. 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
  187. 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
  188. 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
  189. 88.417,44.462 88.417,44.449 L88.417,44.449 Z" id="Mustafa-Face" fill="#FFE0A5"&gt;&lt;/path&gt;
  190. &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
  191. 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
  192. 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;
  193. &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
  194. 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
  195. 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
  196. L85.984,78.799 Z" id="Mustafa-Right-Collar" fill="#EFEFEF"&gt;&lt;/path&gt;
  197. &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
  198. 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
  199. 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
  200. 45.621,35.719 L45.821,47.087 L45.821,47.087 Z" id="Mustafa-Hair-2" fill="#3F372E"&gt;&lt;/path&gt;
  201. &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
  202. 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
  203. 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;
  204. &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
  205. 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
  206. 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;
  207. &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
  208. 65.8852394,70.5763405 C63.7043817,70.5763405 59.6097044,68.9318757 58.3813209,68.0499693 C57.1529374,67.1680629 53.4953577,63.8108791
  209. 54.8127441,62.3565674 C56.1301305,60.9022556 58.2236035,63.1233233 59.4535298,63.9693678 C60.6834562,64.8154119 63.4038036,66.1736356
  210. 65.6591608,66.1736357 C67.2722666,66.1736358 69.8272118,65.4283507 71.0461488,64.5069182 C72.2650857,63.5854857 74.7594486,61.012262
  211. 76.4456778,62.3565674 Z" id="Mustafa-Mouth" fill="#E6BE7C"&gt;&lt;/path&gt;&lt;/g&gt;
  212. </code>
  213. <h2>Abstract</h2>
  214. <p>Основна ідея мати чистий SVG фреймворк що усі елементи були однотипними,
  215. і підхід був уніфікований, кнопки будь якого розміру, форми і які легко
  216. було би змінити в майбутньому. HTML/CSS підхід в подальшому не даcть
  217. змогу легко замінити контрольні елементи, карти і таке інше, доведеть
  218. повністью розбирати CSS елементи і верску. Уявіть що ми захочемо в
  219. майбутньому просто відкрити SVG у векторному редакторі, перемалювати
  220. і зберегти з тими самими element ID. У випадку з CSS при зміні дизайну ми
  221. постійно будемо змушені пестворювати верстку, знову наймати одноразову ручну роботу.
  222. У випадку з SVG нам доведеться тільки замінити елементи SVG.</P>
  223. <h2>SVG Integration Process</h2>
  224. <p>Підхід який пропонується нагадуеє уніфіковану роботу з векторними
  225. XML елементами, як це є в WPF наприклад. Тут справа не в байтах, в
  226. інтеграції процессу між дизайнерами, розробниками, верстальниками і
  227. серверними програмістами. Як наприклад Expression Blend у Microsoft для WPF.
  228. Саме з цих міркувань була вибрана технологія SVG.</p>
  229. <h2>SVG DOM Control</h2>
  230. <p>Інша частина це інтеграція SVG DOM і управління ним на сервері.
  231. Ми хочемо мати можливість модифікувати SVG DOM з сервера. Для цього
  232. нам потрібно прозорий та уніфікований підхід до усіх елементів.
  233. Це дасть нам змогу використовувати підхід як товстого (гра повністю в браузері),
  234. так і тонкого клієнту (коли стан гри повнітю контролюється сервером).</p>
  235. <h2>Sample Client</h2>
  236. <p>Прототип тонкого клієнту на елементах HTML/CSS викладений тут:<p>
  237. <code><a href="http://srv5.kakaranet.com:8080">http://srv5.kakaranet.com:8080</a></code>
  238. </div>
  239. <div class="contents">
  240. <!--iframe src="contents.htm" frameborder=0 width=340 height=510></iframe-->
  241. </div>
  242. </div>
  243. <script src='../nitrogen/bullet.js' type='text/javascript' charset='utf-8'></script>
  244. <script src='../nitrogen/n2o.js' type='text/javascript' charset='utf-8'></script>
  245. <script src='../nitrogen/bert.js' type='text/javascript' charset='utf-8'></script>
  246. </body>
  247. </html>