diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5e5f0f2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,44 @@ +matrix: + include: + - os: linux + language: java + jdk: oraclejdk8 + env: KBUILD=linux + install: + - nvm install 8 + - nvm use 8 + - node --version + - npm -g install mocha + - which node + - which mocha + script: + - ./gradlew -s -i check build + - os: windows + env: KBUILD=windows + language: shell # java is not supported but jdk is installed + script: + - powershell -Command "cmd /c travis_win.bat" + - os: osx + env: KBUILD=macos + language: java + jdk: oraclejdk8 + install: + - nvm install 8 + - nvm use 8 + - node --version + - npm -g install mocha + - which node + - which mocha + script: + - ./gradlew -s -i check build + +#before_cache: +# - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock +# - rm -f $HOME/.gradle-linux/caches/modules-2/modules-2.lock +# - rm -f $HOME/.gradle-win/caches/modules-2/modules-2.lock +# +#cache: +# directories: +# - $HOME/.gradle/caches/ +# - $HOME/.gradle/wrapper/ +# - $HOME/.konan diff --git a/build.gradle b/build.gradle index 0286ecc..85973e9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,115 +1,201 @@ -buildscript { - repositories { - mavenLocal() - maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2' } - mavenCentral() - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" - classpath "com.soywiz:korge-gradle-plugin:$korVersion" - } - - ext { - libraries = [ - kotlin_stdlib_common: "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", - kotlin_stdlib_jvm : "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", - kotlin_stdlib_js : "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", - - kotlin_test_common : "org.jetbrains.kotlin:kotlin-test-common:$kotlinVersion", - kotlin_test_jvm : "org.jetbrains.kotlin:kotlin-test:$kotlinVersion", - kotlin_test_js : "org.jetbrains.kotlin:kotlin-test-js:$kotlinVersion", - - kotlin_reflect : "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion", - ] - } -} - -configurations { - provided +plugins { + id 'kotlin-multiplatform' version '1.3.0-rc-146' + id 'com.moowork.node' version '1.2.0' } allprojects { - configurations { - provided - } - repositories { mavenLocal() + maven { url "https://dl.bintray.com/soywiz/soywiz" } + maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } jcenter() - maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2' } mavenCentral() } - it.afterEvaluate { - if (it.plugins.hasPlugin("kotlin-platform-common")) { - dependencies { - compile libraries.kotlin_stdlib_common - testCompile libraries.kotlin_test_common - } +} - kotlin { - experimental { coroutines 'enable' } - } - } - if (it.plugins.hasPlugin("kotlin-platform-jvm") || it.plugins.hasPlugin("kotlin")) { - dependencies { - compile libraries.kotlin_stdlib_jvm - testCompile libraries.kotlin_test_jvm - testCompile "junit:junit:4.12" - } +subprojects { + apply plugin: 'kotlin-multiplatform' + apply plugin: 'com.moowork.node' - kotlin { - experimental { coroutines 'enable' } - } - } - if (it.plugins.hasPlugin("kotlin-platform-js") || it.plugins.hasPlugin("kotlin2js")) { - dependencies { - compile libraries.kotlin_stdlib_js - testCompile libraries.kotlin_test_js - } + kotlin { + targets { + //fromPreset(presets.iosX64, 'iosX64') + //fromPreset(presets.iosArm32, 'iosArm32') + //fromPreset(presets.iosArm64, 'iosArm64') + fromPreset(presets.macosX64, 'macosX64') + //fromPreset(presets.linuxX64, 'linuxX64') + fromPreset(presets.mingwX64, 'mingwX64') + fromPreset(presets.jvm, 'jvm') + fromPreset(presets.js, 'js') { + compilations.main { + compileKotlinJs.kotlinOptions { + languageVersion = "1.3" + sourceMap = true + metaInfo = true + moduleKind = "umd" + } + compileTestKotlinJs.kotlinOptions { + languageVersion = "1.3" + moduleKind = "commonjs" + } + } + } + } + sourceSets { + nonNativeCommonMain + nativeCommonMain + nativeCommonTest + nativePosixMain + configure([jvmMain, jsMain]) { + dependsOn nonNativeCommonMain + } + mingwX64Main { + dependsOn nativeCommonMain + } + mingwX64Test { + dependsOn nativeCommonTest + } + //configure([iosX64Main, iosArm32Main, iosArm64Main, macosX64Main, linuxX64Main]) { + configure([macosX64Main]) { + dependsOn nativeCommonMain + dependsOn nativePosixMain + } + //configure([iosX64Test, iosArm32Test, iosArm64Test, macosX64Test, linuxX64Test]) { + configure([macosX64Test]) { + dependsOn nativeCommonTest + } + } + } - kotlin { - experimental { coroutines 'enable' } - } + dependencies { + commonMainImplementation "org.jetbrains.kotlin:kotlin-stdlib-common" + commonTestImplementation "org.jetbrains.kotlin:kotlin-test-annotations-common" + commonTestImplementation "org.jetbrains.kotlin:kotlin-test-common" - compileKotlin2Js { - kotlinOptions.moduleKind = "umd" - kotlinOptions.sourceMap = true - } + jsMainImplementation "org.jetbrains.kotlin:kotlin-stdlib-js" + jsTestImplementation "org.jetbrains.kotlin:kotlin-test-js" + jvmMainImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + jvmTestImplementation "org.jetbrains.kotlin:kotlin-test" + jvmTestImplementation "org.jetbrains.kotlin:kotlin-test-junit" + } - compileKotlin2Js { - kotlinOptions.outputFile = "${projectDir}/web/output.js" - kotlinOptions.sourceMap = false - } + // Javascript test configuration + node { + version = '8.11.4' + download = true + nodeModulesDir = file("$buildDir/yarn") + } - clean { - delete new File("${projectDir}/web") - } + def jsCompilations = kotlin.targets.js.compilations + task addYarnDeps(type: YarnTask) { + doFirst { + mkdir "$buildDir/yarn" + } + args = ["add", "mocha@5.2.0"] + } - compileKotlin2Js.doLast { - configurations.compile.each { File file -> - copy { - includeEmptyDirs = false + task populateNodeModules { + doLast { + copy { + from "$buildDir/yarn/node_modules" + from jsCompilations.main.output.first() + jsCompilations.test.runtimeDependencyFiles.each { + if (it.exists() && !it.isDirectory()) { + from zipTree(it.absolutePath).matching { include '*.js' } + } + } + into "$buildDir/node_modules" + } + } + } - from zipTree(file.absolutePath) - into "${projectDir}/web" - include { fileTreeElement -> - def path = fileTreeElement.path - (path.endsWith(".js") || path.endsWith(".js.map")) && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/")) - } - } - } + task runMocha(type: NodeTask, dependsOn: [jsCompilations.test.compileKotlinTaskName, addYarnDeps, populateNodeModules]) { + script = file("$buildDir/node_modules/mocha/bin/mocha") + args = [relativePath("${jsCompilations.test.output.first()}/${project.name}_test.js")] + } - copy { - from sourceSets.main.resources.srcDirs - into "${projectDir}/web" - } - } + jsTest.dependsOn runMocha - jar.enabled = false + // Fix for https://github.com/srs/gradle-node-plugin/issues/301 + repositories.whenObjectAdded { + if (it instanceof IvyArtifactRepository) { + metadataSources { + artifact() + } + } + } + // Publishing + group 'com.soywiz' + version projectVersion + apply plugin: 'maven-publish' + + def pomBaseData = { + licenses { + license { + name "MIT License" + url "https://raw.githubusercontent.com/korlibs/korge-samples/master/LICENSE" + } + } + scm { + url "https://github.com/korlibs/korge-samples" + } + } + + def generatePom = { pom -> + pom.withXml { + def root = it.asNode() + root.appendNode('name', project.name) + root.appendNode('description', 'Multiplatform Game Engine written in Kotlin (JVM, JS, Native and COMMON)') + root.appendNode('url', 'https://github.com/korlibs/korge-samples') + root.children().last() + pomBaseData + } + } + + ext.generatePom = generatePom + + def publishUser = rootProject.findProperty('BINTRAY_USER') ?: project.findProperty('bintrayUser') ?: System.getenv('BINTRAY_USER') + def publishPassword = rootProject.findProperty('BINTRAY_KEY') ?: project.findProperty('bintrayApiKey') ?: System.getenv('BINTRAY_API_KEY') + + if (publishUser && publishPassword) { + publishing { + repositories { + maven { + credentials { + username publishUser + password publishPassword + } + url 'https://api.bintray.com/maven/soywiz/soywiz/korlibs/' + //url "https://api.bintray.com/content/soywiz/soywiz/korlibs/$projectVersion" + } + } + + configure(publications) { + generatePom(pom) + } + } + } +} + +apply plugin: 'idea' + +idea { + module { + excludeDirs = [file(".gradle")] + [ + ".idea", + "@old", + "docs", + "korge-samples-build", + "korge-samples-samples", + "korge-samples-intellij-plugin", + "korge-samples-gradle-plugin", + "korge-samples-flash-plugin", + + ].each { + excludeDirs << file("$it") } } } - diff --git a/gradle.properties b/gradle.properties index fd35f04..c4dfe2e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,12 @@ -korVersion=0.14.0 -jtranscVersion=0.6.7 -kotlinVersion=1.2.0-beta-31 -vertxVersion=3.4.2 +# sytleguide +kotlin.code.style=official + +# version +projectVersion=0.0.1-SNAPSHOT + +# external versions +joglVersion=2.3.2 +gluegenVersion=2.3.2 + +# versions +korgeVersion=0.5.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 771a052..91ca28c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1b1cadc..16d2805 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sun Aug 27 17:47:24 CEST 2017 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4453cce..cccdd3d 100644 --- a/gradlew +++ b/gradlew @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -155,7 +155,7 @@ if $cygwin ; then fi # Escape application args -save ( ) { +save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } diff --git a/gradlew_linux b/gradlew_linux new file mode 100755 index 0000000..63c1081 --- /dev/null +++ b/gradlew_linux @@ -0,0 +1,8 @@ +#!/bin/bash +docker run \ + "-v$PWD:/work" \ + "-v$HOME/.gradle-linux:/root/.gradle" \ + "-v$HOME/.m2:/root/.m2" \ + "-v$HOME/.konan:/root/.konan" \ + soywiz/kotlin-native-win \ + ./gradlew $* diff --git a/gradlew_win b/gradlew_win new file mode 100755 index 0000000..689bb0f --- /dev/null +++ b/gradlew_win @@ -0,0 +1,10 @@ +#!/bin/bash +HOME=`echo ~` + +docker run -it \ + "-v$PWD:/work" \ + "-v$HOME/.gradle-win:/root/.wine/drive_c/users/root/.gradle" \ + "-v$HOME/.m2:/root/.wine/drive_c/users/root/.m2" \ + "-v$HOME/.konan:/root/.wine/drive_c/users/root/.konan" \ + soywiz/kotlin-native-win \ + winecmd gradlew.bat $* diff --git a/gradlew_wine b/gradlew_wine new file mode 100755 index 0000000..3e7b0b9 --- /dev/null +++ b/gradlew_wine @@ -0,0 +1,2 @@ +#!/bin/bash +WINEDEBUG=-all wine cmd /c gradlew.bat $* diff --git a/korge-coffee/common/.gitignore b/korge-coffee/common/.gitignore deleted file mode 100644 index 7f99310..0000000 --- a/korge-coffee/common/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources diff --git a/korge-coffee/common/build.gradle b/korge-coffee/common/build.gradle deleted file mode 100644 index 4795301..0000000 --- a/korge-coffee/common/build.gradle +++ /dev/null @@ -1,48 +0,0 @@ -apply plugin: 'kotlin-platform-common' - -//mainClassName = "com.soywiz.korge.games.coffee.KorgeCoffeeModule" - -sourceSets { - //generated.resources.srcDirs = ['src/generated/resources'] - //main.resources.srcDirs = [ 'src/main/resources' ] - main.resources.srcDirs = [ 'src/main/resources', 'src/generated/resources' ] -} - -//sourceSets { -// generated.resources.srcDirs = [ 'genresources' ] -// -// main.kotlin.srcDirs = [ 'src' ] -// main.resources.srcDirs = [ 'resources', 'genresources' ] -// test.kotlin.srcDirs = [ 'test' ] -//} - - -dependencies { - compile "com.soywiz:korge-common:$korVersion" - compile "com.soywiz:korge-ext-swf-common:$korVersion" - compile "com.soywiz:korau-mp3-common:$korVersion" - - //nojtransc "com.soywiz:korge-ext-swf:$korVersion" - //nojtransc "com.soywiz:korau-mp3:$korVersion" -} - -/* -jtransc { - minimizeNames = true - //minimizeNames = false - treeshaking = true - - assets("resources") - assets("genresources") - - skipServiceLoader("com.soywiz.korim.format.JPEG") - skipServiceLoader("com.soywiz.korim.format.PNG") - - skipServiceLoader("com.soywiz.korau.format.MP3") - skipServiceLoader("com.soywiz.korau.format.OGG") -} -*/ - -//jar.enabled = false -//distTar.enabled = false -//distZip.enabled = false diff --git a/korge-coffee/common/settings.gradle b/korge-coffee/common/settings.gradle deleted file mode 100644 index 4d60155..0000000 --- a/korge-coffee/common/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'korge-coffee-common' diff --git a/korge-coffee/common/src/generated/resources/icon.ani b/korge-coffee/common/src/generated/resources/icon.ani deleted file mode 100644 index abc65ba..0000000 Binary files a/korge-coffee/common/src/generated/resources/icon.ani and /dev/null differ diff --git a/korge-coffee/common/src/generated/resources/icon.ani.0.png b/korge-coffee/common/src/generated/resources/icon.ani.0.png deleted file mode 100644 index 1efb014..0000000 Binary files a/korge-coffee/common/src/generated/resources/icon.ani.0.png and /dev/null differ diff --git a/korge-coffee/common/src/generated/resources/icon.ani.meta b/korge-coffee/common/src/generated/resources/icon.ani.meta deleted file mode 100644 index 7331073..0000000 --- a/korge-coffee/common/src/generated/resources/icon.ani.meta +++ /dev/null @@ -1 +0,0 @@ -{"name":"icon.swf","loaderVersion":16,"sha1":"9cdde618c8d67a214d0c8dddcbeec0bd668191ec","configSha1":""} \ No newline at end of file diff --git a/korge-coffee/common/src/generated/resources/main.ani b/korge-coffee/common/src/generated/resources/main.ani deleted file mode 100644 index 2508481..0000000 Binary files a/korge-coffee/common/src/generated/resources/main.ani and /dev/null differ diff --git a/korge-coffee/common/src/generated/resources/main.ani.0.png b/korge-coffee/common/src/generated/resources/main.ani.0.png deleted file mode 100644 index 5eac7eb..0000000 Binary files a/korge-coffee/common/src/generated/resources/main.ani.0.png and /dev/null differ diff --git a/korge-coffee/common/src/generated/resources/main.ani.meta b/korge-coffee/common/src/generated/resources/main.ani.meta deleted file mode 100644 index 2c13376..0000000 --- a/korge-coffee/common/src/generated/resources/main.ani.meta +++ /dev/null @@ -1 +0,0 @@ -{"name":"main.swf","loaderVersion":16,"sha1":"868c170d4f89f18fdcc12f91e731753ec55d3976","configSha1":"56181ca92b60e35d04d35cb4e32175ef5953c435"} \ No newline at end of file diff --git a/korge-coffee/common/src/main/kotlin/com/soywiz/korge/games/coffee/main.kt b/korge-coffee/common/src/main/kotlin/com/soywiz/korge/games/coffee/main.kt deleted file mode 100644 index 6dcacaf..0000000 --- a/korge-coffee/common/src/main/kotlin/com/soywiz/korge/games/coffee/main.kt +++ /dev/null @@ -1,489 +0,0 @@ -package com.soywiz.korge.games.coffee - -import com.soywiz.korge.Korge -import com.soywiz.korge.animate.* -import com.soywiz.korge.bitmapfont.BitmapFont -import com.soywiz.korge.component.docking.jellyButton -import com.soywiz.korge.event.addEventListener -import com.soywiz.korge.input.mouse -import com.soywiz.korge.resources.getPath -import com.soywiz.korge.scene.* -import com.soywiz.korge.service.Browser -import com.soywiz.korge.service.storage.Storage -import com.soywiz.korge.service.storage.item -import com.soywiz.korge.time.TimeSpan -import com.soywiz.korge.time.seconds -import com.soywiz.korge.time.sleep -import com.soywiz.korge.tween.* -import com.soywiz.korge.view.* -import com.soywiz.korim.color.ColorTransform -import com.soywiz.korio.async.AsyncSignal -import com.soywiz.korio.async.Promise -import com.soywiz.korio.async.go -import com.soywiz.korio.inject.AsyncInjector -import com.soywiz.korio.inject.InjectorAsyncDependency -import com.soywiz.korio.inject.Optional -import com.soywiz.korio.inject.Singleton -import com.soywiz.korio.lang.JvmStatic -import com.soywiz.korio.util.closeable -import com.soywiz.korma.geom.Anchor -import com.soywiz.korma.geom.Point2d -import com.soywiz.korma.geom.SizeInt -import com.soywiz.korma.random.MtRand -import com.soywiz.korma.random.get -import kotlin.math.max - -@Suppress("unused") -object KorgeCoffeeModule : Module() { - @JvmStatic - fun main(args: Array) = Korge(KorgeCoffeeModule, injector = AsyncInjector().prepareKoffee()) - - fun AsyncInjector.prepareKoffee() = this.apply { - mapSingleton { Storage() } - mapSingleton { com.soywiz.korge.service.Browser() } - mapSingleton { GameStorage(get(Storage::class)) } - mapSingleton { LibraryContainer() } - mapPrototype { CreditsScene(get(LibraryContainer::class), get(Browser::class), get(GameStorage::class)) } - mapPrototype { MainMenuScene(get(LibraryContainer::class), get(GameStorage::class)) } - mapPrototype { MainScene(get(LibraryContainer::class), getOrNull(com.soywiz.korge.games.coffee.KorgeCoffeeModule.MainScene.State::class), get(GameStorage::class)) } - } - - object MainDebug { - @JvmStatic - fun main(args: Array) = Korge(KorgeCoffeeModule, sceneClass = MainScene::class, injector = AsyncInjector().prepareKoffee(), sceneInjects = listOf(MainScene.State.MAIN_MENU), debug = true) - } - - // Go directly to ingame to avoid testing main menu - object IngameDebug { - //@JvmStatic fun main(args: Array) = Korge.invoke(KorgeCoffeeModule, sceneClass = MainScene::class.java, sceneInjects = listOf(MainScene.State.INGAME), debug = true) - @JvmStatic - fun main(args: Array) = Korge.invoke(KorgeCoffeeModule, sceneClass = MainScene::class, injector = AsyncInjector().prepareKoffee(), sceneInjects = listOf(MainScene.State.INGAME), debug = false) - } - - override val title: String = "KorGE Coffee" - override val mainScene = MainScene::class - override val size: SizeInt = SizeInt(720, 1280) - override val windowSize: SizeInt = size * 0.75 - override val icon: String = "icon.png" - override val plugins = super.plugins + listOf( - AnLibraryPlugin - ) - - @Singleton - class GameStorage( - val storage: Storage - ) { - var HiScore by storage.item("HiScore") { 0 } - } - - suspend override fun init(injector: AsyncInjector) { - injector.get().registerPropertyTriggerSuspend("disabled") { view, key, value -> - view.mouseEnabled = false - } - } - - @Singleton - class LibraryContainer : InjectorAsyncDependency { - lateinit var font: BitmapFont; private set - lateinit var library: AnLibrary; private set - - suspend override fun init(injector: AsyncInjector) { - font = injector.getPath(BitmapFont::class, "font.fnt") - library = injector.getPath(AnLibrary::class, "main.ani") - } - } - - class CreditsScene( - val libraryContainer: LibraryContainer, - val browser: Browser, - val gameStorage: GameStorage - ) : Scene() { - val lib = libraryContainer.library - suspend override fun sceneInit(sceneView: Container) { - sceneView += lib.createMovieClip("Credits") - sceneView["korge"].jellyButton(1.2).onClick { browser.browse("http://korge.soywiz.com/") } - sceneView["kotlin"].jellyButton(1.2).onClick { browser.browse("https://kotlinlang.org/") } - sceneView["animate"].jellyButton(1.2).onClick { browser.browse("http://www.adobe.com/products/animate.html") } - sceneView["github"].jellyButton(1.2).onClick { browser.browse("https://github.com/soywiz/korge-samples/tree/master/korge-coffee") } - sceneView["soywiz"].jellyButton(1.2).onClick { browser.browse("https://blog.soywiz.com/") } - sceneView["tamy"].jellyButton(1.2).onClick { browser.browse("https://tamy.es/") } - sceneView["close"].jellyButton(1.2).onClick { this.sceneContainer.back(time = 0.3.seconds) } - } - - suspend override fun sceneBeforeLeaving() { - super.sceneBeforeLeaving() - sceneView.mouseEnabled = false - } - } - - class MainMenuScene( - val libraryContainer: LibraryContainer, - val gameStorage: GameStorage - ) : Scene() { - val lib = libraryContainer.library - lateinit var creditsSC: SceneContainer - val onStart = AsyncSignal() - - suspend override fun sceneInit(sceneView: Container) { - sceneView += lib.createMovieClip("MainMenu") - creditsSC = views.sceneContainer() - sceneView += creditsSC - sceneView["playButton"].jellyButton(1.2).onClick { - onStart(Unit) - } - sceneView["creditsButton"].jellyButton(1.2).onClick { - creditsSC.pushTo(time = 0.2.seconds) - } - sceneView["hiscore"].setText("${gameStorage.HiScore}") - } - - suspend override fun sceneBeforeLeaving() { - super.sceneBeforeLeaving() - sceneView.mouseEnabled = false - } - } - - class MainScene( - val lib: LibraryContainer, - @Optional val initialState: State?, - val gameStorage: GameStorage - ) : Scene() { - enum class State { MAIN_MENU, INGAME } - - lateinit var camera: Camera - lateinit var hud: View - lateinit var ingame: View - lateinit var mainMenuSC: SceneContainer - - private suspend fun openMainMenu(transition: Boolean, callback: suspend () -> Unit) { - hud.alpha = 0.0 - val mainMenu = mainMenuSC.pushTo() - mainMenu.onStart { - callback() - } - if (transition) { - camera.tweenTo( - sceneView["menuCamera"]!!, - sceneView["action"]!!::colorTransform[ColorTransform.Add(-255, -255, -255, 0)], - time = 0.5.seconds, easing = Easing.EASE_OUT_QUAD - ) - } else { - camera.setTo(sceneView["menuCamera"]!!) - sceneView["action"]?.colorTransform = ColorTransform.Add(-255, -255, -255, 0) - } - } - - private suspend fun closeMainMenu() { - go { - mainMenuSC.back(time = 1.seconds, transition = AlphaTransition.withEasing(Easing.EASE_OUT_QUAD)) - } - } - - suspend override fun sceneInit(sceneView: Container) { - camera = views.camera() - - sceneView += lib.library.createMovieClip("Cameras").apply { visible = false } - sceneView += camera.apply { - ingame = lib.library.createMovieClip("Ingame") - this += ingame - } - hud = lib.library.createMovieClip("Hud") - //(hud["scoreLabel"] as? AnTextField?)?.format = (hud["scoreLabel"] as? AnTextField?)?.format?.copy(face = Html.FontFace.Bitmap(lib.font))!! - //(hud["scoreText"] as? AnTextField?)?.format = (hud["scoreText"] as? AnTextField?)?.format?.copy(face = Html.FontFace.Bitmap(lib.font))!! - sceneView += hud - mainMenuSC = views.sceneContainer() - sceneView += mainMenuSC - - when (initialState) { - null, State.MAIN_MENU -> { - hud.alpha = 0.0 - openMainMenu(transition = false) { - closeMainMenu() - startGame() - doIngame() - } - } - State.INGAME -> { - camera.setTo(sceneView["ingameCamera"]!!) - sceneView["action"]?.colorTransform = ColorTransform.Add(0, 0, 0, 0) - sceneView["background"]?.alpha = 1.0 - doIngame() - } - } - - sceneView["pauseButton"]?.mouseEnabled = false - sceneView["pauseButton"].jellyButton(1.125).onClick { - //sceneView["ingame"]?.speed = 0.0 - updateHiScore() - ingame.speed = 0.0 - - val oldCamera = camera.localMatrix.copy() - - openMainMenu(transition = true) { - closeMainMenu() - camera.tween( - camera::localMatrix[oldCamera], - sceneView["action"]!!::colorTransform[ColorTransform.Add(0, 0, 0, 0)], - hud::alpha[1.0], - time = 0.5.seconds, easing = Easing.EASE_OUT_QUAD - ) - ingame.speed = 1.0 - } - - //mainMenuSC.pushTo() - } - - } - - suspend fun startGame() { - allowSpeedUp { - go { - val action = sceneView["action"] - action?.tween(action::colorTransform[ColorTransform.Add(0, 0, 0, 0)], time = 5.seconds, easing = Easing.LINEAR) - } - go { - hud.tween(hud::alpha[1.0], time = 2.seconds, easing = Easing.LINEAR) - } - camera.tweenTo(sceneView["showCamera"], time = 2.seconds, easing = Easing.EASE_IN_OUT_QUAD) - sceneView["messages"]?.speed = 0.7 - sceneView["messages"].playAndWaitEvent("tap", "tap_continue") - camera.sleep(0.5.seconds) - go { - val background = sceneView["background"] - background?.tween(background::alpha[1.0], time = 1.seconds, easing = Easing.EASE_OUT_ELASTIC) - } - camera.tweenTo(sceneView["ingameCamera"], time = 1.seconds, easing = Easing.EASE_OUT_ELASTIC) - } - } - - var score = 0 - - private fun updateScore() { - sceneView["scoreText"].setText("$score") - } - - private fun incrementScore(delta: Int) { - score += delta - updateScore() - } - - private suspend fun incrementScore(view: View, delta: Int) { - val scoreView = sceneView["score"] ?: views.container() - //val entityHigh = sceneView["entityHigh"] ?: views.container() - val entityHigh = sceneView["hudContainer"] ?: views.container() - val text = views.text("+$delta", textSize = 16.0).apply { entityHigh += this } - text.globalX = view.globalX - text.globalY = view.globalY - text.tween( - text::globalX[scoreView.globalX], - text::globalY[scoreView.globalY], - text::alpha[0.0], - time = 0.3.seconds - ) - text.removeFromParent() - scoreView.tween( - scoreView::scale[0.7], - time = 0.2.seconds, - easing = Easing.EASE_OUT_ELASTIC - ) - incrementScore(delta) - scoreView.tween( - scoreView::scale[1.0], - time = 0.2.seconds, - easing = Easing.EASE_OUT_ELASTIC - ) - } - - private val colorAddBlack = ColorTransform.Add(-255, -255, -255, 0).colorAdd - private val colorAddNormal = ColorTransform.Add(0, 0, 0, 0).colorAdd - - class DismissKotlinMessage(val givePoints: Boolean) - - fun destroyAllEntities() { - sceneView.dispatch(DismissKotlinMessage(givePoints = false)) - } - - var spawner = Promise.resolved(Unit) - var running = true - - private fun updateHiScore() { - gameStorage.HiScore = max(gameStorage.HiScore, score) - } - - suspend fun allowSpeedUp(callback: suspend () -> Unit) { - val events = listOf( - views.stage.mouse.onDown { sceneView.speed = 5.0 }, - views.stage.mouse.onUpAnywhere { sceneView.speed = 1.0 } - ).closeable() - try { - callback() - } finally { - events.close() - sceneView.speed = 1.0 - } - } - - suspend fun gameOver() { - allowSpeedUp { - updateHiScore() - sceneView["pauseButton"]?.alpha = 0.0 - destroyAllEntities() - spawner.cancel() - running = false - camera.tweenTo(sceneView["showCamera"], time = 0.5.seconds, easing = Easing.EASE_OUT_ELASTIC) - sceneView["action"].waitEvent("mainLoop") - sceneView["action"].playAndWaitEvent("drop", "dropZoom") - camera.tweenTo(sceneView["zoomCamera"], time = 0.5.seconds, easing = Easing.EASE_OUT_QUAD) - sceneView["action"].waitStop() - sceneView["messages"].playAndWaitStop("gameover") - sceneView.sleep(1.seconds) - sceneView.tween(sceneView::colorTransform[ColorTransform.Add(-255, -255, -255, 0)], time = 0.5.seconds) - this.sceneContainer.changeTo(initialState ?: State.MAIN_MENU) - //sceneView["action"].play("drop") - } - } - - fun createEntity(globalPos: Point2d, scale: Double, reachTime: TimeSpan): View { - val kotlinHigh = lib.library.createMovieClip("KotlinHigh") - val kotlinLow = lib.library.createMovieClip("KotlinLow") - val entityHigh = sceneView["entityHigh"] ?: views.container() - val entityLow = sceneView["entityLow"] ?: views.container() - entityHigh += kotlinHigh - entityLow += kotlinLow - // Synchronize low part with high part - entityHigh.addUpdatable { - kotlinLow.globalMatrix = kotlinHigh.globalMatrix - kotlinLow.alpha = kotlinHigh.alpha - kotlinLow.colorAdd = kotlinHigh.colorAdd - } - - val localDestination = kotlinHigh.globalToLocal(sceneView["rope"]!!.globalBounds.getAnchoredPosition(Anchor.MIDDLE_CENTER)) - - kotlinHigh.globalX = globalPos.x - kotlinHigh.globalY = globalPos.y - - var cancelled = false - - val movePromise = go { - kotlinHigh.tween( - kotlinHigh::scale[0.8, scale], - kotlinHigh::colorAdd[colorAddBlack, colorAddNormal].color(), - time = 0.3.seconds - ) - - //val distance = Math.hypot(globalDestination.x - kotlin.globalX, globalDestination.y - kotlin.globalY) - - kotlinHigh.tween( - kotlinHigh::x[localDestination.x], - kotlinHigh::y[localDestination.y], - kotlinHigh::scale[kotlinHigh.scale * 0.75].easeOutQuad(), - //time = (distance * 5).milliseconds - time = reachTime - ) - - if (!cancelled) { // @TODO: Shouldn't be necessary since cancelling should cancell the whole process - go { - gameOver() - } - } - } - - kotlinHigh.addEventListener { - kotlinHigh.mouseEnabled = false - cancelled = true - movePromise.cancel() - go { - if (it.givePoints) { - go { - incrementScore(kotlinHigh, delta = +1) - } - } - go { - kotlinHigh.tween( - kotlinHigh::colorAdd[colorAddBlack].color(), - kotlinHigh::scale[0.0], - time = 0.3.seconds - ) - kotlinHigh.removeFromParent() - kotlinLow.removeFromParent() - //createEntity(x = random[0.0, 600.0 * 2], y = random[0.0, 1200.0 * 2], scale = 2.5) - } - } - } - - kotlinHigh.mouse.apply { hitTestType = View.HitTestType.SHAPE }.onDown { - kotlinHigh.dispatch(DismissKotlinMessage(givePoints = true)) - } - go { - while (true) { - kotlinHigh.tween(kotlinHigh::rotationDegrees[0, 360], time = 2.seconds) - } - } - return kotlinHigh - } - - val random = MtRand() - - data class DifficultyConfig( - val spawnCount: Int = 2, - val nextSpawnTime: ClosedRange = 1.seconds..1.seconds, - val scale: ClosedRange = 2.5..2.5, - val reachTime: ClosedRange = 2.seconds..2.seconds - ) - - private fun buildDifficultyConfig(step: Int): DifficultyConfig { - val spawnCount = when { - step < 5 -> 1 - step < 20 -> random[listOf(1, 2)] - step < 30 -> random[listOf(1, 2, 2)] - step < 50 -> random[listOf(1, 2, 2, 2, 3)] - else -> random[listOf(1, 2, 2, 2, 3, 3, 3, 3, 3, 3)] - } - - val reachTime = when { - step < 50 -> 2.seconds - else -> 1.5.seconds - } * spawnCount - - return DifficultyConfig( - spawnCount = spawnCount, - nextSpawnTime = when { - step < 5 -> 1.8.seconds..2.2.seconds - step < 10 -> 1.5.seconds..2.0.seconds - step < 20 -> 1.seconds..1.5.seconds - else -> 0.8.seconds..1.seconds - }, - scale = when { - step < 50 -> 2.5..2.5 - step < 100 -> 2.0..2.5 - step < 200 -> 1.5..2.0 - else -> 1.0..1.5 - }, - reachTime = reachTime..reachTime * 1.1 - ) - } - - suspend fun doSpawner() { - val spawnZones = sceneView.descendantsWithProp("spawnZone") - - var step = 0 - while (running) { - val config = buildDifficultyConfig(step) - for (n in 0 until config.spawnCount) { - val point = random[random[spawnZones].globalBounds] - createEntity(globalPos = point, scale = random[config.scale], reachTime = random[config.reachTime]) - } - ingame.sleep(random[config.nextSpawnTime]) - step++ - } - } - - suspend fun doIngame() { - sceneView["pauseButton"]?.mouseEnabled = true - spawner = go { - doSpawner() - } - } - } -} - diff --git a/korge-coffee/common/src/main/resources/font.fnt b/korge-coffee/common/src/main/resources/font.fnt deleted file mode 100644 index b1ad9ae..0000000 --- a/korge-coffee/common/src/main/resources/font.fnt +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/korge-coffee/common/src/main/resources/font.png b/korge-coffee/common/src/main/resources/font.png deleted file mode 100644 index 3e4bea7..0000000 Binary files a/korge-coffee/common/src/main/resources/font.png and /dev/null differ diff --git a/korge-coffee/common/src/main/resources/icon.fla b/korge-coffee/common/src/main/resources/icon.fla deleted file mode 100644 index d39843b..0000000 Binary files a/korge-coffee/common/src/main/resources/icon.fla and /dev/null differ diff --git a/korge-coffee/common/src/main/resources/icon.png b/korge-coffee/common/src/main/resources/icon.png deleted file mode 100644 index 76b22d0..0000000 Binary files a/korge-coffee/common/src/main/resources/icon.png and /dev/null differ diff --git a/korge-coffee/common/src/main/resources/icon.swf b/korge-coffee/common/src/main/resources/icon.swf deleted file mode 100644 index 575fda1..0000000 Binary files a/korge-coffee/common/src/main/resources/icon.swf and /dev/null differ diff --git a/korge-coffee/common/src/main/resources/index.html b/korge-coffee/common/src/main/resources/index.html deleted file mode 100644 index ae77558..0000000 --- a/korge-coffee/common/src/main/resources/index.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - diff --git a/korge-coffee/common/src/main/resources/main.fla b/korge-coffee/common/src/main/resources/main.fla deleted file mode 100644 index 550aa3b..0000000 Binary files a/korge-coffee/common/src/main/resources/main.fla and /dev/null differ diff --git a/korge-coffee/common/src/main/resources/main.swf b/korge-coffee/common/src/main/resources/main.swf deleted file mode 100644 index b34277c..0000000 Binary files a/korge-coffee/common/src/main/resources/main.swf and /dev/null differ diff --git a/korge-coffee/common/src/main/resources/main.swf.config b/korge-coffee/common/src/main/resources/main.swf.config deleted file mode 100644 index d55d20d..0000000 --- a/korge-coffee/common/src/main/resources/main.swf.config +++ /dev/null @@ -1,6 +0,0 @@ -mipmaps: true -exportScale: 2.0 -adaptiveScaling: true -smoothInterpolation: true -maxShapeSide: 400 -maxTextureSide: 2048 diff --git a/korge-coffee/js/.gitignore b/korge-coffee/js/.gitignore deleted file mode 100644 index d88dafb..0000000 --- a/korge-coffee/js/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources -/web diff --git a/korge-coffee/js/build.gradle b/korge-coffee/js/build.gradle deleted file mode 100644 index cea2877..0000000 --- a/korge-coffee/js/build.gradle +++ /dev/null @@ -1,21 +0,0 @@ -apply plugin: 'kotlin-platform-js' -//apply plugin: 'kotlin-dce-js' -//runDceKotlinJs.keep "korge-coffee-js.com.soywiz.korge.games.coffee.KorgeCoffeeModule.main", "korge-coffee-js.com.soywiz.korge.games.coffee.KorgeCoffeeModule" - -//apply plugin: 'application' - -//mainClassName = "com.soywiz.korge.games.coffee.KorgeCoffeeModule" - - -sourceSets { - main.resources.srcDirs = [ '../common/src/main/resources', '../common/src/generated/resources' ] -} - -dependencies { - implement project(":korge-coffee:common") - - compile "com.soywiz:korge-js:$korVersion" - compile "com.soywiz:korge-ext-swf-js:$korVersion" - compile "com.soywiz:korau-mp3-js:$korVersion" - testCompile "com.soywiz:korge-tests-js:$korVersion" -} diff --git a/korge-coffee/js/settings.gradle b/korge-coffee/js/settings.gradle deleted file mode 100644 index 2f573bb..0000000 --- a/korge-coffee/js/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'korge-coffee-js' diff --git a/korge-coffee/jvm/.gitignore b/korge-coffee/jvm/.gitignore deleted file mode 100644 index 7f99310..0000000 --- a/korge-coffee/jvm/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources diff --git a/korge-coffee/jvm/build.gradle b/korge-coffee/jvm/build.gradle deleted file mode 100644 index bbfafe5..0000000 --- a/korge-coffee/jvm/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ -apply plugin: 'kotlin-platform-jvm' - -apply plugin: 'application' - -mainClassName = "com.soywiz.korge.games.coffee.KorgeCoffeeModule" - -sourceSets { - main.resources.srcDirs = [ '../common/src/main/resources', '../common/src/generated/resources' ] -} - -dependencies { - implement project(":korge-coffee:common") - - compile "com.soywiz:korge:$korVersion" - compile "com.soywiz:korge-ext-swf:$korVersion" - compile "com.soywiz:korau-mp3:$korVersion" - testCompile "com.soywiz:korge-tests:$korVersion" -} diff --git a/korge-coffee/jvm/settings.gradle b/korge-coffee/jvm/settings.gradle deleted file mode 100644 index 1476430..0000000 --- a/korge-coffee/jvm/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'korge-coffee' diff --git a/korge-sample1/build.gradle b/korge-sample1/build.gradle new file mode 100644 index 0000000..d7859b2 --- /dev/null +++ b/korge-sample1/build.gradle @@ -0,0 +1,28 @@ +dependencies { + commonMainApi "com.soywiz:korge:$korgeVersion" + + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-android-aarch64" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-android-armv6" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-linux-amd64" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-linux-armv6" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-linux-armv6hf" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-linux-i586" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-macosx-universal" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-solaris-amd64" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-solaris-i586" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-windows-amd64" + jvmMainApi "org.jogamp.gluegen:gluegen-rt:$gluegenVersion:natives-windows-i586" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-android-aarch64" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-android-armv6" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-linux-amd64" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-linux-armv6" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-linux-armv6hf" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-linux-i586" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-macosx-universal" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-solaris-amd64" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-solaris-i586" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-windows-amd64" + jvmMainApi "org.jogamp.jogl:jogl-all:$joglVersion:natives-windows-i586" +} diff --git a/korge-sample1/src/commonMain/kotlin/com.soywiz.korge.sample1/Sample1.kt b/korge-sample1/src/commonMain/kotlin/com.soywiz.korge.sample1/Sample1.kt new file mode 100644 index 0000000..a894d5e --- /dev/null +++ b/korge-sample1/src/commonMain/kotlin/com.soywiz.korge.sample1/Sample1.kt @@ -0,0 +1,9 @@ +package com.soywiz.korge.sample1 + +import com.soywiz.korge.Korge +import com.soywiz.korge.view.solidRect +import com.soywiz.korim.color.Colors + +fun main(args: Array) = Korge { + solidRect(100, 100, Colors.RED) +} diff --git a/korge-simon/.gitignore b/korge-simon/.gitignore deleted file mode 100644 index 7f99310..0000000 --- a/korge-simon/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources diff --git a/korge-simon/build.gradle.old b/korge-simon/build.gradle.old deleted file mode 100644 index b10891c..0000000 --- a/korge-simon/build.gradle.old +++ /dev/null @@ -1,46 +0,0 @@ -apply from: "../include.gradle" - -apply plugin: 'kotlin' -apply plugin: 'application' - -mainClassName = "com.soywiz.korge.samples.simon.Simon" - -sourceSets { - generated.resources.srcDirs = [ 'genresources' ] - - main.kotlin.srcDirs = [ 'src' ] - main.resources.srcDirs = [ 'resources', 'genresources' ] - test.kotlin.srcDirs = [ 'test' ] -} - - -dependencies { - compile "com.soywiz:korge:$korVersion" - compile "com.soywiz:korge-ext-swf:$korVersion" - compile "com.soywiz:korge-ext-ui:$korVersion" - compile "com.soywiz:korau-mp3:$korVersion" - - //nojtransc "com.soywiz:korge-ext-swf:$korVersion" - //nojtransc "com.soywiz:korau-mp3:$korVersion" -} - -/* -jtransc { - //minimizeNames = true - minimizeNames = false - treeshaking = true - - assets("resources") - assets("genresources") - - skipServiceLoader("com.soywiz.korim.format.JPEG") - skipServiceLoader("com.soywiz.korim.format.PNG") - - skipServiceLoader("com.soywiz.korau.format.MP3") - skipServiceLoader("com.soywiz.korau.format.OGG") -} -*/ - -jar.enabled = false -distTar.enabled = false -distZip.enabled = false diff --git a/korge-simon/common/.gitignore b/korge-simon/common/.gitignore deleted file mode 100644 index 7f99310..0000000 --- a/korge-simon/common/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources diff --git a/korge-simon/common/build.gradle b/korge-simon/common/build.gradle deleted file mode 100644 index 70a61a1..0000000 --- a/korge-simon/common/build.gradle +++ /dev/null @@ -1,12 +0,0 @@ -apply plugin: 'kotlin-platform-common' - -sourceSets { - main.resources.srcDirs = [ 'src/main/resources', 'src/generated/resources' ] -} - -dependencies { - compile "com.soywiz:korge-common:$korVersion" - compile "com.soywiz:korge-ext-swf-common:$korVersion" - compile "com.soywiz:korge-ext-ui-common:$korVersion" - compile "com.soywiz:korau-mp3-common:$korVersion" -} diff --git a/korge-simon/common/settings.gradle b/korge-simon/common/settings.gradle deleted file mode 100644 index 9879513..0000000 --- a/korge-simon/common/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'korge-simon-common' diff --git a/korge-simon/common/src/generated/resources/kotlin.atlas.json b/korge-simon/common/src/generated/resources/kotlin.atlas.json deleted file mode 100644 index 3e8fbac..0000000 --- a/korge-simon/common/src/generated/resources/kotlin.atlas.json +++ /dev/null @@ -1,135 +0,0 @@ -{ - "frames": { - "0.png": { - "frame": { - "x": 2, - "y": 2, - "w": 32, - "h": 40 - }, - "rotated": false, - "sourceSize": { - "w": 32, - "h": 40 - }, - "spriteSourceSize": { - "x": 0, - "y": 0, - "w": 32, - "h": 40 - }, - "trimmed": false - }, - "1.png": { - "frame": { - "x": 2, - "y": 42, - "w": 32, - "h": 40 - }, - "rotated": false, - "sourceSize": { - "w": 32, - "h": 40 - }, - "spriteSourceSize": { - "x": 0, - "y": 0, - "w": 32, - "h": 40 - }, - "trimmed": false - }, - "2.png": { - "frame": { - "x": 2, - "y": 82, - "w": 32, - "h": 40 - }, - "rotated": false, - "sourceSize": { - "w": 32, - "h": 40 - }, - "spriteSourceSize": { - "x": 0, - "y": 0, - "w": 32, - "h": 40 - }, - "trimmed": false - }, - "3.png": { - "frame": { - "x": 2, - "y": 122, - "w": 32, - "h": 40 - }, - "rotated": false, - "sourceSize": { - "w": 32, - "h": 40 - }, - "spriteSourceSize": { - "x": 0, - "y": 0, - "w": 32, - "h": 40 - }, - "trimmed": false - }, - "4.png": { - "frame": { - "x": 2, - "y": 162, - "w": 32, - "h": 40 - }, - "rotated": false, - "sourceSize": { - "w": 32, - "h": 40 - }, - "spriteSourceSize": { - "x": 0, - "y": 0, - "w": 32, - "h": 40 - }, - "trimmed": false - }, - "5.png": { - "frame": { - "x": 2, - "y": 202, - "w": 32, - "h": 40 - }, - "rotated": false, - "sourceSize": { - "w": 32, - "h": 40 - }, - "spriteSourceSize": { - "x": 0, - "y": 0, - "w": 32, - "h": 40 - }, - "trimmed": false - } - }, - "meta": { - "app": "korge", - "format": "RGBA8888", - "image": "kotlin.atlas.png", - "scale": 1.0, - "size": { - "w": 32, - "h": 240 - }, - "version": "0.10.0" - } -} \ No newline at end of file diff --git a/korge-simon/common/src/generated/resources/kotlin.atlas.json.meta b/korge-simon/common/src/generated/resources/kotlin.atlas.json.meta deleted file mode 100644 index 71878b1..0000000 --- a/korge-simon/common/src/generated/resources/kotlin.atlas.json.meta +++ /dev/null @@ -1 +0,0 @@ -{"name":"kotlin.atlas","loaderVersion":0,"sha1":"f096d009db1e83bdd171bdd91f830bcb32e2be70","configSha1":""} \ No newline at end of file diff --git a/korge-simon/common/src/generated/resources/kotlin.atlas.png b/korge-simon/common/src/generated/resources/kotlin.atlas.png deleted file mode 100644 index e992e23..0000000 Binary files a/korge-simon/common/src/generated/resources/kotlin.atlas.png and /dev/null differ diff --git a/korge-simon/common/src/main/kotlin/com/soywiz/korge/samples/simon/Simon.kt b/korge-simon/common/src/main/kotlin/com/soywiz/korge/samples/simon/Simon.kt deleted file mode 100644 index 27c5d05..0000000 --- a/korge-simon/common/src/main/kotlin/com/soywiz/korge/samples/simon/Simon.kt +++ /dev/null @@ -1,220 +0,0 @@ -package com.soywiz.korge.samples.simon - -import com.soywiz.korge.Korge -import com.soywiz.korge.atlas.Atlas -import com.soywiz.korge.audio.SoundFile -import com.soywiz.korge.audio.SoundSystem -import com.soywiz.korge.audio.readSoundFile -import com.soywiz.korge.input.mouse -import com.soywiz.korge.plugin.KorgePlugin -import com.soywiz.korge.resources.getPath -import com.soywiz.korge.scene.Module -import com.soywiz.korge.scene.ScaledScene -import com.soywiz.korge.scene.Scene -import com.soywiz.korge.scene.sleep -import com.soywiz.korge.time.seconds -import com.soywiz.korge.ui.UIFactory -import com.soywiz.korge.ui.UIPlugin -import com.soywiz.korge.ui.korui.koruiFrame -import com.soywiz.korge.util.AutoClose -import com.soywiz.korge.view.Container -import com.soywiz.korge.view.Image -import com.soywiz.korge.view.image -import com.soywiz.korim.color.Colors -import com.soywiz.korio.async.Signal -import com.soywiz.korio.async.go -import com.soywiz.korio.async.waitOne -import com.soywiz.korio.inject.AsyncInjector -import com.soywiz.korio.inject.InjectorAsyncDependency -import com.soywiz.korio.lang.JvmStatic -import com.soywiz.korma.geom.ISize -import com.soywiz.korma.geom.SizeInt -import com.soywiz.korma.random.MtRand -import com.soywiz.korma.random.get -import com.soywiz.korui.geom.len.Padding -import com.soywiz.korui.geom.len.em -import com.soywiz.korui.style.padding -import com.soywiz.korui.ui.button -import com.soywiz.korui.ui.click -import com.soywiz.korui.ui.horizontal - -object Simon : Module() { - @JvmStatic - fun main(args: Array) = Korge(this, injector = AsyncInjector() - .mapPrototype { SelectLevelScene() } - .mapPrototype { IngameScene() } - ) - - override val size = SizeInt(1280, 720) - override val windowSize = size * 0.75 - override val title = "Kotlin Simon" - override val icon = "kotlin/0.png" - override val mainScene = SelectLevelScene::class - - override val plugins: List = super.plugins + listOf(UIPlugin) - - class Sequence( - val max: Int, - val random: MtRand = MtRand() - ) { - val items = ArrayList() - - fun ensure(num: Int): List { - while (items.size < num) items.add(random[0, max]) - return items - } - } - - enum class Difficulty(val items: Int) { - EASY(3), MEDIUM(4), HARD(6) - } - - class SelectLevelScene : Scene(), InjectorAsyncDependency { - lateinit var atlas: Atlas; private set - lateinit var ui: UIFactory; private set - - override suspend fun init(injector: AsyncInjector) { - super.init(injector) - - atlas = injector.getPath(Atlas::class, "kotlin.atlas") - ui = injector.get(UIFactory::class) - } - - suspend override fun sceneInit(sceneView: Container) { - // BUG: Kotlin-JS - - sceneView += ui.koruiFrame { - horizontal { - padding = Padding(0.2.em) - button("EASY").click { sceneContainer.pushTo(Difficulty.EASY) } - button("MEDIUM").click { sceneContainer.pushTo(Difficulty.MEDIUM) } - button("HARD").click { sceneContainer.pushTo(Difficulty.HARD) } - } - } - - //sceneView += ui.koruiFrame { - // add(com.soywiz.korui.ui.Container(this.app, HorizontalLayout(app)).apply { - // padding = Padding(0.2.em) - // button("EASY").click { sceneContainer.pushTo(Difficulty.EASY) } - // button("MEDIUM").click { sceneContainer.pushTo(Difficulty.MEDIUM) } - // button("HARD").click { sceneContainer.pushTo(Difficulty.HARD) } - // }) - //} - } - } - - class IngameScene : ScaledScene() { - private lateinit var atlas: Atlas - private lateinit var successSound: SoundFile - private lateinit var failSound: SoundFile - private lateinit var difficulty: Difficulty - private lateinit var soundSystem: SoundSystem - - override val sceneSize = ISize(128, 72) - override val sceneScale: Double = 10.0 - - val sequence by lazy { Sequence(difficulty.items) } - val images = arrayListOf() - lateinit var sounds: List - - override suspend fun init(injector: AsyncInjector) { - super.init(injector) - atlas = injector.getPath(Atlas::class, "kotlin.atlas") - successSound = injector.getPath(SoundFile::class, "sounds/success.wav") - failSound = injector.getPath(SoundFile::class, "sounds/fail.mp3") - difficulty = injector.getOrNull(Difficulty::class) ?: Difficulty.MEDIUM - soundSystem = injector.get(SoundSystem::class) - println("IngameScene.difficulty: $difficulty") - } - - suspend override fun sceneInit(sceneView: Container) { - sounds = (0..8).map { resourcesRoot["sounds/$it.mp3"].readSoundFile(soundSystem) } - - //val sv = views.scaleView(128, 72, 10.0) - //sv += views.solidRect(72, 72, Colors.RED).apply { y = 10.0 } - for (n in 0 until difficulty.items) { - val image = views.image(atlas["$n.png"].texture).apply { - //anchorX = 0.5 - anchorY = 0.5 - val w = (difficulty.items) * 20 - x = (128 / 2).toDouble() - (w / 2) + n * 20 - 4 - y = (72 / 2).toDouble() - } - images += image - sceneView += image - } - //sceneView += sv - - go { - sleep(1.seconds) - ingame() - sceneContainer.back() - } - } - - suspend fun ingame() { - var turn = 1 - while (true) { - cpuTurn(turn) - if (!playerTurn(turn)) { - println("FAILED!") - val sound = failSound.play() - //sound.await() - sleep(0.5.seconds) - break - } else { - println("SUCCESS START") - val sound = successSound.play() - //sound.await() - sleep(0.5.seconds) - println("SUCCESS END") - } - turn++ - } - } - - suspend fun cpuTurn(turn: Int) { - val seq = sequence.ensure(turn) - for (item in seq) { - highlight(item) - } - } - - suspend fun playerTurn(turn: Int): Boolean { - val seq = sequence.ensure(turn) - for (pos in 0 until seq.size) { - val item = readOne() - if (seq[pos] != item) return false - } - return true - } - - private suspend fun readOne(): Int { - return AutoClose { toclose -> - val signal = Signal() - for ((index, image) in images.withIndex()) { - toclose += image.mouse.onUp { - toclose.cancel() - signal(index) - go { - highlight(index) - } - } - } - signal.waitOne() - } - } - - suspend fun highlight(index: Int) { - println("PLAY START") - val sound = soundSystem.play(sounds[index]) - println("PLAY PROGRESS") - images[index].colorMul = Colors["#ff7f7f"] - sleep(0.3.seconds) - images[index].colorMul = Colors.WHITE - //sound.await() - sleep(0.5.seconds) - println("PLAY END") - } - } -} diff --git a/korge-simon/common/src/main/resources/index.html b/korge-simon/common/src/main/resources/index.html deleted file mode 100644 index 037d9d5..0000000 --- a/korge-simon/common/src/main/resources/index.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - diff --git a/korge-simon/common/src/main/resources/korge-ui.png b/korge-simon/common/src/main/resources/korge-ui.png deleted file mode 100644 index c222293..0000000 Binary files a/korge-simon/common/src/main/resources/korge-ui.png and /dev/null differ diff --git a/korge-simon/common/src/main/resources/kotlin.atlas b/korge-simon/common/src/main/resources/kotlin.atlas deleted file mode 100644 index 1eebdb9..0000000 --- a/korge-simon/common/src/main/resources/kotlin.atlas +++ /dev/null @@ -1 +0,0 @@ -kotlin diff --git a/korge-simon/common/src/main/resources/kotlin.psd b/korge-simon/common/src/main/resources/kotlin.psd deleted file mode 100644 index a6989e4..0000000 Binary files a/korge-simon/common/src/main/resources/kotlin.psd and /dev/null differ diff --git a/korge-simon/common/src/main/resources/kotlin/0.png b/korge-simon/common/src/main/resources/kotlin/0.png deleted file mode 100644 index 7a2502d..0000000 Binary files a/korge-simon/common/src/main/resources/kotlin/0.png and /dev/null differ diff --git a/korge-simon/common/src/main/resources/kotlin/1.png b/korge-simon/common/src/main/resources/kotlin/1.png deleted file mode 100644 index a3fa887..0000000 Binary files a/korge-simon/common/src/main/resources/kotlin/1.png and /dev/null differ diff --git a/korge-simon/common/src/main/resources/kotlin/2.png b/korge-simon/common/src/main/resources/kotlin/2.png deleted file mode 100644 index 8641adf..0000000 Binary files a/korge-simon/common/src/main/resources/kotlin/2.png and /dev/null differ diff --git a/korge-simon/common/src/main/resources/kotlin/3.png b/korge-simon/common/src/main/resources/kotlin/3.png deleted file mode 100644 index 5e017b7..0000000 Binary files a/korge-simon/common/src/main/resources/kotlin/3.png and /dev/null differ diff --git a/korge-simon/common/src/main/resources/kotlin/4.png b/korge-simon/common/src/main/resources/kotlin/4.png deleted file mode 100644 index 5690c2f..0000000 Binary files a/korge-simon/common/src/main/resources/kotlin/4.png and /dev/null differ diff --git a/korge-simon/common/src/main/resources/kotlin/5.png b/korge-simon/common/src/main/resources/kotlin/5.png deleted file mode 100644 index e4bb6d4..0000000 Binary files a/korge-simon/common/src/main/resources/kotlin/5.png and /dev/null differ diff --git a/korge-simon/common/src/main/resources/kotlin_images.png b/korge-simon/common/src/main/resources/kotlin_images.png deleted file mode 100644 index 77bdae0..0000000 Binary files a/korge-simon/common/src/main/resources/kotlin_images.png and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/0.mp3 b/korge-simon/common/src/main/resources/sounds/0.mp3 deleted file mode 100644 index 67ed0e8..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/0.mp3 and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/1.mp3 b/korge-simon/common/src/main/resources/sounds/1.mp3 deleted file mode 100644 index a494783..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/1.mp3 and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/2.mp3 b/korge-simon/common/src/main/resources/sounds/2.mp3 deleted file mode 100644 index 0cbf56b..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/2.mp3 and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/3.mp3 b/korge-simon/common/src/main/resources/sounds/3.mp3 deleted file mode 100644 index 44a151e..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/3.mp3 and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/4.mp3 b/korge-simon/common/src/main/resources/sounds/4.mp3 deleted file mode 100644 index ecd72fd..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/4.mp3 and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/5.mp3 b/korge-simon/common/src/main/resources/sounds/5.mp3 deleted file mode 100644 index 291c045..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/5.mp3 and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/6.mp3 b/korge-simon/common/src/main/resources/sounds/6.mp3 deleted file mode 100644 index c9bcd2c..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/6.mp3 and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/7.mp3 b/korge-simon/common/src/main/resources/sounds/7.mp3 deleted file mode 100644 index d287d92..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/7.mp3 and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/8.mp3 b/korge-simon/common/src/main/resources/sounds/8.mp3 deleted file mode 100644 index 6619cbb..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/8.mp3 and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/fail.mp3 b/korge-simon/common/src/main/resources/sounds/fail.mp3 deleted file mode 100644 index 78dc04a..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/fail.mp3 and /dev/null differ diff --git a/korge-simon/common/src/main/resources/sounds/success.wav b/korge-simon/common/src/main/resources/sounds/success.wav deleted file mode 100644 index 50547d2..0000000 Binary files a/korge-simon/common/src/main/resources/sounds/success.wav and /dev/null differ diff --git a/korge-simon/js/.gitignore b/korge-simon/js/.gitignore deleted file mode 100644 index d88dafb..0000000 --- a/korge-simon/js/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources -/web diff --git a/korge-simon/js/build.gradle b/korge-simon/js/build.gradle deleted file mode 100644 index 1970612..0000000 --- a/korge-simon/js/build.gradle +++ /dev/null @@ -1,14 +0,0 @@ -apply plugin: 'kotlin-platform-js' - -sourceSets { - main.resources.srcDirs = [ '../common/src/main/resources', '../common/src/generated/resources' ] -} - -dependencies { - implement project(":korge-simon:common") - - compile "com.soywiz:korge-js:$korVersion" - compile "com.soywiz:korge-ext-swf-js:$korVersion" - compile "com.soywiz:korge-ext-ui-js:$korVersion" - compile "com.soywiz:korau-mp3-js:$korVersion" -} diff --git a/korge-simon/js/settings.gradle b/korge-simon/js/settings.gradle deleted file mode 100644 index bdfd8af..0000000 --- a/korge-simon/js/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'korge-simon' diff --git a/korge-simon/jvm/.gitignore b/korge-simon/jvm/.gitignore deleted file mode 100644 index 7f99310..0000000 --- a/korge-simon/jvm/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources diff --git a/korge-simon/jvm/build.gradle b/korge-simon/jvm/build.gradle deleted file mode 100644 index d3916e4..0000000 --- a/korge-simon/jvm/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -apply plugin: 'kotlin-platform-jvm' -apply plugin: 'application' - -mainClassName = 'com.soywiz.korge.samples.simon.Simon' - -sourceSets { - main.resources.srcDirs = [ '../common/src/main/resources', '../common/src/generated/resources' ] -} - -dependencies { - implement project(":korge-simon:common") - - compile "com.soywiz:korge:$korVersion" - compile "com.soywiz:korge-ext-swf:$korVersion" - compile "com.soywiz:korge-ext-ui:$korVersion" - compile "com.soywiz:korau-mp3:$korVersion" -} diff --git a/korge-simon/jvm/settings.gradle b/korge-simon/jvm/settings.gradle deleted file mode 100644 index bdfd8af..0000000 --- a/korge-simon/jvm/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'korge-simon' diff --git a/korge-tic-tac-toe/.gitignore b/korge-tic-tac-toe/.gitignore deleted file mode 100644 index d88dafb..0000000 --- a/korge-tic-tac-toe/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources -/web diff --git a/korge-tic-tac-toe/common/.gitignore b/korge-tic-tac-toe/common/.gitignore deleted file mode 100644 index d88dafb..0000000 --- a/korge-tic-tac-toe/common/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources -/web diff --git a/korge-tic-tac-toe/common/build.gradle b/korge-tic-tac-toe/common/build.gradle deleted file mode 100644 index 489f77c..0000000 --- a/korge-tic-tac-toe/common/build.gradle +++ /dev/null @@ -1,100 +0,0 @@ -apply plugin: 'kotlin-platform-common' -//apply plugin: 'application' - -//mainClassName = "com.soywiz.korge.tictactoe.TicTacToe" - -sourceSets { - //generated.resources.srcDirs = ['src/generated/resources'] - //main.resources.srcDirs = [ 'src/main/resources' ] - main.resources.srcDirs = [ 'src/main/resources', 'src/generated/resources' ] -} - -/* -sourceSets { - generated.resources.srcDirs = [ 'genresources' ] - - main.kotlin.srcDirs = [ 'src' ] - main.resources.srcDirs = [ 'resources', 'genresources' ] - test.kotlin.srcDirs = [ 'test' ] -} -*/ - - -dependencies { - compile "com.soywiz:korge-common:$korVersion" - compile "com.soywiz:korge-ext-swf-common:$korVersion" - compile "com.soywiz:korau-mp3-common:$korVersion" - testCompile "com.soywiz:korge-tests-common:$korVersion" - //compile "com.soywiz:korge:$korVersion" - //compile "com.soywiz:korge-ext-swf:$korVersion" - //compile "com.soywiz:korau-mp3:$korVersion" -} - -/* -compileKotlin2Js { - kotlinOptions.outputFile = "${projectDir}/web/output.js" - //kotlinOptions.moduleKind = "amd" - kotlinOptions.moduleKind = "umd" - //kotlinOptions.moduleKind = "commonjs" - //kotlinOptions.sourceMap = true - kotlinOptions.sourceMap = false -} - - -clean { - delete new File("${projectDir}/web") -} - -compileKotlin2Js.doLast { - configurations.compile.each { File file -> - copy { - includeEmptyDirs = false - - from zipTree(file.absolutePath) - into "${projectDir}/web" - include { fileTreeElement -> - def path = fileTreeElement.path - (path.endsWith(".js") || path.endsWith(".js.map")) && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/")) - } - } - } - - copy { - from sourceSets.main.resources.srcDirs - into "${projectDir}/web" - } -} - -jar.enabled = false -*/ -//distTar.enabled = false -//distZip.enabled = false - - -/* -apply from: "../include.gradle" - -apply plugin: 'kotlin' -apply plugin: 'application' - -mainClassName = "com.soywiz.korge.tictactoe.TicTacToe" - -sourceSets { - generated.resources.srcDirs = [ 'genresources' ] - - main.kotlin.srcDirs = [ 'src' ] - main.resources.srcDirs = [ 'resources', 'genresources' ] - test.kotlin.srcDirs = [ 'test' ] -} - - -dependencies { - compile "com.soywiz:korge:$korVersion" - compile "com.soywiz:korge-ext-swf:$korVersion" - compile "com.soywiz:korau-mp3:$korVersion" -} - -jar.enabled = false -distTar.enabled = false -distZip.enabled = false -*/ diff --git a/korge-tic-tac-toe/common/settings.gradle b/korge-tic-tac-toe/common/settings.gradle deleted file mode 100644 index 6fae12c..0000000 --- a/korge-tic-tac-toe/common/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'korge-tic-tac-toe-common' diff --git a/korge-tic-tac-toe/common/src/generated/resources/main.ani b/korge-tic-tac-toe/common/src/generated/resources/main.ani deleted file mode 100644 index 9064af1..0000000 Binary files a/korge-tic-tac-toe/common/src/generated/resources/main.ani and /dev/null differ diff --git a/korge-tic-tac-toe/common/src/generated/resources/main.ani.0.png b/korge-tic-tac-toe/common/src/generated/resources/main.ani.0.png deleted file mode 100644 index 5b24934..0000000 Binary files a/korge-tic-tac-toe/common/src/generated/resources/main.ani.0.png and /dev/null differ diff --git a/korge-tic-tac-toe/common/src/generated/resources/main.ani.meta b/korge-tic-tac-toe/common/src/generated/resources/main.ani.meta deleted file mode 100644 index 7f774be..0000000 --- a/korge-tic-tac-toe/common/src/generated/resources/main.ani.meta +++ /dev/null @@ -1 +0,0 @@ -{"name":"main.swf","loaderVersion":16,"sha1":"516c0fac4fbcac08b7740d2cabcc718d08c6fab4","configSha1":"3c38f2d222663a800a900cf37498c8ff3b43e9fb"} \ No newline at end of file diff --git a/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/Board.kt b/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/Board.kt deleted file mode 100644 index b749c38..0000000 --- a/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/Board.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.soywiz.korge.tictactoe - -import com.soywiz.korio.util.Extra -import com.soywiz.korma.ds.Array2 -import com.soywiz.korma.geom.PointInt -import kotlin.collections.ArrayList - -enum class Chip { EMPTY, CROSS, CIRCLE } - -class Board(val width: Int = 3, val height: Int = width, val lineSize: Int = width) { - class Cell(val x: Int, val y: Int) : Extra by Extra.Mixin() { - val pos = PointInt(x, y) - var value = Chip.EMPTY - } - - val cells = Array2(width, height) { Cell(it % width, it / width) } - - fun inside(x: Int, y: Int) = cells.inside(x, y) - - fun select(x: Int, y: Int, dx: Int, dy: Int, size: Int): List? { - if (!inside(x, y)) return null - if (!inside(x + dx * (size - 1), y + dy * (size - 1))) return null - return (0 until size).map { cells[x + dx * it, y + dy * it] } - } - - val lines = kotlin.collections.ArrayList>() - - init { - fun addLine(line: List?) { - if (line != null) lines += line - } - for (y in 0..height) { - for (x in 0..width) { - addLine(select(x, y, 1, 0, lineSize)) - addLine(select(x, y, 0, 1, lineSize)) - addLine(select(x, y, 1, 1, lineSize)) - addLine(select(width - x - 1, y, -1, 1, lineSize)) - } - } - } - - operator fun get(x: Int, y: Int) = cells[x, y] - operator fun set(x: Int, y: Int, value: Chip) = run { cells[x, y].value = value } - - val Iterable.chipLine: Chip? - get() { - val expected = this.first().value - return if (expected == Chip.EMPTY) null else if (this.all { it.value == expected }) expected else null - } - - val moreMovements: Boolean get() = cells.any { it.value == Chip.EMPTY } - - val winnerLine: List? - get() { - val out = kotlin.collections.ArrayList() - for (line in lines) if (line.chipLine != null) out += line - return if (out.isEmpty()) null else out.toSet().toList() - } - - val winner: Chip? - get() { - return winnerLine?.firstOrNull()?.value - } -} diff --git a/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/BoardMediator.kt b/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/BoardMediator.kt deleted file mode 100644 index 646dc0f..0000000 --- a/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/BoardMediator.kt +++ /dev/null @@ -1,93 +0,0 @@ -package com.soywiz.korge.tictactoe - -import com.soywiz.korge.animate.play -import com.soywiz.korge.input.onClick -import com.soywiz.korge.input.onUp -import com.soywiz.korge.time.milliseconds -import com.soywiz.korge.tween.* -import com.soywiz.korge.view.View -import com.soywiz.korge.view.get -import com.soywiz.korio.async.Signal -import com.soywiz.korio.async.async -import com.soywiz.korio.util.Extra - -var Board.Cell.view by Extra.Property { null } -val Board.Cell.vview: View get() = this.view!! -val Board.Cell.onPress by Extra.Property { Signal() } - -fun Board.Cell.set(type: Chip) { - this.value = type - view["chip"].play(when (type) { - Chip.EMPTY -> "empty" - Chip.CIRCLE -> "circle" - Chip.CROSS -> "cross" - }) -} - -suspend fun Board.Cell.setAnimate(type: Chip) { - set(type) - async { - view.tween( - (view["chip"]!!::alpha[0.7, 1.0]).linear(), - (view["chip"]!!::scale[0.8, 1.0]).easeOutElastic(), - time = 300.milliseconds - ) - } -} - -var Board.Cell.highlighting by Extra.Property { false } - -suspend fun Board.Cell.highlight(highlight: Boolean) { - view["highlight"].play(if (highlight) "highlight" else "none") - this.highlighting = highlight - if (highlight) { - async { - - val hl = view["highlight"]!! - while (highlighting) { - hl.tween((hl::alpha[0.7]).easeInOutQuad(), time = 300.milliseconds) - hl.tween((hl::alpha[1.0]).easeInOutQuad(), time = 200.milliseconds) - } - } - - async { - val ch = view["chip"]!! - ch.tween((ch::scale[0.4]).easeOutQuad(), time = 100.milliseconds) - ch.tween((ch::scale[1.2]).easeOutElastic(), time = 300.milliseconds) - while (highlighting) { - ch.tween((ch::scale[1.0]).easeOutQuad(), time = 300.milliseconds) - ch.tween((ch::scale[1.2]).easeOutElastic(), time = 300.milliseconds) - } - } - } -} - -suspend fun Board.Cell.lowlight(lowlight: Boolean) { - async { - view.tween( - view!!::scale[1.0, 0.7], - view!!::alpha[0.3], - time = 300.milliseconds, easing = Easings.EASE_OUT_QUAD - ) - } -} - -suspend fun Board.reset() { - for (cell in cells) { - //cell.view?.removeAllComponents() - cell.set(Chip.EMPTY) - cell.highlight(false) - cell.view?.scale = 1.0 - cell.view?.alpha = 1.0 - cell.view["chip"]?.scale = 1.0 - cell.view["chip"]?.alpha = 1.0 - } -} - -fun Board.Cell.init(view: View) { - this.view = view - set(this.value) - view["hit"].onUp { - onPress(Unit) - } -} diff --git a/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/InjectExt.kt b/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/InjectExt.kt deleted file mode 100644 index 4af597c..0000000 --- a/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/InjectExt.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.soywiz.korge.tictactoe - -import com.soywiz.korge.animate.AnLibrary -import com.soywiz.korge.resources.getPath -import com.soywiz.korio.inject.AsyncInjector - -// AUTOGENERATED: -fun AsyncInjector.generatedInject() = this - //.mapPrototype { TicTacToeMainScene(getPath("main.ani")) } // @TODO: kotlin.js bug - //.mapPrototype { TicTacToeMainScene(getPath(AnLibrary::class, "main.ani")) } - .mapPrototype { TicTacToeMainScene() } diff --git a/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/TicTacToe.kt b/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/TicTacToe.kt deleted file mode 100644 index f43e549..0000000 --- a/korge-tic-tac-toe/common/src/main/kotlin/com/soywiz/korge/tictactoe/TicTacToe.kt +++ /dev/null @@ -1,152 +0,0 @@ -package com.soywiz.korge.tictactoe - -import com.soywiz.korge.Korge -import com.soywiz.korge.animate.AnLibrary -import com.soywiz.korge.animate.AnLibraryPlugin -import com.soywiz.korge.input.mouse -import com.soywiz.korge.plugin.KorgePlugin -import com.soywiz.korge.resources.getPath -import com.soywiz.korge.scene.Module -import com.soywiz.korge.scene.Scene -import com.soywiz.korge.view.Container -import com.soywiz.korge.view.descendantsWithPropInt -import com.soywiz.korge.view.get -import com.soywiz.korge.view.setText -import com.soywiz.korio.async.Signal -import com.soywiz.korio.async.go -import com.soywiz.korio.async.waitOne -import com.soywiz.korio.error.invalidOp -import com.soywiz.korio.inject.AsyncInjector -import com.soywiz.korio.lang.JvmStatic -import com.soywiz.korma.geom.PointInt - -object TicTacToe { - @JvmStatic - fun main(args: Array) = Korge(TicTacToeModule, injector = AsyncInjector().generatedInject()) -} - -object TicTacToeModule : Module() { - override val mainScene = TicTacToeMainScene::class - override val title: String = "tic-tac-toe" - override val icon: String = "icon.png" - override val plugins: List = super.plugins + listOf( - AnLibraryPlugin - ) - - suspend override fun init(injector: AsyncInjector) { - //injector.get().mapExtensions("swf" to "ani") - //injector.get().mapExtensionsJustInJTransc("swf" to "ani") - } -} - -// Controller -class TicTacToeMainScene : Scene() { - private lateinit var mainLibrary: AnLibrary - - val board = Board(3, 3) - lateinit var game: Game - - override suspend fun init(injector: AsyncInjector) { - super.init(injector) - - mainLibrary = injector.getPath(AnLibrary::class, "main.ani") - } - - suspend override fun sceneInit(sceneView: Container) { - sceneView += mainLibrary.createMainTimeLine() - - for ((rowView, row) in sceneView.descendantsWithPropInt("row")) { - for ((cellView, cell) in rowView.descendantsWithPropInt("cell")) { - board.cells[row, cell].init(cellView) - } - } - - val p1 = InteractivePlayer(board, Chip.CROSS) - val p2 = BotPlayer(board, Chip.CIRCLE) - //val p2 = InteractivePlayer(board, Chip.CIRCLE) - - game = Game(board, listOf(p1, p2)) - cancellables += go { - while (true) { - game.board.reset() - val result = game.game() - - println(result) - - val results = mainLibrary.createMovieClip("Results") - //(results["result"] as AnTextField).format?.face = Html.FontFace.Bitmap(font) - when (result) { - is Game.Result.DRAW -> results["result"].setText("DRAW") - is Game.Result.WIN -> { - results["result"].setText("WIN") - for (cell in result.cells) cell.highlight(true) - for (cell in game.board.cells.toList() - result.cells) cell.lowlight(true) - } - } - sceneView += results - results["hit"]?.mouse?.onClick?.waitOne() - //sceneView -= results - results.removeFromParent() - - } - } - } -} - -interface Player { - val chip: Chip - suspend fun move(): PointInt -} - -class Game(val board: Board, val players: List) { - interface Result { - object DRAW : Result - class WIN(val player: Player?, val cells: List) : Result - } - - suspend fun game(): Result { - var turn = 0 - while (board.moreMovements) { - val currentPlayer = players[turn % players.size] - while (true) { - val pos = currentPlayer.move() - println(pos) - if (board.cells[pos].value == Chip.EMPTY) { - board.cells[pos].setAnimate(currentPlayer.chip) - break - } - } - if (board.winner != null) return Result.WIN(currentPlayer, board.winnerLine ?: listOf()) - turn++ - } - return Result.DRAW - } -} - -class BotPlayer(val board: Board, override val chip: Chip) : Player { - suspend override fun move(): PointInt { - for (cell in board.cells) { - if (cell.value == Chip.EMPTY) { - return cell.pos - } - } - invalidOp("No more movements") - } -} - -class InteractivePlayer(val board: Board, override val chip: Chip) : Player { - val clicked = Signal() - - init { - for (cell in board.cells) { - cell.onPress { - clicked(cell.pos) - } - } - } - - suspend override fun move(): PointInt { - return clicked.waitOne() - } - -} diff --git a/korge-tic-tac-toe/common/src/main/resources/icon.png b/korge-tic-tac-toe/common/src/main/resources/icon.png deleted file mode 100644 index 77e3dc2..0000000 Binary files a/korge-tic-tac-toe/common/src/main/resources/icon.png and /dev/null differ diff --git a/korge-tic-tac-toe/common/src/main/resources/index.html b/korge-tic-tac-toe/common/src/main/resources/index.html deleted file mode 100644 index 2508ada..0000000 --- a/korge-tic-tac-toe/common/src/main/resources/index.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - diff --git a/korge-tic-tac-toe/common/src/main/resources/main.fla b/korge-tic-tac-toe/common/src/main/resources/main.fla deleted file mode 100644 index e42e22a..0000000 Binary files a/korge-tic-tac-toe/common/src/main/resources/main.fla and /dev/null differ diff --git a/korge-tic-tac-toe/common/src/main/resources/main.swf b/korge-tic-tac-toe/common/src/main/resources/main.swf deleted file mode 100644 index f25c6e9..0000000 Binary files a/korge-tic-tac-toe/common/src/main/resources/main.swf and /dev/null differ diff --git a/korge-tic-tac-toe/common/src/main/resources/main.swf.config b/korge-tic-tac-toe/common/src/main/resources/main.swf.config deleted file mode 100644 index 5821822..0000000 --- a/korge-tic-tac-toe/common/src/main/resources/main.swf.config +++ /dev/null @@ -1,9 +0,0 @@ -mipmaps: true -antialiasing: true -rasterizerMethod: X4 -exportScale: 2.0 -minShapeSide: 64 -maxShapeSide: 512 -minMorphShapeSide: 16 -maxMorphShapeSide: 128 -exportPaths: false \ No newline at end of file diff --git a/korge-tic-tac-toe/common/src/test/kotlin/com/soywiz/korge/tictactoe/BoardTest.kt b/korge-tic-tac-toe/common/src/test/kotlin/com/soywiz/korge/tictactoe/BoardTest.kt deleted file mode 100644 index f3abed5..0000000 --- a/korge-tic-tac-toe/common/src/test/kotlin/com/soywiz/korge/tictactoe/BoardTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.soywiz.korge.tictactoe - -import org.junit.Test -import kotlin.test.assertEquals - -class BoardTest { - @Test - fun name() { - val board = Board() - assertEquals(null, board.winner) - board[0, 0] = Chip.CROSS - board[1, 0] = Chip.CROSS - assertEquals(null, board.winner) - board[2, 0] = Chip.CROSS - assertEquals(Chip.CROSS, board.winner) - } -} diff --git a/korge-tic-tac-toe/js/.gitignore b/korge-tic-tac-toe/js/.gitignore deleted file mode 100644 index d88dafb..0000000 --- a/korge-tic-tac-toe/js/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources -/web diff --git a/korge-tic-tac-toe/js/build.gradle b/korge-tic-tac-toe/js/build.gradle deleted file mode 100644 index 4491f07..0000000 --- a/korge-tic-tac-toe/js/build.gradle +++ /dev/null @@ -1,14 +0,0 @@ -apply plugin: 'kotlin-platform-js' - -sourceSets { - main.resources.srcDirs = [ '../common/src/main/resources', '../common/src/generated/resources' ] -} - -dependencies { - implement project(":korge-tic-tac-toe:common") - - compile "com.soywiz:korge-js:$korVersion" - compile "com.soywiz:korge-ext-swf-js:$korVersion" - compile "com.soywiz:korau-mp3-js:$korVersion" - testCompile "com.soywiz:korge-tests-js:$korVersion" -} diff --git a/korge-tic-tac-toe/js/settings.gradle b/korge-tic-tac-toe/js/settings.gradle deleted file mode 100644 index 1578f51..0000000 --- a/korge-tic-tac-toe/js/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'korge-tic-tac-toe-js' diff --git a/korge-tic-tac-toe/jvm/.gitignore b/korge-tic-tac-toe/jvm/.gitignore deleted file mode 100644 index d88dafb..0000000 --- a/korge-tic-tac-toe/jvm/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/.idea -/.gradle -/build -/classes -/out -/genresources -/web diff --git a/korge-tic-tac-toe/jvm/build.gradle b/korge-tic-tac-toe/jvm/build.gradle deleted file mode 100644 index cc74a08..0000000 --- a/korge-tic-tac-toe/jvm/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ -apply plugin: 'kotlin-platform-jvm' - -apply plugin: 'application' - -mainClassName = 'com.soywiz.korge.tictactoe.TicTacToe' - -sourceSets { - main.resources.srcDirs = [ '../common/src/main/resources', '../common/src/generated/resources' ] -} - -dependencies { - implement project(":korge-tic-tac-toe:common") - - compile "com.soywiz:korge:$korVersion" - compile "com.soywiz:korge-ext-swf:$korVersion" - compile "com.soywiz:korau-mp3:$korVersion" - testCompile "com.soywiz:korge-tests:$korVersion" -} diff --git a/korge-tic-tac-toe/jvm/settings.gradle b/korge-tic-tac-toe/jvm/settings.gradle deleted file mode 100644 index 57aa17e..0000000 --- a/korge-tic-tac-toe/jvm/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'korge-tic-tac-toe' diff --git a/settings.gradle b/settings.gradle index 727803f..3cb511b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,16 +1,23 @@ +pluginManagement { + resolutionStrategy { + eachPlugin { + if (requested.id.id == "kotlin-multiplatform") { + useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") + } + } + } + + repositories { + mavenLocal() + maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' } + maven { url 'https://plugins.gradle.org/m2/' } + jcenter() + mavenCentral() + } +} + rootProject.name = 'korge-samples' -include( - 'korge-tic-tac-toe:common', - 'korge-tic-tac-toe:js', - 'korge-tic-tac-toe:jvm', - - 'korge-simon:common', - 'korge-simon:js', - 'korge-simon:jvm', - - 'korge-coffee:common', - 'korge-coffee:js', - 'korge-coffee:jvm', -) +enableFeaturePreview('GRADLE_METADATA') +include ':korge-sample1' diff --git a/travis_win.bat b/travis_win.bat new file mode 100644 index 0000000..19fb271 --- /dev/null +++ b/travis_win.bat @@ -0,0 +1,45 @@ +REM free some space + +dir + +REM dir c:\ +REM dir "c:\Program Files" +REM dir "c:\Program Files (x86)" + +REM dir /s C:\ProgramData\chocolatey +REM choco uninstall all +REM choco uninstall -y -f cmake cmake.install DotNet4.5 DotNet4.6 windows-sdk-10.0 winscp winscp.install ruby microsoft-build-tools visualstudio2017-workload-netcorebuildtools visualstudio2017-workload-vctools visualstudio2017-workload-webbuildtools visualstudio2017buildtools + +RD /s /q "c:\Program Files\IIS" +RD /s /q "c:\Program Files\Java" +RD /s /q "c:\Program Files\Microsoft" +RD /s /q "c:\Program Files\Microsoft Visual Studio" +RD /s /q "c:\Program Files\Microsoft Visual Studio 14.0" +RD /s /q "c:\Program Files\cmake" +RD /s /q "c:\Program Files\Microsoft SDKs" +RD /s /q "c:\Program Files (x86)\IIS" +RD /s /q "c:\Program Files (x86)\Java" +RD /s /q "c:\Program Files (x86)\Microsoft" +RD /s /q "c:\Program Files (x86)\Microsoft Visual Studio" +RD /s /q "c:\Program Files (x86)\Microsoft Visual Studio 14.0" +RD /s /q "c:\Program Files (x86)\cmake" +RD /s /q "c:\Program Files (x86)\Microsoft SDKs" +REM RD /s /q C:\ProgramData\chocolatey +REM RD /s /q C:\ProgramData + +dir + +choco list --local-only +choco install jdk8 -y -params "installdir=c:\\java8" + +del c:\java8\src.zip +del c:\java8\javafx-src.zip + +dir c:\java8 +dir c:\java8\lib + +CALL refreshenv + +SET JAVA_HOME=c:\java8 +CALL gradlew.bat --no-daemon -s -i mingwX64Test +CALL gradlew.bat --stop