shawn42 / gamebox

A game template for building and distributing Gosu apps.
267 stars 29 forks source link

Make actors responsible for adding behavior to themselves #71

Closed jacius closed 12 years ago

jacius commented 12 years ago

The rationale for this is that internal details of the actor (specifically its "this_object_context") are necessary to build a behavior to be used by the actor. So, I think it makes sense that the responsibility for this should rest with the Actor class. Plus, this makes the Actor API more logical and useful. Before, Actor#add_behavior was useless except as an implementation detail used by BehaviorFactory.

In practical terms, these commits shift all the work from the BehaviorFactory class into the Actor#add_behavior and Actor#build_behavior methods (build_behavior is a newly added method). As a result, the BehaviorFactory class is obsolete, but I have retained it for backward compatibility. BehaviorFactory#add_behavior now just calls Actor#add_behavior.

P.S. There are 3 pending Actor specs that I couldn't figure out how to make work, because of the unusual conjecting and mocking going on with actors in the specs.

shawn42 commented 12 years ago

This functionality lives in all Behaviors; #add_behavior and #remove_behavior can be called from any behavior.