In a level editor that supports multiple editing modes, written in an oop language, how would you go about switching from mode to mode, considering that data itself remains the same?
I am using a MVC pattern like so.
- A data model for the level's structure.
- One model for the editor's state depending on the current editing mode and it contains data about the user's editing activities that was not applied or does not affect the level model (i.e what entities or item are currently selected).
- A view for each mode (they all render similarly but differently cause they put emphasis on different items in the level).
- Controllers accepting input and manipulating the state. These also differ from one mode to another.
Controller accepts input from the user. It calls the corresponding methods on the
State model which in turn modifies the
LevelData. The controller refreshes the
View after changes are made to the
State so these changes are properly reflected to the user.
Currently, to switch, I have all controllers inherit from a base controller that contains the mode switching capability. I have a class called AppContainer (each mode is like an app) that is being informed that a switch needs to be made. This class deactivates the controller and activates a new controller instead. The new controller refreshes the view and clears the state upon reinitialization.
I am wondering if there is a simple way to accomplish the same thing that I haven't though of.
I basically need to switch the Controller, the State and the View. HaxeFlixel does this pretty elegantly. Does anyone know how that is accomplished in high level abstraction?