Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,17 @@ catalogue's de-duplication can swap the rows the demo points at.
Things the emulator needs that a phone does not:

- **Scores are never persisted**, so the tracker always restores at 0–0. Tap points in
(press a seat's right half, then a dot) before capturing.
(press a seat's right half, then a dot) before capturing — or, for the four-player
shot, run `scripts/screenshot-demo.sh <serial> --four-players`: it seeds
`DemoData.fourPlayerSeats` with scores, logs and XP, and the debug-only `DemoScores`
(bound through the `Optional<RestoredScoresPolicy>` seam in `PointTrackerViewModel`)
keeps them on restore for the rest of that process. Release builds bind nothing there.
- **A debug build from another checkout can carry a higher versionCode**, and the
script's `install -r` then fails with `INSTALL_FAILED_VERSION_DOWNGRADE`;
`adb uninstall com.scanrift.android.debug` first (the seed replaces the data anyway).
- **The Fold's rotation lock is per display state**: `settings get system user_rotation`
can say 1 while the inner display sits at ROTATION_0. Use
`cmd window user-rotation -d 0 lock 1` and check `dumpsys window displays`.
- **The binder-page shot** comes from a photo, not the camera: compose a 3×3 page from
nine card images, `adb push` it to `/sdcard/Pictures/`, run
`adb shell content call --uri content://media/external/file --method scan_volume --arg external_primary`,
Expand Down
33 changes: 32 additions & 1 deletion app/src/debug/java/com/scanrift/android/demo/DemoData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.scanrift.android.demo

import com.scanrift.android.domain.model.CardLanguage
import com.scanrift.android.domain.model.GameResult
import com.scanrift.android.domain.model.ScoreCategory

/**
* The store-screenshot data set, as plain values.
Expand Down Expand Up @@ -52,7 +53,19 @@ internal object DemoData {
val hold: Int,
)

data class Seat(val name: String, val legend: String, val deck: String?)
/**
* A tracker seat. [scoreLog] is the order the points were scored in; the seeder
* derives the per-category counts from it, so the two always agree.
*/
data class Seat(
val name: String,
val legend: String,
val deck: String?,
val scoreLog: List<ScoreCategory> = emptyList(),
val xp: Int = 0,
) {
fun count(category: ScoreCategory): Int = scoreLog.count { it == category }
}

private fun stack(
riftboundId: String,
Expand Down Expand Up @@ -284,6 +297,24 @@ internal object DemoData {
Seat(name = "Hugo", legend = "sfd-246-221", deck = null),
)

private val C = ScoreCategory.CONQUER
private val H = ScoreCategory.HOLD
private val O = ScoreCategory.OTHER

/**
* The four-player game in progress (`--ez fourPlayers true`), for the multiplayer
* screenshot. Every legend is a special printing — Secret Garden Lillia, the overnumbered
* Irelia, the Ahri Signature and the overnumbered Riven — and every
* score sits below victory, with a mix of categories so each track reads as a game.
* Unlike [seats], these scores survive the tracker's load: see [DemoScores].
*/
val fourPlayerSeats: List<Seat> = listOf(
Seat(name = "Lena", legend = "sgn-001-003", deck = "Lillia Dreams", scoreLog = listOf(H, C, H, O, C, H), xp = 7),
Seat(name = "Hugo", legend = "sfd-246-221", deck = "Irelia Blade Dance", scoreLog = listOf(C, C, H, C), xp = 4),
Seat(name = "Sam", legend = "ogn-303*-298", deck = null, scoreLog = listOf(H, H, O, C, H), xp = 5),
Seat(name = "Jules", legend = "rad-173-167", deck = null, scoreLog = listOf(C, H, O), xp = 2),
)

/** Cards on the system Wishlist. */
val wishlist: List<String> = listOf("unl-058a-219", "sfd-246-221", "rad-149-167", "ven-109-166")
}
30 changes: 30 additions & 0 deletions app/src/debug/java/com/scanrift/android/demo/DemoScores.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.scanrift.android.demo

import com.scanrift.android.ui.game.RestoredScoresPolicy
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Inject
import javax.inject.Singleton

/**
* Lets the point tracker open on the seeded game in progress instead of zeroing it.
*
* Held in memory only, and set only by the four-player seed, so it lasts for the
* screenshot session's process and no longer: the next cold start of a debug build is
* back to the normal zero-on-load behaviour.
*/
@Singleton
class DemoScores @Inject constructor() : RestoredScoresPolicy {
@Volatile var keepScores: Boolean = false

override fun keepsRestoredScores(): Boolean = keepScores
}

@Module
@InstallIn(SingletonComponent::class)
abstract class DemoScoresModule {
@Binds
abstract fun restoredScoresPolicy(impl: DemoScores): RestoredScoresPolicy
}
16 changes: 13 additions & 3 deletions app/src/debug/java/com/scanrift/android/demo/DemoSeeder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.scanrift.android.di.IoDispatcher
import com.scanrift.android.domain.model.CardCondition
import com.scanrift.android.domain.model.DeckSection
import com.scanrift.android.domain.model.ScanLanguage
import com.scanrift.android.domain.model.ScoreCategory
import com.scanrift.android.ui.game.PlayerState
import java.util.UUID
import java.util.concurrent.TimeUnit
Expand All @@ -45,12 +46,14 @@ class DemoSeeder @Inject constructor(
private val cardListDao: CardListDao,
private val listRepository: CardListRepository,
private val userPreferences: UserPreferences,
private val demoScores: DemoScores,
@param:IoDispatcher private val io: CoroutineDispatcher,
) {

data class Summary(val stacks: Int, val copies: Int, val decks: Int, val games: Int)

suspend fun seed(now: Long = System.currentTimeMillis()): Summary = withContext(io) {
/** [fourPlayers] swaps the two-seat roster for [DemoData.fourPlayerSeats], scores and all. */
suspend fun seed(now: Long = System.currentTimeMillis(), fourPlayers: Boolean = false): Summary = withContext(io) {
val cards = resolveCards()
fun card(rid: String): CardEntity = cards.getValue(rid)
val deckIds = DemoData.decks.associate { it.name to UUID.nameUUIDFromBytes(it.name.toByteArray()).toString() }
Expand Down Expand Up @@ -121,14 +124,21 @@ class DemoSeeder @Inject constructor(
cardListDao.addCardsToList(DemoData.wishlist.map { CardListCrossRef(wishlist, card(it).id) })
}

val roster = DemoData.seats.map { seat ->
val seats = if (fourPlayers) DemoData.fourPlayerSeats else DemoData.seats
val roster = seats.map { seat ->
PlayerState(
name = seat.name,
conquer = seat.count(ScoreCategory.CONQUER),
hold = seat.count(ScoreCategory.HOLD),
ability = seat.count(ScoreCategory.OTHER),
xp = seat.xp,
scoreLog = seat.scoreLog,
legendCardId = card(seat.legend).id,
deckId = seat.deck?.let(deckIds::getValue),
)
}
userPreferences.setPointTrackerRoster(Json.encodeToString(roster))
demoScores.keepScores = fourPlayers
// The demo binder page is all English. Forcing English also skips the Chinese and
// Korean OCR pass, whose Play Services TFLite module dies with SIGILL on the
// arm64 emulator — with Auto, importing a page photo kills the app there.
Expand All @@ -154,7 +164,7 @@ class DemoSeeder @Inject constructor(
addAll(deck.battlefields)
}
DemoData.games.forEach { add(it.legend); add(it.opponentLegend) }
DemoData.seats.forEach { add(it.legend) }
(DemoData.seats + DemoData.fourPlayerSeats).forEach { add(it.legend) }
addAll(DemoData.wishlist)
}
val resolved = wanted.associateWith { rid ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import kotlinx.coroutines.withTimeoutOrNull
* adb shell am start -n com.scanrift.android.debug/com.scanrift.android.demo.ScreenshotDemoActivity
* ```
*
* Add `--ez fourPlayers true` to seed the four-player game in progress instead of the
* two empty seats.
*
* Lives in the debug source set and is declared only in the debug manifest, so release
* builds contain neither the activity nor the seeder.
*
Expand Down Expand Up @@ -70,7 +73,8 @@ class ScreenshotDemoActivity : ComponentActivity() {
withTimeoutOrNull(BOOTSTRAP_TIMEOUT_MS) { bootstrapper.state.first { !it.isLoading } }

status = "Seeding demo data…"
val outcome = runCatching { seeder.seed() }
val fourPlayers = intent.getBooleanExtra(EXTRA_FOUR_PLAYERS, false)
val outcome = runCatching { seeder.seed(fourPlayers = fourPlayers) }
outcome.onFailure { Log.database.e(it, "Demo seeding failed") }
status = outcome.fold(
onSuccess = { "Seeded ${it.stacks} stacks, ${it.decks} decks, ${it.games} games" },
Expand All @@ -86,6 +90,7 @@ class ScreenshotDemoActivity : ComponentActivity() {
}

private companion object {
const val EXTRA_FOUR_PLAYERS = "fourPlayers"
const val BOOTSTRAP_START_TIMEOUT_MS = 5_000L
const val BOOTSTRAP_TIMEOUT_MS = 120_000L
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AutoAwesome
import androidx.compose.material.icons.filled.Block
import androidx.compose.material.icons.filled.EditNote
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.outlined.Circle
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -27,6 +29,7 @@ import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
Expand All @@ -40,6 +43,8 @@ import com.scanrift.android.domain.model.Rarity
import com.scanrift.android.ui.components.domainIcon
import com.scanrift.android.ui.components.SectionLabel
import com.scanrift.android.ui.components.SheetHeader
import com.scanrift.android.ui.components.StatusBannedRed
import com.scanrift.android.ui.components.StatusErrataOrange
import com.scanrift.android.ui.theme.Dimens
import com.scanrift.android.ui.theme.RarityShowcase
import kotlin.math.roundToInt
Expand Down Expand Up @@ -97,6 +102,32 @@ fun CollectionFilterSheet(
onClick = { onFiltersChange(filters.copy(foilOnly = !filters.foilOnly)) },
)
}
if (facets.statuses.isNotEmpty()) {
item(key = "header-Status") { SectionLabel("Status", Modifier.padding(horizontal = 20.dp)) }
items(facets.statuses, key = { "Status-${it.status.name}" }) { facet ->
FilterRow(
label = facet.status.label,
count = facet.count,
selected = facet.status in filters.statuses,
leading = {
Icon(
facet.status.icon,
contentDescription = null,
tint = facet.status.color,
modifier = Modifier.size(20.dp),
)
},
onClick = {
val statuses = filters.statuses
onFiltersChange(
filters.copy(
statuses = if (facet.status in statuses) statuses - facet.status else statuses + facet.status,
),
)
},
)
}
}
if (facets.languages.isNotEmpty()) {
item(key = "header-Language") { SectionLabel("Language", Modifier.padding(horizontal = 20.dp)) }
items(facets.languages, key = { "Language-${it.value}" }) { facet ->
Expand Down Expand Up @@ -240,6 +271,19 @@ private fun RangeRow(bounds: IntRange, min: Int?, max: Int?, onChange: (Int?, In
}
}

private val CardStatusFilter.icon
get() = when (this) {
CardStatusFilter.BANNED -> Icons.Filled.Block
CardStatusFilter.ERRATA -> Icons.Filled.EditNote
}

/** Same red and orange as the card detail's status pills. */
internal val CardStatusFilter.color: Color
get() = when (this) {
CardStatusFilter.BANNED -> StatusBannedRed
CardStatusFilter.ERRATA -> StatusErrataOrange
}

@DrawableRes
private fun typeIcon(type: String): Int? = when (type) {
CardType.UNIT -> R.drawable.ic_type_unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,35 @@ data class CollectionFilters(
val energyMax: Int? = null,
val powerMin: Int? = null,
val powerMax: Int? = null,
/** Card statuses to keep; a card matches if it has any of them. */
val statuses: Set<CardStatusFilter> = emptySet(),
) {
val hasEnergyRange: Boolean get() = energyMin != null || energyMax != null
val hasPowerRange: Boolean get() = powerMin != null || powerMax != null

val isEmpty: Boolean
get() = domains.isEmpty() && types.isEmpty() && supertypes.isEmpty() && rarities.isEmpty() &&
sets.isEmpty() && artists.isEmpty() && languages.isEmpty() && !foilOnly && !hasEnergyRange &&
!hasPowerRange
!hasPowerRange && statuses.isEmpty()
}

/**
* Rules statuses a card can be filtered on. [BANNED] reads [Card.banned], which is
* already resolved for the user's competitive region.
*/
enum class CardStatusFilter(val label: String) {
BANNED("Banned"),
ERRATA("Errata"),
;

fun matches(card: Card): Boolean = when (this) {
BANNED -> card.banned
ERRATA -> !card.errata.isNullOrBlank()
}
}

data class StatusFacet(val status: CardStatusFilter, val count: Int)

data class Facet(val value: String, val count: Int)

data class FilterFacets(
Expand All @@ -81,6 +100,8 @@ data class FilterFacets(
val artists: List<Facet> = emptyList(),
/** Languages of the owned copies in scope, by raw value; empty unless there are two or more. */
val languages: List<Facet> = emptyList(),
/** Statuses held by at least one card in scope, in declaration order. */
val statuses: List<StatusFacet> = emptyList(),
val energy: IntRange? = null,
val power: IntRange? = null,
)
Expand Down Expand Up @@ -164,6 +185,9 @@ object CollectionQuery {
sets = setCounts.toSortedMap().map { (value, n) -> Facet(value, n) },
artists = artistCounts.toSortedMap().map { (value, n) -> Facet(value, n) },
languages = languageFacets(entries),
statuses = CardStatusFilter.entries.mapNotNull { status ->
cards.count(status::matches).takeIf { it > 0 }?.let { StatusFacet(status, it) }
},
energy = spread(cards.mapNotNull { it.energy }),
power = spread(cards.mapNotNull { it.power }),
)
Expand Down Expand Up @@ -228,6 +252,7 @@ object CollectionQuery {
if (filters.domains.isNotEmpty() && card.domains.none { it in filters.domains }) return false
if (filters.hasEnergyRange && !card.energy.within(filters.energyMin, filters.energyMax)) return false
if (filters.hasPowerRange && !card.power.within(filters.powerMin, filters.powerMax)) return false
if (filters.statuses.isNotEmpty() && filters.statuses.none { it.matches(card) }) return false
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.ImeAction
Expand Down Expand Up @@ -342,6 +343,11 @@ fun ActiveFiltersBar(filters: CollectionFilters, onChange: (CollectionFilters) -
RemovableChip(it) { onChange(filters.copy(supertypes = filters.supertypes - it)) }
}
if (filters.foilOnly) RemovableChip("Foil Only") { onChange(filters.copy(foilOnly = false)) }
CardStatusFilter.entries.filter { it in filters.statuses }.forEach { status ->
RemovableChip(status.label, accent = status.color) {
onChange(filters.copy(statuses = filters.statuses - status))
}
}
filters.rarities.sortedBy { Rarity.sortRank(it) }.forEach {
RemovableChip(it) { onChange(filters.copy(rarities = filters.rarities - it)) }
}
Expand Down Expand Up @@ -372,8 +378,7 @@ fun ActiveFiltersBar(filters: CollectionFilters, onChange: (CollectionFilters) -
}

@Composable
private fun RemovableChip(label: String, onRemove: () -> Unit) {
val accent = MaterialTheme.colorScheme.primary
private fun RemovableChip(label: String, accent: Color = MaterialTheme.colorScheme.primary, onRemove: () -> Unit) {
Row(
modifier = Modifier
.clip(CircleShape)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ fun CardInfo(card: Card, modifier: Modifier = Modifier) {
}
}

private val StatusBannedRed = Color(0xFFD70015)
private val StatusErrataOrange = Color(0xFFFF9500)
internal val StatusBannedRed = Color(0xFFD70015)
internal val StatusErrataOrange = Color(0xFFFF9500)

/**
* "Banned" and "Errata" pills right under the image, so a card's status reads at a
Expand Down
Loading
Loading