Skip to content

Commit

Permalink
Update to the latest project template and Korge Gradle plugin version…
Browse files Browse the repository at this point in the history
…. Fix tests.
  • Loading branch information
yvolk committed Sep 20, 2020
1 parent 6034e32 commit d8aee0a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 40 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ You can run your tests using Node.JS by calling `jsTest` or in a headless chrome
Using gradle tasks on the terminal:

```bash
./gradlew linkMainDebugExecutableMacosX64 # Outputs to /build/bin/macosX64/mainDebugExecutable/main.kexe
./gradlew linkMainDebugExecutableLinuxX64 # Outputs to /build/bin/linuxX64/mainDebugExecutable/main.kexe
./gradlew linkMainDebugExecutableMingwX64 # Outputs to /build/bin/mingwX64/mainDebugExecutable/main.exe
./gradlew linkDebugExecutableMacosX64 # Outputs to /build/bin/macosX64/mainDebugExecutable/main.kexe
./gradlew linkDebugExecutableLinuxX64 # Outputs to /build/bin/linuxX64/mainDebugExecutable/main.kexe
./gradlew linkDebugExecutableMingwX64 # Outputs to /build/bin/mingwX64/mainDebugExecutable/main.exe
```

Note that windows executables doesn't have icons bundled.
Expand All @@ -66,8 +66,8 @@ If you have docker installed, you can generate native executables for linux and
using the cross-compiling gradle wrappers:

```bash
./gradlew_linux linkMainDebugExecutableLinuxX64 # Outputs to /build/web
./gradlew_win linkMainDebugExecutableMingwX64 # Outputs to /build/web
./gradlew_linux linkDebugExecutableLinuxX64 # Outputs to /build/web
./gradlew_win linkDebugExecutableMingwX64 # Outputs to /build/web
```

### Generating MacOS `.app`
Expand Down
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import com.soywiz.korge.gradle.*

buildscript {
val korgePluginVersion: String by project

repositories {
mavenLocal()
maven { url = uri("https://dl.bintray.com/korlibs/korlibs") }
maven { url = uri("https://plugins.gradle.org/m2/") }
mavenCentral()
google()
}
dependencies {
classpath("com.soywiz.korlibs.korge.plugins:korge-gradle-plugin:$korgePluginVersion")
classpath("com.soywiz.korlibs.korge.plugins:korge-gradle-plugin:1.15.0.0")
}
}

Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
korgePluginVersion=1.13.8.0
org.gradle.jvmargs=-Xmx2g
korgeVersion=1.13.5
29 changes: 12 additions & 17 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -175,14 +175,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
3 changes: 3 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

Expand Down
26 changes: 15 additions & 11 deletions src/commonMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import com.soywiz.korma.geom.*
import com.soywiz.korma.geom.vector.*
import com.soywiz.korma.interpolation.*
import kotlin.collections.set
import kotlin.properties.Delegates
import kotlin.random.*

var font: BitmapFont? = null
var font: BitmapFont by Delegates.notNull()
var fieldSize: Double = 0.0
var cellSize: Double = 0.0
var leftIndent: Double = 0.0
Expand All @@ -29,14 +30,14 @@ fun columnX(number: Int) = leftIndent + 10 + (cellSize + 10) * number
fun rowY(number: Int) = topIndent + 10 + (cellSize + 10) * number

var map = PositionMap()
val history = History(NativeStorage.getOrNull("history")) { NativeStorage["history"] = it.toString() }
var history: History by Delegates.notNull()
val blocks = mutableMapOf<Int, Block>()

fun numberFor(blockId: Int) = blocks[blockId]!!.number
fun deleteBlock(blockId: Int) = blocks.remove(blockId)!!.removeFromParent()

val score = ObservableProperty(0)
val best = ObservableProperty(NativeStorage.getOrNull("best")?.toInt() ?: 0)
val best = ObservableProperty(0)

var freeId = 0
var animationRunning = false
Expand All @@ -45,11 +46,14 @@ var isGameOver = false
suspend fun main() = Korge(width = 480, height = 640, title = "2048", bgcolor = RGBA(253, 247, 240)) {
font = resourcesVfs["clear_sans.fnt"].readBitmapFont()

val storage = NativeStorage(views)
history = History(storage.getOrNull("history")) { storage["history"] = it.toString() }
best.update(storage.getOrNull("best")?.toInt() ?: 0)
score.observe {
if (it > best.value) best.update(it)
}
best.observe {
NativeStorage["best"] = it.toString()
storage["best"] = it.toString()
}

cellSize = views.virtualWidth / 5.0
Expand All @@ -74,17 +78,17 @@ suspend fun main() = Korge(width = 480, height = 640, title = "2048", bgcolor =
val bgLogo = roundRect(cellSize, cellSize, 5.0, color = RGBA(237, 196, 3)) {
position(leftIndent, 30.0)
}
text("2048", cellSize * 0.5, Colors.WHITE, font!!).centerOn(bgLogo)
text("2048", cellSize * 0.5, Colors.WHITE, font).centerOn(bgLogo)

val bgBest = roundRect(cellSize * 1.5, cellSize * 0.8, 5.0, color = Colors["#bbae9e"]) {
alignRightToRightOf(bgField)
alignTopToTopOf(bgLogo)
}
text("BEST", cellSize * 0.25, RGBA(239, 226, 210), font!!) {
text("BEST", cellSize * 0.25, RGBA(239, 226, 210), font) {
centerXOn(bgBest)
alignTopToTopOf(bgBest, 5.0)
}
text(best.value.toString(), cellSize * 0.5, Colors.WHITE, font!!) {
text(best.value.toString(), cellSize * 0.5, Colors.WHITE, font) {
setTextBounds(Rectangle(0.0, 0.0, bgBest.width, cellSize - 24.0))
format = format.copy(align = Html.Alignment.MIDDLE_CENTER)
alignTopToTopOf(bgBest, 12.0)
Expand All @@ -98,11 +102,11 @@ suspend fun main() = Korge(width = 480, height = 640, title = "2048", bgcolor =
alignRightToLeftOf(bgBest, 24.0)
alignTopToTopOf(bgBest)
}
text("SCORE", cellSize * 0.25, RGBA(239, 226, 210), font!!) {
text("SCORE", cellSize * 0.25, RGBA(239, 226, 210), font) {
centerXOn(bgScore)
alignTopToTopOf(bgScore, 5.0)
}
text(score.value.toString(), cellSize * 0.5, Colors.WHITE, font!!) {
text(score.value.toString(), cellSize * 0.5, Colors.WHITE, font) {
setTextBounds(Rectangle(0.0, 0.0, bgScore.width, cellSize - 24.0))
format = format.copy(align = Html.Alignment.MIDDLE_CENTER)
centerXOn(bgScore)
Expand Down Expand Up @@ -299,7 +303,7 @@ fun Animator.animateScale(block: Block) {
}

fun Container.showGameOver(onRestart: () -> Unit) = container {
val format = TextFormat(RGBA(0, 0, 0), 40, Html.FontFace.Bitmap(font!!))
val format = TextFormat(RGBA(0, 0, 0), 40, Html.FontFace.Bitmap(font))
val skin = TextSkin(
normal = format,
over = format.copy(RGBA(90, 90, 90)),
Expand All @@ -318,7 +322,7 @@ fun Container.showGameOver(onRestart: () -> Unit) = container {
roundRect(0, 0, fieldSize, fieldSize, 5, 5)
}
}
text("Game Over", 60.0, Colors.BLACK, font!!) {
text("Game Over", 60.0, Colors.BLACK, font) {
centerBetween(0, 0, fieldSize, fieldSize)
y -= 60
}
Expand Down
3 changes: 1 addition & 2 deletions src/commonTest/kotlin/PositionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ class PositionTest {

private fun checkMap(direction: Direction, oldMapArray: IntArray, newMapArray: IntArray) {
val oldMap = PositionMap(IntArray2(4, 4, oldMapArray))
val newMap = PositionMap()
val moves = mutableListOf<Pair<Int, Position>>()
val merges = mutableListOf<Triple<Int, Int, Position>>()
calculateNewMap(oldMap, newMap, direction, moves, merges)
val newMap = calculateNewMap(oldMap, direction, moves, merges)
assertEquals(PositionMap(IntArray2(4, 4, newMapArray)), newMap)
}
}

0 comments on commit d8aee0a

Please sign in to comment.