Skip to content

Commit

Permalink
Merge branch 'main' of github.com:manuel-martos/puzzyx
Browse files Browse the repository at this point in the history
  • Loading branch information
mmartosdev committed Sep 30, 2023
2 parents bdee04d + 1d740eb commit a9a9718
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ val entries = listOf(
)
)

val puzzle1Entries = entries.filter { it.puzzle == Puzzle.PUZZLE1 }
val puzzle1Entries = entries
.filter { it.puzzle == Puzzle.PUZZLE1 }
.also { if (it.size > Puzzle.PUZZLE1.maxEntryCount)
error("This puzzle is already filled up. Add your entry to another one!")
}
11 changes: 9 additions & 2 deletions shared/src/commonMain/kotlin/com/bumble/puzzyx/model/Puzzle.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.bumble.puzzyx.model

enum class Puzzle {
PUZZLE1
enum class Puzzle(
val imagesDir: String,
val columns: Int,
val rows: Int
) {

PUZZLE1("bumble_logo", 19, 9);

val maxEntryCount: Int = columns * rows
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.bumble.puzzyx.model

import com.bumble.appyx.utils.multiplatform.Parcelable
import com.bumble.appyx.utils.multiplatform.Parcelize

@Parcelize
data class PuzzlePiece(
val i: Int,
val j: Int,
val entry: Entry
)
val entryId: Int
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.bumble.appyx.utils.multiplatform.Parcelize
import com.bumble.puzzyx.appyx.component.backstackclipper.BackStackClipper
import com.bumble.puzzyx.composable.CallToActionScreen
import com.bumble.puzzyx.composable.MessageBoard
import com.bumble.puzzyx.model.Puzzle.PUZZLE1
import com.bumble.puzzyx.node.app.PuzzyxAppNode.NavTarget
import com.bumble.puzzyx.node.app.PuzzyxAppNode.NavTarget.CallToAction
import com.bumble.puzzyx.node.app.PuzzyxAppNode.NavTarget.MessageBoard
Expand Down Expand Up @@ -72,9 +73,7 @@ class PuzzyxAppNode(
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node =
when (navTarget) {
is Puzzle1 -> Puzzle1Node(
imageDirectory = "bumble_logo/",
columns = 19,
rows = 9,
puzzle = PUZZLE1,
buildContext = buildContext
)
is CallToAction -> node(buildContext) { modifier -> CallToActionScreen(modifier) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,18 @@ private val animationSpec = spring<Float>(

class Puzzle1Node(
buildContext: BuildContext,
private val imageDirectory: String,
private val columns: Int,
private val rows: Int,
private val puzzle: Puzzle,
private val gridPuzzle: GridPuzzle = GridPuzzle(
gridRows = rows,
gridCols = columns,
pieces = IntRange(0, rows * columns - 1)
gridRows = puzzle.rows,
gridCols = puzzle.columns,
pieces = IntRange(0, puzzle.rows * puzzle.columns - 1)
.shuffled(Random(123))
.take(puzzle1Entries.size)
.mapIndexed { sequentialIdx, shuffledIdx ->
PuzzlePiece(
i = shuffledIdx % columns,
j = shuffledIdx / columns,
entry = puzzle1Entries[sequentialIdx]
i = shuffledIdx % puzzle.columns,
j = shuffledIdx / puzzle.columns,
entryId = sequentialIdx
)
},
savedStateMap = buildContext.savedStateMap,
Expand All @@ -86,14 +84,14 @@ class Puzzle1Node(

Box(
modifier = modifier
.fillMaxWidth(1f / columns)
.fillMaxHeight(1f / rows)
.fillMaxWidth(1f / puzzle.columns)
.fillMaxHeight(1f / puzzle.rows)
) {
FlashCard(
flash = Color.White,
front = { modifier ->
ResourceImage(
path = "${imageDirectory}slice_${puzzlePiece.j}_${puzzlePiece.i}.png",
path = "${puzzle.imagesDir}/slice_${puzzlePiece.j}_${puzzlePiece.i}.png",
contentScale = ContentScale.FillBounds,
modifier = modifier
.fillMaxSize()
Expand All @@ -105,7 +103,7 @@ class Puzzle1Node(
.fillMaxSize()
.background(color),
// TODO decide on the fate of this
puzzlePiece.entry as? Entry.Text ?: Entry.Text(Puzzle.PUZZLE1, "n/a")
entry = puzzle1Entries[puzzlePiece.entryId] as? Entry.Text ?: Entry.Text(Puzzle.PUZZLE1, "n/a")
)
}
)
Expand All @@ -130,7 +128,7 @@ class Puzzle1Node(
appyxComponent = gridPuzzle,
modifier = Modifier
.align(Alignment.Center)
.aspectRatio(1f * columns / rows)
.aspectRatio(1f * puzzle.columns / puzzle.rows)
.background(Color.DarkGray)
)
Controls(
Expand Down

0 comments on commit a9a9718

Please sign in to comment.