Skip to content

Commit

Permalink
Fix login popup dismissing
Browse files Browse the repository at this point in the history
  • Loading branch information
waicool20 committed Aug 2, 2024
1 parent e1a3a23 commit 2b2168d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 37 deletions.
Binary file modified modules/assets/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,12 @@ interface ScriptComponent {
*/
suspend fun waitForLog(
str: String,
period: Long = -1,
timeout: Long = Long.MAX_VALUE,
fn: suspend () -> Unit = {}
fnMaxIter: Int = Int.MAX_VALUE,
fn: (suspend () -> Unit)? = null
): Boolean {
val job = scriptRunner.sessionScope.launch {
delay(250)
while (coroutineContext.isActive) fn()
}
try {
withTimeout(timeout) {
scriptRunner.logcatListener!!.lines.first { it.contains(str) }
}
return true
} catch (e: TimeoutCancellationException) {
return false
} finally {
job.cancel()
}
return waitForLog(Regex(".*$str.*"), period, timeout, fnMaxIter, fn)
}

/**
Expand All @@ -73,22 +62,31 @@ interface ScriptComponent {
*/
suspend fun waitForLog(
regex: Regex,
period: Long = -1,
timeout: Long = Long.MAX_VALUE,
fn: suspend () -> Unit = {}
fnMaxIter: Int = Int.MAX_VALUE,
fn: (suspend () -> Unit)? = null
): Boolean {
val job = scriptRunner.sessionScope.launch {
delay(250)
while (coroutineContext.isActive) fn()
val log = scriptRunner.sessionScope.async {
try {
withTimeout(timeout) {
scriptRunner.logcatListener!!.lines.first { regex.matchEntire(it) != null }
}
true
} catch (e: TimeoutCancellationException) {
false
}
}
try {
withTimeout(timeout) {
scriptRunner.logcatListener!!.lines.first { regex.matchEntire(it) != null }
val job = scriptRunner.sessionScope.launch {
if (fn == null) return@launch
var i = 0
while (coroutineContext.isActive && i++ < fnMaxIter) {
fn()
if (period > 0) delay(period)
}
return true
} catch (e: TimeoutCancellationException) {
return false
} finally {
job.cancel()
}
val b = log.await()
job.cancel()
return b
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package com.waicool20.wai2k.script.modules

import com.waicool20.cvauto.core.AnyRegion
import com.waicool20.cvauto.core.template.FT
import com.waicool20.cvauto.core.util.isSimilar
import com.waicool20.wai2k.game.LogisticsSupport
import com.waicool20.wai2k.game.LogisticsSupport.Assignment
import com.waicool20.wai2k.game.location.LocationId
Expand All @@ -34,7 +33,6 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import java.awt.Color
import java.awt.image.BufferedImage
import java.awt.image.RasterFormatException
import java.time.Duration
Expand Down Expand Up @@ -207,13 +205,7 @@ class InitModule(navigator: Navigator) : ScriptModule(navigator) {

private suspend fun terminateExistingBattle() {
logger.info("Detected ongoing battle, terminating it first")
while (coroutineContext.isActive) {
val capture = region.freeze()
// Check if in transition to map
if (capture.pickColor(50, 1050).isSimilar(Color(16, 16, 16)) &&
capture.pickColor(680, 580).isSimilar(Color(222, 223, 74))
) break
// Region that contains the word `RESUME` if there's an ongoing battle
waitForLog("地图位置初始化", fnMaxIter = 3) {
region.subRegion(1700, 780, 170, 75).click()
navigator.checkLogistics()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ abstract class MapRunner(
} else {
logger.info("Waiting for combat menu")
}
waitForLog("UICombatSettlement(Clone)")
waitForLog("UICombatSettlement")
waitForLog("MissionSelectionController:Start()") {
repeat(Random.nextInt(2, 4)) {
mapRunnerRegions.battleEndClick.click()
Expand Down

0 comments on commit 2b2168d

Please sign in to comment.