Character cameos, phase 2: the chooser and its rules, no artwork (0.108.66)

Paul, 6 November 2026, with his answers: Riot, ToonZ evenings and Nite Owl
first; off by default; Luna's glance and eye-roll end about one gag in three.
chooseCameo decides when the cast may appear between programmes: never next to
a film, never on Tots, the Drive-In or for Kids, at most one per channel every
60 to 90 minutes, 20 minutes apart, no gag twice in a session, and the same
answer for the same changeover. CameoTest checks a synthetic week; the
hand-run CameoReplayTest held every rule over the box's real week. Character
cameos and Mini shorts switches added to On screen, off. Nothing new shows.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-06 18:01:49 +00:00
co-authored by Claude Opus 5.5
parent f5dbfa6d22
commit 99fa3adfb8
7 changed files with 232 additions and 5 deletions
@@ -0,0 +1,89 @@
package tv.orbit.classic
import java.time.Instant
import java.time.ZoneId
/**
* Character cameos, phase 2 (Paul, 6 November 2026, docs/character-continuity.md): the choice of when the cast may appear
* between programmes, with no artwork yet. Paul's answers: Riot, ToonZ's evening and ToonZ Late, and Nite Owl go first;
* cameos are off until he turns them on; Luna's fourth-wall glance and eye-roll end about one gag in three.
*
* The rules, all editorial, none touching the schedule:
* - Only at a changeover Orbit owns: one programme running straight into the next, the ending one at least ten minutes.
* - Never next to a film (its credits or its start), never on the Drive-In, Tots or for a Kids profile.
* - At most one per channel every 60 to 90 minutes, at least 20 minutes between any two, and no gag twice in a session.
* - The same changeover always gets the same answer, so changing channel and coming back can't set one off again.
* Mini shorts need gaps the schedule already has and their own artwork; they're chosen in a later phase.
*/
internal enum class Gag(val title: String, val overnightOnly: Boolean = false) {
Chase("The Chase"), WindUp("The Wind-Up"), Sign("The Sign"), RunningLate("Running Late"), NiteOwlShift("Nite Owl's Shift", overnightOnly = true)
}
internal data class Cameo(val gag: Gag, val lunaEnds: Boolean)
/** One changeover: the programme ending and the one starting straight after it. */
internal data class Changeover(val channel: Int, val endingStartMs: Long, val endingType: String, val nextStartMs: Long, val nextType: String)
internal const val CAMEO_MIN_GAP_MS = 60 * 60_000L
internal const val CAMEO_GAP_SPREAD_MS = 30 * 60_000L
internal const val CAMEO_HOUSEHOLD_MS = 20 * 60_000L
private const val CAMEO_SHORTEST_MS = 10 * 60_000L
private const val RIOT = 105
private const val TOONZ = 605
/** Where cameos may appear first: Riot, ToonZ from 18:00 through ToonZ Late, and Junior during Nite Owl. */
internal fun cameoWindow(channel: Int, atMs: Long, zone: ZoneId = ZoneId.systemDefault()): Boolean {
val hour = Instant.ofEpochMilli(atMs).atZone(zone).hour
return when (channel) {
RIOT -> true
TOONZ -> hour >= 18 || hour < TOONZ_LATE.toHour
NITE_OWL.channel -> hour >= NITE_OWL.fromHour || hour < NITE_OWL.toHour
else -> false
}
}
/** The household's record for this time Orbit is open: kept in memory only, gone when Orbit closes. */
internal class CameoDiary {
val lastByChannel = mutableMapOf<Int, Long>()
var lastAny: Long? = null
val seen = mutableSetOf<Gag>()
val decided = mutableMapOf<Pair<Int, Long>, Cameo?>()
}
internal object CameoSession { val diary = CameoDiary() }
/** A steady number from a changeover, so its answer is the same every time it's asked. */
private fun mix(channel: Int, atMs: Long): Int {
var h = channel.toLong() * 1_000_003L xor (atMs / 60_000)
h = (h xor (h ushr 33)) * -0x00ae502812aa7333L; h = h xor (h ushr 29)
return (h and 0x7fffffff).toInt()
}
/** How long this channel rests after a cameo: 60 to 90 minutes, steady for the changeover. */
internal fun cameoGap(channel: Int, atMs: Long) = CAMEO_MIN_GAP_MS + (mix(channel, atMs) % (CAMEO_GAP_SPREAD_MS / 60_000 + 1)) * 60_000L
/**
* Whether this changeover gets a cameo, and which. [on] is Character cameos with the cast switched on; [kids] a Kids
* profile watching. Asked again for the same changeover, it gives the same answer and records nothing more.
*/
internal fun chooseCameo(c: Changeover, diary: CameoDiary, on: Boolean, kids: Boolean, zone: ZoneId = ZoneId.systemDefault()): Cameo? {
if (!on || kids) return null
val key = c.channel to c.nextStartMs
if (key in diary.decided) return diary.decided[key]
val answer = run {
if (c.channel == TOTS_NUMBER || c.channel == DRIVE_IN_NUMBER) return@run null
if (c.endingType == "Movie" || c.nextType == "Movie") return@run null
if (c.nextStartMs - c.endingStartMs < CAMEO_SHORTEST_MS) return@run null
if (!cameoWindow(c.channel, c.nextStartMs, zone)) return@run null
diary.lastByChannel[c.channel]?.let { if (c.nextStartMs - it < cameoGap(c.channel, it)) return@run null }
diary.lastAny?.let { if (c.nextStartMs - it < CAMEO_HOUSEHOLD_MS) return@run null }
val overnight = c.channel == NITE_OWL.channel
val left = Gag.entries.filter { it !in diary.seen && (!it.overnightOnly || overnight) }
if (left.isEmpty()) return@run null
val m = mix(c.channel, c.nextStartMs)
Cameo(left[m % left.size], lunaEnds = (m / 7) % 3 == 0)
}
diary.decided[key] = answer
if (answer != null) { diary.lastByChannel[c.channel] = c.nextStartMs; diary.lastAny = c.nextStartMs; diary.seen += answer.gag }
return answer
}
@@ -62,9 +62,9 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
}
/** The sign-in headers for this kind of server. */
internal fun authHeaders(token: String?): Map<String, String> = when (kind) {
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.65\"") +
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.66\"") +
(token?.let { mapOf("X-Emby-Token" to it) } ?: emptyMap())
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.65\"" +
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.66\"" +
(token?.let { ", Token=\"$it\"" } ?: ""))
}
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
@@ -39,7 +39,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
next.instanceFollowRedirects = false
next.connectTimeout = 10_000
next.readTimeout = 20_000
next.setRequestProperty("User-Agent", "OrbitTV/0.108.65")
next.setRequestProperty("User-Agent", "OrbitTV/0.108.66")
next.setRequestProperty("Accept-Encoding", "identity")
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {
@@ -116,6 +116,14 @@ internal class OrbitSettings(context: Context) {
get() = saved.getString("look", null)?.let { name -> OrbitLook.entries.firstOrNull { it.name == name } } ?: OrbitLook.Night
set(value) { saved.edit().putString("look", value.name).apply() }
/** Turns off moving presentation: the Drive-In's curtains, and every slide and rise becomes a short fade (design/motion). */
/** The cast between programmes, now and then (docs/character-continuity.md); off until Paul turns it on. */
var characterCameos: Boolean
get() = saved.getBoolean("character_cameos", false)
set(value) { saved.edit().putBoolean("character_cameos", value).apply() }
/** The cast's mini shorts, rarer still; off until Paul turns them on. */
var miniShorts: Boolean
get() = saved.getBoolean("mini_shorts", false)
set(value) { saved.edit().putBoolean("mini_shorts", value).apply() }
/** Brick Break's power-up sounds (Paul, 6 November 2026). */
var arcadeSounds: Boolean
get() = saved.getBoolean("arcade_sounds", true)
@@ -254,6 +262,8 @@ private fun ViewingDetail(firstSwitch: FocusRequester, modifier: Modifier, top:
var reduceMotion by remember { mutableStateOf(settings.reduceMotion) }
var squeezeBack by remember { mutableStateOf(settings.squeezeBack) }
var castOn by remember { mutableStateOf(settings.castOn) }
var cameos by remember { mutableStateOf(settings.characterCameos) }
var miniShorts by remember { mutableStateOf(settings.miniShorts) }
var specialIdents by remember { mutableStateOf(settings.specialIdents) }
var blockIdentSound by remember { mutableStateOf(settings.blockIdentSound) }
Column(modifier.verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(8.dp)) {
@@ -284,6 +294,13 @@ private fun ViewingDetail(firstSwitch: FocusRequester, modifier: Modifier, top:
SettingLine("The cast", "Show Ollie, Zip, Blaze, Drift and Luna in the squeeze-back and promos.") {
OnOff(castOn, Modifier, onClick = { castOn = !castOn; settings.castOn = castOn })
}
// Character Shorts (Paul, 6 November 2026): both follow The cast, which turns everything off.
SettingLine("Character cameos", if (castOn) "Now and then the cast pop up between programmes on Riot, ToonZ in the evening and Nite Owl. Never over a programme or a film." else "Turn on The cast first.") {
OnOff(cameos, Modifier, enabled = castOn, onClick = { cameos = !cameos; settings.characterCameos = cameos })
}
SettingLine("Mini shorts", if (castOn) "Rarer still: a short cartoon with the cast in a gap the schedule already has. Coming in a later update." else "Turn on The cast first.") {
OnOff(miniShorts, Modifier, enabled = castOn, onClick = { miniShorts = !miniShorts; settings.miniShorts = miniShorts })
}
var promoNote by remember { mutableStateOf<String?>(null) }
SettingLine("Promos", promoNote ?: "Now and then a promo for tonight's highlights plays in place of a channel's ident. See one now; it closes by itself.") {
OrbitButton("Show one", onClick = {