mirror of
https://github.com/meowarex/rl-mobile.git
synced 2026-08-27 06:27:46 +10:00
Word by Word Lyrics <3
This commit is contained in:
@@ -79,6 +79,8 @@ data class PatchOptions(
|
||||
if (spec.variants.isEmpty()) {
|
||||
if (!enabled) addAll(spec.fileNames)
|
||||
} else {
|
||||
// base fileNames apply for every variant while enabled; disable them when off
|
||||
if (!enabled) addAll(spec.fileNames)
|
||||
val selected = variantIndex(spec)
|
||||
spec.variants.forEachIndexed { index, variant ->
|
||||
if (!enabled || index != selected) addAll(variant.fileNames)
|
||||
|
||||
@@ -48,6 +48,7 @@ data class VariantSpec(
|
||||
val title: String,
|
||||
val fileNames: List<String> = emptyList(),
|
||||
val extensionFiles: List<String> = emptyList(),
|
||||
val enabled: Boolean = true,
|
||||
)
|
||||
|
||||
/** A single advanced option. Discriminated by `"type"` in JSON. */
|
||||
@@ -173,7 +174,7 @@ fun builtinPatchSpecs(context: Context, json: Json): List<PatchSpec> = try {
|
||||
}
|
||||
|
||||
@Immutable
|
||||
data class EffectiveVariant(val originalIndex: Int, val title: String)
|
||||
data class EffectiveVariant(val originalIndex: Int, val title: String, val enabled: Boolean = true)
|
||||
|
||||
fun PatchSpec.effectiveVariants(isOptionOn: (OptionSpec.Toggle) -> Boolean): List<EffectiveVariant> {
|
||||
if (variants.isEmpty()) return emptyList()
|
||||
@@ -186,19 +187,22 @@ fun PatchSpec.effectiveVariants(isOptionOn: (OptionSpec.Toggle) -> Boolean): Lis
|
||||
}
|
||||
}
|
||||
return variants.mapIndexedNotNull { index, variant ->
|
||||
if (index in hidden) null else EffectiveVariant(index, relabel[index] ?: variant.title)
|
||||
if (index in hidden) null
|
||||
else EffectiveVariant(index, relabel[index] ?: variant.title, variant.enabled)
|
||||
}
|
||||
}
|
||||
|
||||
fun PatchSpec.resolveVariantIndex(stored: Int, isOptionOn: (OptionSpec.Toggle) -> Boolean): Int {
|
||||
val visible = effectiveVariants(isOptionOn)
|
||||
if (visible.isEmpty() || visible.any { it.originalIndex == stored }) return stored
|
||||
// never resolve onto a greyed/disabled variant
|
||||
if (visible.isEmpty() || visible.any { it.originalIndex == stored && it.enabled }) return stored
|
||||
val relabelKeys = buildSet {
|
||||
for (option in advancedOptions) {
|
||||
if (option is OptionSpec.Toggle && isOptionOn(option)) addAll(option.relabelVariants.keys)
|
||||
}
|
||||
}
|
||||
return visible.firstOrNull { it.originalIndex in relabelKeys }?.originalIndex
|
||||
return visible.firstOrNull { it.originalIndex in relabelKeys && it.enabled }?.originalIndex
|
||||
?: visible.firstOrNull { it.enabled }?.originalIndex
|
||||
?: visible.first().originalIndex
|
||||
}
|
||||
|
||||
|
||||
+17
-10
@@ -169,15 +169,18 @@ fun PatchSelectionAccordion(
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 8.dp),
|
||||
) {
|
||||
val resolvedVariant =
|
||||
if (patch.variants.isNotEmpty())
|
||||
patch.resolveVariantIndex(variantIndex(patch)) {
|
||||
optionState.toggle(patch, it)
|
||||
}
|
||||
else -1
|
||||
if (patch.variants.isNotEmpty()) {
|
||||
val effective = patch.effectiveVariants { optionState.toggle(patch, it) }
|
||||
val resolved = patch.resolveVariantIndex(variantIndex(patch)) {
|
||||
optionState.toggle(patch, it)
|
||||
}
|
||||
PatchVariantSelector(
|
||||
variants = effective,
|
||||
selectedIndex = effective
|
||||
.indexOfFirst { it.originalIndex == resolved }
|
||||
.indexOfFirst { it.originalIndex == resolvedVariant }
|
||||
.coerceAtLeast(0),
|
||||
onSelect = { pos ->
|
||||
effective.getOrNull(pos)?.let { onSelectVariant(patch, it.originalIndex) }
|
||||
@@ -186,12 +189,16 @@ fun PatchSelectionAccordion(
|
||||
}
|
||||
|
||||
for (option in inlineToggles) key(option.key) {
|
||||
InlineToggleRow(
|
||||
title = option.title,
|
||||
description = option.description,
|
||||
checked = optionState.toggle(patch, option),
|
||||
onCheckedChange = { optionState.setToggle(patch, option, it) },
|
||||
)
|
||||
val show = option.requiresVariant == null ||
|
||||
option.requiresVariant == resolvedVariant
|
||||
if (show) {
|
||||
InlineToggleRow(
|
||||
title = option.title,
|
||||
description = option.description,
|
||||
checked = optionState.toggle(patch, option),
|
||||
onCheckedChange = { optionState.setToggle(patch, option, it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (hasSheetOptions) {
|
||||
|
||||
+2
-1
@@ -22,7 +22,8 @@ fun PatchVariantSelector(
|
||||
variants.forEachIndexed { index, variant ->
|
||||
SegmentedButton(
|
||||
selected = index == selectedIndex,
|
||||
onClick = { onSelect(index) },
|
||||
enabled = variant.enabled,
|
||||
onClick = { if (variant.enabled) onSelect(index) },
|
||||
shape = SegmentedButtonDefaults.itemShape(
|
||||
index = index,
|
||||
count = variants.size,
|
||||
|
||||
Reference in New Issue
Block a user