colorful rat Ratfactor.com > Dave's Repos

hoot

Silly HTML game building engine
git clone http://ratfactor.com/repos/hoot/hoot.git

hoot/js/hoot-builder.js

Download raw file: js/hoot-builder.js

1 /* 2 3 This is the script which runs the hoot.html tool itself. Mostly, it just 4 contains a bunch of click handlers. But if you're not sure how anything is 5 being done, this is the place to start. 6 7 */ 8 9 10 11 var grammar = getGrammar(); 12 13 14 function clickTab(tab, tabContent){ 15 $(".tabContent").hide(); 16 $(".tab").removeClass("selected"); 17 tab.addClass("selected"); 18 tabContent.show(); 19 } 20 21 function parseScript(){ 22 return parser($("#source").val(), grammar); 23 } 24 25 function showError(results, where){ 26 $(where+" .errorhell") 27 .html(getErrorMessage(results, $("#source").val())) 28 .show(); 29 } 30 31 32 function showPrettyStructure(){ 33 34 var results = parseScript(); 35 if(!results.success){ 36 $("#structurearea").html(""); 37 showError(results, "#structure"); 38 return; 39 } 40 41 var display = getPrettyStructure(results.tree); 42 $("#structure .errorhell").hide(); 43 $("#structurearea").html(display); 44 } 45 46 function playGame(){ 47 var results = parseScript(); 48 if(!results.success){ 49 $("#playarea").hide(); 50 showError(results, "#play"); 51 return; 52 } 53 54 // do play here 55 $("#play .errorhell").hide(); 56 $("#playarea").show(); 57 rungame(results.tree, $("#playarea")); 58 } 59 60 function buildGame(){ 61 var results = parseScript(); 62 if(!results.success){ 63 $("#buildarea").hide(); 64 $("#buildtest").hide(); 65 showError(results, "#build"); 66 return; 67 } 68 69 // do build here 70 $("#build .errorhell").hide(); 71 $("#buildarea").show(); 72 $("#buildtest").show(); 73 var orig = JSON.stringify(results.tree); 74 global_compressed_game = hootCompress(orig); 75 $("#buildarea").val("var game=\""+global_compressed_game+"\";"); 76 } 77 78 var global_compressed_game = ""; 79 80 81 82 $(function(){ 83 84 // On startup: 85 86 87 $('#tab_docs').click(function(){ 88 clickTab($(this), $('#docs')); 89 return false; 90 }); 91 92 // structure tab! 93 $('#tab_structure').click(function(){ 94 clickTab($(this), $('#structure')); 95 showPrettyStructure(); 96 return false; 97 }); 98 99 // play tab! 100 $('#tab_play').click(function(){ 101 clickTab($(this), $('#play')); 102 playGame(); 103 return false; 104 }); 105 106 // build tab! 107 $('#tab_build').click(function(){ 108 clickTab($(this), $('#build')); 109 buildGame(); 110 return false; 111 }); 112 113 // build playtest link 114 $("#buildtest").click(function(){ 115 $("#play").show(); 116 $("#play .errorhell").hide(); 117 $("#playarea").show(); 118 rungame(JSON.parse(hootDecompress(global_compressed_game)), $("#playarea")); 119 return false; 120 }); 121 122 // start with docs tab selected 123 $('#tab_docs').click(); 124 125 126 127 $('#generate-script').click(function(){ 128 $('#source').val(generateExampleScript()); 129 return false; 130 }); 131 132 133 134 }); 135