Skip to content

Commit

Permalink
Merge pull request #51 from sergioborne/Fix_puzzle_entries
Browse files Browse the repository at this point in the history
Fix mosaic entries
  • Loading branch information
sergioborne authored Oct 25, 2023
2 parents 2c75c71 + 31b9903 commit e93229c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.bumble.livemosaic.model

import com.bumble.livemosaic.model.MosaicConfig.MOSAIC1
import com.bumble.livemosaic.model.MosaicConfig.MOSAIC2
import com.bumble.livemosaic.model.MosaicConfig.MOSAIC3

val entries = listOf(
Entry.Text(
Expand All @@ -19,9 +21,38 @@ val mosaic1Entries = entries
.filter { it.mosaic == MOSAIC1 }
.also {
if (it.size > MOSAIC1.maxEntryCount)
error("This mosaic is already filled up. Add your entry to another one!")
error("Mosaic 1 is already filled up. Add your entry to another one!")
if (it.map { it.githubUserName }.distinct().size < it.size) {
error("One entry per mosaic is the limit, but you can try again in the next one!")
}
}

val mosaic2Entries = entries
.filter { it.mosaic == MOSAIC2 }
.also {
if (it.size > MOSAIC2.maxEntryCount)
error("Mosaic 2 is already filled up. Add your entry to another one!")
if (it.isNotEmpty() && entries.filter { it.mosaic == MOSAIC1 }.size < MOSAIC1.maxEntryCount)
error("Mosaic 1 is not yet filled up. Add your entry to it!")
if (it.map { it.githubUserName }.distinct().size < it.size) {
error("One entry per mosaic is the limit, but you can try again in the next one!")
}
}

val mosaic3Entries = entries
.filter { it.mosaic == MOSAIC3 }
.also {
if (it.size > MOSAIC3.maxEntryCount)
error("Mosaic 3 is already filled up. Add your entry to another one!")
if (it.isNotEmpty() && entries.filter { it.mosaic == MOSAIC1 }.size > MOSAIC1.maxEntryCount)
error("Mosaic 1 is not yet filled up. Add your entry to it!")
if (it.isNotEmpty() && entries.filter { it.mosaic == MOSAIC2 }.size < MOSAIC2.maxEntryCount)
error("Mosaic 2 is not yet filled up. Add your entry to it!")
if (it.map { it.githubUserName }.distinct().size < it.size) {
error("One entry per mosaic is the limit, but you can try again in the next one!")
}
}

fun List<Entry>.hasMosaic2Entries() = any { it.mosaic == MOSAIC2 }

fun List<Entry>.hasMosaic3Entries() = any { it.mosaic == MOSAIC3 }
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import com.bumble.livemosaic.composable.CallToActionScreen
import com.bumble.livemosaic.model.MosaicConfig.MOSAIC1
import com.bumble.livemosaic.model.MosaicConfig.MOSAIC2
import com.bumble.livemosaic.model.MosaicConfig.MOSAIC3
import com.bumble.livemosaic.model.entries
import com.bumble.livemosaic.model.hasMosaic2Entries
import com.bumble.livemosaic.model.hasMosaic3Entries
import com.bumble.livemosaic.node.app.LiveMosaicAppNode.NavTarget
import com.bumble.livemosaic.node.app.LiveMosaicAppNode.NavTarget.CallToAction
import com.bumble.livemosaic.node.app.LiveMosaicAppNode.NavTarget.Mosaic1
Expand All @@ -52,13 +55,16 @@ import com.bumble.livemosaic.node.starfield.StarFieldNode
import com.bumble.livemosaic.ui.DottedMeshShape
import com.bumble.livemosaic.ui.LocalAutoPlayFlow

private val screens = listOf(
private val screens = listOfNotNull(
Mosaic1,
Mosaic2,
Mosaic3,
CallToAction,
StarField,
StackedMessages,
Mosaic2.takeIf { entries.hasMosaic2Entries() },
CallToAction.takeIf { entries.hasMosaic2Entries() },
StackedMessages.takeIf { entries.hasMosaic2Entries() },
Mosaic3.takeIf { entries.hasMosaic3Entries() },
CallToAction.takeIf { entries.hasMosaic3Entries() },
StarField.takeIf { entries.hasMosaic3Entries() },
)

class LiveMosaicAppNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import com.bumble.livemosaic.imageloader.EmbeddableResourceImage
import com.bumble.livemosaic.model.MosaicConfig
import com.bumble.livemosaic.model.MosaicPiece
import com.bumble.livemosaic.model.mosaic1Entries
import com.bumble.livemosaic.model.mosaic2Entries
import com.bumble.livemosaic.model.mosaic3Entries
import com.bumble.livemosaic.ui.LocalAutoPlayFlow
import com.bumble.livemosaic.ui.appyx_dark
import com.bumble.livemosaic.ui.colors
Expand All @@ -58,7 +60,13 @@ class MosaicNode(
gridCols = config.columns,
pieces = IntRange(0, config.rows * config.columns - 1)
.shuffled(Random(123))
.take(mosaic1Entries.size)
.take(
when (config) {
MosaicConfig.MOSAIC1 -> mosaic1Entries
MosaicConfig.MOSAIC2 -> mosaic2Entries
MosaicConfig.MOSAIC3 -> mosaic3Entries
}.size
)
.mapIndexed { sequentialIdx, shuffledIdx ->
MosaicPiece(
i = shuffledIdx % config.columns,
Expand Down

0 comments on commit e93229c

Please sign in to comment.