Skip to content

Commit

Permalink
Some build cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinorg committed May 14, 2022
1 parent ce6edfe commit dfa14ed
Show file tree
Hide file tree
Showing 26 changed files with 265 additions and 174 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*.war
*.ear
hs_err_pid*
keystore.properties
test.jks
*.jks
.java-version

## Robovm
/ios/robovm-build/
Expand Down Expand Up @@ -95,6 +95,7 @@ nb-configuration.xml
## Gradle

/local.properties
/keystore.properties
.gradle/
gradle-app.setting
/build/
Expand Down
77 changes: 67 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,34 @@ for contemporary mobile and game development. Based loosely on a
The code is horrid and shameful. It contains state and mutation, inconsistencies,
aberrations and general travesties. Nothing is nice here.

At the time of writing this uses JDK 11, Scala 2.13.8, libgdx 1.11.0 and Android SDK 30.
At the time of writing this was built with JDK 17, Scala 2.13.8, libgdx 1.11.0
and Android SDK 29.

## Install the Android SDK command-line tools

Before building this you need to install the Android SDK command-line tools, even
if you're just building the Desktop version.

* Go to the [Android Studio](https://developer.android.com/studio#command-tools) Website
and witness the command line tools.

* Then decide to just use [Homebrew](https://brew.sh/):

```shell
brew install android-commandlinetools
```

* Then install the build tools and platforms (while agreeing to sell your firstborn):

```shell
sdkmanager 'platforms;android-29' 'build-tools;29.0.2' tools
```

* Create a file `local.properties`:

```properties
sdk.dir=/opt/homebrew/share/android-commandlinetools/
```

## Building for the desktop

Expand Down Expand Up @@ -42,6 +69,27 @@ java -jar desktop/build/libs/desktop-0.1.jar
java -XstartOnFirstThread -jar desktop/build/libs/desktop-0.1.jar
```

### Packaging for a Mac

On the Mac you need an icon. See [this answer](https://stackoverflow.com/a/20703594) for incantations.

With this and JDK 17 installed:

```shell
export JAVA_HOME=/path/to/java/17
jpackage \
--input desktop/build/libs/ \
--name Tertis \
--app-version 1.0 \
--main-jar desktop-0.1.jar \
--main-class org.merlin.tertis.DesktopLauncher \
--type dmg \
--java-options '-XstartOnFirstThread' \
--icon mac/Tertis.icns
```

Yielding: `Tertis-1.0.dmg`. Version 0 is not allowed.

## Building for Android

* Get a keystore.
Expand All @@ -58,7 +106,7 @@ storeFile=<file>
* Build it:

```shell
./gradlew assemble
./gradlew android:assemble
```

* Achieve a result:
Expand All @@ -69,17 +117,26 @@ android/build/outputs/apk/release/android-release.apk

* See also the [Android docs](https://developer.android.com/studio/build/building-cmdline).

### Running in the Android emulator

It's probably easiest to just fire up IntelliJ, select the android run configuration, use the
AVD Manager UI to create a Pixel 5 device running Android 11 and be done.


## License

[Apache License, Version 2.0](LICENSE.md)

## Credits

1. assets/click.mp3 - https://freesound.org/people/JonnyRuss01/sounds/478197/
2. assets/drop.mp3 - https://freesound.org/people/TampaJoey/sounds/588502/
3. assets/crash.mp3 - https://freesound.org/people/timgormly/sounds/170958/
4. assets/triangle.mp3 - https://freesound.org/people/acclivity/sounds/31189/
5. assets/gong.mp3 - https://freesound.org/people/josemaria/sounds/55438/
6. assets/OpenSans-Regular.ttf - https://fonts.google.com/specimen/Open+Sans
7. assets/tap.png - https://www.iconfinder.com/icons/446301/finger_gesture_hand_interactive_scroll_swipe_tap_icon
8. the raised fist - https://en.wikipedia.org/wiki/Raised_fist#/media/File:Fist_.svg
1. Audio editing with [Audacity](https://www.audacityteam.org/)
2. Vector editing with [Inkscape](https://inkscape.org/)
3. Pixel editing with [Gimp](https://www.gimp.org/)
4. The raised fist - https://en.wikipedia.org/wiki/Raised_fist#/media/File:Fist_.svg
5. `assets/click.mp3` - https://freesound.org/people/JonnyRuss01/sounds/478197/
6. `assets/drop.mp3` - https://freesound.org/people/TampaJoey/sounds/588502/
7. `assets/crash.mp3` - https://freesound.org/people/timgormly/sounds/170958/
8. `assets/triangle.mp3` - https://freesound.org/people/acclivity/sounds/31189/
9. `assets/gong.mp3` - https://freesound.org/people/josemaria/sounds/55438/
10. `assets/OpenSans-Regular.ttf` - https://fonts.google.com/specimen/Open+Sans
11. `assets/tap.png` - https://www.iconfinder.com/icons/446301/finger_gesture_hand_interactive_scroll_swipe_tap_icon
4 changes: 3 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
signingConfigs {
Expand Down
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ buildscript {
classpath 'org.wisepersist:gwt-gradle-plugin:1.1.16'
classpath 'org.gretty:gretty:3.0.7'
classpath 'com.android.tools.build:gradle:7.0.4'


// IntelliJ 2022.1 doesn't support 7.1.3 or 7.2.0
// https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
}
}


allprojects {
apply plugin: "eclipse"

Expand Down
15 changes: 9 additions & 6 deletions core/src/org/merlin/tertis/Geometry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import com.badlogic.gdx.Gdx
object Geometry {
val Columns = 10
val Rows = 20

val ScreenWidth: Float = Gdx.graphics.getWidth.toFloat
val ScreenHeight: Float = Gdx.graphics.getHeight.toFloat
// dimension of one block
val Dimension: Int =
(Gdx.graphics.getWidth * 2 / (Columns * 2 + 1)) min (Gdx.graphics.getHeight * 2 / (Rows * 2 + 5))
val OffsetX: Int = (Gdx.graphics.getWidth - Dimension * Columns) / 2
val OffsetY: Int =
(Gdx.graphics.getHeight - Dimension * (Rows + 2) + Dimension / 2) / 2
val Bevel: Int = (Dimension / 50) max 1
val Dimension: Float =
((ScreenWidth * 2 / (Columns * 2 + 1)) min (ScreenHeight * 2 / (Rows * 2 + 5))).floor
val OffsetX: Float = ((ScreenWidth - Dimension * Columns) / 2).floor
val OffsetY: Float =
((ScreenHeight - Dimension * (Rows + 2) + Dimension / 2) / 2).floor
val Bevel: Float = (Dimension / 48).floor max 1

}
20 changes: 8 additions & 12 deletions core/src/org/merlin/tertis/Text.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package org.merlin.tertis
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator
import com.badlogic.gdx.graphics.g2d.{
BitmapFont,
GlyphLayout,
PolygonSpriteBatch
}
import com.badlogic.gdx.graphics.g2d.{BitmapFont, GlyphLayout, PolygonSpriteBatch}
import org.merlin.tertis.Geometry.Dimension
import org.merlin.tertis.home.Home

Expand All @@ -18,13 +14,13 @@ object Text {
)
val parameter = new FreeTypeFontGenerator.FreeTypeFontParameter
parameter.characters = FreeTypeFontGenerator.DEFAULT_CHARS + CharExtras
parameter.size = Dimension
parameter.size = Dimension.toInt
bigFont = generator.generateFont(parameter)
parameter.size = Dimension * 3 / 4
parameter.size = (Dimension * 3 / 4).toInt
mediumFont = generator.generateFont(parameter)
parameter.size = Dimension * 9 / 16
parameter.size = (Dimension * 9 / 16).toInt
smallFont = generator.generateFont(parameter)
parameter.size = Dimension * 3 / 8
parameter.size = (Dimension * 3 / 8).toInt
tinyFont = generator.generateFont(parameter)
generator.dispose()
}
Expand All @@ -42,11 +38,11 @@ object Text {
color: Color,
text: String,
y: Float,
x: Float = 0,
width: Float = Gdx.graphics.getWidth
x: Float = 0f,
width: Float = Geometry.ScreenWidth
): Unit = {
font.setColor(color)
font.draw(batch, text, x, y, width, 1, false)
font.draw(batch, text, x, y, width, CenterAlign, false)
}

def draw(
Expand Down
23 changes: 11 additions & 12 deletions core/src/org/merlin/tertis/common/Frame.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.merlin.tertis.common

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Gdx.graphics
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
import com.badlogic.gdx.math.Rectangle
import org.merlin.tertis.Geometry
import org.merlin.tertis.Geometry._
import org.merlin.tertis.Tertis.pixture

Expand All @@ -21,12 +20,12 @@ object Frame {
alpha = (alpha - delta / FadeSpeedSeconds) max 0f
}

val offsetY = (OffsetY * alpha).toInt
val offsetX = (OffsetX * alpha).toInt
val offsetY = OffsetY * alpha
val offsetX = OffsetX * alpha
val width =
Gdx.graphics.getWidth * (1f - alpha) + Columns * Dimension * alpha
Geometry.ScreenWidth * (1f - alpha) + Columns * Dimension * alpha
val height =
Gdx.graphics.getHeight * (1f - alpha) + Rows * Dimension * alpha
Geometry.ScreenHeight * (1f - alpha) + Rows * Dimension * alpha
frame.set(offsetX, offsetY, width, height)
}

Expand All @@ -36,29 +35,29 @@ object Frame {
pixture,
0,
0,
graphics.getWidth,
Geometry.ScreenWidth,
frame.y
)
batch.draw(
pixture,
0,
frame.y + frame.height,
graphics.getWidth,
graphics.getHeight - frame.y - frame.height
Geometry.ScreenWidth,
Geometry.ScreenHeight - frame.y - frame.height
)
batch.draw(
pixture,
0,
0,
frame.x,
graphics.getHeight
Geometry.ScreenHeight
)
batch.draw(
pixture,
frame.x + frame.width,
0,
graphics.getWidth - frame.x - frame.width,
graphics.getHeight
Geometry.ScreenWidth - frame.x - frame.width,
Geometry.ScreenHeight
)
Starfield.renderOnFrame(batch)
GreyColour.a = alpha
Expand Down
12 changes: 5 additions & 7 deletions core/src/org/merlin/tertis/common/Star.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.merlin.tertis.common

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Gdx.graphics
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
import com.badlogic.gdx.math.{MathUtils, Quaternion, Vector3}
import org.merlin.tertis.Tertis
import org.merlin.tertis.{Geometry, Tertis}

case class Star(
location: Vector3
Expand All @@ -18,7 +16,7 @@ case class Star(
z = rotated.z
x = (rotated.x * ViewerDistance / z + w2).floor
y = (rotated.y * ViewerDistance / z + h2).floor
(z > ViewerDistance) && (x >= 0) && (y >= 0) && (x < Gdx.graphics.getWidth) && (y < Gdx.graphics.getHeight)
(z > ViewerDistance) && (x >= 0) && (y >= 0) && (x < Geometry.ScreenWidth) && (y < Geometry.ScreenHeight)
}

def draw(
Expand All @@ -41,9 +39,9 @@ case class Star(
}

object Star {
private val size = (graphics.getWidth / 500f).floor
private val w2 = Gdx.graphics.getWidth * .5f
private val h2 = Gdx.graphics.getHeight * .5f
private val size = (Geometry.ScreenWidth / 500f).floor
private val w2 = Geometry.ScreenWidth * .5f
private val h2 = Geometry.ScreenHeight * .5f
private val ViewerDistance = h2 * 2
val FarDistance = 10 * ViewerDistance

Expand Down
5 changes: 4 additions & 1 deletion core/src/org/merlin/tertis/common/Starfield.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object Starfield {
val NumStars = 256
val FadeInSeconds = 5f

var alpha = 1f
var alpha = 0f

val stars: ListBuffer[Star] = mutable.ListBuffer
.fill(NumStars)(Star.newStar)
Expand Down Expand Up @@ -55,6 +55,9 @@ object Starfield {
stars.prepend(Star.newStar(rotation))
}

// This is all a bit wonky but I switched from stars only within the frame to stars only outside the
// frame to a bit of both...

def render(batch: PolygonSpriteBatch): Unit = {
renderImpl(batch, within = true)
}
Expand Down
Loading

0 comments on commit dfa14ed

Please sign in to comment.