target.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Fri Aug 05 16:11:47 2016
  3. Model author: Joeri Exelmans+Raphael Mannadiar+Simon Van Mierlo
  4. Model name: Bouncing_Balls_JavaScript_Version
  5. Model description:
  6. SVG canvas with bouncing balls in it.*/
  7. // package "Bouncing_Balls_JavaScript_Version"
  8. var Bouncing_Balls_JavaScript_Version = {};
  9. (function() {
  10. var MainApp = function(controller) {
  11. RuntimeClassBase.call(this, controller);
  12. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  13. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  14. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  15. this.semantics.priority = StatechartSemantics.SourceParent;
  16. this.semantics.concurrency = StatechartSemantics.Single;
  17. // build Statechart structure
  18. this.build_statechart_structure();
  19. // call user defined constructor
  20. MainApp.prototype.user_defined_constructor.call(this);
  21. };
  22. MainApp.prototype = new Object();
  23. (function() {
  24. var proto = new RuntimeClassBase();
  25. for (prop in proto) {
  26. MainApp.prototype[prop] = proto[prop];
  27. }
  28. })();
  29. MainApp.prototype.user_defined_constructor = function() {
  30. this.nr_of_fields = 0;
  31. };
  32. MainApp.prototype.user_defined_destructor = function() {
  33. };
  34. // builds Statechart structure
  35. MainApp.prototype.build_statechart_structure = function() {
  36. // state <root>
  37. this.states[""] = new State(0, this);
  38. // state /running
  39. this.states["/running"] = new State(1, this);
  40. // state /running/root
  41. this.states["/running/root"] = new ParallelState(2, this);
  42. // state /running/root/main_behaviour
  43. this.states["/running/root/main_behaviour"] = new State(3, this);
  44. // state /running/root/main_behaviour/initializing
  45. this.states["/running/root/main_behaviour/initializing"] = new State(4, this);
  46. // state /running/root/main_behaviour/running
  47. this.states["/running/root/main_behaviour/running"] = new State(5, this);
  48. // state /running/root/cd_behaviour
  49. this.states["/running/root/cd_behaviour"] = new State(6, this);
  50. // state /running/root/cd_behaviour/waiting
  51. this.states["/running/root/cd_behaviour/waiting"] = new State(7, this);
  52. // state /running/root/cd_behaviour/creating
  53. this.states["/running/root/cd_behaviour/creating"] = new State(8, this);
  54. // state /running/root/cd_behaviour/check_nr_of_fields
  55. this.states["/running/root/cd_behaviour/check_nr_of_fields"] = new State(9, this);
  56. // state /running/stopped
  57. this.states["/running/stopped"] = new State(10, this);
  58. // add children
  59. this.states[""].addChild(this.states["/running"]);
  60. this.states["/running"].addChild(this.states["/running/root"]);
  61. this.states["/running"].addChild(this.states["/running/stopped"]);
  62. this.states["/running/root"].addChild(this.states["/running/root/main_behaviour"]);
  63. this.states["/running/root"].addChild(this.states["/running/root/cd_behaviour"]);
  64. this.states["/running/root/main_behaviour"].addChild(this.states["/running/root/main_behaviour/initializing"]);
  65. this.states["/running/root/main_behaviour"].addChild(this.states["/running/root/main_behaviour/running"]);
  66. this.states["/running/root/cd_behaviour"].addChild(this.states["/running/root/cd_behaviour/waiting"]);
  67. this.states["/running/root/cd_behaviour"].addChild(this.states["/running/root/cd_behaviour/creating"]);
  68. this.states["/running/root/cd_behaviour"].addChild(this.states["/running/root/cd_behaviour/check_nr_of_fields"]);
  69. this.states[""].fixTree();
  70. this.states[""].default_state = this.states["/running"];
  71. this.states["/running"].default_state = this.states["/running/root"];
  72. this.states["/running/root/main_behaviour"].default_state = this.states["/running/root/main_behaviour/initializing"];
  73. this.states["/running/root/cd_behaviour"].default_state = this.states["/running/root/cd_behaviour/waiting"];
  74. // transition /running/root/main_behaviour/initializing
  75. var _running_root_main_behaviour_initializing_0 = new Transition(this, this.states["/running/root/main_behaviour/initializing"], [this.states["/running/root/main_behaviour/running"]]);
  76. _running_root_main_behaviour_initializing_0.setAction(this._running_root_main_behaviour_initializing_0_exec);
  77. _running_root_main_behaviour_initializing_0.setTrigger(null);
  78. this.states["/running/root/main_behaviour/initializing"].addTransition(_running_root_main_behaviour_initializing_0);
  79. // transition /running/root/main_behaviour/running
  80. var _running_root_main_behaviour_running_0 = new Transition(this, this.states["/running/root/main_behaviour/running"], [this.states["/running/root/main_behaviour/running"]]);
  81. _running_root_main_behaviour_running_0.setAction(this._running_root_main_behaviour_running_0_exec);
  82. _running_root_main_behaviour_running_0.setTrigger(new Event("button_pressed", null));
  83. _running_root_main_behaviour_running_0.setGuard(this._running_root_main_behaviour_running_0_guard);
  84. this.states["/running/root/main_behaviour/running"].addTransition(_running_root_main_behaviour_running_0);
  85. // transition /running/root/cd_behaviour/waiting
  86. var _running_root_cd_behaviour_waiting_0 = new Transition(this, this.states["/running/root/cd_behaviour/waiting"], [this.states["/running/root/cd_behaviour/creating"]]);
  87. _running_root_cd_behaviour_waiting_0.setAction(this._running_root_cd_behaviour_waiting_0_exec);
  88. _running_root_cd_behaviour_waiting_0.setTrigger(new Event("create_field", null));
  89. this.states["/running/root/cd_behaviour/waiting"].addTransition(_running_root_cd_behaviour_waiting_0);
  90. var _running_root_cd_behaviour_waiting_1 = new Transition(this, this.states["/running/root/cd_behaviour/waiting"], [this.states["/running/root/cd_behaviour/check_nr_of_fields"]]);
  91. _running_root_cd_behaviour_waiting_1.setAction(this._running_root_cd_behaviour_waiting_1_exec);
  92. _running_root_cd_behaviour_waiting_1.setTrigger(new Event("delete_field", null));
  93. this.states["/running/root/cd_behaviour/waiting"].addTransition(_running_root_cd_behaviour_waiting_1);
  94. // transition /running/root/cd_behaviour/creating
  95. var _running_root_cd_behaviour_creating_0 = new Transition(this, this.states["/running/root/cd_behaviour/creating"], [this.states["/running/root/cd_behaviour/waiting"]]);
  96. _running_root_cd_behaviour_creating_0.setAction(this._running_root_cd_behaviour_creating_0_exec);
  97. _running_root_cd_behaviour_creating_0.setTrigger(new Event("instance_created", null));
  98. this.states["/running/root/cd_behaviour/creating"].addTransition(_running_root_cd_behaviour_creating_0);
  99. // transition /running/root/cd_behaviour/check_nr_of_fields
  100. var _running_root_cd_behaviour_check_nr_of_fields_0 = new Transition(this, this.states["/running/root/cd_behaviour/check_nr_of_fields"], [this.states["/running/stopped"]]);
  101. _running_root_cd_behaviour_check_nr_of_fields_0.setAction(this._running_root_cd_behaviour_check_nr_of_fields_0_exec);
  102. _running_root_cd_behaviour_check_nr_of_fields_0.setTrigger(null);
  103. _running_root_cd_behaviour_check_nr_of_fields_0.setGuard(this._running_root_cd_behaviour_check_nr_of_fields_0_guard);
  104. this.states["/running/root/cd_behaviour/check_nr_of_fields"].addTransition(_running_root_cd_behaviour_check_nr_of_fields_0);
  105. var _running_root_cd_behaviour_check_nr_of_fields_1 = new Transition(this, this.states["/running/root/cd_behaviour/check_nr_of_fields"], [this.states["/running/root/cd_behaviour/waiting"]]);
  106. _running_root_cd_behaviour_check_nr_of_fields_1.setTrigger(null);
  107. _running_root_cd_behaviour_check_nr_of_fields_1.setGuard(this._running_root_cd_behaviour_check_nr_of_fields_1_guard);
  108. this.states["/running/root/cd_behaviour/check_nr_of_fields"].addTransition(_running_root_cd_behaviour_check_nr_of_fields_1);
  109. };
  110. MainApp.prototype._running_root_main_behaviour_initializing_0_exec = function(parameters) {
  111. this.raiseInternalEvent(new Event("create_field", null, new Array()));
  112. };
  113. MainApp.prototype._running_root_main_behaviour_running_0_exec = function(parameters) {
  114. var event_name = parameters[0];
  115. this.raiseInternalEvent(new Event("create_field", null, new Array()));
  116. };
  117. MainApp.prototype._running_root_main_behaviour_running_0_guard = function(parameters) {
  118. var event_name = parameters[0];
  119. return event_name == "create_new_field";
  120. };
  121. MainApp.prototype._running_root_cd_behaviour_waiting_0_exec = function(parameters) {
  122. this.big_step.outputEventOM(new Event("create_instance", null, [this, "fields"]));
  123. };
  124. MainApp.prototype._running_root_cd_behaviour_waiting_1_exec = function(parameters) {
  125. var association_name = parameters[0];
  126. this.big_step.outputEventOM(new Event("delete_instance", null, [this, association_name]));
  127. this.nr_of_fields -= 1
  128. };
  129. MainApp.prototype._running_root_cd_behaviour_creating_0_exec = function(parameters) {
  130. var association_name = parameters[0];
  131. this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name]));
  132. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, association_name, new Event("set_association_name", null, [association_name])]));
  133. this.nr_of_fields += 1
  134. };
  135. MainApp.prototype._running_root_cd_behaviour_check_nr_of_fields_0_exec = function(parameters) {
  136. //NOTE: ideally, this should be ui.close_window(ui.window). we can't do this though
  137. // due to a security measure preventing scripts from closing pages they didn't
  138. // open themselves
  139. ui.println('refresh to play again');
  140. };
  141. MainApp.prototype._running_root_cd_behaviour_check_nr_of_fields_0_guard = function(parameters) {
  142. return this.nr_of_fields == 0;
  143. };
  144. MainApp.prototype._running_root_cd_behaviour_check_nr_of_fields_1_guard = function(parameters) {
  145. return this.nr_of_fields != 0;
  146. };
  147. MainApp.prototype.initializeStatechart = function() {
  148. // enter default state
  149. var states = this.states["/running"].getEffectiveTargetStates();
  150. this.updateConfiguration(states);
  151. for (var state_idx in states) {
  152. if (!states.hasOwnProperty(state_idx)) continue;
  153. var state = states[state_idx]
  154. if (state.enter) {
  155. state.enter();
  156. }
  157. }
  158. };
  159. // add symbol 'MainApp' to package 'Bouncing_Balls_JavaScript_Version'
  160. Bouncing_Balls_JavaScript_Version.MainApp = MainApp;
  161. var Field = function(controller) {
  162. RuntimeClassBase.call(this, controller);
  163. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  164. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  165. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  166. this.semantics.priority = StatechartSemantics.SourceParent;
  167. this.semantics.concurrency = StatechartSemantics.Single;
  168. // build Statechart structure
  169. this.build_statechart_structure();
  170. this.inports["field_ui"] = controller.addInputPort("field_ui", this);
  171. // user defined attributes
  172. this.canvas = null;
  173. this.field_window = null;
  174. // call user defined constructor
  175. Field.prototype.user_defined_constructor.call(this);
  176. };
  177. Field.prototype = new Object();
  178. (function() {
  179. var proto = new RuntimeClassBase();
  180. for (prop in proto) {
  181. Field.prototype[prop] = proto[prop];
  182. }
  183. })();
  184. Field.prototype.user_defined_constructor = function() {
  185. this.field_window = ui.new_window(400,450);
  186. this.canvas = ui.append_canvas(this.field_window,400,400,{'background':'#eee'});
  187. ui.bind_event(this.field_window, ui.EVENTS.WINDOW_CLOSE, this.controller, 'window_close', this.inports['field_ui']);
  188. ui.bind_event(this.field_window, ui.EVENTS.KEY_PRESS, this.controller, 'key_press', this.inports['field_ui']);
  189. ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_RIGHT_CLICK, this.controller, 'right_click', this.inports['field_ui']);
  190. ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_MOVE, this.controller, 'mouse_move');
  191. ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_RELEASE, this.controller, 'mouse_release');
  192. };
  193. Field.prototype.user_defined_destructor = function() {
  194. ui.close_window(this.field_window);
  195. };
  196. // builds Statechart structure
  197. Field.prototype.build_statechart_structure = function() {
  198. // state <root>
  199. this.states[""] = new State(0, this);
  200. // state /root
  201. this.states["/root"] = new State(1, this);
  202. // state /root/waiting
  203. this.states["/root/waiting"] = new State(2, this);
  204. // state /root/initializing
  205. this.states["/root/initializing"] = new State(3, this);
  206. // state /root/creating
  207. this.states["/root/creating"] = new State(4, this);
  208. // state /root/packing
  209. this.states["/root/packing"] = new State(5, this);
  210. // state /root/running
  211. this.states["/root/running"] = new ParallelState(6, this);
  212. // state /root/running/main_behaviour
  213. this.states["/root/running/main_behaviour"] = new State(7, this);
  214. // state /root/running/main_behaviour/running
  215. this.states["/root/running/main_behaviour/running"] = new State(8, this);
  216. // state /root/running/main_behaviour/creating
  217. this.states["/root/running/main_behaviour/creating"] = new State(9, this);
  218. // state /root/running/deleting_behaviour
  219. this.states["/root/running/deleting_behaviour"] = new State(10, this);
  220. // state /root/running/deleting_behaviour/running
  221. this.states["/root/running/deleting_behaviour/running"] = new State(11, this);
  222. // state /root/running/child_behaviour
  223. this.states["/root/running/child_behaviour"] = new State(12, this);
  224. // state /root/running/child_behaviour/listening
  225. this.states["/root/running/child_behaviour/listening"] = new State(13, this);
  226. // state /root/running/deleting_balls_behaviour
  227. this.states["/root/running/deleting_balls_behaviour"] = new State(14, this);
  228. // state /root/running/deleting_balls_behaviour/listening
  229. this.states["/root/running/deleting_balls_behaviour/listening"] = new State(15, this);
  230. // state /root/deleting
  231. this.states["/root/deleting"] = new State(16, this);
  232. // state /root/deleted
  233. this.states["/root/deleted"] = new State(17, this);
  234. // add children
  235. this.states[""].addChild(this.states["/root"]);
  236. this.states["/root"].addChild(this.states["/root/waiting"]);
  237. this.states["/root"].addChild(this.states["/root/initializing"]);
  238. this.states["/root"].addChild(this.states["/root/creating"]);
  239. this.states["/root"].addChild(this.states["/root/packing"]);
  240. this.states["/root"].addChild(this.states["/root/running"]);
  241. this.states["/root"].addChild(this.states["/root/deleting"]);
  242. this.states["/root"].addChild(this.states["/root/deleted"]);
  243. this.states["/root/running"].addChild(this.states["/root/running/main_behaviour"]);
  244. this.states["/root/running"].addChild(this.states["/root/running/deleting_behaviour"]);
  245. this.states["/root/running"].addChild(this.states["/root/running/child_behaviour"]);
  246. this.states["/root/running"].addChild(this.states["/root/running/deleting_balls_behaviour"]);
  247. this.states["/root/running/main_behaviour"].addChild(this.states["/root/running/main_behaviour/running"]);
  248. this.states["/root/running/main_behaviour"].addChild(this.states["/root/running/main_behaviour/creating"]);
  249. this.states["/root/running/deleting_behaviour"].addChild(this.states["/root/running/deleting_behaviour/running"]);
  250. this.states["/root/running/child_behaviour"].addChild(this.states["/root/running/child_behaviour/listening"]);
  251. this.states["/root/running/deleting_balls_behaviour"].addChild(this.states["/root/running/deleting_balls_behaviour/listening"]);
  252. this.states[""].fixTree();
  253. this.states[""].default_state = this.states["/root"];
  254. this.states["/root"].default_state = this.states["/root/waiting"];
  255. this.states["/root/running/main_behaviour"].default_state = this.states["/root/running/main_behaviour/running"];
  256. this.states["/root/running/deleting_behaviour"].default_state = this.states["/root/running/deleting_behaviour/running"];
  257. this.states["/root/running/child_behaviour"].default_state = this.states["/root/running/child_behaviour/listening"];
  258. this.states["/root/running/deleting_balls_behaviour"].default_state = this.states["/root/running/deleting_balls_behaviour/listening"];
  259. // transition /root/waiting
  260. var _root_waiting_0 = new Transition(this, this.states["/root/waiting"], [this.states["/root/initializing"]]);
  261. _root_waiting_0.setAction(this._root_waiting_0_exec);
  262. _root_waiting_0.setTrigger(new Event("set_association_name", null));
  263. this.states["/root/waiting"].addTransition(_root_waiting_0);
  264. // transition /root/initializing
  265. var _root_initializing_0 = new Transition(this, this.states["/root/initializing"], [this.states["/root/creating"]]);
  266. _root_initializing_0.setAction(this._root_initializing_0_exec);
  267. _root_initializing_0.setTrigger(null);
  268. this.states["/root/initializing"].addTransition(_root_initializing_0);
  269. // transition /root/creating
  270. var _root_creating_0 = new Transition(this, this.states["/root/creating"], [this.states["/root/packing"]]);
  271. _root_creating_0.setAction(this._root_creating_0_exec);
  272. _root_creating_0.setTrigger(new Event("instance_created", null));
  273. this.states["/root/creating"].addTransition(_root_creating_0);
  274. // transition /root/packing
  275. var _root_packing_0 = new Transition(this, this.states["/root/packing"], [this.states["/root/running"]]);
  276. _root_packing_0.setTrigger(new Event("button_created", null));
  277. this.states["/root/packing"].addTransition(_root_packing_0);
  278. // transition /root/running/main_behaviour/running
  279. var _root_running_main_behaviour_running_0 = new Transition(this, this.states["/root/running/main_behaviour/running"], [this.states["/root/running/main_behaviour/creating"]]);
  280. _root_running_main_behaviour_running_0.setAction(this._root_running_main_behaviour_running_0_exec);
  281. _root_running_main_behaviour_running_0.setTrigger(new Event("right_click", "field_ui"));
  282. this.states["/root/running/main_behaviour/running"].addTransition(_root_running_main_behaviour_running_0);
  283. // transition /root/running/main_behaviour/creating
  284. var _root_running_main_behaviour_creating_0 = new Transition(this, this.states["/root/running/main_behaviour/creating"], [this.states["/root/running/main_behaviour/running"]]);
  285. _root_running_main_behaviour_creating_0.setAction(this._root_running_main_behaviour_creating_0_exec);
  286. _root_running_main_behaviour_creating_0.setTrigger(new Event("instance_created", null));
  287. this.states["/root/running/main_behaviour/creating"].addTransition(_root_running_main_behaviour_creating_0);
  288. // transition /root/running/deleting_behaviour/running
  289. var _root_running_deleting_behaviour_running_0 = new Transition(this, this.states["/root/running/deleting_behaviour/running"], [this.states["/root/running/deleting_behaviour/running"]]);
  290. _root_running_deleting_behaviour_running_0.setAction(this._root_running_deleting_behaviour_running_0_exec);
  291. _root_running_deleting_behaviour_running_0.setTrigger(new Event("delete_ball", null));
  292. this.states["/root/running/deleting_behaviour/running"].addTransition(_root_running_deleting_behaviour_running_0);
  293. // transition /root/running/child_behaviour/listening
  294. var _root_running_child_behaviour_listening_0 = new Transition(this, this.states["/root/running/child_behaviour/listening"], [this.states["/root/running/child_behaviour/listening"]]);
  295. _root_running_child_behaviour_listening_0.setAction(this._root_running_child_behaviour_listening_0_exec);
  296. _root_running_child_behaviour_listening_0.setTrigger(new Event("button_pressed", null));
  297. this.states["/root/running/child_behaviour/listening"].addTransition(_root_running_child_behaviour_listening_0);
  298. // transition /root/running/deleting_balls_behaviour/listening
  299. var _root_running_deleting_balls_behaviour_listening_0 = new Transition(this, this.states["/root/running/deleting_balls_behaviour/listening"], [this.states["/root/running/deleting_balls_behaviour/listening"]]);
  300. _root_running_deleting_balls_behaviour_listening_0.setAction(this._root_running_deleting_balls_behaviour_listening_0_exec);
  301. _root_running_deleting_balls_behaviour_listening_0.setTrigger(new Event("key_press", "field_ui"));
  302. _root_running_deleting_balls_behaviour_listening_0.setGuard(this._root_running_deleting_balls_behaviour_listening_0_guard);
  303. this.states["/root/running/deleting_balls_behaviour/listening"].addTransition(_root_running_deleting_balls_behaviour_listening_0);
  304. // transition /root/deleting
  305. var _root_deleting_0 = new Transition(this, this.states["/root/deleting"], [this.states["/root/deleted"]]);
  306. _root_deleting_0.setAction(this._root_deleting_0_exec);
  307. _root_deleting_0.setTrigger(null);
  308. this.states["/root/deleting"].addTransition(_root_deleting_0);
  309. // transition /root/running
  310. var _root_running_0 = new Transition(this, this.states["/root/running"], [this.states["/root/deleting"]]);
  311. _root_running_0.setAction(this._root_running_0_exec);
  312. _root_running_0.setTrigger(new Event("window_close", "field_ui"));
  313. this.states["/root/running"].addTransition(_root_running_0);
  314. };
  315. Field.prototype._root_running_0_exec = function(parameters) {
  316. this.big_step.outputEventOM(new Event("delete_instance", null, [this, "buttons"]));
  317. this.big_step.outputEventOM(new Event("delete_instance", null, [this, "balls"]));
  318. };
  319. Field.prototype._root_waiting_0_exec = function(parameters) {
  320. var association_name = parameters[0];
  321. this.association_name = association_name
  322. };
  323. Field.prototype._root_initializing_0_exec = function(parameters) {
  324. this.big_step.outputEventOM(new Event("create_instance", null, [this, "buttons", "Button", this, 'create_new_field', 'Spawn New Window']));
  325. };
  326. Field.prototype._root_creating_0_exec = function(parameters) {
  327. var association_name = parameters[0];
  328. this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name]));
  329. };
  330. Field.prototype._root_running_main_behaviour_running_0_exec = function(parameters) {
  331. var x = parameters[0];
  332. var y = parameters[1];
  333. var button = parameters[2];
  334. this.big_step.outputEventOM(new Event("create_instance", null, [this, "balls", "Ball", this.canvas, x, y]));
  335. };
  336. Field.prototype._root_running_main_behaviour_creating_0_exec = function(parameters) {
  337. var association_name = parameters[0];
  338. this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name]));
  339. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, association_name, new Event("set_association_name", null, [association_name])]));
  340. };
  341. Field.prototype._root_running_deleting_behaviour_running_0_exec = function(parameters) {
  342. var association_name = parameters[0];
  343. this.big_step.outputEventOM(new Event("delete_instance", null, [this, association_name]));
  344. };
  345. Field.prototype._root_running_child_behaviour_listening_0_exec = function(parameters) {
  346. var event_name = parameters[0];
  347. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_pressed", null, [event_name])]));
  348. };
  349. Field.prototype._root_running_deleting_balls_behaviour_listening_0_exec = function(parameters) {
  350. var key = parameters[0];
  351. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'balls', new Event("delete_self", null, new Array())]));
  352. };
  353. Field.prototype._root_running_deleting_balls_behaviour_listening_0_guard = function(parameters) {
  354. var key = parameters[0];
  355. return key == ui.KEYCODES.DELETE;
  356. };
  357. Field.prototype._root_deleting_0_exec = function(parameters) {
  358. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("delete_field", null, [this.association_name])]));
  359. };
  360. Field.prototype.initializeStatechart = function() {
  361. // enter default state
  362. var states = this.states["/root"].getEffectiveTargetStates();
  363. this.updateConfiguration(states);
  364. for (var state_idx in states) {
  365. if (!states.hasOwnProperty(state_idx)) continue;
  366. var state = states[state_idx]
  367. if (state.enter) {
  368. state.enter();
  369. }
  370. }
  371. };
  372. // add symbol 'Field' to package 'Bouncing_Balls_JavaScript_Version'
  373. Bouncing_Balls_JavaScript_Version.Field = Field;
  374. var Button = function(controller, parent, event_name, button_text) {
  375. RuntimeClassBase.call(this, controller);
  376. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  377. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  378. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  379. this.semantics.priority = StatechartSemantics.SourceParent;
  380. this.semantics.concurrency = StatechartSemantics.Single;
  381. // build Statechart structure
  382. this.build_statechart_structure();
  383. this.inports["button_ui"] = controller.addInputPort("button_ui", this);
  384. // call user defined constructor
  385. Button.prototype.user_defined_constructor.call(this, parent, event_name, button_text);
  386. };
  387. Button.prototype = new Object();
  388. (function() {
  389. var proto = new RuntimeClassBase();
  390. for (prop in proto) {
  391. Button.prototype[prop] = proto[prop];
  392. }
  393. })();
  394. Button.prototype.user_defined_constructor = function(parent, event_name, button_text) {
  395. this.event_name = event_name;
  396. var button = ui.append_button(parent.field_window, event_name);
  397. ui.bind_event(button.element, ui.EVENTS.MOUSE_CLICK, this.controller, 'mouse_click', this.inports["button_ui"]);
  398. };
  399. Button.prototype.user_defined_destructor = function() {
  400. };
  401. // builds Statechart structure
  402. Button.prototype.build_statechart_structure = function() {
  403. // state <root>
  404. this.states[""] = new State(0, this);
  405. // state /initializing
  406. this.states["/initializing"] = new State(1, this);
  407. // state /running
  408. this.states["/running"] = new State(2, this);
  409. // add children
  410. this.states[""].addChild(this.states["/initializing"]);
  411. this.states[""].addChild(this.states["/running"]);
  412. this.states[""].fixTree();
  413. this.states[""].default_state = this.states["/initializing"];
  414. // transition /initializing
  415. var _initializing_0 = new Transition(this, this.states["/initializing"], [this.states["/running"]]);
  416. _initializing_0.setAction(this._initializing_0_exec);
  417. _initializing_0.setTrigger(null);
  418. this.states["/initializing"].addTransition(_initializing_0);
  419. // transition /running
  420. var _running_0 = new Transition(this, this.states["/running"], [this.states["/running"]]);
  421. _running_0.setAction(this._running_0_exec);
  422. _running_0.setTrigger(new Event("mouse_click", "button_ui"));
  423. _running_0.setGuard(this._running_0_guard);
  424. this.states["/running"].addTransition(_running_0);
  425. };
  426. Button.prototype._initializing_0_exec = function(parameters) {
  427. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_created", null, new Array())]));
  428. };
  429. Button.prototype._running_0_exec = function(parameters) {
  430. var x = parameters[0];
  431. var y = parameters[1];
  432. var button = parameters[2];
  433. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_pressed", null, [this.event_name])]));
  434. };
  435. Button.prototype._running_0_guard = function(parameters) {
  436. var x = parameters[0];
  437. var y = parameters[1];
  438. var button = parameters[2];
  439. return button == ui.MOUSE_BUTTONS.LEFT;
  440. };
  441. Button.prototype.initializeStatechart = function() {
  442. // enter default state
  443. var states = this.states["/initializing"].getEffectiveTargetStates();
  444. this.updateConfiguration(states);
  445. for (var state_idx in states) {
  446. if (!states.hasOwnProperty(state_idx)) continue;
  447. var state = states[state_idx]
  448. if (state.enter) {
  449. state.enter();
  450. }
  451. }
  452. };
  453. // add symbol 'Button' to package 'Bouncing_Balls_JavaScript_Version'
  454. Bouncing_Balls_JavaScript_Version.Button = Button;
  455. var Ball = function(controller, canvas, x, y) {
  456. RuntimeClassBase.call(this, controller);
  457. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  458. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  459. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  460. this.semantics.priority = StatechartSemantics.SourceParent;
  461. this.semantics.concurrency = StatechartSemantics.Single;
  462. // build Statechart structure
  463. this.build_statechart_structure();
  464. this.inports["ball_ui"] = controller.addInputPort("ball_ui", this);
  465. // user defined attributes
  466. this.canvas = null;
  467. // call user defined constructor
  468. Ball.prototype.user_defined_constructor.call(this, canvas, x, y);
  469. };
  470. Ball.prototype = new Object();
  471. (function() {
  472. var proto = new RuntimeClassBase();
  473. for (prop in proto) {
  474. Ball.prototype[prop] = proto[prop];
  475. }
  476. })();
  477. Ball.prototype.user_defined_constructor = function(canvas, x, y) {
  478. this.canvas = canvas;
  479. this.r = 20.0;
  480. this.vel = {'x': utils.random() * 3.0, 'y': utils.random() * 3.0};
  481. this.mouse_pos = {};
  482. this.smooth = 0.4; // value between 0 and 1
  483. var circle = this.canvas.add_circle(x, y, this.r, {'fill':'#000'});
  484. ui.bind_event(circle, ui.EVENTS.MOUSE_PRESS, this.controller, 'mouse_press', this.inports["ball_ui"]);
  485. this.element = circle;
  486. };
  487. Ball.prototype.user_defined_destructor = function() {
  488. this.canvas.remove_element(this.element);
  489. };
  490. // builds Statechart structure
  491. Ball.prototype.build_statechart_structure = function() {
  492. // state <root>
  493. this.states[""] = new State(0, this);
  494. // state /main_behaviour
  495. this.states["/main_behaviour"] = new State(1, this);
  496. // state /main_behaviour/initializing
  497. this.states["/main_behaviour/initializing"] = new State(2, this);
  498. // state /main_behaviour/bouncing
  499. this.states["/main_behaviour/bouncing"] = new State(3, this);
  500. this.states["/main_behaviour/bouncing"].setEnter(this._main_behaviour_bouncing_enter);
  501. this.states["/main_behaviour/bouncing"].setExit(this._main_behaviour_bouncing_exit);
  502. // state /main_behaviour/dragging
  503. this.states["/main_behaviour/dragging"] = new State(4, this);
  504. // state /main_behaviour/selected
  505. this.states["/main_behaviour/selected"] = new State(5, this);
  506. // state /deleted
  507. this.states["/deleted"] = new State(6, this);
  508. // add children
  509. this.states[""].addChild(this.states["/main_behaviour"]);
  510. this.states[""].addChild(this.states["/deleted"]);
  511. this.states["/main_behaviour"].addChild(this.states["/main_behaviour/initializing"]);
  512. this.states["/main_behaviour"].addChild(this.states["/main_behaviour/bouncing"]);
  513. this.states["/main_behaviour"].addChild(this.states["/main_behaviour/dragging"]);
  514. this.states["/main_behaviour"].addChild(this.states["/main_behaviour/selected"]);
  515. this.states[""].fixTree();
  516. this.states[""].default_state = this.states["/main_behaviour"];
  517. this.states["/main_behaviour"].default_state = this.states["/main_behaviour/initializing"];
  518. // transition /main_behaviour/initializing
  519. var _main_behaviour_initializing_0 = new Transition(this, this.states["/main_behaviour/initializing"], [this.states["/main_behaviour/bouncing"]]);
  520. _main_behaviour_initializing_0.setAction(this._main_behaviour_initializing_0_exec);
  521. _main_behaviour_initializing_0.setTrigger(new Event("set_association_name", null));
  522. this.states["/main_behaviour/initializing"].addTransition(_main_behaviour_initializing_0);
  523. // transition /main_behaviour/bouncing
  524. var _main_behaviour_bouncing_0 = new Transition(this, this.states["/main_behaviour/bouncing"], [this.states["/main_behaviour/bouncing"]]);
  525. _main_behaviour_bouncing_0.setAction(this._main_behaviour_bouncing_0_exec);
  526. _main_behaviour_bouncing_0.setTrigger(new Event("_0after"));
  527. this.states["/main_behaviour/bouncing"].addTransition(_main_behaviour_bouncing_0);
  528. var _main_behaviour_bouncing_1 = new Transition(this, this.states["/main_behaviour/bouncing"], [this.states["/main_behaviour/selected"]]);
  529. _main_behaviour_bouncing_1.setAction(this._main_behaviour_bouncing_1_exec);
  530. _main_behaviour_bouncing_1.setTrigger(new Event("mouse_press", "ball_ui"));
  531. _main_behaviour_bouncing_1.setGuard(this._main_behaviour_bouncing_1_guard);
  532. this.states["/main_behaviour/bouncing"].addTransition(_main_behaviour_bouncing_1);
  533. // transition /main_behaviour/dragging
  534. var _main_behaviour_dragging_0 = new Transition(this, this.states["/main_behaviour/dragging"], [this.states["/main_behaviour/dragging"]]);
  535. _main_behaviour_dragging_0.setAction(this._main_behaviour_dragging_0_exec);
  536. _main_behaviour_dragging_0.setTrigger(new Event("mouse_move", "ui"));
  537. this.states["/main_behaviour/dragging"].addTransition(_main_behaviour_dragging_0);
  538. var _main_behaviour_dragging_1 = new Transition(this, this.states["/main_behaviour/dragging"], [this.states["/main_behaviour/bouncing"]]);
  539. _main_behaviour_dragging_1.setAction(this._main_behaviour_dragging_1_exec);
  540. _main_behaviour_dragging_1.setTrigger(new Event("mouse_release", "ui"));
  541. this.states["/main_behaviour/dragging"].addTransition(_main_behaviour_dragging_1);
  542. // transition /main_behaviour/selected
  543. var _main_behaviour_selected_0 = new Transition(this, this.states["/main_behaviour/selected"], [this.states["/main_behaviour/dragging"]]);
  544. _main_behaviour_selected_0.setAction(this._main_behaviour_selected_0_exec);
  545. _main_behaviour_selected_0.setTrigger(new Event("mouse_press", "ball_ui"));
  546. _main_behaviour_selected_0.setGuard(this._main_behaviour_selected_0_guard);
  547. this.states["/main_behaviour/selected"].addTransition(_main_behaviour_selected_0);
  548. var _main_behaviour_selected_1 = new Transition(this, this.states["/main_behaviour/selected"], [this.states["/deleted"]]);
  549. _main_behaviour_selected_1.setAction(this._main_behaviour_selected_1_exec);
  550. _main_behaviour_selected_1.setTrigger(new Event("delete_self", null));
  551. this.states["/main_behaviour/selected"].addTransition(_main_behaviour_selected_1);
  552. };
  553. Ball.prototype._main_behaviour_bouncing_enter = function() {
  554. this.addTimer(0, 0.05);
  555. };
  556. Ball.prototype._main_behaviour_bouncing_exit = function() {
  557. this.removeTimer(0);
  558. };
  559. Ball.prototype._main_behaviour_initializing_0_exec = function(parameters) {
  560. var association_name = parameters[0];
  561. this.association_name = association_name;
  562. };
  563. Ball.prototype._main_behaviour_bouncing_0_exec = function(parameters) {
  564. var pos = this.element.get_position();
  565. if (pos.x-this.r <= 0 || pos.x+this.r >= this.canvas.width)
  566. this.vel.x = -this.vel.x;
  567. if (pos.y-this.r <= 0 || pos.y+this.r >= this.canvas.height)
  568. this.vel.y = -this.vel.y;
  569. this.element.move(this.vel.x, this.vel.y);
  570. };
  571. Ball.prototype._main_behaviour_bouncing_1_exec = function(parameters) {
  572. var x = parameters[0];
  573. var y = parameters[1];
  574. var button = parameters[2];
  575. this.element.set_color("#ff0");
  576. };
  577. Ball.prototype._main_behaviour_bouncing_1_guard = function(parameters) {
  578. var x = parameters[0];
  579. var y = parameters[1];
  580. var button = parameters[2];
  581. return button == ui.MOUSE_BUTTONS.LEFT;
  582. };
  583. Ball.prototype._main_behaviour_dragging_0_exec = function(parameters) {
  584. var x = parameters[0];
  585. var y = parameters[1];
  586. var button = parameters[2];
  587. var dx = x - this.mouse_pos.x;
  588. var dy = y - this.mouse_pos.y;
  589. this.element.move(dx, dy);
  590. // keep ball within boundaries
  591. var pos = this.element.get_position();
  592. if (pos.x-this.r <= 0)
  593. pos.x = this.r + 1;
  594. else if (pos.x+this.r >= this.canvas.width)
  595. pos.x = this.canvas.width-this.r-1;
  596. if (pos.y-this.r <= 0)
  597. pos.y = this.r + 1;
  598. else if (pos.y+this.r >= this.canvas.height)
  599. pos.y = this.canvas.height-this.r-1;
  600. this.element.set_position(pos.x, pos.y);
  601. this.mouse_pos = {'x':x, 'y':y};
  602. this.vel = {
  603. 'x': (1-this.smooth)*dx + this.smooth*this.vel.x,
  604. 'y': (1-this.smooth)*dy + this.smooth*this.vel.y
  605. };
  606. };
  607. Ball.prototype._main_behaviour_dragging_1_exec = function(parameters) {
  608. var x = parameters[0];
  609. var y = parameters[1];
  610. this.element.set_color("#f00");
  611. };
  612. Ball.prototype._main_behaviour_selected_0_exec = function(parameters) {
  613. var x = parameters[0];
  614. var y = parameters[1];
  615. var button = parameters[2];
  616. this.mouse_pos = {'x':x, 'y':y};
  617. };
  618. Ball.prototype._main_behaviour_selected_0_guard = function(parameters) {
  619. var x = parameters[0];
  620. var y = parameters[1];
  621. var button = parameters[2];
  622. return button == ui.MOUSE_BUTTONS.LEFT;
  623. };
  624. Ball.prototype._main_behaviour_selected_1_exec = function(parameters) {
  625. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("delete_ball", null, [this.association_name])]));
  626. };
  627. Ball.prototype.initializeStatechart = function() {
  628. // enter default state
  629. var states = this.states["/main_behaviour"].getEffectiveTargetStates();
  630. this.updateConfiguration(states);
  631. for (var state_idx in states) {
  632. if (!states.hasOwnProperty(state_idx)) continue;
  633. var state = states[state_idx]
  634. if (state.enter) {
  635. state.enter();
  636. }
  637. }
  638. };
  639. // add symbol 'Ball' to package 'Bouncing_Balls_JavaScript_Version'
  640. Bouncing_Balls_JavaScript_Version.Ball = Ball;
  641. var ObjectManager = function(controller) {
  642. ObjectManagerBase.call(this, controller);
  643. };
  644. ObjectManager.prototype = new Object();
  645. (function() {
  646. var proto = new ObjectManagerBase();
  647. for (prop in proto) {
  648. ObjectManager.prototype[prop] = proto[prop];
  649. }
  650. })();
  651. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  652. if (class_name === "MainApp") {
  653. var instance = new MainApp(this.controller);
  654. instance.associations = new Object();
  655. instance.associations["fields"] = new Association("Field", 0, -1);
  656. } else if (class_name === "Field") {
  657. var instance = new Field(this.controller);
  658. instance.associations = new Object();
  659. instance.associations["balls"] = new Association("Ball", 0, -1);
  660. instance.associations["buttons"] = new Association("Button", 0, -1);
  661. instance.associations["parent"] = new Association("MainApp", 1, 1);
  662. } else if (class_name === "Button") {
  663. var instance = new Button(this.controller, construct_params[0], construct_params[1], construct_params[2]);
  664. instance.associations = new Object();
  665. instance.associations["parent"] = new Association("Field", 1, 1);
  666. } else if (class_name === "Ball") {
  667. var instance = new Ball(this.controller, construct_params[0], construct_params[1], construct_params[2]);
  668. instance.associations = new Object();
  669. instance.associations["parent"] = new Association("Field", 1, 1);
  670. } else {
  671. throw new Error("Cannot instantiate class " + class_name);
  672. }
  673. return instance;
  674. };
  675. // add symbol 'ObjectManager' to package 'Bouncing_Balls_JavaScript_Version'
  676. Bouncing_Balls_JavaScript_Version.ObjectManager = ObjectManager;
  677. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  678. if (finished_callback === undefined) finished_callback = null;
  679. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  680. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  681. this.addInputPort("ui");
  682. this.object_manager.createInstance("MainApp", new Array());
  683. };
  684. Controller.prototype = new Object();
  685. (function() {
  686. var proto = new EventLoopControllerBase();
  687. for (prop in proto) {
  688. Controller.prototype[prop] = proto[prop];
  689. }
  690. })();
  691. // add symbol 'Controller' to package 'Bouncing_Balls_JavaScript_Version'
  692. Bouncing_Balls_JavaScript_Version.Controller = Controller;
  693. })();