Skip to content

Commit

Permalink
include android in the multibuild file
Browse files Browse the repository at this point in the history
  • Loading branch information
regb committed Nov 12, 2016
1 parent be22faf commit ad76293
Show file tree
Hide file tree
Showing 17 changed files with 225 additions and 27 deletions.
1 change: 0 additions & 1 deletion android/project/build.properties

This file was deleted.

1 change: 0 additions & 1 deletion android/project/plugins.sbt

This file was deleted.

4 changes: 2 additions & 2 deletions android/src/main/scala/sgl/android/AndroidApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import util._

trait AndroidApp extends GameApp
with AndroidGraphicsProvider with AndroidInputProvider with AndroidAudioProvider
with AndroidWindowProvider with GameLoopComponent
with AndroidSystemProvider with GameScreensComponent {
with AndroidWindowProvider with ThreadBasedGameLoopProvider
with AndroidSystemProvider with GameStateComponent {

this: LoggingProvider =>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.google.firebase.analytics._
import _root_.android.os.Bundle

trait FirebaseAnalyticsProvider extends AnalyticsProvider with Lifecycle {
this: GameScreensComponent with AndroidWindowProvider =>
this: GameStateComponent with AndroidWindowProvider =>

private var firebaseAnalytics: FirebaseAnalytics = null

Expand Down
64 changes: 56 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
val scalaVer = "2.12.0"

lazy val root = (project in file("."))
.settings(name := "sgl")
.aggregate(coreJVM, coreJS, desktopAWT, html5)

lazy val commonSettings = Seq(
version := "0.0.1",
scalaVersion := scalaVer,
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
)

lazy val jvmSettings = Seq(
exportJars := true
)
lazy val root = (project in file("."))
.settings(
name := "sgl",
sourcesInBase := false
)
.settings(commonSettings: _*)
.aggregate(coreJVM, coreJS, coreAndroid, desktopAWT, html5, android)


lazy val core = (crossProject.crossType(CrossType.Pure) in file("./core"))
.settings(commonSettings: _*)
.settings(name := "sgl-core")
.jvmSettings(jvmSettings: _*)

lazy val coreJVM = core.jvm
lazy val coreJS = core.js
Expand All @@ -40,3 +40,51 @@ lazy val html5 = (project in file("./html5"))
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.1"
)
.dependsOn(coreJS)


//Android cannot run on Java8 so we stick with 2.11. We
//need to build core separately for the right version

val scalaAndroidVer = "2.11.8"

val commonAndroidSettings = Seq(
scalaVersion := scalaAndroidVer,
scalacOptions += "-target:jvm-1.7",
javacOptions ++= Seq("-source", "1.7", "-target", "1.7"),
exportJars := true
)

lazy val coreAndroid = (project in file("./core"))
.settings(commonSettings: _*)
.settings(commonAndroidSettings: _*)
.settings(
name := "sgl-core",
target := baseDirectory.value / ".android" / "target"
)


lazy val android = (project in file("./android"))
.enablePlugins(AndroidLib)
.settings(commonSettings: _*)
.settings(commonAndroidSettings: _*)
.settings(
name := "sgl-android",
libraryDependencies += "com.google.firebase" % "firebase-core" % "9.0.0",
libraryDependencies += "com.google.android.gms" % "play-services-ads" % "9.0.0",
libraryDependencies += "com.google.android.gms" % "play-services-drive" % "9.0.0",
libraryDependencies += "com.google.android.gms" % "play-services-games" % "9.0.0",
libraryDependencies += "com.google.android.gms" % "play-services-plus" % "9.0.0",
useProguard := true,
proguardOptions ++= Seq(
"-dontobfuscate",
"-dontoptimize",
"-keepattributes Signature",
"-dontwarn scala.collection.**", // required from Scala 2.11.3
"-dontwarn scala.collection.mutable.**", // required from Scala 2.11.0
"-ignorewarnings",
"-keep class scala.Dynamic",
"-keep class test.**"
),
platformTarget := "android-23"
)
.dependsOn(coreAndroid)
3 changes: 3 additions & 0 deletions core/src/main/scala/sgl/ThreadBasedGameLoopProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import util._
* The idea is that the game loop component should handle its lifecycle
* via its Lifecycle methods, it would stop running the game loop during
* a pause, and restart it on a resume.
*
* We should probably try to extract this code from the core package,
* since it will not work with some backend such as scalajs (no thread).
*/
trait ThreadBasedGameLoopProvider extends GameLoopProvider with Lifecycle {
self: GraphicsProvider with GameStateComponent with LoggingProvider =>
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/scala/sgl/scene/SceneGraph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ trait SceneGraphComponent {
node.notifyClick(x, y)
}
node.downEvent = None
case _ =>
throw new Exception("Should never reach that point")
}
})

Expand Down
55 changes: 55 additions & 0 deletions examples/test/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.regblanc.sgl.test.android"
android:versionCode="1"
android:versionName="0.1">

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="23" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:label="SGL-Test"
android:isGame="true"
android:hardwareAccelerated="true">

<!--This meta-data tag is required to use Google Play Services.-->
<!--
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
-->

<activity
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="SGL-Test"
android:screenOrientation="portrait"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<!--
<activity android:name="com.jirbo.adcolony.AdColonyOverlay"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity android:name="com.jirbo.adcolony.AdColonyFullscreen"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
<activity android:name="com.jirbo.adcolony.AdColonyBrowser"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
-->

</application>

</manifest>
27 changes: 27 additions & 0 deletions examples/test/android/src/main/scala/MainActivity.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.regblanc.sgl
package test.android

import android.app.Activity
import android.os.Bundle

import sgl._
import sgl.android._
import test.core._
import sgl.util._

class MainActivity extends DefaultGameActivity {
override def onCreate(bundle: Bundle) {
gameApp = new SGLTestApp(this)
super.onCreate(bundle)
}
}

/** Wire backend to the App here */
class SGLTestApp(activity: MainActivity)
extends AbstractApp with AndroidApp with NoLoggingProvider with InputHelpersComponent {

override val Fps = Some(40)

override val mainActivity = activity

}
55 changes: 55 additions & 0 deletions examples/test/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ lazy val commonSettings = Seq(

lazy val sglCoreJVM = ProjectRef(file("../.."), "coreJVM")
lazy val sglCoreJS = ProjectRef(file("../.."), "coreJS")
lazy val sglCoreAndroid = ProjectRef(file("../.."), "coreAndroid")
lazy val sglHtml5 = ProjectRef(file("../.."), "html5")
lazy val sglDesktop = ProjectRef(file("../.."), "desktopAWT")
lazy val sglAndroid = ProjectRef(file("../.."), "android")

lazy val core = (crossProject.crossType(CrossType.Pure) in file("./core"))
.settings(commonSettings: _*)
Expand Down Expand Up @@ -38,3 +40,56 @@ lazy val html5 = (project in file("./html5"))
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.1"
)
.dependsOn(sglCoreJS, sglHtml5, coreJS)


//Android cannot run on Java8 so we stick with 2.11. We
//need to build core separately for the right version

val scalaAndroidVer = "2.11.8"


val commonAndroidSettings = Seq(
scalaVersion := scalaAndroidVer,
scalacOptions += "-target:jvm-1.7",
javacOptions ++= Seq("-source", "1.7", "-target", "1.7"),
exportJars := true
)


lazy val coreAndroid = (project in file("./core"))
.settings(commonSettings: _*)
.settings(commonAndroidSettings: _*)
.settings(
name := "sgl-test-core",
target := baseDirectory.value / ".android" / "target"
)
.dependsOn(sglCoreAndroid)

lazy val android = (project in file("./android"))
.enablePlugins(AndroidApp)
.settings(commonSettings: _*)
.settings(commonAndroidSettings: _*)
.settings(
name := "sgl-test-android",
libraryDependencies += "com.google.firebase" % "firebase-core" % "9.0.0",
libraryDependencies += "com.google.android.gms" % "play-services-ads" % "9.0.0",
libraryDependencies += "com.google.android.gms" % "play-services-drive" % "9.0.0",
libraryDependencies += "com.google.android.gms" % "play-services-games" % "9.0.0",
libraryDependencies += "com.google.android.gms" % "play-services-plus" % "9.0.0",
useProguard := true,
proguardOptions ++= Seq(
"-dontobfuscate",
"-dontoptimize",
"-keepattributes Signature",
"-dontwarn scala.collection.**", // required from Scala 2.11.3
"-dontwarn scala.collection.mutable.**", // required from Scala 2.11.0
"-dontwarn android.webkit.**", //required by adcolony
"-dontwarn com.immersion.**", //required by adcolony
"-dontnote com.immersion.**", //required by adcolony
"-ignorewarnings",
"-keep class scala.Dynamic",
"-keep class test.**"
),
platformTarget := "android-23"
)
.dependsOn(sglCoreAndroid, sglAndroid, coreAndroid)
32 changes: 18 additions & 14 deletions examples/test/core/src/main/scala/MainScreen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ trait MainScreenComponent {

class MainScreen extends GameScreen {

private val characterBitmap = loadImageFromResource("character.png")
private val characterBitmap = loadImageFromResource("drawable/character.png")
private val characterFrames = Array(
BitmapRegion(characterBitmap, 0, 0, 48, 68),
BitmapRegion(characterBitmap, 48, 0, 48, 68),
BitmapRegion(characterBitmap, 96, 0, 48, 68),
BitmapRegion(characterBitmap, 144, 0, 48, 68)
BitmapRegion(characterBitmap, 0, 0, dp2px(48), dp2px(68)),
BitmapRegion(characterBitmap, dp2px(48), 0, dp2px(48), dp2px(68)),
BitmapRegion(characterBitmap, dp2px(96), 0, dp2px(48), dp2px(68)),
BitmapRegion(characterBitmap, dp2px(144), 0, dp2px(48), dp2px(68))
)
val characterAnimation = new Animation(200, characterFrames, Animation.Loop)

Expand All @@ -29,31 +29,35 @@ trait MainScreenComponent {

var totalTime: Long = 0
override def update(dt: Long): Unit = {
InputHelpers.processEvents(e => println("got event: " + e))

InputHelpers.processEvents(e => e match {
case Input.PointerDownEvent(x, y, _) =>
this.x = x
this.y = y
case _ => ()
})
totalTime += dt

if(Inputs.Keyboard.left) {
x -= 50*(dt/1000d)
x -= dp2px(50)*(dt/1000d)
}
if(Inputs.Keyboard.right) {
x += 50*(dt/1000d)
x += dp2px(50)*(dt/1000d)
}

if(Inputs.Keyboard.up) {
y -= 50*(dt/1000d)
y -= dp2px(50)*(dt/1000d)
}
if(Inputs.Keyboard.down) {
y += 50*(dt/1000d)
y += dp2px(50)*(dt/1000d)
}

autoX += 50*(dt/1000d)
autoY += 50*(dt/1000d)
autoX += dp2px(50)*(dt/1000d)
autoY += dp2px(50)*(dt/1000d)
}

override def render(canvas: Canvas): Unit = {
canvas.drawRect(0, 0, WindowWidth, WindowHeight, defaultPaint.withColor(Color.rgb(204, 242, 204)))
canvas.drawCircle(autoX.toInt, autoY.toInt, 50, defaultPaint.withColor(Color.Black))
canvas.drawCircle(autoX.toInt, autoY.toInt, dp2px(50), defaultPaint.withColor(Color.Black))

canvas.drawBitmap(characterAnimation.currentFrame(totalTime), x.toInt, y.toInt)
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/test/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.13
2 changes: 2 additions & 0 deletions examples/test/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.13")

addSbtPlugin("org.scala-android" % "sbt-android" % "1.7.1")
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.13
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.13")

addSbtPlugin("org.scala-android" % "sbt-android" % "1.7.1")

0 comments on commit ad76293

Please sign in to comment.