Skip to content

Commit

Permalink
Log detection tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
waicool20 committed Aug 1, 2024
1 parent 2ae7dd5 commit 70ab58e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,9 @@ interface ScriptComponent {
period: Long = -1,
timeout: Long = Long.MAX_VALUE,
fnMaxIter: Int = Int.MAX_VALUE,
fn: suspend () -> Unit = {}
fn: (suspend () -> Unit)? = null
): Boolean {
val job = scriptRunner.sessionScope.launch {
delay(300)
var i = 0
while (coroutineContext.isActive && i++ < fnMaxIter) {
fn()
if (period > 0) delay(period)
}
}
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 @@ -82,25 +65,28 @@ interface ScriptComponent {
period: Long = -1,
timeout: Long = Long.MAX_VALUE,
fnMaxIter: Int = Int.MAX_VALUE,
fn: suspend () -> Unit = {}
fn: (suspend () -> Unit)? = null
): Boolean {
val log = scriptRunner.sessionScope.async {
try {
withTimeout(timeout) {
scriptRunner.logcatListener!!.lines.first { regex.matchEntire(it) != null }
}
true
} catch (e: TimeoutCancellationException) {
false
}
}
val job = scriptRunner.sessionScope.launch {
delay(250)
if (fn == null) return@launch
var i = 0
while (coroutineContext.isActive && i++ < fnMaxIter) {
fn()
if (period > 0) delay(period)
}
}
try {
withTimeout(timeout) {
scriptRunner.logcatListener!!.lines.first { regex.matchEntire(it) != null }
}
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 @@ -545,7 +545,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 Expand Up @@ -640,12 +640,13 @@ abstract class MapRunner(
mapRunnerRegions.pauseButton.has(FT("combat/battle/pause.png", 0.9))

protected suspend fun openEchelon(node: MapNode) {
waitForLog("异步获取对象DaBao", 1000) {
waitForLog("异步获取对象DaBao", 1000, fnMaxIter = 3) {
node.findRegion().click()
}
if (node.type == MapNode.Type.HeavyHeliport && gameState.requiresMapInit) {
mapRunnerRegions.chooseEchelon.click(); delay(2000)
mapRunnerRegions.chooseEchelon.click()
}
delay(1000)
logger.info("Waiting for echelons to show up")
while (coroutineContext.isActive) {
if (hasMember(region.capture().img, 0)) break;
Expand Down

0 comments on commit 70ab58e

Please sign in to comment.