Skip to content

Commit

Permalink
Updated all references of kcauto kai to kcauto; Removed all temporary…
Browse files Browse the repository at this point in the history
… disabled code
  • Loading branch information
waicool20 committed Jun 22, 2018
1 parent c43ba8b commit 13e78a6
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 247 deletions.
8 changes: 4 additions & 4 deletions src/main/kotlin/com/waicool20/kaga/Kaga.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import com.waicool20.kaga.handlers.GlobalShortcutHandler
import com.waicool20.kaga.handlers.KeyboardIncrementHandler
import com.waicool20.kaga.handlers.MouseIncrementHandler
import com.waicool20.kaga.handlers.ToolTipHandler
import com.waicool20.kaga.kcauto.KancolleAutoKai
import com.waicool20.kaga.kcauto.KCAuto
import com.waicool20.kaga.kcauto.YuuBot
import com.waicool20.kaga.views.ConsoleView
import com.waicool20.kaga.views.PathChooserView
Expand Down Expand Up @@ -158,7 +158,7 @@ object Kaga {
KancolleAutoProfile()
}

val KCAUTO_KAI by lazy { KancolleAutoKai() }
val KCAUTO by lazy { KCAuto() }

fun startMainApplication() {
SikuliXLoader.loadAndTest(CONFIG.sikulixJarPath)
Expand Down Expand Up @@ -191,14 +191,14 @@ object Kaga {

fun exit() {
System.setSecurityManager(null)
KCAUTO_KAI.stop()
KCAUTO.stop()
Platform.exit()
System.exit(0)
}

fun checkForUpdates(showNoUpdatesDialog: Boolean = false) {
logger.info("KAGA - ${VERSION_INFO.version}")
logger.info("KCAuto-Kai Compatibility: v${VERSION_INFO.kcAutoCompatibility}")
logger.info("KCAuto Compatibility: v${VERSION_INFO.kcAutoCompatibility}")
if (!CONFIG.checkForUpdates) {
logger.info("Update checking disabled, skipping")
return
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/waicool20/kaga/config/KagaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import java.util.jar.JarFile
@JsonIgnoreProperties(ignoreUnknown = true)
class KagaConfig(currentProfile: String = "",
sikulixJarPath: Path = Paths.get(""),
kcaKaiRootDirPath: Path = Paths.get(""),
kcaRootDirPath: Path = Paths.get(""),
preventLock: Boolean = false,
clearConsoleOnStart: Boolean = true,
autoRestartOnKCAutoCrash: Boolean = true,
Expand All @@ -53,7 +53,7 @@ class KagaConfig(currentProfile: String = "",
) {
val currentProfileProperty = currentProfile.toProperty()
val sikulixJarPathProperty = sikulixJarPath.toProperty()
val kcaKaiRootDirPathProperty = kcaKaiRootDirPath.toProperty()
val kcaRootDirPathProperty = kcaRootDirPath.toProperty()
val preventLockProperty = preventLock.toProperty()
val clearConsoleOnStartProperty = clearConsoleOnStart.toProperty()
val autoRestartOnKCAutoCrashProperty = autoRestartOnKCAutoCrash.toProperty()
Expand All @@ -67,7 +67,7 @@ class KagaConfig(currentProfile: String = "",

var currentProfile by currentProfileProperty
var sikulixJarPath by sikulixJarPathProperty
var kcaKaiRootDirPath by kcaKaiRootDirPathProperty
var kcaRootDirPath by kcaRootDirPathProperty
var preventLock by preventLockProperty
var clearConsoleOnStart by clearConsoleOnStartProperty
var autoRestartOnKCAutoCrash by autoRestartOnKCAutoCrashProperty
Expand Down Expand Up @@ -124,7 +124,7 @@ class KagaConfig(currentProfile: String = "",
}

fun kancolleAutoRootDirPathIsValid(): Boolean =
Files.exists(kcaKaiRootDirPath.resolve("kcauto-kai.sikuli"))
Files.exists(kcaRootDirPath.resolve("kcauto.sikuli"))

@JsonIgnore
fun isValid(): Boolean =
Expand Down
22 changes: 1 addition & 21 deletions src/main/kotlin/com/waicool20/kaga/config/KancolleAutoProfile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ data class KancolleAutoProfile(
add("PvP").fromObject(pvp)
add("Combat").fromObject(sortie)
add("ShipSwitcher").fromObject(shipSwitcher)
/* TODO Disabled temporarily till kcauto-kai is finalized
quests.quests.setAll(quests.quests.map(String::toLowerCase))*/
add("Quests").fromObject(quests)
}

Expand All @@ -126,7 +124,7 @@ data class KancolleAutoProfile(
.plus(listOf("Z1", "Z2", "Z3", "Z4", "Z5", "Z6", "Z7", "Z8", "Z9", "ZZ1", "ZZ2", "ZZ3"))
.toProperty()

fun load(path: Path = Kaga.CONFIG.kcaKaiRootDirPath.resolve("config.ini")): KancolleAutoProfile {
fun load(path: Path = Kaga.CONFIG.kcaRootDirPath.resolve("config.ini")): KancolleAutoProfile {
if (Files.exists(path)) {
loaderLogger.info("Attempting to load KancolleAuto Profile")
loaderLogger.debug("Loading KancolleAuto Profile from $path")
Expand Down Expand Up @@ -268,35 +266,17 @@ data class KancolleAutoProfile(
class General(
program: String = "Chrome",
pause: Boolean = false
/* TODO Disabled temporarily till kcauto-kai is finalized
recoveryMethod: RecoveryMethod = RecoveryMethod.KC3,
basicRecovery: Boolean = true,
sleepCycle: Int = 20,
paranoia: Int = 1,
sleepModifier: Int = 0*/
) {
@IniConfig(key = "Program")
val programProperty = program.toProperty()
@IniConfig(key = "JSTOffset", shouldRead = false)
val jstOffsetProperty = ((TimeZone.getDefault().rawOffset - TimeZone.getTimeZone("Japan").rawOffset) / 3600000).toProperty()
@IniConfig(key = "Pause")
val pauseProperty = pause.toProperty()
/* TODO Disabled temporarily till kcauto-kai is finalized
@IniConfig(key = "RecoveryMethod") val recoveryMethodProperty = SimpleObjectProperty<RecoveryMethod>(recoveryMethod)
@IniConfig(key = "BasicRecovery") val basicRecoveryProperty: BooleanProperty = basicRecovery.toProperty()
@IniConfig(key = "SleepCycle") val sleepCycleProperty: IntegerProperty = sleepCycle.toProperty()
@IniConfig(key = "Paranoia") val paranoiaProperty: IntegerProperty = paranoia.toProperty()
@IniConfig(key = "SleepModifier") val sleepModifierProperty: IntegerProperty = sleepModifier.toProperty()*/

var program by programProperty
var jstOffset by jstOffsetProperty
var pause by pauseProperty
/* TODO Disabled temporarily till kcauto-kai is finalized
var recoveryMethod by recoveryMethodProperty
var basicRecovery by basicRecoveryProperty
var sleepCycle by sleepCycleProperty
var paranoia by paranoiaProperty
var sleepModifier by sleepModifierProperty*/
}

class ScheduledSleep(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ import java.util.concurrent.atomic.AtomicBoolean
import kotlin.concurrent.thread


class KancolleAutoKai {
class KCAuto {
private val logger = LoggerFactory.getLogger(javaClass)
private var kancolleAutoProcess: Process? = null
private val shouldStop = AtomicBoolean(false)

val statsTracker = KancolleAutoKaiStatsTracker
val statsTracker = KCAutoStatsTracker

val version by lazy {
Files.readAllLines(Kaga.CONFIG.kcaKaiRootDirPath.resolve("CHANGELOG.md")).first().let {
Files.readAllLines(Kaga.CONFIG.kcaRootDirPath.resolve("CHANGELOG.md")).first().let {
it.dropWhile { !it.isDigit() }
}
}
Expand All @@ -53,15 +53,15 @@ class KancolleAutoKai {
val args = listOf(
"java", "-jar",
"${Kaga.CONFIG.sikulixJarPath}", "-r",
"${Kaga.CONFIG.kcaKaiRootDirPath.resolve("kcauto-kai.sikuli")}",
"${Kaga.CONFIG.kcaRootDirPath.resolve("kcauto.sikuli")}",
"--", "cfg", "${Kaga.PROFILE.path()}"
)
val lockPreventer = LockPreventer().takeIf { Kaga.CONFIG.preventLock }
statsTracker.startNewSession()
shouldStop.set(false)
KCAutoLoop@ while (true) {
if (Kaga.CONFIG.clearConsoleOnStart) println("\u001b[2J\u001b[H") // Clear console
logger.info("Starting new KCAuto-Kai session (Version: $version)")
logger.info("Starting new KCAuto session (Version: $version)")
logger.debug("Launching with command: ${args.joinToString(" ")}")
logger.debug("Session profile: ${Kaga.PROFILE}")
// Start Processes
Expand All @@ -75,14 +75,14 @@ class KancolleAutoKai {
val exitVal = kancolleAutoProcess?.waitFor()
streamGobbler?.waitFor()

logger.info("KCAuto-Kai session has terminated!")
logger.info("KCAuto session has terminated!")
logger.debug("Exit value was $exitVal")
lockPreventer?.stop()
Kaga.PROFILE.general.pause = false

// Detect Crash
val scriptCrashed = exitVal !in listOf(0, 143)
if (scriptCrashed) logger.info("KCAuto-Kai crashed!")
if (scriptCrashed) logger.info("KCAuto crashed!")

YuuBot.reportStats()

Expand Down Expand Up @@ -112,13 +112,13 @@ class KancolleAutoKai {
}

fun stop() {
logger.info("Terminating current KCAuto-Kai session")
logger.info("Terminating current KCAuto session")
kancolleAutoProcess?.destroy()
shouldStop.set(true)
}

fun stopAtPort() {
logger.info("Will wait for any ongoing battle to finish first before terminating current KCAuto-Kai session!")
logger.info("Will wait for any ongoing battle to finish first before terminating current KCAuto session!")
thread {
while (!statsTracker.atPort) TimeUnit.MILLISECONDS.sleep(10)
stop()
Expand All @@ -131,7 +131,7 @@ class KancolleAutoKai {
val template = Kaga::class.java.classLoader.getResourceAsStream("crashlog_template.md").bufferedReader().readText()
val logs = find<ConsoleView>().logs()
val crashTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH.mm.ss"))
val logFile = Kaga.CONFIG.kcaKaiRootDirPath.resolve("crashes/$crashTime.log")
val logFile = Kaga.CONFIG.kcaRootDirPath.resolve("crashes/$crashTime.log")
if (Files.notExists(logFile)) Files.createDirectories(logFile.parent)
val logSection = template.replace("<DateTime>", crashTime)
.replace("<Version>", version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import com.waicool20.waicoolutils.logging.LoggingEventBus
import java.time.Instant
import kotlin.reflect.KMutableProperty1

object KancolleAutoKaiStatsTracker {
object KCAutoStatsTracker {
var startingTime: Instant? = null
var crashes = 0
var atPort = true
val history = mutableListOf<KancolleAutoKaiStats>()
val history = mutableListOf<KCAutoStats>()

init {
val stat = Regex("(\\d+)(?: \\(.+?\\))?")
Expand Down Expand Up @@ -81,7 +81,7 @@ object KancolleAutoKaiStatsTracker {
}

// Track crashes occurred
subscribe(Regex(".*KCAuto-Kai crashed!.*")) {
subscribe(Regex(".*KCAuto crashed!.*")) {
crashes++
}

Expand All @@ -107,14 +107,14 @@ object KancolleAutoKaiStatsTracker {
trackNewChild()
}

fun trackNewChild() = history.add(KancolleAutoKaiStats())
fun trackNewChild() = history.add(KCAutoStats())

operator fun get(stat: KMutableProperty1<KancolleAutoKaiStats, Int>) = history.sumBy { stat.get(it) }
operator fun get(stat: KMutableProperty1<KCAutoStats, Int>) = history.sumBy { stat.get(it) }

private fun currentStats() = history.last()
}

data class KancolleAutoKaiStats(
data class KCAutoStats(
var sortiesDone: Int = 0,
var sortiesAttempted: Int = 0,
var expeditionsSent: Int = 0,
Expand Down
34 changes: 17 additions & 17 deletions src/main/kotlin/com/waicool20/kaga/kcauto/YuuBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object YuuBot {

init {
with(LoggingEventBus) {
// Listen to the end when kca-kai is done report stats
// Listen to the end when kca is done report stats
subscribe(Regex(".*Recoveries done:.*")) { reportStats() }
}
}
Expand All @@ -64,7 +64,7 @@ object YuuBot {
readResources()
logger.info("Reporting stats to YuuBot!")
try {
val stats = KCAutoKaiStatsDto(KancolleAutoKaiStatsTracker, resources)
val stats = KCAutoStatsDto(KCAutoStatsTracker, resources)
val response = HttpPost(endpoint + Kaga.CONFIG.apiKey + "/stats").apply {
entity = StringEntity(mapper.writeValueAsString(stats), ContentType.APPLICATION_JSON)
}.let { client.execute(it) }.statusLine.statusCode
Expand Down Expand Up @@ -140,7 +140,7 @@ object YuuBot {

data class CrashInfoDto(val log: String)

data class KCAutoKaiStatsDto(
data class KCAutoStatsDto(
val profileName: String,
val isRunning: Boolean,
val startingTime: Instant,
Expand All @@ -159,23 +159,23 @@ data class KCAutoKaiStatsDto(
val recoveries: Int,
val resources: Resources
) {
constructor(tracker: KancolleAutoKaiStatsTracker, resources: Resources) : this(
constructor(tracker: KCAutoStatsTracker, resources: Resources) : this(
profileName = Kaga.PROFILE.name,
isRunning = Kaga.KCAUTO_KAI.isRunning(),
isRunning = Kaga.KCAUTO.isRunning(),
startingTime = tracker.startingTime ?: Instant.now(),
crashes = tracker.crashes,
sortiesDone = tracker[KancolleAutoKaiStats::sortiesDone],
sortiesAttempted = tracker[KancolleAutoKaiStats::sortiesAttempted],
expeditionsSent = tracker[KancolleAutoKaiStats::expeditionsSent],
expeditionsReceived = tracker[KancolleAutoKaiStats::expeditionsReceived],
pvpsDone = tracker[KancolleAutoKaiStats::pvpsDone],
questsDone = tracker[KancolleAutoKaiStats::questsDone],
questsStarted = tracker[KancolleAutoKaiStats::questsStarted],
resupplies = tracker[KancolleAutoKaiStats::resupplies],
repairs = tracker[KancolleAutoKaiStats::repairs],
bucketsUsed = tracker[KancolleAutoKaiStats::bucketsUsed],
shipsSwitched = tracker[KancolleAutoKaiStats::shipsSwitched],
recoveries = tracker[KancolleAutoKaiStats::recoveries],
sortiesDone = tracker[KCAutoStats::sortiesDone],
sortiesAttempted = tracker[KCAutoStats::sortiesAttempted],
expeditionsSent = tracker[KCAutoStats::expeditionsSent],
expeditionsReceived = tracker[KCAutoStats::expeditionsReceived],
pvpsDone = tracker[KCAutoStats::pvpsDone],
questsDone = tracker[KCAutoStats::questsDone],
questsStarted = tracker[KCAutoStats::questsStarted],
resupplies = tracker[KCAutoStats::resupplies],
repairs = tracker[KCAutoStats::repairs],
bucketsUsed = tracker[KCAutoStats::bucketsUsed],
shipsSwitched = tracker[KCAutoStats::shipsSwitched],
recoveries = tracker[KCAutoStats::recoveries],
resources = resources
)
}
Loading

0 comments on commit 13e78a6

Please sign in to comment.