Added flash swf views

This commit is contained in:
Carlos Ballesteros Velasco
2017-04-20 02:05:47 +02:00
parent 1efc0c5478
commit b883695bc5
5 changed files with 70 additions and 1 deletions

View File

@@ -4,4 +4,5 @@ apply plugin: 'kotlin'
dependencies {
compile "com.soywiz:korge:$korVersion"
compile "com.soywiz:korge-ext-swf:$korVersion"
}

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,13 @@
package com.soywiz.korge.tictactoe
import com.soywiz.korio.util.Extra
import com.soywiz.korma.ds.Array2
class Board {
class Cell : Extra by Extra.Mixin() {
enum class Type { EMPTY, CROSS, CIRCLE }
var value = Type.EMPTY
}
val cells = Array2(3, 3) { Cell() }
}

View File

@@ -1,9 +1,19 @@
package com.soywiz.korge.tictactoe
import com.soywiz.korge.Korge
import com.soywiz.korge.animate.AnLibrary
import com.soywiz.korge.animate.play
import com.soywiz.korge.input.onClick
import com.soywiz.korge.resources.Path
import com.soywiz.korge.scene.Module
import com.soywiz.korge.scene.Scene
import com.soywiz.korge.view.Container
import com.soywiz.korge.view.View
import com.soywiz.korge.view.descendantsWithPropInt
import com.soywiz.korge.view.get
import com.soywiz.korio.async.Signal
import com.soywiz.korio.util.Extra
import com.soywiz.korma.ds.Array2
fun main(args: Array<String>) = Korge(TicTacToeModule)
@@ -11,7 +21,52 @@ object TicTacToeModule : Module() {
override val mainScene: Class<out Scene> = TicTacToeMainScene::class.java
}
class TicTacToeMainScene : Scene() {
var Board.Cell.view by Extra.Property<View?> { null }
val Board.Cell.onPress by Extra.Property { Signal<Unit>() }
fun Board.Cell.set(type: Board.Cell.Type) {
this.value = type
view.play(when (type) {
Board.Cell.Type.EMPTY -> "empty"
Board.Cell.Type.CIRCLE -> "circle"
Board.Cell.Type.CROSS -> "cross"
})
}
fun Board.Cell.init(view: View) {
this.view = view
set(this.value)
view["hit"].onClick {
onPress(Unit)
}
}
class TicTacToeMainScene(
@Path("main.swf") val mainLibrary: AnLibrary
) : Scene() {
val board = Board()
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)
//println("$rowId, $cellId")
}
}
var turn = true
for (cell in board.cells) {
cell.onPress {
if (turn) {
cell.set(Board.Cell.Type.CIRCLE)
} else {
cell.set(Board.Cell.Type.CROSS)
}
turn = !turn
}
}
}
}