Linking Views to Models

SamPotasz's Avatar

SamPotasz

06 Jan, 2012 04:30 PM

Hi all,

I'm making a game in Flash Pro & Flash Builder, and I've recently started playing around with RobotLegs. It seems great for handling some of my higher-level communication, and I'm wondering if it's possible to use it for my in-game communication. In games, a View is essentially the on-screen representation of a single Model instance so what's what's the best RobotLegs setup for linking the View and Model instances?

Let's say our game consists of simple clickable Goombas. A Goomba starts out with 10 Health, and each time you click on one of these mushroom baddies, it loses one health. When you rollover a Goomba its health is displayed at the top of the screen.

My interpretation of the "RL way" to do this:

GoombaView, GoombaMediator, GoombaModel, ClickGoombaCommand, RolloverGoombaCommand, ClickGoombaSignal, and RolloverGoombaSignal classes.

The mediator dispatches signals on clicks and rollovers which then execute corresponding commands. ClickGoombaCommand needs to have a GoombaModel injected into it so that on its execute(), it can say, model.decrementHealth(). This injection happens when the signal is dispatched, which is in the Mediator.

Similarly, on a rollover, I'd want my Mediator to dispatch a Signal like:
RolloverGoombaSignal.dispatch( 7 )
and that 7 would need come from the same model that gets referenced on a click.

So, it seems there is no way to do this without having a reference to a Model in my Mediator - something that is highly inadvisable :\

Am I missing something here, or is it just the nature of the project that these views are in fact not very modular and so it's no big deal if the mediators reference a Model?

  1. Support Staff 1 Posted by creynders on 07 Jan, 2012 10:24 AM

    creynders's Avatar

    First and foremost, RL is not really intended to be used for such detail implementations as you describe. Shaun just wrote an excellent explanation on another thread here:
    http://knowledge.robotlegs.org/discussions/questions/767-why-comman...

    Second: injecting models into mediators is perfectly acceptable if you're using a presentation model pattern (which you are). There's a direct correlation between GoombaView and GoombaModel, in the sense that a specific GoombaModel instance holds the state of a specific GoombaView instance. In this case the model is not an aggregated collection of data from several sources or will not be used for anything else than keeping state of a GoombaView instance. In other words the view and the model are conceptually tightly coupled anyway.

    But as Shaun wrote in the link I gave, the application framework should not be dragged into such low-level implementations.
    In your example all logic and state is split up into the various views, mediators, commands, etc. while actually it's all view logic and view state and shouldn't involve the framework at all.

  2. Ondina D.F. closed this discussion on 23 Feb, 2012 10:33 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac