Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Code cleanup.

  • Loading branch information...
commit 75a7e256e0bd2d8dc0e6f77e9b58e98bc771f11e 1 parent f985eca
@fversnel authored
View
11 src/main/scala/org/frankversnel/poortjes/common/entity_manager.scala
@@ -21,7 +21,7 @@ class EntityManager private(val renderer: Renderer) extends Logging {
def spawn(newGameObject: GameObject) {
_gameObjects ::= newGameObject
- onGameObjectAndChildren(newGameObject) { gameObject =>
+ newGameObject.onGameObjectAndChildren { gameObject =>
val component = gameObject.asInstanceOf[Component]
componentManagers.foreach(_.addComponent(component))
}
@@ -39,18 +39,11 @@ class EntityManager private(val renderer: Renderer) extends Logging {
_gameObjects = _gameObjects.filterNot(g => destroyedGameObjects.contains(g))
destroyedGameObjects.foreach { destroyedGameObject =>
- onGameObjectAndChildren(destroyedGameObject) { gameObject =>
+ destroyedGameObject.onGameObjectAndChildren { gameObject =>
componentManagers.foreach(_.removeComponent(gameObject.asInstanceOf[Component]))
}
}
}
-
- private def onGameObjectAndChildren(gameObject: GameObject)(apply: GameObject => Unit) {
- apply(gameObject)
- gameObject.children.foreach { childGameObject =>
- onGameObjectAndChildren(childGameObject)(apply)
- }
- }
}
object EntityManager {
var entityManager: Option[EntityManager] = None
View
5 src/main/scala/org/frankversnel/poortjes/common/game_object.scala
@@ -31,4 +31,9 @@ abstract class GameObject {
private def addChild(child: GameObject) {
_children = child :: _children
}
+
+ def onGameObjectAndChildren(apply: GameObject => Unit) {
+ apply(this)
+ children.foreach(_.onGameObjectAndChildren(apply))
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.