Advertisement
Guest User

Untitled

a guest
May 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. import '../components/gameButtons.html';
  2. import '../components/dropdown.js';
  3. import './board.js';
  4.  
  5. //var blocks = [];
  6. var i = 0;
  7.  
  8. //Session.set('allBlocks', blocks );
  9.  
  10. //var coords = Session.get('allBlocks');
  11.  
  12. Template.gameButtons.rendered = function(){
  13. if(Session.get('allBlocks') != undefined){
  14. recreateBlocks(Session.get('allBlocks'));
  15. }else{
  16. document.getElementById("startButton").disabled = false;
  17. document.getElementById("endButton").disabled = true;
  18. document.getElementById("ifButton").disabled = false; //testning
  19. //document.getElementById("ifButton").disabled = true;
  20. //document.getElementById("thenButton").disabled = true;
  21. document.getElementById("thenButton").disabled = false; //testning
  22. }
  23. };
  24.  
  25. Template.gameButtons.events({
  26.  
  27. "click #startButton": function(event){
  28. var div = createStartBlock();
  29. addBlockToSession(div);
  30.  
  31. },
  32.  
  33. "click #endButton": function(event){
  34. var div = createEndBlock();
  35. addBlockToSession(div);
  36.  
  37. },
  38.  
  39. "click #ifButton": function(event){
  40. var div = createIfBlock();
  41. addBlockToSession(div);
  42.  
  43. },
  44.  
  45. "click #thenButton": function(event){
  46. var div = createThenBlock();
  47. addBlockToSession(div);
  48.  
  49. }
  50.  
  51. });
  52.  
  53. function createBuildningBlock(src){
  54. var div = document.createElement("div");
  55. div.className ="container";
  56. div.style.position = "relative";
  57. div.style.width = "100%";
  58. div.style.padding = "10px";
  59.  
  60. var img = document.createElement("img");
  61. img.setAttribute("src", src);
  62. img.style.width = "100%";
  63.  
  64. div.appendChild(img);
  65. return div;
  66. }
  67.  
  68. //metod för att styla, positionering
  69. //wc3schools javascript x.style.fonrsez
  70. //materialize ikoner
  71. function createTextDiv(text){
  72. var content = document.createElement("div");
  73. content.className ="white col s4 black-text center-align";
  74. content.style.position = "absolute";
  75. content.style.right = "70%";
  76. content.style.bottom = "60%";
  77.  
  78. var paragraph = document.createElement("P");
  79. paragraph.innerText = text;
  80.  
  81. content.appendChild(paragraph); // till "content" som parent lägga på texten som child
  82.  
  83. return content;
  84.  
  85. }
  86.  
  87. var lampSensors = ["ljus sensorn", "ljud sensorn", "tryck sensorn"];
  88. var lampStatus = ["aktiverad", "inaktiverad"];
  89. var lampPosts = ["1", "2", "3", "4", "5", "6"];
  90. var lampColors = ["röd", "blå", "grön"];
  91.  
  92. function createDropDownDiv(blockOptions) {
  93. var content = document.createElement("div");
  94. content.className = "white dropdown";
  95. content.innerText = "test";
  96.  
  97. var selectButton = document.createElement("button");
  98. selectButton.className = "dropbtn";
  99. selectButton.innerText = "______"
  100. content.appendChild(selectButton);
  101.  
  102. var dropdown = document.createElement("div");
  103. dropdown.id = "blockDropdown";
  104. dropdown.className = "dropdown-content";
  105.  
  106. var item = document.createElement("a");
  107. item.innerText = "ljus sensorn";
  108.  
  109. dropdown.appendChild(item);
  110.  
  111. // content.className ="dropdown-content";
  112. content.style.position = "absolute";
  113. content.style.right = "45%";
  114. content.style.bottom = "60%";
  115.  
  116. // var dropdown = document.createElement("P");
  117.  
  118. return content;
  119.  
  120. //var dropdown = document.getElementById("blockDropdown");
  121. // var row = document.createElement("div");
  122. // row.className = "row";
  123. // var col = document.createElement("div");
  124. // col.className = "col s4";
  125. // var row = document.createElement("div");
  126. // row.className = "row";
  127. // var col = document.createElement("div");
  128. // col.className = "white col s4 black-text center-align";
  129. // col.innertext = "Om";
  130.  
  131. }
  132. // document.addEventListener('blockDropdown', function() {
  133. // var elems = document.querySelectorAll('select');
  134. // var instances = M.FormSelect.init(elems, options);
  135. // });
  136.  
  137. // Or with jQuery
  138.  
  139. $(document).ready(function() {
  140. $('select').material_select();
  141. });
  142.  
  143. //använda grid-system
  144. // en div för text, en div för dropdown, en div för modal (i)
  145. // rad 1 "text" dropdown info-modal-ikon -- om ljus/ljud/tryck -- i en och samma div-container
  146. // rad 2 "text" dropdown info-modal-ikon -- i lyktstople 1-6 -- i en och samma div-container
  147. // rad 2 "text" dropdown info-modal-ikon -- är aktiverad/inaktiverad -- i en och samma div-container
  148.  
  149.  
  150. function addBlockToSession(block){
  151. if(Session.get('allBlocks') == undefined){
  152. var blocks = [block];
  153. Session.set('allBlocks', blocks);
  154. return;
  155. }else{
  156. var blocks = Session.get('allBlocks');
  157. blocks.push(block);
  158. Session.set('allBlocks', blocks);
  159. return;
  160. }
  161. }
  162.  
  163. function recreateBlocks(blockArray){
  164. for(var i = 0; i < blockArray.length; i++){
  165. if(blockArray[i].name == "start"){
  166. createStartBlock();
  167. }else if (blockArray[i].name == "end") {
  168. createEndBlock();
  169. }else if (blockArray[i].name == "if") {
  170. createIfBlock();
  171. }else if (blockArray[i].name == "then") {
  172. createThenBlock();
  173. }
  174. }
  175. }
  176.  
  177. function createStartBlock(){
  178. var div = createBuildningBlock("images/startBlock.png");
  179. var textDiv = createTextDiv("start-block");
  180. div.appendChild(textDiv);
  181. document.getElementById("placeBlock").appendChild(div);
  182. div.name = "start";
  183.  
  184. return div;
  185. }
  186.  
  187. function createEndBlock(){
  188. var div = createBuildningBlock("images/endBlock.png");
  189. var textDiv = createTextDiv("end-block");
  190. div.appendChild(textDiv);
  191. document.getElementById("placeBlock").appendChild(div);
  192. div.name = "end";
  193.  
  194. return div;
  195. }
  196.  
  197. //i denna göra innehåll
  198. function createIfBlock(){
  199. var ifDiv = createBuildningBlock("images/ifBlock.png");
  200. var textDiv = createTextDiv("Om");
  201. var dropDownDiv = createDropDownDiv();
  202. //var infoDiv = createInfoDiv(); // info-modal till blocket höger sida /B
  203. ifDiv.appendChild(textDiv);
  204. ifDiv.appendChild(dropDownDiv);
  205. //IfDiv.appendChild(infoDiv); // info-modal till blocket höger sida /B
  206. document.getElementById("placeBlock").appendChild(ifDiv);
  207. ifDiv.name = "if";
  208.  
  209. return ifDiv;
  210. }
  211.  
  212. //i denna göra innehåll
  213. function createThenBlock(){
  214. var thenDiv = createBuildningBlock("images/thenBlock.png");
  215. var textDiv = createTextDiv("så");
  216. var dropDownDiv = createDropDownDiv();
  217. //var infoDiv = createInfoDiv(); // info-modal till blocket höger sida /B
  218. thenDiv.appendChild(textDiv);
  219. thenDiv.appendChild(dropDownDiv);
  220. //thenDiv.appendChild(infoDiv); // info-modal till blocket höger sida /B
  221. document.getElementById("placeBlock").appendChild(thenDiv);
  222. thenDiv.name = "then";
  223.  
  224. return thenDiv;
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement