Arcade Daily: one free challenge a day across the games, a star on the day, no streaks; stars awarded as runs end

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 11:24:51 +00:00
co-authored by Claude Opus 5.5
parent 111a9f5d5b
commit d4d9c80746
7 changed files with 232 additions and 8 deletions
@@ -116,6 +116,12 @@ internal object ArcadeGames {
tv.orbit.classic.arcade.codebreaker.CodebreakerScreen(it)
}
val Daily: ArcadeGame = GameDef("ArcadeDaily", "Arcade Daily", "One free challenge a day", "A different challenge from across the Arcade each day: a star if you fancy it.", Mascot.Ollie,
kidsSuitable = true, original = true, launchable = true, ScoreKind.Solved, keepsLevels = true, legacyRecordKey = null,
listOf(Control("◀▶", "Choose"), Control("OK", "Play today's game"), Control("Back", "Arcade home")), "No streaks, nothing lost by missing a day.") {
tv.orbit.classic.arcade.daily.ArcadeDailyScreen(it)
}
// Classics: the eight Kotlin games, unchanged, each in a thin wrapper.
val OrbMan: ArcadeGame = GameDef("OrbMan", "Star Chase", "Maze chase starring Ollie", "Help Ollie clear the stars, and dodge Blaze, Zip, Drift and Luna.", Mascot.Ollie,
kidsSuitable = true, original = false, launchable = true, ScoreKind.Points, keepsLevels = false, legacyRecordKey = "orb_man_best",
@@ -146,7 +152,7 @@ internal object ArcadeGames {
listOf(Control("◀▶▲▼", "Point"), Control("OK", "Pick up / put down"), Control("OK twice", "Send a card home"), Control("Back", "Put back, or pause")),
"Klondike, one card at a time: build each suit home, ace to king.") { PatienceScreen(it) }
val originals = listOf(OrbiRaiders, ChannelChaos, Hive, NightShift, Orbiteroids, QuizNight, TestCardTangle, Codebreaker)
val originals = listOf(OrbiRaiders, ChannelChaos, Hive, NightShift, Orbiteroids, QuizNight, TestCardTangle, Codebreaker, Daily)
val classics = listOf(OrbMan, Blast, Sky, Snake, Blocks, Bricks, Pairs, Patience)
val all = originals + classics
@@ -138,13 +138,15 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit, onExi
writeSetting = { key, on -> update { d -> d.withGame(game.id) { it.copy(settings = it.settings + (key to on)) } } },
writeLevel = { key, value -> update { d -> d.withGame(game.id) { it.copy(level = it.level + (key to value)) } } },
writeLevels = { values -> update { d -> d.withGame(game.id) { it.copy(level = it.level + values) } } },
onRunEnd = { end -> update { recordRun(it, game.id, game.scoreKind, end, System.currentTimeMillis()) } },
onRunEndIn = { table, end -> if (table in scoreTables(game.id)) update { recordRun(it, table, tableKind(game.id, table, game.scoreKind), end, System.currentTimeMillis()) } },
// Every run also counts towards Arcade Daily's challenge, when it's the day's game.
onRunEnd = { end -> update { tv.orbit.classic.arcade.daily.awardDaily(recordRun(it, game.id, game.scoreKind, end, System.currentTimeMillis()), game.id, end, java.time.LocalDate.now(), tv.orbit.classic.arcade.daily.playableIds(visible), System.currentTimeMillis()) } },
onRunEndIn = { table, end -> if (table in scoreTables(game.id)) update { tv.orbit.classic.arcade.daily.awardDaily(recordRun(it, table, tableKind(game.id, table, game.scoreKind), end, System.currentTimeMillis()), table, end, java.time.LocalDate.now(), tv.orbit.classic.arcade.daily.playableIds(visible), System.currentTimeMillis()) } },
onLeave = { session = SessionState.Exited; playing = null },
difficulty = difficultyFor(data, profile.kind), autoFire = autoFireFor(data), reduceFlashing = reduceFlashingFor(data),
kept = record.kept, writeKept = { values -> update { d -> d.withGame(game.id) { it.copy(kept = it.kept + values) } } },
bests = scoreTableDefs(game.id, game.scoreKind).associate { t -> t.id to bestOf(data.game(t.id), t.kind) },
kids = profile.kind == ProfileKind.Kids)
kids = profile.kind == ProfileKind.Kids, playable = tv.orbit.classic.arcade.daily.playableIds(visible),
openGame = { id -> ArcadeGames.byId(id)?.let { next -> session = SessionState.Exited; playing = null; launch(next) } })
key(game.id) { game.Content(play) }
return
}
@@ -40,6 +40,10 @@ internal class ArcadePlay(
val bests: Map<String, Int> = emptyMap(),
/** A Kids profile is playing (Quiz Night keeps to its Kid and Older kid questions). */
val kids: Boolean = false,
/** The games this profile can play (Arcade Daily picks its challenge from them). */
val playable: Set<String> = emptySet(),
/** Opens another game (Arcade Daily's Play): the Arcade leaves this one for that. */
val openGame: (String) -> Unit = {},
) {
/** The best in [table], or the game's own best. */
fun bestIn(table: String) = bests[table] ?: best
@@ -0,0 +1,72 @@
package tv.orbit.classic.arcade.daily
import tv.orbit.classic.arcade.ArcadeGames
import tv.orbit.classic.arcade.ArcadeProfileData
import tv.orbit.classic.arcade.RunEnd
import tv.orbit.classic.arcade.ScoreKind
import tv.orbit.classic.arcade.recordRun
/**
* Arcade Daily (9 November 2026): one free challenge a day, across the games. Meet it and the day gets a star. No streaks,
* nothing lost by missing a day, no pressure (Paul: "free and optional"). The same challenge for everyone on the day,
* from the games a profile can play (a Kids profile's from the kids-suitable ones).
*/
internal const val ARCADE_DAILY_ID = "ArcadeDaily"
/** A challenge: which game, what to do, and how a finished run ([table] it was saved in, its [RunEnd]) meets it. */
internal class DailyChallenge(val gameId: String, val text: String, val met: (table: String, end: RunEnd) -> Boolean)
private fun points(id: String, at: Int, text: String) = DailyChallenge(id, text) { table, end -> table == id && end.score >= at }
private fun finished(id: String, text: String) = DailyChallenge(id, text) { table, end -> table == id && end.finished }
/** Every challenge there is; [dailyFor] picks one a day. Points ones count in the game's own (Classic) table. */
internal val DailyChallenges: List<DailyChallenge> = listOf(
points("OrbMan", 2_000, "Score 2,000 in Star Chase"),
points("Bricks", 1_500, "Score 1,500 in Brick Break"),
points("Snake", 150, "Score 150 in Comet Trail"),
points("Blocks", 2_000, "Score 2,000 in Block Drop"),
points("Blast", 300, "Score 300 in Blast Off"),
finished("Pairs", "Clear a board of Pairs"),
finished("Patience", "Win a game of Patience"),
finished("Sky", "Solve a Skydoku"),
points("Hive", 1_000, "Score 1,000 in BumbleHive"),
points("OrbiRaiders", 3_000, "Score 3,000 in Orbi-Raiders"),
points("ChannelChaos", 1_000, "Score 1,000 in Channel Chaos"),
finished("NightShift", "Finish a level of Nite Owl's Night Shift"),
points("Orbiteroids", 2_500, "Score 2,500 in Orbiteroids"),
points("QuizNight", 300, "Get three right in Quiz Night, on your own"),
finished("TestCardTangle", "Get a picture back on in Test Card Tangle"),
finished("Codebreaker", "Crack a code in Orbi-Fax Codebreaker"),
)
/** The day's challenge: the same for everyone on [day], from the games open to [ids] (a profile's playable games). */
internal fun dailyFor(day: java.time.LocalDate, ids: Set<String>): DailyChallenge? {
val open = DailyChallenges.filter { it.gameId in ids }
if (open.isEmpty()) return null
val order = open.indices.shuffled(java.util.Random(4_242L + open.size))
return open[order[Math.floorMod(day.toEpochDay(), open.size.toLong()).toInt()]]
}
internal fun starKey(day: java.time.LocalDate) = "star.$day"
/**
* A run has ended in [gameId]'s [table]: if it meets the day's challenge and the day has no star yet, the star goes on
* (kept in Arcade Daily's level progress), and Arcade Daily's High Scores count the days with a star.
*/
internal fun awardDaily(data: ArcadeProfileData, table: String, end: RunEnd, day: java.time.LocalDate, ids: Set<String>, nowMs: Long): ArcadeProfileData {
val ch = dailyFor(day, ids) ?: return data
if (data.game(ARCADE_DAILY_ID).level[starKey(day)] != null || !ch.met(table, end)) return data
val starred = data.withGame(ARCADE_DAILY_ID) { it.copy(level = it.level + (starKey(day) to ch.gameId)) }
return recordRun(starred, ARCADE_DAILY_ID, ScoreKind.Solved, RunEnd(1, finished = true, detail = ch.text), nowMs)
}
/** The week's stars, Monday to Sunday, for the page. */
internal fun weekStars(level: Map<String, String>, day: java.time.LocalDate): List<Pair<java.time.LocalDate, Boolean>> {
val monday = day.minusDays((day.dayOfWeek.value - 1).toLong())
return (0 until 7).map { monday.plusDays(it.toLong()).let { d -> d to (level[starKey(d)] != null) } }
}
/** The ids a profile can play, for [dailyFor]. */
internal fun playableIds(visible: List<tv.orbit.classic.arcade.ArcadeGame>) = visible.filter { it.launchable && it.id != ARCADE_DAILY_ID }.map { it.id }.toSet()
internal val dailyGame get() = ArcadeGames.byId(ARCADE_DAILY_ID)
@@ -0,0 +1,88 @@
package tv.orbit.classic.arcade.daily
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.tv.material3.Text
import tv.orbit.classic.Anton
import tv.orbit.classic.ArcadeBackdrop
import tv.orbit.classic.ArcadeBackdropLayer
import tv.orbit.classic.arcade.ArcadeButton
import tv.orbit.classic.arcade.ArcadeColours
import tv.orbit.classic.arcade.ArcadeGames
import tv.orbit.classic.arcade.ArcadePlay
import tv.orbit.classic.arcade.Control
import tv.orbit.classic.arcade.KeyFooter
import tv.orbit.classic.arcade.SpeechBubble
import tv.orbit.classic.arcade.drawMascot
import tv.orbit.classic.arcade.onBackKey
import tv.orbit.classic.starPath
/** Arcade Daily's page: today's challenge, Play it, and the week's stars. Nothing to lose, nothing counting down. */
@Composable
internal fun ArcadeDailyScreen(play: ArcadePlay) {
val latestPlay by rememberUpdatedState(play)
val today = remember { java.time.LocalDate.now() }
val ch = remember(play.playable) { dailyFor(today, play.playable) }
val done = play.level[starKey(today)] != null
val first = remember { FocusRequester() }
LaunchedEffect(Unit) { runCatching { first.requestFocus() } }
BackHandler { latestPlay.onLeave() }
Box(Modifier.fillMaxSize().onBackKey(action = { latestPlay.onLeave() })) {
ArcadeBackdropLayer(ArcadeBackdrop.DeepSpace)
Column(Modifier.fillMaxSize().padding(start = 48.dp, end = 48.dp, top = 28.dp, bottom = 12.dp)) {
Text("AN ORBIT ARCADE ORIGINAL", color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 5.sp)
Text("ARCADE DAILY", color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 56.sp)
Text("One free challenge a day. A star if you fancy it; no streaks, nothing to lose.", color = ArcadeColours.Muted, fontSize = 15.sp)
Spacer(Modifier.height(16.dp))
Row(Modifier.fillMaxWidth().weight(1f), horizontalArrangement = Arrangement.spacedBy(24.dp)) {
val game = ch?.let { ArcadeGames.byId(it.gameId) }
Column(Modifier.weight(1f).background(ArcadeColours.PanelDeep.copy(alpha = .9f), RoundedCornerShape(14.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(14.dp)).padding(20.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)) {
Text("TODAY'S CHALLENGE · ${today.dayOfWeek.name.lowercase().replaceFirstChar { it.uppercase() }} ${today.dayOfMonth}", color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 3.sp)
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(14.dp)) {
if (game != null) Canvas(Modifier.size(70.dp)) { drawMascot(game.mascot, center, size.minDimension * .38f) }
Text(ch?.text ?: "No games to play today", color = ArcadeColours.Ink, fontSize = 24.sp, fontWeight = FontWeight.SemiBold)
}
Text(if (done) "Done: today has its star ★" else "Not yet. Whenever you like, or not at all.", color = if (done) ArcadeColours.Yellow else ArcadeColours.Muted, fontSize = 16.sp, fontWeight = FontWeight.SemiBold)
Spacer(Modifier.weight(1f))
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
if (game != null) ArcadeButton("Play ${game.title}", Modifier.width(280.dp).focusRequester(first), icon = "▶", primary = true, height = 36.dp, onClick = { latestPlay.openGame(game.id) })
ArcadeButton("Back to Arcade", Modifier.width(200.dp).then(if (game == null) Modifier.focusRequester(first) else Modifier), icon = "←", height = 36.dp, onClick = { latestPlay.onLeave() })
}
}
Column(Modifier.width(240.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(10.dp)) {
SpeechBubble(if (done) "Lovely! See you\ntomorrow, maybe." else "Fancy it? No\npressure at all.")
Canvas(Modifier.size(90.dp)) { drawMascot(tv.orbit.classic.arcade.Mascot.Ollie, center, size.minDimension * .36f) }
Text("THIS WEEK", color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 3.sp)
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
for ((d, star) in weekStars(play.level, today)) Column(horizontalAlignment = Alignment.CenterHorizontally) {
Canvas(Modifier.size(26.dp)) {
val p = starPath(center, size.minDimension * .48f, size.minDimension * .2f, 0f)
if (star) drawPath(p, ArcadeColours.Yellow) else drawPath(p, ArcadeColours.Line, style = Stroke(2f))
}
Text(d.dayOfWeek.name.take(1), color = if (d == today) ArcadeColours.Ink else ArcadeColours.Muted, fontSize = 12.sp, textAlign = TextAlign.Center)
}
}
Text("${play.best} stars in all", color = ArcadeColours.Muted, fontSize = 13.sp)
}
}
Spacer(Modifier.height(8.dp))
KeyFooter(listOf(Control("◀▶", "Choose"), Control("OK", "Select"), Control("Back", "Arcade home")))
}
}
}
@@ -16,7 +16,7 @@ class KidsArcadeTest {
@Test fun grownUpsSeeEveryGame() {
assertEquals(ArcadeGames.all.map { it.id }, ids(grown))
assertEquals(16, ids(grown).size)
assertEquals(17, ids(grown).size)
// A grown-up's Arcade for Kids setting means nothing.
assertEquals(ArcadeGames.all.map { it.id }, ids(grown.withKidsArcade(KidsArcade.Off)))
assertEquals(ArcadeGames.all.map { it.id }, ids(null))
@@ -70,16 +70,16 @@ class KidsArcadeTest {
@Test fun theFamilyLineSaysWhatKidsReallySee() {
// The audit: "On: the games chosen for Kids" promised a choice that didn't exist.
assertEquals("Off: no Arcade for Kids", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Off)))
assertEquals("Kids-suitable games: 14 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.KidsSuitable)))
assertEquals("Kids-suitable games: 15 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.KidsSuitable)))
assertEquals("Chosen games: 2 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Chosen, setOf("Pairs", "Sky", "Retired"))))
assertEquals("Chosen games: none chosen yet, so no Arcade", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Chosen, emptySet())))
}
@Test fun everyGameIsDescribed() {
assertEquals(ArcadeGames.all.size, ArcadeGames.all.map { it.id }.toSet().size)
assertEquals(8, ArcadeGames.originals.size); assertEquals(8, ArcadeGames.classics.size)
assertEquals(9, ArcadeGames.originals.size); assertEquals(8, ArcadeGames.classics.size)
// All five Originals play now (Orbiteroids, the last, 9 November 2026); every Classic does.
assertEquals(listOf("OrbiRaiders", "ChannelChaos", "Hive", "NightShift", "Orbiteroids", "QuizNight", "TestCardTangle", "Codebreaker"), ArcadeGames.originals.filter { it.launchable }.map { it.id })
assertEquals(listOf("OrbiRaiders", "ChannelChaos", "Hive", "NightShift", "Orbiteroids", "QuizNight", "TestCardTangle", "Codebreaker", "ArcadeDaily"), ArcadeGames.originals.filter { it.launchable }.map { it.id })
assertTrue(ArcadeGames.classics.all { it.launchable })
ArcadeGames.all.forEach { g ->
assertTrue(g.id, g.controls.isNotEmpty()); assertTrue(g.id, g.title.isNotBlank()); assertTrue(g.id, g.goal.isNotBlank())
@@ -0,0 +1,52 @@
package tv.orbit.classic.arcade.daily
import org.junit.Assert.*
import org.junit.Test
import tv.orbit.classic.arcade.ArcadeGames
import tv.orbit.classic.arcade.ArcadeProfileData
import tv.orbit.classic.arcade.RunEnd
import tv.orbit.classic.arcade.ScoreKind
import tv.orbit.classic.arcade.bestOf
class ArcadeDailyTest {
private val day = java.time.LocalDate.of(2026, 11, 9)
private val all = playableIds(ArcadeGames.all)
@Test fun everyChallengeIsForARealGameAndTheDayPicksOne() {
assertTrue(DailyChallenges.all { ArcadeGames.byId(it.gameId)?.launchable == true })
assertFalse(ARCADE_DAILY_ID in all)
assertEquals(dailyFor(day, all)!!.text, dailyFor(day, all)!!.text)
// Over a fortnight it moves round the games.
assertTrue((0L until 14L).map { dailyFor(day.plusDays(it), all)!!.gameId }.toSet().size >= 8)
// Only from the games a profile can play: a Kids profile without Blast Off never gets it.
val kids = all - "Blast" - "Sky"
assertTrue((0L until 60L).none { dailyFor(day.plusDays(it), kids)!!.gameId in setOf("Blast", "Sky") })
assertNull(dailyFor(day, emptySet()))
}
@Test fun meetingTheChallengeStarsTheDayOnceAndMissingItCostsNothing() {
val ch = dailyFor(day, all)!!
var d = ArcadeProfileData(profileId = "p1")
// A run in another game does nothing.
val other = DailyChallenges.first { it.gameId != ch.gameId }.gameId
d = awardDaily(d, other, RunEnd(999_999, true), day, all, 1)
assertNull(d.game(ARCADE_DAILY_ID).level[starKey(day)])
// A run that meets it stars the day, once.
d = awardDaily(d, ch.gameId, RunEnd(999_999, true), day, all, 2)
assertEquals(ch.gameId, d.game(ARCADE_DAILY_ID).level[starKey(day)])
d = awardDaily(d, ch.gameId, RunEnd(999_999, true), day, all, 3)
assertEquals(1, bestOf(d.game(ARCADE_DAILY_ID), ScoreKind.Solved))
// The week shows it; there is no streak to lose.
val week = weekStars(d.game(ARCADE_DAILY_ID).level, day)
assertEquals(7, week.size); assertEquals(1, week.count { it.second }); assertEquals(java.time.DayOfWeek.MONDAY, week.first().first.dayOfWeek)
}
@Test fun aRunThatFallsShortDoesntCount() {
val pts = DailyChallenges.first { it.gameId == "OrbMan" }
assertFalse(pts.met("OrbMan", RunEnd(1_999, true))); assertTrue(pts.met("OrbMan", RunEnd(2_000, false)))
// Signal Run's table isn't Classic's.
assertFalse(pts.met("OrbManSignal", RunEnd(5_000, true)))
val fin = DailyChallenges.first { it.gameId == "Patience" }
assertFalse(fin.met("Patience", RunEnd(80, false))); assertTrue(fin.met("Patience", RunEnd(80, true)))
}
}