Skip to content

Commit

Permalink
Added Auto screenshot of bond CE and bond level up! And reduce the Pl…
Browse files Browse the repository at this point in the history
…ay button's alpha to make it more translucent (#1726)
  • Loading branch information
ArthurKun21 authored Jan 7, 2024
1 parent 45f3201 commit d8a0f26
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ class ScriptManager @Inject constructor(
}

is AutoBattle.ExitException -> {
preferences.hidePlayButton = false

if (e.reason !is AutoBattle.ExitReason.Abort) {
messages.notify(scriptExitedString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ScriptRunnerOverlay @Inject constructor(
layout = FakedComposeView(service) {
ScriptRunnerUI(
state = uiStateHolder.uiState,
prefsCore = prefsCore,
updateState = { act(it) },
isRecording = uiStateHolder.isRecording,
enabled = uiStateHolder.isPlayButtonEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ fun LazyListScope.battleGroup(
icon = icon(R.drawable.ic_screenshot)
)
}
item {
prefs.screenshotBond.SwitchPreference(
title = stringResource(R.string.p_screenshot_bond),
summary = stringResource(R.string.p_screenshot_bond_summary),
icon = icon(R.drawable.ic_screenshot)
)
}

item {
prefs.boostItemSelectionMode.SingleSelectChipPreference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,31 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import io.github.fate_grand_automata.R
import io.github.fate_grand_automata.prefs.core.PrefsCore
import io.github.fate_grand_automata.scripts.enums.ScriptModeEnum
import io.github.fate_grand_automata.ui.FGATheme
import io.github.fate_grand_automata.ui.prefs.remember

@Composable
fun ScriptRunnerUI(
state: ScriptRunnerUIState,
prefsCore: PrefsCore,
updateState: (ScriptRunnerUIAction) -> Unit,
onDrag: (Float, Float) -> Unit,
enabled: Boolean,
isRecording: Boolean
) {
val hidePlayButton by prefsCore.hidePlayButton.remember()
val script by prefsCore.scriptMode.remember()

FGATheme(
darkTheme = true,
background = Color.Transparent
Expand All @@ -49,8 +57,22 @@ fun ScriptRunnerUI(
}

Surface(
color = MaterialTheme.colorScheme.surface,
contentColor = if (isRecording) MaterialTheme.colorScheme.error else Color.White,
color = when (state) {
ScriptRunnerUIState.Running ->
MaterialTheme.colorScheme.surface.copy(
alpha = if (hidePlayButton && script == ScriptModeEnum.Battle) 0f else 0.5f
)
else -> MaterialTheme.colorScheme.surface
},
contentColor = when (state) {
ScriptRunnerUIState.Running -> {
val color = if (isRecording) MaterialTheme.colorScheme.error else Color.White
color.copy(
alpha = if (hidePlayButton && script == ScriptModeEnum.Battle) 0f else 0.5f
)
}
else -> Color.White
},
tonalElevation = 5.dp,
shape = CircleShape,
onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ class ScriptMessages @Inject constructor(

toast(msg)
}
is ScriptNotify.BondLevelUp -> {
notify(
context.getString(R.string.bond_level_up)
)
}
}

private fun makeRefillAndRunsMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.github.fate_grand_automata.BuildConfig
import io.github.fate_grand_automata.IStorageProvider
import io.github.fate_grand_automata.SupportImageKind
import io.github.fate_grand_automata.prefs.core.PrefsCore
import io.github.fate_grand_automata.scripts.enums.GameServer
import io.github.lib_automata.Pattern
import timber.log.Timber
import java.io.File
Expand Down Expand Up @@ -183,6 +184,25 @@ class StorageProvider @Inject constructor(
}
}

private val bondFolder
get() = dirRoot.getOrCreateDir("bond")

override fun dropBondScreenShot(pattern: Pattern, server: GameServer) {
val sdf = SimpleDateFormat("yyyy-MM-dd-hh-mm-ss", Locale.getDefault())
val timeString = sdf.format(Date())

val dropFileName = "bond-${server.simple.uppercase()}-${timeString}.png"

pattern.use {
val file = bondFolder.createFile(mimePng, dropFileName)
?: throw KnownException(KnownException.Reason.CouldNotCreateDropScreenshotFile)

resolver.openOutputStream(file.uri)?.use { stream ->
pattern.save(stream)
}
}
}

override fun dump(name: String, image: Pattern) {
image.use {
if (BuildConfig.DEBUG) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/localized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,8 @@ After pressing on the button, switch the app filter from \"Not optimized\" to \"
<string name="p_app_language">"App Language"</string>
<string name="p_treat_support_like_own_servant">Treat Support like own Servants</string>
<string name="p_treat_support_like_own_servant_summary">Will do normal face card checks instead of looking for the "Support" icon on face cards. This solves problems with super-buffed Support Servants, but will break card priority if you have 2 of the same Servant in the party.</string>

<string name="p_screenshot_bond">"Screenshot Bond"</string>
<string name="p_screenshot_bond_summary">"Experimental screenshot of bond level up regardless of level to 'bond' folder\nNote: Auto-click on another results screen might cause occasional missed screenshots, potentially skipping the bond level-up."</string>
<string name="bond_level_up">Bond Level up!</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class PreferencesImpl @Inject constructor(

override val screenshotDropsUnmodified by prefs.screenshotDropsUnmodified

override val screenshotBond by prefs.screenshotBond

override var hidePlayButton by prefs.hidePlayButton

override val stageCounterSimilarity by prefs.stageCounterSimilarity.map { it / 100.0 }

override val stageCounterNew by prefs.stageCounterNew
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class PrefsCore @Inject constructor(
val recordScreen = maker.bool("record_screen")
val screenshotDrops = maker.bool("screenshot_drops")
val screenshotDropsUnmodified = maker.bool("screenshot_drops_unmodified")
val screenshotBond = maker.bool("screenshot_bond")
val hidePlayButton = maker.bool("hide_play_button")
val debugMode = maker.bool("debug_mode")
val autoStartService = maker.bool("auto_start_service")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.fate_grand_automata

import io.github.fate_grand_automata.scripts.enums.GameServer
import io.github.lib_automata.Pattern
import java.io.File
import java.io.InputStream
Expand All @@ -16,6 +17,8 @@ interface IStorageProvider {

fun dropScreenshot(patterns: List<Pattern>)

fun dropBondScreenShot(pattern: Pattern, server: GameServer = GameServer.default)

/**
* For debugging images
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import io.github.fate_grand_automata.scripts.models.TeamSlot
import kotlin.time.Duration

sealed class ScriptNotify {
object CEGet : ScriptNotify()
object CEDropped : ScriptNotify()
data object CEGet : ScriptNotify()
data object CEDropped : ScriptNotify()
class WaitForAPRegen(val minutes: Int = 1) : ScriptNotify()
class FailedToDetermineCards(val cards: List<CommandCard.Face>, val unknownCardTypes: Boolean, val unknownServants: Boolean) : ScriptNotify()
class FailedToDetermineCards(val cards: List<CommandCard.Face>,
val unknownCardTypes: Boolean, val unknownServants: Boolean) : ScriptNotify()
class SupportListUpdatingIn(val time: Duration) : ScriptNotify()
class BetweenRuns(val refills: Int, val runs: Int, val ceDrops: Int) : ScriptNotify()
data object BondLevelUp : ScriptNotify()
}

sealed class ScriptLog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class AutoBattle @Inject constructor(
// for tracking whether to check for servant death and wave transition animations
private var isInBattle = false


private var canScreenshotBondCE = false

override fun script(): Nothing {
try {
loop()
Expand Down Expand Up @@ -180,6 +183,7 @@ class AutoBattle @Inject constructor(
},
{ isInMenu() } to { menu() },
{ isStartingNp() } to { skipNp() },
{ isInBondScreen() } to { handleBondScreen() },
{ isInResult() } to { result() },
{ isInDropsScreen() } to { dropScreen() },
{ isInOrdealCallOutOfPodsScreen() } to { ordealCallOutOfPods() },
Expand Down Expand Up @@ -249,22 +253,42 @@ class AutoBattle @Inject constructor(
private fun isInResult(): Boolean {
val cases = sequenceOf(
images[Images.Result] to locations.resultScreenRegion,
images[Images.Bond] to locations.resultBondRegion,
images[Images.MasterLevelUp] to locations.resultMasterLvlUpRegion,
images[Images.MasterExp] to locations.resultMasterExpRegion
)

return cases.any { (image, region) -> image in region }
}

private fun isInBondScreen() = images[Images.Bond] in locations.resultBondRegion

private fun handleBondScreen(){
canScreenshotBondCE = true

if (prefs.screenshotBond){
screenshotDrops.screenshotBond()
messages.notify(ScriptNotify.BondLevelUp)
0.5.seconds.wait()
}

result()
}

private fun isBond10CEReward() =
locations.resultCeRewardRegion.exists(images[Images.Bond10Reward], similarity = 0.75)

/**
* It seems like we need to click on CE (center of screen) to accept them
*/
private fun bond10CEReward() =
private fun bond10CEReward(){
if (prefs.screenshotBond && canScreenshotBondCE){
screenshotDrops.screenshotBond()
0.5.seconds.wait()
canScreenshotBondCE = false
}

locations.scriptArea.center.click()
}

private fun isCeRewardDetails() =
images[Images.CEDetails] in locations.resultCeRewardDetailsRegion
Expand All @@ -290,14 +314,18 @@ class AutoBattle @Inject constructor(
*/
private fun result() {
isInBattle = false
locations.resultClick.click(15)
locations.resultClick.click(
times = if (prefs.screenshotBond) 5 else 15
)
storySkipPossible = true
}

private fun isInDropsScreen() =
images[Images.MatRewards] in locations.resultMatRewardsRegion

private fun dropScreen() {
canScreenshotBondCE = false

ceDropsTracker.lookForCEDrops()
matTracker.parseMaterials()
screenshotDrops.screenshotDrops()
Expand Down Expand Up @@ -403,6 +431,8 @@ class AutoBattle @Inject constructor(

// Selections Support option
private fun support() {
canScreenshotBondCE = false

support.selectSupport()

if (!isContinuing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.github.lib_automata.Pattern
import io.github.lib_automata.ScreenshotService
import io.github.lib_automata.dagger.ScriptScope
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds

@ScriptScope
class ScreenshotDrops @Inject constructor(
Expand Down Expand Up @@ -38,4 +39,23 @@ class ScreenshotDrops @Inject constructor(

storageProvider.dropScreenshot(drops)
}

fun screenshotBond(){
if (!prefs.screenshotBond){
return
}

useColor {
try {
prefs.hidePlayButton = true
1.seconds.wait()
val pattern = screenshotService.takeScreenshot()

storageProvider.dropBondScreenShot(pattern, server = prefs.gameServer)
}
finally {
prefs.hidePlayButton = false
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface IPreferences {
val skillDelay: Duration
val screenshotDrops: Boolean
val screenshotDropsUnmodified: Boolean
val screenshotBond: Boolean
var hidePlayButton: Boolean
var maxGoldEmberStackSize: Int
var maxGoldEmberTotalCount: Int
var stopAfterThisRun: Boolean
Expand Down

0 comments on commit d8a0f26

Please sign in to comment.