bouncing_balls.js 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743
  1. /* Generated by Statechart compiler by Glenn De Jonghe and Joeri Exelmans
  2. Date: Tue Feb 16 09:43:52 2016
  3. Model author: Simon Van Mierlo+Joeri Exelmans+Raphael Mannadiar
  4. Model name: Bouncing_Balls
  5. Model description:
  6. Tkinter frame with bouncing balls in it.*/
  7. // package "Bouncing_Balls"
  8. var Bouncing_Balls = {};
  9. (function() {
  10. var Button = function(controller, parent, event_name, button_text) {
  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. // Call user defined constructor
  18. Button.prototype.user_defined_constructor.call(this, parent, event_name, button_text);
  19. };
  20. Button.prototype = new Object();
  21. (function() {
  22. var proto = new RuntimeClassBase();
  23. for (prop in proto) {
  24. Button.prototype[prop] = proto[prop];
  25. }
  26. })();
  27. Button.prototype.user_defined_constructor = function(parent, event_name, button_text) {
  28. this.event_name = event_name;
  29. var button = ui.append_button(parent.field_window, event_name);
  30. ui.bind_event(button.element, ui.EVENTS.MOUSE_CLICK, this.controller, 'mouse_click');
  31. };
  32. Button.prototype.user_defined_destructor = function() {
  33. };
  34. Button.prototype.initializeStatechart = function() {
  35. this.current_state[this.Root] = new Array();
  36. // Enter default state
  37. this.enter_Root_initializing();
  38. };
  39. // Unique IDs for all statechart nodes
  40. Button.prototype.Root = 0;
  41. Button.prototype.Root_initializing = 1;
  42. Button.prototype.Root_running = 2;
  43. // Statechart enter/exit action method(s)
  44. Button.prototype.enter_Root_initializing = function() {
  45. this.current_state[this.Root].push(this.Root_initializing);
  46. };
  47. Button.prototype.exit_Root_initializing = function() {
  48. this.current_state[this.Root] = new Array();
  49. };
  50. Button.prototype.enter_Root_running = function() {
  51. this.current_state[this.Root].push(this.Root_running);
  52. };
  53. Button.prototype.exit_Root_running = function() {
  54. this.current_state[this.Root] = new Array();
  55. };
  56. // Statechart transitions
  57. Button.prototype.generateCandidatesChildren_Root = function() {
  58. if (this.current_state[this.Root][0] === this.Root_initializing) {
  59. return this.generateCandidates_Root_initializing();
  60. } else if (this.current_state[this.Root][0] === this.Root_running) {
  61. return this.generateCandidates_Root_running();
  62. }
  63. return false;
  64. };
  65. Button.prototype.generateCandidates_Root = function() {
  66. if (!this.combo_step.isArenaChanged(this.Root)) {
  67. return this.generateCandidatesChildren_Root();
  68. } else {
  69. return true;
  70. }
  71. };
  72. Button.prototype.generateCandidatesCurrent_Root_initializing = function() {
  73. var enabled_events = this.getEnabledEvents();
  74. this.small_step.addCandidate(this.transition_Root_initializing_1, new Array());
  75. return true;
  76. return false;
  77. };
  78. Button.prototype.generateCandidates_Root_initializing = function() {
  79. if (!this.combo_step.isArenaChanged(this.Root_initializing)) {
  80. return this.generateCandidatesCurrent_Root_initializing();
  81. } else {
  82. return true;
  83. }
  84. };
  85. Button.prototype.transition_Root_initializing_1 = function(parameters) {
  86. this.exit_Root_initializing();
  87. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_created", null, new Array())]));
  88. this.combo_step.setArenaChanged(this.Root);
  89. this.enter_Root_running();
  90. };
  91. Button.prototype.generateCandidatesCurrent_Root_running = function() {
  92. var enabled_events = this.getEnabledEvents();
  93. for (var e in enabled_events) {
  94. if (!enabled_events.hasOwnProperty(e)) continue;
  95. if ((enabled_events[e].name === "mouse_click") && (enabled_events[e].port === "ui")) {
  96. var parameters = enabled_events[e].parameters;
  97. var x = parameters[0];
  98. var y = parameters[1];
  99. var button = parameters[2];
  100. if (button == ui.MOUSE_BUTTONS.LEFT) {
  101. this.small_step.addCandidate(this.transition_Root_running_1, enabled_events[e].parameters);
  102. return true;
  103. }
  104. }
  105. }
  106. return false;
  107. };
  108. Button.prototype.generateCandidates_Root_running = function() {
  109. if (!this.combo_step.isArenaChanged(this.Root_running)) {
  110. return this.generateCandidatesCurrent_Root_running();
  111. } else {
  112. return true;
  113. }
  114. };
  115. Button.prototype.transition_Root_running_1 = function(parameters) {
  116. var x = parameters[0];
  117. var y = parameters[1];
  118. var button = parameters[2];
  119. this.exit_Root_running();
  120. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_pressed", null, [this.event_name])]));
  121. this.combo_step.setArenaChanged(this.Root);
  122. this.enter_Root_running();
  123. };
  124. // Generate transition candidates for current small step
  125. // Generate transition candidates for current small step
  126. Button.prototype.generateCandidates = function() {
  127. this.generateCandidates_Root();
  128. };
  129. // add symbol 'Button' to package 'Bouncing_Balls'
  130. Bouncing_Balls.Button = Button;
  131. var Field = function(controller) {
  132. RuntimeClassBase.call(this, controller);
  133. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  134. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  135. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  136. this.semantics.priority = StatechartSemantics.SourceParent;
  137. this.semantics.concurrency = StatechartSemantics.Single;
  138. this.inports["field_ui"] = controller.addInputPort("field_ui", this);
  139. // User defined attributes
  140. this.field_window = null;
  141. this.canvas = null;
  142. // Call user defined constructor
  143. Field.prototype.user_defined_constructor.call(this);
  144. };
  145. Field.prototype = new Object();
  146. (function() {
  147. var proto = new RuntimeClassBase();
  148. for (prop in proto) {
  149. Field.prototype[prop] = proto[prop];
  150. }
  151. })();
  152. Field.prototype.user_defined_constructor = function() {
  153. this.field_window = ui.new_window(400, 450);
  154. this.canvas = ui.append_canvas(this.field_window, 400, 400, {'background':'#eee'});
  155. ui.bind_event(this.field_window, ui.EVENTS.WINDOW_CLOSE, this.controller, 'window_close');
  156. ui.bind_event(this.field_window, ui.EVENTS.KEY_PRESS, this.controller, 'key_press');
  157. ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_RIGHT_CLICK, this.controller, 'right_click', this.inports['field_ui']);
  158. ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_MOVE, this.controller, 'mouse_move');
  159. ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_RELEASE, this.controller, 'mouse_release');
  160. };
  161. Field.prototype.user_defined_destructor = function() {
  162. ui.close_window(this.field_window);
  163. };
  164. Field.prototype.initializeStatechart = function() {
  165. this.current_state[this.Root] = new Array();
  166. this.current_state[this.Root_root] = new Array();
  167. this.current_state[this.Root_root_running] = new Array();
  168. this.current_state[this.Root_root_running_main_behaviour] = new Array();
  169. this.current_state[this.Root_root_running_deleting_behaviour] = new Array();
  170. this.current_state[this.Root_root_running_child_behaviour] = new Array();
  171. // Enter default state
  172. this.enterDefault_Root_root();
  173. };
  174. // Unique IDs for all statechart nodes
  175. Field.prototype.Root = 0;
  176. Field.prototype.Root_root = 1;
  177. Field.prototype.Root_root_running = 2;
  178. Field.prototype.Root_root_running_main_behaviour = 3;
  179. Field.prototype.Root_root_running_deleting_behaviour = 4;
  180. Field.prototype.Root_root_running_child_behaviour = 5;
  181. Field.prototype.Root_root_waiting = 6;
  182. Field.prototype.Root_root_packing = 7;
  183. Field.prototype.Root_root_deleting = 8;
  184. Field.prototype.Root_root_creating = 9;
  185. Field.prototype.Root_root_initializing = 10;
  186. Field.prototype.Root_root_deleted = 11;
  187. Field.prototype.Root_root_running_main_behaviour_running = 12;
  188. Field.prototype.Root_root_running_main_behaviour_creating = 13;
  189. Field.prototype.Root_root_running_deleting_behaviour_running = 14;
  190. Field.prototype.Root_root_running_child_behaviour_listening = 15;
  191. // Statechart enter/exit action method(s)
  192. Field.prototype.enter_Root_root = function() {
  193. this.current_state[this.Root].push(this.Root_root);
  194. };
  195. Field.prototype.exit_Root_root = function() {
  196. if ((this.current_state[this.Root_root].indexOf(this.Root_root_waiting) !== -1)) {
  197. this.exit_Root_root_waiting();
  198. }
  199. if ((this.current_state[this.Root_root].indexOf(this.Root_root_packing) !== -1)) {
  200. this.exit_Root_root_packing();
  201. }
  202. if ((this.current_state[this.Root_root].indexOf(this.Root_root_deleting) !== -1)) {
  203. this.exit_Root_root_deleting();
  204. }
  205. if ((this.current_state[this.Root_root].indexOf(this.Root_root_creating) !== -1)) {
  206. this.exit_Root_root_creating();
  207. }
  208. if ((this.current_state[this.Root_root].indexOf(this.Root_root_initializing) !== -1)) {
  209. this.exit_Root_root_initializing();
  210. }
  211. if ((this.current_state[this.Root_root].indexOf(this.Root_root_deleted) !== -1)) {
  212. this.exit_Root_root_deleted();
  213. }
  214. if ((this.current_state[this.Root_root].indexOf(this.Root_root_running) !== -1)) {
  215. this.exit_Root_root_running();
  216. }
  217. this.current_state[this.Root] = new Array();
  218. };
  219. Field.prototype.enter_Root_root_running = function() {
  220. this.current_state[this.Root_root].push(this.Root_root_running);
  221. };
  222. Field.prototype.exit_Root_root_running = function() {
  223. this.exit_Root_root_running_main_behaviour();
  224. this.exit_Root_root_running_deleting_behaviour();
  225. this.exit_Root_root_running_child_behaviour();
  226. this.current_state[this.Root_root] = new Array();
  227. };
  228. Field.prototype.enter_Root_root_running_main_behaviour = function() {
  229. this.current_state[this.Root_root_running].push(this.Root_root_running_main_behaviour);
  230. };
  231. Field.prototype.exit_Root_root_running_main_behaviour = function() {
  232. if ((this.current_state[this.Root_root_running_main_behaviour].indexOf(this.Root_root_running_main_behaviour_running) !== -1)) {
  233. this.exit_Root_root_running_main_behaviour_running();
  234. }
  235. if ((this.current_state[this.Root_root_running_main_behaviour].indexOf(this.Root_root_running_main_behaviour_creating) !== -1)) {
  236. this.exit_Root_root_running_main_behaviour_creating();
  237. }
  238. this.current_state[this.Root_root_running] = new Array();
  239. };
  240. Field.prototype.enter_Root_root_running_deleting_behaviour = function() {
  241. this.current_state[this.Root_root_running].push(this.Root_root_running_deleting_behaviour);
  242. };
  243. Field.prototype.exit_Root_root_running_deleting_behaviour = function() {
  244. if ((this.current_state[this.Root_root_running_deleting_behaviour].indexOf(this.Root_root_running_deleting_behaviour_running) !== -1)) {
  245. this.exit_Root_root_running_deleting_behaviour_running();
  246. }
  247. this.current_state[this.Root_root_running] = new Array();
  248. };
  249. Field.prototype.enter_Root_root_running_child_behaviour = function() {
  250. this.current_state[this.Root_root_running].push(this.Root_root_running_child_behaviour);
  251. };
  252. Field.prototype.exit_Root_root_running_child_behaviour = function() {
  253. if ((this.current_state[this.Root_root_running_child_behaviour].indexOf(this.Root_root_running_child_behaviour_listening) !== -1)) {
  254. this.exit_Root_root_running_child_behaviour_listening();
  255. }
  256. this.current_state[this.Root_root_running] = new Array();
  257. };
  258. Field.prototype.enter_Root_root_waiting = function() {
  259. this.current_state[this.Root_root].push(this.Root_root_waiting);
  260. };
  261. Field.prototype.exit_Root_root_waiting = function() {
  262. this.current_state[this.Root_root] = new Array();
  263. };
  264. Field.prototype.enter_Root_root_packing = function() {
  265. this.current_state[this.Root_root].push(this.Root_root_packing);
  266. };
  267. Field.prototype.exit_Root_root_packing = function() {
  268. this.current_state[this.Root_root] = new Array();
  269. };
  270. Field.prototype.enter_Root_root_deleting = function() {
  271. this.timers[0] = 0.05;
  272. this.current_state[this.Root_root].push(this.Root_root_deleting);
  273. };
  274. Field.prototype.exit_Root_root_deleting = function() {
  275. delete this.timers[0];
  276. this.current_state[this.Root_root] = new Array();
  277. };
  278. Field.prototype.enter_Root_root_creating = function() {
  279. this.current_state[this.Root_root].push(this.Root_root_creating);
  280. };
  281. Field.prototype.exit_Root_root_creating = function() {
  282. this.current_state[this.Root_root] = new Array();
  283. };
  284. Field.prototype.enter_Root_root_initializing = function() {
  285. this.current_state[this.Root_root].push(this.Root_root_initializing);
  286. };
  287. Field.prototype.exit_Root_root_initializing = function() {
  288. this.current_state[this.Root_root] = new Array();
  289. };
  290. Field.prototype.enter_Root_root_deleted = function() {
  291. this.current_state[this.Root_root].push(this.Root_root_deleted);
  292. };
  293. Field.prototype.exit_Root_root_deleted = function() {
  294. this.current_state[this.Root_root] = new Array();
  295. };
  296. Field.prototype.enter_Root_root_running_main_behaviour_running = function() {
  297. this.current_state[this.Root_root_running_main_behaviour].push(this.Root_root_running_main_behaviour_running);
  298. };
  299. Field.prototype.exit_Root_root_running_main_behaviour_running = function() {
  300. this.current_state[this.Root_root_running_main_behaviour] = new Array();
  301. };
  302. Field.prototype.enter_Root_root_running_main_behaviour_creating = function() {
  303. this.current_state[this.Root_root_running_main_behaviour].push(this.Root_root_running_main_behaviour_creating);
  304. };
  305. Field.prototype.exit_Root_root_running_main_behaviour_creating = function() {
  306. this.current_state[this.Root_root_running_main_behaviour] = new Array();
  307. };
  308. Field.prototype.enter_Root_root_running_deleting_behaviour_running = function() {
  309. this.current_state[this.Root_root_running_deleting_behaviour].push(this.Root_root_running_deleting_behaviour_running);
  310. };
  311. Field.prototype.exit_Root_root_running_deleting_behaviour_running = function() {
  312. this.current_state[this.Root_root_running_deleting_behaviour] = new Array();
  313. };
  314. Field.prototype.enter_Root_root_running_child_behaviour_listening = function() {
  315. this.current_state[this.Root_root_running_child_behaviour].push(this.Root_root_running_child_behaviour_listening);
  316. };
  317. Field.prototype.exit_Root_root_running_child_behaviour_listening = function() {
  318. this.current_state[this.Root_root_running_child_behaviour] = new Array();
  319. };
  320. // Statechart enter/exit default method(s)
  321. Field.prototype.enterDefault_Root_root = function() {
  322. this.enter_Root_root();
  323. this.enter_Root_root_waiting();
  324. };
  325. Field.prototype.enterDefault_Root_root_running = function() {
  326. this.enter_Root_root_running();
  327. this.enterDefault_Root_root_running_main_behaviour();
  328. this.enterDefault_Root_root_running_deleting_behaviour();
  329. this.enterDefault_Root_root_running_child_behaviour();
  330. };
  331. Field.prototype.enterDefault_Root_root_running_main_behaviour = function() {
  332. this.enter_Root_root_running_main_behaviour();
  333. this.enter_Root_root_running_main_behaviour_running();
  334. };
  335. Field.prototype.enterDefault_Root_root_running_deleting_behaviour = function() {
  336. this.enter_Root_root_running_deleting_behaviour();
  337. this.enter_Root_root_running_deleting_behaviour_running();
  338. };
  339. Field.prototype.enterDefault_Root_root_running_child_behaviour = function() {
  340. this.enter_Root_root_running_child_behaviour();
  341. this.enter_Root_root_running_child_behaviour_listening();
  342. };
  343. // Statechart transitions
  344. Field.prototype.generateCandidatesChildren_Root = function() {
  345. if (this.current_state[this.Root][0] === this.Root_root) {
  346. return this.generateCandidates_Root_root();
  347. }
  348. return false;
  349. };
  350. Field.prototype.generateCandidates_Root = function() {
  351. if (!this.combo_step.isArenaChanged(this.Root)) {
  352. return this.generateCandidatesChildren_Root();
  353. } else {
  354. return true;
  355. }
  356. };
  357. Field.prototype.generateCandidatesChildren_Root_root = function() {
  358. if (this.current_state[this.Root_root][0] === this.Root_root_waiting) {
  359. return this.generateCandidates_Root_root_waiting();
  360. } else if (this.current_state[this.Root_root][0] === this.Root_root_packing) {
  361. return this.generateCandidates_Root_root_packing();
  362. } else if (this.current_state[this.Root_root][0] === this.Root_root_deleting) {
  363. return this.generateCandidates_Root_root_deleting();
  364. } else if (this.current_state[this.Root_root][0] === this.Root_root_creating) {
  365. return this.generateCandidates_Root_root_creating();
  366. } else if (this.current_state[this.Root_root][0] === this.Root_root_initializing) {
  367. return this.generateCandidates_Root_root_initializing();
  368. } else if (this.current_state[this.Root_root][0] === this.Root_root_deleted) {
  369. return this.generateCandidates_Root_root_deleted();
  370. } else if (this.current_state[this.Root_root][0] === this.Root_root_running) {
  371. return this.generateCandidates_Root_root_running();
  372. }
  373. return false;
  374. };
  375. Field.prototype.generateCandidates_Root_root = function() {
  376. if (!this.combo_step.isArenaChanged(this.Root_root)) {
  377. return this.generateCandidatesChildren_Root_root();
  378. } else {
  379. return true;
  380. }
  381. };
  382. Field.prototype.generateCandidatesCurrent_Root_root_waiting = function() {
  383. var enabled_events = this.getEnabledEvents();
  384. for (var e in enabled_events) {
  385. if (!enabled_events.hasOwnProperty(e)) continue;
  386. if (enabled_events[e].name === "set_association_name") {
  387. this.small_step.addCandidate(this.transition_Root_root_waiting_1, enabled_events[e].parameters);
  388. return true;
  389. }
  390. }
  391. return false;
  392. };
  393. Field.prototype.generateCandidates_Root_root_waiting = function() {
  394. if (!this.combo_step.isArenaChanged(this.Root_root_waiting)) {
  395. return this.generateCandidatesCurrent_Root_root_waiting();
  396. } else {
  397. return true;
  398. }
  399. };
  400. Field.prototype.transition_Root_root_waiting_1 = function(parameters) {
  401. var association_name = parameters[0];
  402. this.exit_Root_root_waiting();
  403. this.association_name = association_name;
  404. this.combo_step.setArenaChanged(this.Root_root);
  405. this.enter_Root_root_initializing();
  406. };
  407. Field.prototype.generateCandidatesCurrent_Root_root_packing = function() {
  408. var enabled_events = this.getEnabledEvents();
  409. for (var e in enabled_events) {
  410. if (!enabled_events.hasOwnProperty(e)) continue;
  411. if (enabled_events[e].name === "button_created") {
  412. this.small_step.addCandidate(this.transition_Root_root_packing_1, enabled_events[e].parameters);
  413. return true;
  414. }
  415. }
  416. return false;
  417. };
  418. Field.prototype.generateCandidates_Root_root_packing = function() {
  419. if (!this.combo_step.isArenaChanged(this.Root_root_packing)) {
  420. return this.generateCandidatesCurrent_Root_root_packing();
  421. } else {
  422. return true;
  423. }
  424. };
  425. Field.prototype.transition_Root_root_packing_1 = function(parameters) {
  426. this.exit_Root_root_packing();
  427. this.combo_step.setArenaChanged(this.Root_root);
  428. this.enterDefault_Root_root_running();
  429. };
  430. Field.prototype.generateCandidatesCurrent_Root_root_deleting = function() {
  431. var enabled_events = this.getEnabledEvents();
  432. for (var e in enabled_events) {
  433. if (!enabled_events.hasOwnProperty(e)) continue;
  434. if (enabled_events[e].name === "_0after") {
  435. this.small_step.addCandidate(this.transition_Root_root_deleting_1, enabled_events[e].parameters);
  436. return true;
  437. }
  438. }
  439. return false;
  440. };
  441. Field.prototype.generateCandidates_Root_root_deleting = function() {
  442. if (!this.combo_step.isArenaChanged(this.Root_root_deleting)) {
  443. return this.generateCandidatesCurrent_Root_root_deleting();
  444. } else {
  445. return true;
  446. }
  447. };
  448. Field.prototype.transition_Root_root_deleting_1 = function(parameters) {
  449. this.exit_Root_root_deleting();
  450. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("delete_field", null, [this.association_name])]));
  451. this.combo_step.setArenaChanged(this.Root_root);
  452. this.enter_Root_root_deleted();
  453. };
  454. Field.prototype.generateCandidatesCurrent_Root_root_creating = function() {
  455. var enabled_events = this.getEnabledEvents();
  456. for (var e in enabled_events) {
  457. if (!enabled_events.hasOwnProperty(e)) continue;
  458. if (enabled_events[e].name === "instance_created") {
  459. this.small_step.addCandidate(this.transition_Root_root_creating_1, enabled_events[e].parameters);
  460. return true;
  461. }
  462. }
  463. return false;
  464. };
  465. Field.prototype.generateCandidates_Root_root_creating = function() {
  466. if (!this.combo_step.isArenaChanged(this.Root_root_creating)) {
  467. return this.generateCandidatesCurrent_Root_root_creating();
  468. } else {
  469. return true;
  470. }
  471. };
  472. Field.prototype.transition_Root_root_creating_1 = function(parameters) {
  473. var association_name = parameters[0];
  474. this.exit_Root_root_creating();
  475. this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name]));
  476. this.combo_step.setArenaChanged(this.Root_root);
  477. this.enter_Root_root_packing();
  478. };
  479. Field.prototype.generateCandidatesCurrent_Root_root_initializing = function() {
  480. var enabled_events = this.getEnabledEvents();
  481. this.small_step.addCandidate(this.transition_Root_root_initializing_1, new Array());
  482. return true;
  483. return false;
  484. };
  485. Field.prototype.generateCandidates_Root_root_initializing = function() {
  486. if (!this.combo_step.isArenaChanged(this.Root_root_initializing)) {
  487. return this.generateCandidatesCurrent_Root_root_initializing();
  488. } else {
  489. return true;
  490. }
  491. };
  492. Field.prototype.transition_Root_root_initializing_1 = function(parameters) {
  493. this.exit_Root_root_initializing();
  494. this.big_step.outputEventOM(new Event("create_instance", null, [this, 'buttons', 'Button', this, 'create_new_field', 'Spawn New Window']));
  495. this.combo_step.setArenaChanged(this.Root_root);
  496. this.enter_Root_root_creating();
  497. };
  498. Field.prototype.generateCandidates_Root_root_deleted = function() {
  499. return false;
  500. };
  501. Field.prototype.generateCandidatesChildren_Root_root_running = function() {
  502. var branch_done = false;
  503. branch_done = (this.generateCandidates_Root_root_running_main_behaviour() || branch_done);
  504. branch_done = (this.generateCandidates_Root_root_running_deleting_behaviour() || branch_done);
  505. branch_done = (this.generateCandidates_Root_root_running_child_behaviour() || branch_done);
  506. return branch_done;
  507. };
  508. Field.prototype.generateCandidatesCurrent_Root_root_running = function() {
  509. var enabled_events = this.getEnabledEvents();
  510. for (var e in enabled_events) {
  511. if (!enabled_events.hasOwnProperty(e)) continue;
  512. if ((enabled_events[e].name === "window_close") && (enabled_events[e].port === "ui")) {
  513. var parameters = enabled_events[e].parameters;
  514. var window = parameters[0];
  515. if (window == this.field_window || window == ui.window) {
  516. this.small_step.addCandidate(this.transition_Root_root_running_1, enabled_events[e].parameters);
  517. return true;
  518. }
  519. }
  520. }
  521. return false;
  522. };
  523. Field.prototype.generateCandidates_Root_root_running = function() {
  524. if (!this.combo_step.isArenaChanged(this.Root_root_running)) {
  525. var branch_done = false;
  526. if (this.semantics.priority === StatechartSemantics.SourceParent) {
  527. branch_done = this.generateCandidatesCurrent_Root_root_running();
  528. if (!branch_done) {
  529. branch_done = this.generateCandidatesChildren_Root_root_running();
  530. }
  531. } else if (this.semantics.priority === StatechartSemantics.SourceChild) {
  532. branch_done = this.generateCandidatesChildren_Root_root_running();
  533. if (!branch_done) {
  534. branch_done = this.generateCandidatesCurrent_Root_root_running();
  535. }
  536. }
  537. return branch_done;
  538. } else {
  539. return true;
  540. }
  541. };
  542. Field.prototype.transition_Root_root_running_1 = function(parameters) {
  543. var window = parameters[0];
  544. this.exit_Root_root_running();
  545. this.big_step.outputEventOM(new Event("delete_instance", null, [this, 'buttons']));
  546. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'balls', new Event("delete_self", null, new Array())]));
  547. this.combo_step.setArenaChanged(this.Root_root);
  548. this.enter_Root_root_deleting();
  549. };
  550. Field.prototype.generateCandidatesChildren_Root_root_running_main_behaviour = function() {
  551. if (this.current_state[this.Root_root_running_main_behaviour][0] === this.Root_root_running_main_behaviour_running) {
  552. return this.generateCandidates_Root_root_running_main_behaviour_running();
  553. } else if (this.current_state[this.Root_root_running_main_behaviour][0] === this.Root_root_running_main_behaviour_creating) {
  554. return this.generateCandidates_Root_root_running_main_behaviour_creating();
  555. }
  556. return false;
  557. };
  558. Field.prototype.generateCandidates_Root_root_running_main_behaviour = function() {
  559. if (!this.combo_step.isArenaChanged(this.Root_root_running_main_behaviour)) {
  560. return this.generateCandidatesChildren_Root_root_running_main_behaviour();
  561. } else {
  562. return true;
  563. }
  564. };
  565. Field.prototype.generateCandidatesCurrent_Root_root_running_main_behaviour_running = function() {
  566. var enabled_events = this.getEnabledEvents();
  567. for (var e in enabled_events) {
  568. if (!enabled_events.hasOwnProperty(e)) continue;
  569. if ((enabled_events[e].name === "right_click") && (enabled_events[e].port === "field_ui")) {
  570. this.small_step.addCandidate(this.transition_Root_root_running_main_behaviour_running_1, enabled_events[e].parameters);
  571. return true;
  572. }
  573. }
  574. return false;
  575. };
  576. Field.prototype.generateCandidates_Root_root_running_main_behaviour_running = function() {
  577. if (!this.combo_step.isArenaChanged(this.Root_root_running_main_behaviour_running)) {
  578. return this.generateCandidatesCurrent_Root_root_running_main_behaviour_running();
  579. } else {
  580. return true;
  581. }
  582. };
  583. Field.prototype.transition_Root_root_running_main_behaviour_running_1 = function(parameters) {
  584. var x = parameters[0];
  585. var y = parameters[1];
  586. var button = parameters[2];
  587. this.exit_Root_root_running_main_behaviour_running();
  588. this.big_step.outputEventOM(new Event("create_instance", null, [this, 'balls', 'Ball', this.canvas, x, y, this.field_window]));
  589. this.combo_step.setArenaChanged(this.Root_root_running_main_behaviour);
  590. this.enter_Root_root_running_main_behaviour_creating();
  591. };
  592. Field.prototype.generateCandidatesCurrent_Root_root_running_main_behaviour_creating = function() {
  593. var enabled_events = this.getEnabledEvents();
  594. for (var e in enabled_events) {
  595. if (!enabled_events.hasOwnProperty(e)) continue;
  596. if (enabled_events[e].name === "instance_created") {
  597. this.small_step.addCandidate(this.transition_Root_root_running_main_behaviour_creating_1, enabled_events[e].parameters);
  598. return true;
  599. }
  600. }
  601. return false;
  602. };
  603. Field.prototype.generateCandidates_Root_root_running_main_behaviour_creating = function() {
  604. if (!this.combo_step.isArenaChanged(this.Root_root_running_main_behaviour_creating)) {
  605. return this.generateCandidatesCurrent_Root_root_running_main_behaviour_creating();
  606. } else {
  607. return true;
  608. }
  609. };
  610. Field.prototype.transition_Root_root_running_main_behaviour_creating_1 = function(parameters) {
  611. var association_name = parameters[0];
  612. this.exit_Root_root_running_main_behaviour_creating();
  613. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, association_name, new Event("set_association_name", null, [association_name])]));
  614. this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name]));
  615. this.combo_step.setArenaChanged(this.Root_root_running_main_behaviour);
  616. this.enter_Root_root_running_main_behaviour_running();
  617. };
  618. Field.prototype.generateCandidatesChildren_Root_root_running_deleting_behaviour = function() {
  619. if (this.current_state[this.Root_root_running_deleting_behaviour][0] === this.Root_root_running_deleting_behaviour_running) {
  620. return this.generateCandidates_Root_root_running_deleting_behaviour_running();
  621. }
  622. return false;
  623. };
  624. Field.prototype.generateCandidates_Root_root_running_deleting_behaviour = function() {
  625. if (!this.combo_step.isArenaChanged(this.Root_root_running_deleting_behaviour)) {
  626. return this.generateCandidatesChildren_Root_root_running_deleting_behaviour();
  627. } else {
  628. return true;
  629. }
  630. };
  631. Field.prototype.generateCandidatesCurrent_Root_root_running_deleting_behaviour_running = function() {
  632. var enabled_events = this.getEnabledEvents();
  633. for (var e in enabled_events) {
  634. if (!enabled_events.hasOwnProperty(e)) continue;
  635. if (enabled_events[e].name === "delete_ball") {
  636. this.small_step.addCandidate(this.transition_Root_root_running_deleting_behaviour_running_1, enabled_events[e].parameters);
  637. return true;
  638. }
  639. }
  640. return false;
  641. };
  642. Field.prototype.generateCandidates_Root_root_running_deleting_behaviour_running = function() {
  643. if (!this.combo_step.isArenaChanged(this.Root_root_running_deleting_behaviour_running)) {
  644. return this.generateCandidatesCurrent_Root_root_running_deleting_behaviour_running();
  645. } else {
  646. return true;
  647. }
  648. };
  649. Field.prototype.transition_Root_root_running_deleting_behaviour_running_1 = function(parameters) {
  650. var association_name = parameters[0];
  651. this.exit_Root_root_running_deleting_behaviour_running();
  652. this.big_step.outputEventOM(new Event("delete_instance", null, [this, association_name]));
  653. this.combo_step.setArenaChanged(this.Root_root_running_deleting_behaviour);
  654. this.enter_Root_root_running_deleting_behaviour_running();
  655. };
  656. Field.prototype.generateCandidatesChildren_Root_root_running_child_behaviour = function() {
  657. if (this.current_state[this.Root_root_running_child_behaviour][0] === this.Root_root_running_child_behaviour_listening) {
  658. return this.generateCandidates_Root_root_running_child_behaviour_listening();
  659. }
  660. return false;
  661. };
  662. Field.prototype.generateCandidates_Root_root_running_child_behaviour = function() {
  663. if (!this.combo_step.isArenaChanged(this.Root_root_running_child_behaviour)) {
  664. return this.generateCandidatesChildren_Root_root_running_child_behaviour();
  665. } else {
  666. return true;
  667. }
  668. };
  669. Field.prototype.generateCandidatesCurrent_Root_root_running_child_behaviour_listening = function() {
  670. var enabled_events = this.getEnabledEvents();
  671. for (var e in enabled_events) {
  672. if (!enabled_events.hasOwnProperty(e)) continue;
  673. if (enabled_events[e].name === "button_pressed") {
  674. this.small_step.addCandidate(this.transition_Root_root_running_child_behaviour_listening_1, enabled_events[e].parameters);
  675. return true;
  676. }
  677. }
  678. return false;
  679. };
  680. Field.prototype.generateCandidates_Root_root_running_child_behaviour_listening = function() {
  681. if (!this.combo_step.isArenaChanged(this.Root_root_running_child_behaviour_listening)) {
  682. return this.generateCandidatesCurrent_Root_root_running_child_behaviour_listening();
  683. } else {
  684. return true;
  685. }
  686. };
  687. Field.prototype.transition_Root_root_running_child_behaviour_listening_1 = function(parameters) {
  688. var event_name = parameters[0];
  689. this.exit_Root_root_running_child_behaviour_listening();
  690. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_pressed", null, [event_name])]));
  691. this.combo_step.setArenaChanged(this.Root_root_running_child_behaviour);
  692. this.enter_Root_root_running_child_behaviour_listening();
  693. };
  694. // Generate transition candidates for current small step
  695. // Generate transition candidates for current small step
  696. Field.prototype.generateCandidates = function() {
  697. this.generateCandidates_Root();
  698. };
  699. // add symbol 'Field' to package 'Bouncing_Balls'
  700. Bouncing_Balls.Field = Field;
  701. var MainApp = function(controller) {
  702. RuntimeClassBase.call(this, controller);
  703. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  704. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  705. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  706. this.semantics.priority = StatechartSemantics.SourceParent;
  707. this.semantics.concurrency = StatechartSemantics.Single;
  708. // Call user defined constructor
  709. MainApp.prototype.user_defined_constructor.call(this);
  710. };
  711. MainApp.prototype = new Object();
  712. (function() {
  713. var proto = new RuntimeClassBase();
  714. for (prop in proto) {
  715. MainApp.prototype[prop] = proto[prop];
  716. }
  717. })();
  718. MainApp.prototype.user_defined_constructor = function() {
  719. this.nr_of_fields = 0;
  720. ui.bind_event(ui.window, ui.EVENTS.WINDOW_CLOSE, this.controller, 'window_close');
  721. };
  722. MainApp.prototype.user_defined_destructor = function() {
  723. };
  724. MainApp.prototype.initializeStatechart = function() {
  725. this.current_state[this.Root] = new Array();
  726. this.current_state[this.Root_running] = new Array();
  727. this.current_state[this.Root_running_root] = new Array();
  728. this.current_state[this.Root_running_root_main_behaviour] = new Array();
  729. this.current_state[this.Root_running_root_cd_behaviour] = new Array();
  730. // Enter default state
  731. this.enterDefault_Root_running();
  732. };
  733. // Unique IDs for all statechart nodes
  734. MainApp.prototype.Root = 0;
  735. MainApp.prototype.Root_running = 1;
  736. MainApp.prototype.Root_running_root = 2;
  737. MainApp.prototype.Root_running_root_main_behaviour = 3;
  738. MainApp.prototype.Root_running_root_cd_behaviour = 4;
  739. MainApp.prototype.Root_running_stopped = 5;
  740. MainApp.prototype.Root_running_root_main_behaviour_initializing = 6;
  741. MainApp.prototype.Root_running_root_main_behaviour_running = 7;
  742. MainApp.prototype.Root_running_root_cd_behaviour_creating = 8;
  743. MainApp.prototype.Root_running_root_cd_behaviour_waiting = 9;
  744. MainApp.prototype.Root_running_root_cd_behaviour_check_nr_of_fields = 10;
  745. // Statechart enter/exit action method(s)
  746. MainApp.prototype.enter_Root_running = function() {
  747. this.current_state[this.Root].push(this.Root_running);
  748. };
  749. MainApp.prototype.exit_Root_running = function() {
  750. if ((this.current_state[this.Root_running].indexOf(this.Root_running_stopped) !== -1)) {
  751. this.exit_Root_running_stopped();
  752. }
  753. if ((this.current_state[this.Root_running].indexOf(this.Root_running_root) !== -1)) {
  754. this.exit_Root_running_root();
  755. }
  756. this.current_state[this.Root] = new Array();
  757. };
  758. MainApp.prototype.enter_Root_running_root = function() {
  759. this.current_state[this.Root_running].push(this.Root_running_root);
  760. };
  761. MainApp.prototype.exit_Root_running_root = function() {
  762. this.exit_Root_running_root_main_behaviour();
  763. this.exit_Root_running_root_cd_behaviour();
  764. this.current_state[this.Root_running] = new Array();
  765. };
  766. MainApp.prototype.enter_Root_running_root_main_behaviour = function() {
  767. this.current_state[this.Root_running_root].push(this.Root_running_root_main_behaviour);
  768. };
  769. MainApp.prototype.exit_Root_running_root_main_behaviour = function() {
  770. if ((this.current_state[this.Root_running_root_main_behaviour].indexOf(this.Root_running_root_main_behaviour_initializing) !== -1)) {
  771. this.exit_Root_running_root_main_behaviour_initializing();
  772. }
  773. if ((this.current_state[this.Root_running_root_main_behaviour].indexOf(this.Root_running_root_main_behaviour_running) !== -1)) {
  774. this.exit_Root_running_root_main_behaviour_running();
  775. }
  776. this.current_state[this.Root_running_root] = new Array();
  777. };
  778. MainApp.prototype.enter_Root_running_root_cd_behaviour = function() {
  779. this.current_state[this.Root_running_root].push(this.Root_running_root_cd_behaviour);
  780. };
  781. MainApp.prototype.exit_Root_running_root_cd_behaviour = function() {
  782. if ((this.current_state[this.Root_running_root_cd_behaviour].indexOf(this.Root_running_root_cd_behaviour_creating) !== -1)) {
  783. this.exit_Root_running_root_cd_behaviour_creating();
  784. }
  785. if ((this.current_state[this.Root_running_root_cd_behaviour].indexOf(this.Root_running_root_cd_behaviour_waiting) !== -1)) {
  786. this.exit_Root_running_root_cd_behaviour_waiting();
  787. }
  788. if ((this.current_state[this.Root_running_root_cd_behaviour].indexOf(this.Root_running_root_cd_behaviour_check_nr_of_fields) !== -1)) {
  789. this.exit_Root_running_root_cd_behaviour_check_nr_of_fields();
  790. }
  791. this.current_state[this.Root_running_root] = new Array();
  792. };
  793. MainApp.prototype.enter_Root_running_stopped = function() {
  794. this.current_state[this.Root_running].push(this.Root_running_stopped);
  795. };
  796. MainApp.prototype.exit_Root_running_stopped = function() {
  797. this.current_state[this.Root_running] = new Array();
  798. };
  799. MainApp.prototype.enter_Root_running_root_main_behaviour_initializing = function() {
  800. this.current_state[this.Root_running_root_main_behaviour].push(this.Root_running_root_main_behaviour_initializing);
  801. };
  802. MainApp.prototype.exit_Root_running_root_main_behaviour_initializing = function() {
  803. this.current_state[this.Root_running_root_main_behaviour] = new Array();
  804. };
  805. MainApp.prototype.enter_Root_running_root_main_behaviour_running = function() {
  806. this.current_state[this.Root_running_root_main_behaviour].push(this.Root_running_root_main_behaviour_running);
  807. };
  808. MainApp.prototype.exit_Root_running_root_main_behaviour_running = function() {
  809. this.current_state[this.Root_running_root_main_behaviour] = new Array();
  810. };
  811. MainApp.prototype.enter_Root_running_root_cd_behaviour_creating = function() {
  812. this.current_state[this.Root_running_root_cd_behaviour].push(this.Root_running_root_cd_behaviour_creating);
  813. };
  814. MainApp.prototype.exit_Root_running_root_cd_behaviour_creating = function() {
  815. this.current_state[this.Root_running_root_cd_behaviour] = new Array();
  816. };
  817. MainApp.prototype.enter_Root_running_root_cd_behaviour_waiting = function() {
  818. this.current_state[this.Root_running_root_cd_behaviour].push(this.Root_running_root_cd_behaviour_waiting);
  819. };
  820. MainApp.prototype.exit_Root_running_root_cd_behaviour_waiting = function() {
  821. this.current_state[this.Root_running_root_cd_behaviour] = new Array();
  822. };
  823. MainApp.prototype.enter_Root_running_root_cd_behaviour_check_nr_of_fields = function() {
  824. this.current_state[this.Root_running_root_cd_behaviour].push(this.Root_running_root_cd_behaviour_check_nr_of_fields);
  825. };
  826. MainApp.prototype.exit_Root_running_root_cd_behaviour_check_nr_of_fields = function() {
  827. this.current_state[this.Root_running_root_cd_behaviour] = new Array();
  828. };
  829. // Statechart enter/exit default method(s)
  830. MainApp.prototype.enterDefault_Root_running = function() {
  831. this.enter_Root_running();
  832. this.enterDefault_Root_running_root();
  833. };
  834. MainApp.prototype.enterDefault_Root_running_root = function() {
  835. this.enter_Root_running_root();
  836. this.enterDefault_Root_running_root_main_behaviour();
  837. this.enterDefault_Root_running_root_cd_behaviour();
  838. };
  839. MainApp.prototype.enterDefault_Root_running_root_main_behaviour = function() {
  840. this.enter_Root_running_root_main_behaviour();
  841. this.enter_Root_running_root_main_behaviour_initializing();
  842. };
  843. MainApp.prototype.enterDefault_Root_running_root_cd_behaviour = function() {
  844. this.enter_Root_running_root_cd_behaviour();
  845. this.enter_Root_running_root_cd_behaviour_waiting();
  846. };
  847. // Statechart transitions
  848. MainApp.prototype.generateCandidatesChildren_Root = function() {
  849. if (this.current_state[this.Root][0] === this.Root_running) {
  850. return this.generateCandidates_Root_running();
  851. }
  852. return false;
  853. };
  854. MainApp.prototype.generateCandidates_Root = function() {
  855. if (!this.combo_step.isArenaChanged(this.Root)) {
  856. return this.generateCandidatesChildren_Root();
  857. } else {
  858. return true;
  859. }
  860. };
  861. MainApp.prototype.generateCandidatesChildren_Root_running = function() {
  862. if (this.current_state[this.Root_running][0] === this.Root_running_stopped) {
  863. return this.generateCandidates_Root_running_stopped();
  864. } else if (this.current_state[this.Root_running][0] === this.Root_running_root) {
  865. return this.generateCandidates_Root_running_root();
  866. }
  867. return false;
  868. };
  869. MainApp.prototype.generateCandidates_Root_running = function() {
  870. if (!this.combo_step.isArenaChanged(this.Root_running)) {
  871. return this.generateCandidatesChildren_Root_running();
  872. } else {
  873. return true;
  874. }
  875. };
  876. MainApp.prototype.generateCandidates_Root_running_stopped = function() {
  877. return false;
  878. };
  879. MainApp.prototype.generateCandidatesChildren_Root_running_root = function() {
  880. var branch_done = false;
  881. branch_done = (this.generateCandidates_Root_running_root_main_behaviour() || branch_done);
  882. branch_done = (this.generateCandidates_Root_running_root_cd_behaviour() || branch_done);
  883. return branch_done;
  884. };
  885. MainApp.prototype.generateCandidates_Root_running_root = function() {
  886. if (!this.combo_step.isArenaChanged(this.Root_running_root)) {
  887. return this.generateCandidatesChildren_Root_running_root();
  888. } else {
  889. return true;
  890. }
  891. };
  892. MainApp.prototype.generateCandidatesChildren_Root_running_root_main_behaviour = function() {
  893. if (this.current_state[this.Root_running_root_main_behaviour][0] === this.Root_running_root_main_behaviour_initializing) {
  894. return this.generateCandidates_Root_running_root_main_behaviour_initializing();
  895. } else if (this.current_state[this.Root_running_root_main_behaviour][0] === this.Root_running_root_main_behaviour_running) {
  896. return this.generateCandidates_Root_running_root_main_behaviour_running();
  897. }
  898. return false;
  899. };
  900. MainApp.prototype.generateCandidates_Root_running_root_main_behaviour = function() {
  901. if (!this.combo_step.isArenaChanged(this.Root_running_root_main_behaviour)) {
  902. return this.generateCandidatesChildren_Root_running_root_main_behaviour();
  903. } else {
  904. return true;
  905. }
  906. };
  907. MainApp.prototype.generateCandidatesCurrent_Root_running_root_main_behaviour_initializing = function() {
  908. var enabled_events = this.getEnabledEvents();
  909. this.small_step.addCandidate(this.transition_Root_running_root_main_behaviour_initializing_1, new Array());
  910. return true;
  911. return false;
  912. };
  913. MainApp.prototype.generateCandidates_Root_running_root_main_behaviour_initializing = function() {
  914. if (!this.combo_step.isArenaChanged(this.Root_running_root_main_behaviour_initializing)) {
  915. return this.generateCandidatesCurrent_Root_running_root_main_behaviour_initializing();
  916. } else {
  917. return true;
  918. }
  919. };
  920. MainApp.prototype.transition_Root_running_root_main_behaviour_initializing_1 = function(parameters) {
  921. this.exit_Root_running_root_main_behaviour_initializing();
  922. this.raiseInternalEvent(new Event("create_field", null, new Array()));
  923. this.combo_step.setArenaChanged(this.Root_running_root_main_behaviour);
  924. this.enter_Root_running_root_main_behaviour_running();
  925. };
  926. MainApp.prototype.generateCandidatesCurrent_Root_running_root_main_behaviour_running = function() {
  927. var enabled_events = this.getEnabledEvents();
  928. for (var e in enabled_events) {
  929. if (!enabled_events.hasOwnProperty(e)) continue;
  930. if (enabled_events[e].name === "button_pressed") {
  931. var parameters = enabled_events[e].parameters;
  932. var event_name = parameters[0];
  933. if (event_name == 'create_new_field') {
  934. this.small_step.addCandidate(this.transition_Root_running_root_main_behaviour_running_1, enabled_events[e].parameters);
  935. return true;
  936. }
  937. }
  938. }
  939. return false;
  940. };
  941. MainApp.prototype.generateCandidates_Root_running_root_main_behaviour_running = function() {
  942. if (!this.combo_step.isArenaChanged(this.Root_running_root_main_behaviour_running)) {
  943. return this.generateCandidatesCurrent_Root_running_root_main_behaviour_running();
  944. } else {
  945. return true;
  946. }
  947. };
  948. MainApp.prototype.transition_Root_running_root_main_behaviour_running_1 = function(parameters) {
  949. var event_name = parameters[0];
  950. this.exit_Root_running_root_main_behaviour_running();
  951. this.raiseInternalEvent(new Event("create_field", null, new Array()));
  952. this.combo_step.setArenaChanged(this.Root_running_root_main_behaviour);
  953. this.enter_Root_running_root_main_behaviour_running();
  954. };
  955. MainApp.prototype.generateCandidatesChildren_Root_running_root_cd_behaviour = function() {
  956. if (this.current_state[this.Root_running_root_cd_behaviour][0] === this.Root_running_root_cd_behaviour_creating) {
  957. return this.generateCandidates_Root_running_root_cd_behaviour_creating();
  958. } else if (this.current_state[this.Root_running_root_cd_behaviour][0] === this.Root_running_root_cd_behaviour_waiting) {
  959. return this.generateCandidates_Root_running_root_cd_behaviour_waiting();
  960. } else if (this.current_state[this.Root_running_root_cd_behaviour][0] === this.Root_running_root_cd_behaviour_check_nr_of_fields) {
  961. return this.generateCandidates_Root_running_root_cd_behaviour_check_nr_of_fields();
  962. }
  963. return false;
  964. };
  965. MainApp.prototype.generateCandidates_Root_running_root_cd_behaviour = function() {
  966. if (!this.combo_step.isArenaChanged(this.Root_running_root_cd_behaviour)) {
  967. return this.generateCandidatesChildren_Root_running_root_cd_behaviour();
  968. } else {
  969. return true;
  970. }
  971. };
  972. MainApp.prototype.generateCandidatesCurrent_Root_running_root_cd_behaviour_creating = function() {
  973. var enabled_events = this.getEnabledEvents();
  974. for (var e in enabled_events) {
  975. if (!enabled_events.hasOwnProperty(e)) continue;
  976. if (enabled_events[e].name === "instance_created") {
  977. this.small_step.addCandidate(this.transition_Root_running_root_cd_behaviour_creating_1, enabled_events[e].parameters);
  978. return true;
  979. }
  980. }
  981. return false;
  982. };
  983. MainApp.prototype.generateCandidates_Root_running_root_cd_behaviour_creating = function() {
  984. if (!this.combo_step.isArenaChanged(this.Root_running_root_cd_behaviour_creating)) {
  985. return this.generateCandidatesCurrent_Root_running_root_cd_behaviour_creating();
  986. } else {
  987. return true;
  988. }
  989. };
  990. MainApp.prototype.transition_Root_running_root_cd_behaviour_creating_1 = function(parameters) {
  991. var association_name = parameters[0];
  992. this.exit_Root_running_root_cd_behaviour_creating();
  993. this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name]));
  994. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, association_name, new Event("set_association_name", null, [association_name])]));
  995. this.nr_of_fields += 1;
  996. this.combo_step.setArenaChanged(this.Root_running_root_cd_behaviour);
  997. this.enter_Root_running_root_cd_behaviour_waiting();
  998. };
  999. MainApp.prototype.generateCandidatesCurrent_Root_running_root_cd_behaviour_waiting = function() {
  1000. var enabled_events = this.getEnabledEvents();
  1001. for (var e in enabled_events) {
  1002. if (!enabled_events.hasOwnProperty(e)) continue;
  1003. if (enabled_events[e].name === "create_field") {
  1004. this.small_step.addCandidate(this.transition_Root_running_root_cd_behaviour_waiting_1, enabled_events[e].parameters);
  1005. return true;
  1006. }
  1007. }
  1008. var enabled_events = this.getEnabledEvents();
  1009. for (var e in enabled_events) {
  1010. if (!enabled_events.hasOwnProperty(e)) continue;
  1011. if (enabled_events[e].name === "delete_field") {
  1012. this.small_step.addCandidate(this.transition_Root_running_root_cd_behaviour_waiting_2, enabled_events[e].parameters);
  1013. return true;
  1014. }
  1015. }
  1016. return false;
  1017. };
  1018. MainApp.prototype.generateCandidates_Root_running_root_cd_behaviour_waiting = function() {
  1019. if (!this.combo_step.isArenaChanged(this.Root_running_root_cd_behaviour_waiting)) {
  1020. return this.generateCandidatesCurrent_Root_running_root_cd_behaviour_waiting();
  1021. } else {
  1022. return true;
  1023. }
  1024. };
  1025. MainApp.prototype.transition_Root_running_root_cd_behaviour_waiting_1 = function(parameters) {
  1026. this.exit_Root_running_root_cd_behaviour_waiting();
  1027. this.big_step.outputEventOM(new Event("create_instance", null, [this, 'fields']));
  1028. this.combo_step.setArenaChanged(this.Root_running_root_cd_behaviour);
  1029. this.enter_Root_running_root_cd_behaviour_creating();
  1030. };
  1031. MainApp.prototype.transition_Root_running_root_cd_behaviour_waiting_2 = function(parameters) {
  1032. var association_name = parameters[0];
  1033. this.exit_Root_running_root_cd_behaviour_waiting();
  1034. this.big_step.outputEventOM(new Event("delete_instance", null, [this, association_name]));
  1035. this.nr_of_fields -= 1;
  1036. this.combo_step.setArenaChanged(this.Root_running_root_cd_behaviour);
  1037. this.enter_Root_running_root_cd_behaviour_check_nr_of_fields();
  1038. };
  1039. MainApp.prototype.generateCandidatesCurrent_Root_running_root_cd_behaviour_check_nr_of_fields = function() {
  1040. var enabled_events = this.getEnabledEvents();
  1041. if (this.nr_of_fields != 0) {
  1042. this.small_step.addCandidate(this.transition_Root_running_root_cd_behaviour_check_nr_of_fields_1, new Array());
  1043. return true;
  1044. }
  1045. var enabled_events = this.getEnabledEvents();
  1046. if (this.nr_of_fields == 0) {
  1047. this.small_step.addCandidate(this.transition_Root_running_root_cd_behaviour_check_nr_of_fields_2, new Array());
  1048. return true;
  1049. }
  1050. return false;
  1051. };
  1052. MainApp.prototype.generateCandidates_Root_running_root_cd_behaviour_check_nr_of_fields = function() {
  1053. if (!this.combo_step.isArenaChanged(this.Root_running_root_cd_behaviour_check_nr_of_fields)) {
  1054. return this.generateCandidatesCurrent_Root_running_root_cd_behaviour_check_nr_of_fields();
  1055. } else {
  1056. return true;
  1057. }
  1058. };
  1059. MainApp.prototype.transition_Root_running_root_cd_behaviour_check_nr_of_fields_1 = function(parameters) {
  1060. this.exit_Root_running_root_cd_behaviour_check_nr_of_fields();
  1061. this.combo_step.setArenaChanged(this.Root_running_root_cd_behaviour);
  1062. this.enter_Root_running_root_cd_behaviour_waiting();
  1063. };
  1064. MainApp.prototype.transition_Root_running_root_cd_behaviour_check_nr_of_fields_2 = function(parameters) {
  1065. this.exit_Root_running_root();
  1066. ui.close_window(ui.window);
  1067. this.combo_step.setArenaChanged(this.Root_running);
  1068. this.enter_Root_running_stopped();
  1069. };
  1070. // Generate transition candidates for current small step
  1071. // Generate transition candidates for current small step
  1072. MainApp.prototype.generateCandidates = function() {
  1073. this.generateCandidates_Root();
  1074. };
  1075. // add symbol 'MainApp' to package 'Bouncing_Balls'
  1076. Bouncing_Balls.MainApp = MainApp;
  1077. var Ball = function(controller, canvas, x, y, field_window) {
  1078. RuntimeClassBase.call(this, controller);
  1079. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  1080. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  1081. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  1082. this.semantics.priority = StatechartSemantics.SourceParent;
  1083. this.semantics.concurrency = StatechartSemantics.Single;
  1084. this.inports["ball_ui"] = controller.addInputPort("ball_ui", this);
  1085. // User defined attributes
  1086. this.field_window = null;
  1087. this.canvas = null;
  1088. this.element = null;
  1089. // Call user defined constructor
  1090. Ball.prototype.user_defined_constructor.call(this, canvas, x, y, field_window);
  1091. };
  1092. Ball.prototype = new Object();
  1093. (function() {
  1094. var proto = new RuntimeClassBase();
  1095. for (prop in proto) {
  1096. Ball.prototype[prop] = proto[prop];
  1097. }
  1098. })();
  1099. Ball.prototype.user_defined_constructor = function(canvas, x, y, field_window) {
  1100. this.canvas = canvas;
  1101. this.field_window = field_window;
  1102. this.r = 20.0;
  1103. this.vel = {'x':utils.random() * 2.0 - 1.0, 'y':utils.random() * 2.0 - 1.0};
  1104. this.mouse_pos = {'':''};
  1105. this.smooth = 0.4;
  1106. var circle = this.canvas.add_circle(x, y, this.r, {'fill':'#000'});
  1107. ui.bind_event(circle, ui.EVENTS.MOUSE_PRESS, this.controller, 'mouse_press', this.inports['ball_ui']);
  1108. ui.bind_event(circle, ui.EVENTS.MOUSE_RIGHT_CLICK, this.controller, 'right_click');
  1109. this.element = circle;
  1110. };
  1111. Ball.prototype.user_defined_destructor = function() {
  1112. this.canvas.remove_element(this.element);
  1113. };
  1114. Ball.prototype.initializeStatechart = function() {
  1115. this.current_state[this.Root] = new Array();
  1116. this.current_state[this.Root_main_behaviour] = new Array();
  1117. // Enter default state
  1118. this.enterDefault_Root_main_behaviour();
  1119. };
  1120. // Unique IDs for all statechart nodes
  1121. Ball.prototype.Root = 0;
  1122. Ball.prototype.Root_main_behaviour = 1;
  1123. Ball.prototype.Root_main_behaviour_dragging = 2;
  1124. Ball.prototype.Root_main_behaviour_selected = 3;
  1125. Ball.prototype.Root_main_behaviour_initializing = 4;
  1126. Ball.prototype.Root_main_behaviour_bouncing = 5;
  1127. Ball.prototype.Root_deleted = 6;
  1128. // Statechart enter/exit action method(s)
  1129. Ball.prototype.enter_Root_main_behaviour = function() {
  1130. this.current_state[this.Root].push(this.Root_main_behaviour);
  1131. };
  1132. Ball.prototype.exit_Root_main_behaviour = function() {
  1133. if ((this.current_state[this.Root_main_behaviour].indexOf(this.Root_main_behaviour_dragging) !== -1)) {
  1134. this.exit_Root_main_behaviour_dragging();
  1135. }
  1136. if ((this.current_state[this.Root_main_behaviour].indexOf(this.Root_main_behaviour_selected) !== -1)) {
  1137. this.exit_Root_main_behaviour_selected();
  1138. }
  1139. if ((this.current_state[this.Root_main_behaviour].indexOf(this.Root_main_behaviour_initializing) !== -1)) {
  1140. this.exit_Root_main_behaviour_initializing();
  1141. }
  1142. if ((this.current_state[this.Root_main_behaviour].indexOf(this.Root_main_behaviour_bouncing) !== -1)) {
  1143. this.exit_Root_main_behaviour_bouncing();
  1144. }
  1145. this.current_state[this.Root] = new Array();
  1146. };
  1147. Ball.prototype.enter_Root_main_behaviour_dragging = function() {
  1148. this.current_state[this.Root_main_behaviour].push(this.Root_main_behaviour_dragging);
  1149. };
  1150. Ball.prototype.exit_Root_main_behaviour_dragging = function() {
  1151. this.current_state[this.Root_main_behaviour] = new Array();
  1152. };
  1153. Ball.prototype.enter_Root_main_behaviour_selected = function() {
  1154. this.current_state[this.Root_main_behaviour].push(this.Root_main_behaviour_selected);
  1155. };
  1156. Ball.prototype.exit_Root_main_behaviour_selected = function() {
  1157. this.current_state[this.Root_main_behaviour] = new Array();
  1158. };
  1159. Ball.prototype.enter_Root_main_behaviour_initializing = function() {
  1160. this.current_state[this.Root_main_behaviour].push(this.Root_main_behaviour_initializing);
  1161. };
  1162. Ball.prototype.exit_Root_main_behaviour_initializing = function() {
  1163. this.current_state[this.Root_main_behaviour] = new Array();
  1164. };
  1165. Ball.prototype.enter_Root_main_behaviour_bouncing = function() {
  1166. this.timers[0] = 0.01;
  1167. this.current_state[this.Root_main_behaviour].push(this.Root_main_behaviour_bouncing);
  1168. };
  1169. Ball.prototype.exit_Root_main_behaviour_bouncing = function() {
  1170. delete this.timers[0];
  1171. this.current_state[this.Root_main_behaviour] = new Array();
  1172. };
  1173. Ball.prototype.enter_Root_deleted = function() {
  1174. this.current_state[this.Root].push(this.Root_deleted);
  1175. };
  1176. Ball.prototype.exit_Root_deleted = function() {
  1177. this.current_state[this.Root] = new Array();
  1178. };
  1179. // Statechart enter/exit default method(s)
  1180. Ball.prototype.enterDefault_Root_main_behaviour = function() {
  1181. this.enter_Root_main_behaviour();
  1182. this.enter_Root_main_behaviour_initializing();
  1183. };
  1184. // Statechart transitions
  1185. Ball.prototype.generateCandidatesChildren_Root = function() {
  1186. if (this.current_state[this.Root][0] === this.Root_main_behaviour) {
  1187. return this.generateCandidates_Root_main_behaviour();
  1188. } else if (this.current_state[this.Root][0] === this.Root_deleted) {
  1189. return this.generateCandidates_Root_deleted();
  1190. }
  1191. return false;
  1192. };
  1193. Ball.prototype.generateCandidates_Root = function() {
  1194. if (!this.combo_step.isArenaChanged(this.Root)) {
  1195. return this.generateCandidatesChildren_Root();
  1196. } else {
  1197. return true;
  1198. }
  1199. };
  1200. Ball.prototype.generateCandidatesChildren_Root_main_behaviour = function() {
  1201. if (this.current_state[this.Root_main_behaviour][0] === this.Root_main_behaviour_dragging) {
  1202. return this.generateCandidates_Root_main_behaviour_dragging();
  1203. } else if (this.current_state[this.Root_main_behaviour][0] === this.Root_main_behaviour_selected) {
  1204. return this.generateCandidates_Root_main_behaviour_selected();
  1205. } else if (this.current_state[this.Root_main_behaviour][0] === this.Root_main_behaviour_initializing) {
  1206. return this.generateCandidates_Root_main_behaviour_initializing();
  1207. } else if (this.current_state[this.Root_main_behaviour][0] === this.Root_main_behaviour_bouncing) {
  1208. return this.generateCandidates_Root_main_behaviour_bouncing();
  1209. }
  1210. return false;
  1211. };
  1212. Ball.prototype.generateCandidatesCurrent_Root_main_behaviour = function() {
  1213. var enabled_events = this.getEnabledEvents();
  1214. for (var e in enabled_events) {
  1215. if (!enabled_events.hasOwnProperty(e)) continue;
  1216. if (enabled_events[e].name === "delete_self") {
  1217. this.small_step.addCandidate(this.transition_Root_main_behaviour_1, enabled_events[e].parameters);
  1218. return true;
  1219. }
  1220. }
  1221. return false;
  1222. };
  1223. Ball.prototype.generateCandidates_Root_main_behaviour = function() {
  1224. if (!this.combo_step.isArenaChanged(this.Root_main_behaviour)) {
  1225. var branch_done = false;
  1226. if (this.semantics.priority === StatechartSemantics.SourceParent) {
  1227. branch_done = this.generateCandidatesCurrent_Root_main_behaviour();
  1228. if (!branch_done) {
  1229. branch_done = this.generateCandidatesChildren_Root_main_behaviour();
  1230. }
  1231. } else if (this.semantics.priority === StatechartSemantics.SourceChild) {
  1232. branch_done = this.generateCandidatesChildren_Root_main_behaviour();
  1233. if (!branch_done) {
  1234. branch_done = this.generateCandidatesCurrent_Root_main_behaviour();
  1235. }
  1236. }
  1237. return branch_done;
  1238. } else {
  1239. return true;
  1240. }
  1241. };
  1242. Ball.prototype.transition_Root_main_behaviour_1 = function(parameters) {
  1243. this.exit_Root_main_behaviour();
  1244. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("delete_ball", null, [this.association_name])]));
  1245. this.combo_step.setArenaChanged(this.Root);
  1246. this.enter_Root_deleted();
  1247. };
  1248. Ball.prototype.generateCandidatesCurrent_Root_main_behaviour_dragging = function() {
  1249. var enabled_events = this.getEnabledEvents();
  1250. for (var e in enabled_events) {
  1251. if (!enabled_events.hasOwnProperty(e)) continue;
  1252. if ((enabled_events[e].name === "mouse_release") && (enabled_events[e].port === "ui")) {
  1253. this.small_step.addCandidate(this.transition_Root_main_behaviour_dragging_1, enabled_events[e].parameters);
  1254. return true;
  1255. }
  1256. }
  1257. var enabled_events = this.getEnabledEvents();
  1258. for (var e in enabled_events) {
  1259. if (!enabled_events.hasOwnProperty(e)) continue;
  1260. if ((enabled_events[e].name === "mouse_move") && (enabled_events[e].port === "ui")) {
  1261. this.small_step.addCandidate(this.transition_Root_main_behaviour_dragging_2, enabled_events[e].parameters);
  1262. return true;
  1263. }
  1264. }
  1265. return false;
  1266. };
  1267. Ball.prototype.generateCandidates_Root_main_behaviour_dragging = function() {
  1268. if (!this.combo_step.isArenaChanged(this.Root_main_behaviour_dragging)) {
  1269. return this.generateCandidatesCurrent_Root_main_behaviour_dragging();
  1270. } else {
  1271. return true;
  1272. }
  1273. };
  1274. Ball.prototype.transition_Root_main_behaviour_dragging_1 = function(parameters) {
  1275. var x = parameters[0];
  1276. var y = parameters[1];
  1277. this.exit_Root_main_behaviour_dragging();
  1278. this.element.set_color('#f00');
  1279. this.combo_step.setArenaChanged(this.Root_main_behaviour);
  1280. this.enter_Root_main_behaviour_bouncing();
  1281. };
  1282. Ball.prototype.transition_Root_main_behaviour_dragging_2 = function(parameters) {
  1283. var x = parameters[0];
  1284. var y = parameters[1];
  1285. var button = parameters[2];
  1286. this.exit_Root_main_behaviour_dragging();
  1287. var dx = x - this.mouse_pos['x'];
  1288. var dy = y - this.mouse_pos['y'];
  1289. this.element.move(dx, dy);
  1290. var pos = this.element.get_position();
  1291. if(pos.x - this.r <= 0) {
  1292. pos.x = this.r + 1;
  1293. } else {
  1294. if(pos.x + this.r >= this.canvas.width) {
  1295. pos.x = this.canvas.width - this.r - 1;
  1296. }
  1297. }
  1298. if(pos.y - this.r <= 0) {
  1299. pos.y = this.r + 1;
  1300. } else {
  1301. if(pos.y + this.r >= this.canvas.height) {
  1302. pos.y = this.canvas.height - this.r - 1;
  1303. }
  1304. }
  1305. this.element.set_position(pos.x, pos.y);
  1306. this.mouse_pos = {'x':x, 'y':y};
  1307. this.vel = {'x':(1 - this.smooth) * dx + this.smooth * this.vel['x'], 'y':(1 - this.smooth) * dy + this.smooth * this.vel['y']};
  1308. this.combo_step.setArenaChanged(this.Root_main_behaviour);
  1309. this.enter_Root_main_behaviour_dragging();
  1310. };
  1311. Ball.prototype.generateCandidatesCurrent_Root_main_behaviour_selected = function() {
  1312. var enabled_events = this.getEnabledEvents();
  1313. for (var e in enabled_events) {
  1314. if (!enabled_events.hasOwnProperty(e)) continue;
  1315. if ((enabled_events[e].name === "mouse_press") && (enabled_events[e].port === "ball_ui")) {
  1316. var parameters = enabled_events[e].parameters;
  1317. var x = parameters[0];
  1318. var y = parameters[1];
  1319. var button = parameters[2];
  1320. if (button == ui.MOUSE_BUTTONS.LEFT) {
  1321. this.small_step.addCandidate(this.transition_Root_main_behaviour_selected_1, enabled_events[e].parameters);
  1322. return true;
  1323. }
  1324. }
  1325. }
  1326. var enabled_events = this.getEnabledEvents();
  1327. for (var e in enabled_events) {
  1328. if (!enabled_events.hasOwnProperty(e)) continue;
  1329. if ((enabled_events[e].name === "key_press") && (enabled_events[e].port === "ui")) {
  1330. var parameters = enabled_events[e].parameters;
  1331. var key = parameters[0];
  1332. var active_window = parameters[1];
  1333. if (key == ui.KEYCODES.DELETE && active_window == this.field_window) {
  1334. this.small_step.addCandidate(this.transition_Root_main_behaviour_selected_2, enabled_events[e].parameters);
  1335. return true;
  1336. }
  1337. }
  1338. }
  1339. return false;
  1340. };
  1341. Ball.prototype.generateCandidates_Root_main_behaviour_selected = function() {
  1342. if (!this.combo_step.isArenaChanged(this.Root_main_behaviour_selected)) {
  1343. return this.generateCandidatesCurrent_Root_main_behaviour_selected();
  1344. } else {
  1345. return true;
  1346. }
  1347. };
  1348. Ball.prototype.transition_Root_main_behaviour_selected_1 = function(parameters) {
  1349. var x = parameters[0];
  1350. var y = parameters[1];
  1351. var button = parameters[2];
  1352. this.exit_Root_main_behaviour_selected();
  1353. this.mouse_pos = {'x':x, 'y':y};
  1354. this.combo_step.setArenaChanged(this.Root_main_behaviour);
  1355. this.enter_Root_main_behaviour_dragging();
  1356. };
  1357. Ball.prototype.transition_Root_main_behaviour_selected_2 = function(parameters) {
  1358. var key = parameters[0];
  1359. var active_window = parameters[1];
  1360. this.exit_Root_main_behaviour_selected();
  1361. this.raiseInternalEvent(new Event("delete_self", null, new Array()));
  1362. this.combo_step.setArenaChanged(this.Root_main_behaviour);
  1363. this.enter_Root_main_behaviour_selected();
  1364. };
  1365. Ball.prototype.generateCandidatesCurrent_Root_main_behaviour_initializing = function() {
  1366. var enabled_events = this.getEnabledEvents();
  1367. for (var e in enabled_events) {
  1368. if (!enabled_events.hasOwnProperty(e)) continue;
  1369. if (enabled_events[e].name === "set_association_name") {
  1370. this.small_step.addCandidate(this.transition_Root_main_behaviour_initializing_1, enabled_events[e].parameters);
  1371. return true;
  1372. }
  1373. }
  1374. return false;
  1375. };
  1376. Ball.prototype.generateCandidates_Root_main_behaviour_initializing = function() {
  1377. if (!this.combo_step.isArenaChanged(this.Root_main_behaviour_initializing)) {
  1378. return this.generateCandidatesCurrent_Root_main_behaviour_initializing();
  1379. } else {
  1380. return true;
  1381. }
  1382. };
  1383. Ball.prototype.transition_Root_main_behaviour_initializing_1 = function(parameters) {
  1384. var association_name = parameters[0];
  1385. this.exit_Root_main_behaviour_initializing();
  1386. this.association_name = association_name;
  1387. this.combo_step.setArenaChanged(this.Root_main_behaviour);
  1388. this.enter_Root_main_behaviour_bouncing();
  1389. };
  1390. Ball.prototype.generateCandidatesCurrent_Root_main_behaviour_bouncing = function() {
  1391. var enabled_events = this.getEnabledEvents();
  1392. for (var e in enabled_events) {
  1393. if (!enabled_events.hasOwnProperty(e)) continue;
  1394. if (enabled_events[e].name === "_0after") {
  1395. this.small_step.addCandidate(this.transition_Root_main_behaviour_bouncing_1, enabled_events[e].parameters);
  1396. return true;
  1397. }
  1398. }
  1399. var enabled_events = this.getEnabledEvents();
  1400. for (var e in enabled_events) {
  1401. if (!enabled_events.hasOwnProperty(e)) continue;
  1402. if ((enabled_events[e].name === "mouse_press") && (enabled_events[e].port === "ball_ui")) {
  1403. var parameters = enabled_events[e].parameters;
  1404. var x = parameters[0];
  1405. var y = parameters[1];
  1406. var button = parameters[2];
  1407. if (button == ui.MOUSE_BUTTONS.LEFT) {
  1408. this.small_step.addCandidate(this.transition_Root_main_behaviour_bouncing_2, enabled_events[e].parameters);
  1409. return true;
  1410. }
  1411. }
  1412. }
  1413. return false;
  1414. };
  1415. Ball.prototype.generateCandidates_Root_main_behaviour_bouncing = function() {
  1416. if (!this.combo_step.isArenaChanged(this.Root_main_behaviour_bouncing)) {
  1417. return this.generateCandidatesCurrent_Root_main_behaviour_bouncing();
  1418. } else {
  1419. return true;
  1420. }
  1421. };
  1422. Ball.prototype.transition_Root_main_behaviour_bouncing_1 = function(parameters) {
  1423. this.exit_Root_main_behaviour_bouncing();
  1424. var pos = this.element.get_position();
  1425. if(pos.x - this.r <= 0 || pos.x + this.r >= this.canvas.width) {
  1426. this.vel['x'] = -this.vel['x'];
  1427. }
  1428. if(pos.y - this.r <= 0 || pos.y + this.r >= this.canvas.height) {
  1429. this.vel['y'] = -this.vel['y'];
  1430. }
  1431. this.element.move(this.vel['x'], this.vel['y']);
  1432. this.combo_step.setArenaChanged(this.Root_main_behaviour);
  1433. this.enter_Root_main_behaviour_bouncing();
  1434. };
  1435. Ball.prototype.transition_Root_main_behaviour_bouncing_2 = function(parameters) {
  1436. var x = parameters[0];
  1437. var y = parameters[1];
  1438. var button = parameters[2];
  1439. this.exit_Root_main_behaviour_bouncing();
  1440. this.element.set_color('#ff0');
  1441. this.combo_step.setArenaChanged(this.Root_main_behaviour);
  1442. this.enter_Root_main_behaviour_selected();
  1443. };
  1444. Ball.prototype.generateCandidates_Root_deleted = function() {
  1445. return false;
  1446. };
  1447. // Generate transition candidates for current small step
  1448. // Generate transition candidates for current small step
  1449. Ball.prototype.generateCandidates = function() {
  1450. this.generateCandidates_Root();
  1451. };
  1452. // add symbol 'Ball' to package 'Bouncing_Balls'
  1453. Bouncing_Balls.Ball = Ball;
  1454. var ObjectManager = function(controller) {
  1455. ObjectManagerBase.call(this, controller);
  1456. };
  1457. ObjectManager.prototype = new Object();
  1458. (function() {
  1459. var proto = new ObjectManagerBase();
  1460. for (prop in proto) {
  1461. ObjectManager.prototype[prop] = proto[prop];
  1462. }
  1463. })();
  1464. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  1465. if (class_name === "Button") {
  1466. var instance = new Button(this.controller, construct_params[0], construct_params[1], construct_params[2]);
  1467. instance.associations = new Object();
  1468. instance.associations["parent"] = new Association("Field", 1, 1);
  1469. } else if (class_name === "Field") {
  1470. var instance = new Field(this.controller);
  1471. instance.associations = new Object();
  1472. instance.associations["parent"] = new Association("MainApp", 1, 1);
  1473. instance.associations["buttons"] = new Association("Button", 0, -1);
  1474. instance.associations["balls"] = new Association("Ball", 0, -1);
  1475. } else if (class_name === "MainApp") {
  1476. var instance = new MainApp(this.controller);
  1477. instance.associations = new Object();
  1478. instance.associations["fields"] = new Association("Field", 0, -1);
  1479. } else if (class_name === "Ball") {
  1480. var instance = new Ball(this.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3]);
  1481. instance.associations = new Object();
  1482. instance.associations["parent"] = new Association("Field", 1, 1);
  1483. }
  1484. return instance;
  1485. };
  1486. // add symbol 'ObjectManager' to package 'Bouncing_Balls'
  1487. Bouncing_Balls.ObjectManager = ObjectManager;
  1488. var Controller = function(event_loop_callbacks, finished_callback) {
  1489. if (finished_callback === undefined) finished_callback = null;
  1490. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback);
  1491. this.addInputPort("field_ui");
  1492. this.addInputPort("ball_ui");
  1493. this.addInputPort("input");
  1494. this.object_manager.createInstance("MainApp", new Array());
  1495. };
  1496. Controller.prototype = new Object();
  1497. (function() {
  1498. var proto = new EventLoopControllerBase();
  1499. for (prop in proto) {
  1500. Controller.prototype[prop] = proto[prop];
  1501. }
  1502. })();
  1503. // add symbol 'Controller' to package 'Bouncing_Balls'
  1504. Bouncing_Balls.Controller = Controller;
  1505. })();