Advertisement
Guest User

es

a guest
Oct 7th, 2011
146
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *** This comment is now using the Adam's ES:
  2.  
  3. Ok, let's one fast example...
  4. Keep in mind that I'm using the Button and ToggleButton as example for UI. But you can put in a game if you want as a emergency button or a swith that is on/off, if you want
  5.  
  6. I have two scenes:
  7.  
  8. P.S.: I'm represting the entity-id with "quotes" followed by { Components }
  9.  
  10. SCENE_A:
  11. "play_button" { CButton.action = "play" }
  12. "sound_toggle" { CToggleable.action = "sound" }
  13. "music_toggle" { CToggleable.action = "music" }
  14. "exit_button" { CButton.action = "exit" }
  15.  
  16. SCENE_B:
  17. "another_button" { CButton.action = "anotherb" }
  18. "another_toggle" { CToggleable.action = "anothert" }
  19.  
  20. These are my Componentes data:
  21. CToggleable
  22. + toggled : boolean
  23. + action : String
  24.  
  25. CButton
  26. + action : String
  27.  
  28. ----
  29.  
  30. Then I have:
  31.  
  32. SceneAController (<-- maybe this is not the appropriated name)
  33. - will do something when "play", "sound", "music" or "exit" action is perfomed.
  34.  
  35. SceneBController
  36. - will do something when "anotherb", "anothert" action is perfomed.
  37.  
  38. ---
  39.  
  40. Adam's advice is have one system by component. So:
  41.  
  42. SceneAController (controls the SCENE_A actions and creates the entities, components and subsystems for SCENE_A contents)
  43. SceneBController (controls the SCENE_B actions and creates the entities, components and subsystems for SCENE_B contents)
  44. ToggleButtonSubsystem (how any entity with CToggleable behave)
  45. ButtonSubsystem (how any entity with CButton behave)
  46.  
  47. ---
  48.  
  49. ToggleButtonSubsystem
  50. {
  51. // when the bounds of entity (by CPosition) is collided with touch (x, y)), then:
  52. // --> CToggleable.toggled = !CToggleable.toggled
  53. // --> Create an ActionEvent with ActionEvent.action = CToggleable.action
  54. // --> Send the ActionEvent to current controller parent (or SceneAController or SceneBController)
  55. // else do nothing.
  56. }
  57.  
  58. ButtonSubsystem
  59. {
  60. // when the bounds of entity (by CPosition) is collided with touch (x, y)), then:
  61. // --> Create an ActionEvent with ActionEvent.action = CButton.action
  62. // --> Send the ActionEvent to current controller parent (or SceneAController or SceneBController)
  63. // else do nothing.
  64. }
  65.  
  66. ---
  67.  
  68. If I have a SCENE_C with:
  69.  
  70. P.S.: "entity-id" { Components ... }
  71.  
  72. SCENE_C (game scene)
  73. "alarm_button" { CButton.action = "start the alarm" }
  74. "switch_toggle" { CToggleable.action = "toggle the elevator up-down" }
  75.  
  76. I can still use the ButtonSubsystem and ToggleButtonSubsystem.
  77. They are going to be created (together with entities and components) in the SceneCController.
  78. So the parent of ButtonSubsystem and ToggleButtonSubsystem is now the SceneCController that has the ActionEventListener and will know what do do in the action.
  79. And I will not to have everytime make the CTogglable.toggle != CToggable.toggle (in every susbsystem or controller)
  80.  
  81. I'm sending messages to the parent controller, but has any other way to maintain the Toggle and Button "generic" like this without using messages?
  82.  
  83. What do you guys think? :)
  84.  
  85.  
Advertisement
RAW Paste Data Copied
Advertisement