Skip to content

Commit

Permalink
Fix issue 1 and issue 2 - getGroup and registerEntityToGroup created
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Hahn committed Feb 9, 2014
1 parent 8342ae3 commit 1f5b651
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
20 changes: 19 additions & 1 deletion crane/src/main/scala/crane/World.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class World(var delta: Int=1) {
}
}

/** Get Group
*
* @param group the group to get as a string
*/
def getGroup(group: String): ArrayBuffer[Entity] = { groups(group) }

// Mutators

/** Adds entity to world
Expand Down Expand Up @@ -106,13 +112,25 @@ class World(var delta: Int=1) {
groups(group) = new ArrayBuffer[Entity]
}

/** Registers entity to group
*
* @param entity the Entity to add
* @param group the group name as a string
*/
def registerEntityToGroup(entity: Entity, group: String): ArrayBuffer[Entity] = {
if(!(groups.keys.toList contains group)){
createGroup(group)
}
groups(group) += entity
}

/** Removes specific entity from world
*
* @param entity the Entity to remove
* @param second boolean signifying that the Entity has initialized this call - you should not need to use this
*/
def removeEntity(entity: Entity, second: Boolean = false){
if(_entities contains entity){
if(_entities contains entity) {
if(second) {
for(group <- groups) {
if(group._2 contains entity)
Expand Down
10 changes: 6 additions & 4 deletions project/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ object CraneBuild extends Build {

lazy val root = Project(id ="root",
base = file("."),
settings = defaultSettings ++ compileJdk7Settings ++ Seq(
settings = defaultSettings ++ Unidoc.settings ++ Seq(
Unidoc.unidocExclude := Seq(examples.id),
mainClass in (Compile, run) := Some("crane.examples.Example")
)) dependsOn(crane, examples)
)) aggregate(crane) dependsOn(examples)

lazy val crane = Project(id = "crane",
base = file("crane"),
settings = defaultSettings ++ compileJdk7Settings ++ Seq(
libraryDependencies ++= Dependencies.crane))
scalacOptions in (Compile, doc) ++= Seq("-doc-root-content", baseDirectory.value+"/root-doc.html"),
libraryDependencies ++= Dependencies.crane))

lazy val examples = Project(id = "crane-examples",
base = file("crane-examples"),
settings = defaultSettings ++ compileJdk7Settings ++ Seq(
libraryDependencies ++= Dependencies.examples)) dependsOn(crane)
libraryDependencies ++= Dependencies.examples)) dependsOn(crane)

}

Expand Down
4 changes: 4 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven"

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.3.0")

addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.3.0")
54 changes: 54 additions & 0 deletions project/unidoc.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// From: https://github.com/akka/akka/blob/master/project/Unidoc.scala
// and https://github.com/twitter/finagle/tree/master/project

import sbt._
import sbt.Keys._
import sbt.Project.Initialize

object Unidoc {
val unidocDirectory = SettingKey[File]("unidoc-directory")
val unidocExclude = SettingKey[Seq[String]]("unidoc-exclude")
val unidocAllSources = TaskKey[Seq[Seq[File]]]("unidoc-all-sources")
val unidocSources = TaskKey[Seq[File]]("unidoc-sources")
val unidocAllClasspaths = TaskKey[Seq[Classpath]]("unidoc-all-classpaths")
val unidocClasspath = TaskKey[Seq[File]]("unidoc-classpath")
val unidoc = TaskKey[File]("unidoc", "Create unified scaladoc for all aggregates")

lazy val settings = Seq(
unidocDirectory <<= crossTarget / "unidoc",
unidocExclude := Seq.empty,
unidocAllSources <<= (thisProjectRef, buildStructure, unidocExclude) flatMap allSources,
unidocSources <<= unidocAllSources map { _.flatten },
unidocAllClasspaths <<= (thisProjectRef, buildStructure, unidocExclude) flatMap allClasspaths,
unidocClasspath <<= unidocAllClasspaths map { _.flatten.map(_.data).distinct },
unidoc <<= unidocTask
)

def allSources(projectRef: ProjectRef, structure: Load.BuildStructure, exclude: Seq[String]): Task[Seq[Seq[File]]] = {
val projects = aggregated(projectRef, structure, exclude)
projects flatMap { sources in Compile in LocalProject(_) get structure.data } join
}

def allClasspaths(projectRef: ProjectRef, structure: Load.BuildStructure, exclude: Seq[String]): Task[Seq[Classpath]] = {
val projects = aggregated(projectRef, structure, exclude)
projects flatMap { dependencyClasspath in Compile in LocalProject(_) get structure.data } join
}

def aggregated(projectRef: ProjectRef, structure: Load.BuildStructure, exclude: Seq[String]): Seq[String] = {
val aggregate = Project.getProject(projectRef, structure).toSeq.flatMap(_.aggregate)
aggregate flatMap { ref =>
if (exclude contains ref.project) Seq.empty
else ref.project +: aggregated(ref, structure, exclude)
}
}

def unidocTask: Initialize[Task[File]] = {
(compilers, cacheDirectory, unidocSources, unidocClasspath, unidocDirectory, scalacOptions in doc, streams) map {
(compilers, cache, sources, classpath, target, options, s) => {
val scaladoc = new Scaladoc(100, compilers.scalac)
scaladoc.cached(cache / "unidoc", "main", sources, classpath, target, options, s.log)
target
}
}
}
}

0 comments on commit 1f5b651

Please sign in to comment.