Skip to content
This repository has been archived by the owner on Apr 22, 2018. It is now read-only.

Commit

Permalink
Merge pull request #2 from edipo2s/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
edipo2s authored May 19, 2017
2 parents 3ad0883 + 147a723 commit f05f3a7
Show file tree
Hide file tree
Showing 60 changed files with 650 additions and 246 deletions.
52 changes: 36 additions & 16 deletions src/main/kotlin/com/ediposouza/TESLTracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import com.ediposouza.executor.DeckImportExecutor
import com.ediposouza.executor.ScreenExecutor
import com.ediposouza.extensions.addMenu
import com.ediposouza.extensions.addMenuItem
import com.ediposouza.extensions.alertAlwaysOnTop
import com.ediposouza.extensions.getScreenDeckBuilderCrop
import com.ediposouza.model.*
import com.ediposouza.resolution.ReferenceConfig
import com.ediposouza.resolution.ReferenceConfig1360x768
import com.ediposouza.resolution.ReferenceConfig1366x768
import com.ediposouza.resolution.ReferenceConfig1920x1080
import com.ediposouza.state.ArenaState
Expand Down Expand Up @@ -49,6 +51,7 @@ import java.io.FileWriter
import java.io.InputStream
import java.net.URI
import java.net.URLDecoder
import java.util.prefs.Preferences
import javax.swing.KeyStroke
import javax.swing.SwingUtilities

Expand All @@ -60,14 +63,16 @@ class TESLTracker : App(MainStageView::class) {
companion object {

val APP_NAME = "WabbaTrack"
val APP_VERSION = "0.2.0"
val APP_VERSION = "0.2.1"
val DEBUG_FILE_NAME = "WabbaTrack.debug"
val WABBATRACK_URL = "https://edipo2s.github.io/WabbaTrack/"

val preferences: Preferences by lazy { Preferences.userNodeForPackage(TESLTracker::class.java) }
val keyProvider: Provider by lazy { Provider.getCurrentProvider(true) }
var usingSupportedResolution = true
var referenceConfig: ReferenceConfig = ReferenceConfig1366x768()
val screenSize: Dimension by lazy { Toolkit.getDefaultToolkit().screenSize }
lateinit var graphicsDevice: GraphicsDevice
lateinit var screenSize: Dimension

val iconName: String = "/ic_legend.png".takeIf { com.sun.jna.Platform.isWindows() } ?: "/ic_legend_osx.png"
val jarPath: String = URLDecoder.decode(TESLTracker::class.java.protectionDomain.codeSource.location.file, "UTF-8")
Expand Down Expand Up @@ -199,13 +204,20 @@ class TESLTracker : App(MainStageView::class) {
super.start(stage.apply {
initStyle(StageStyle.TRANSPARENT)
isAlwaysOnTop = true
referenceConfig = when {
screenSize.width == 1366 && screenSize.height == 768 -> ReferenceConfig1366x768()
screenSize.width == 1920 && screenSize.height == 1080 -> ReferenceConfig1920x1080()
else -> {
usingSupportedResolution = false
showMessageUnsupportedResolution()
ReferenceConfig1920x1080()
ScreenFuncs.getGameMonitor {
graphicsDevice = it
screenSize = Dimension(it.displayMode.width, it.displayMode.height)
referenceConfig = when {
screenSize.width == 1360 && screenSize.height == 768 -> ReferenceConfig1360x768()
screenSize.width == 1366 && screenSize.height == 768 -> ReferenceConfig1366x768()
screenSize.width == 1920 && screenSize.height == 1080 -> ReferenceConfig1920x1080()
else -> {
usingSupportedResolution = false
Logger.d("Using unsupported resolution: ${screenSize.width}x${screenSize.height}")
showMessageUnsupportedResolution()
Mixpanel.postEventUnsupportedScreenResolution("${screenSize.width}x${screenSize.height}")
ReferenceConfig1920x1080()
}
}
}
with(TESLTracker.referenceConfig) {
Expand Down Expand Up @@ -299,6 +311,13 @@ class TESLTracker : App(MainStageView::class) {
Desktop.getDesktop().browse(URI(url))
Mixpanel.postEventAndroidTESLegendsTracker()
}
addMenu("Settings") {
addMenuItem("Clear default game monitor") {
ScreenFuncs.clearGameMonitorPref()
showMessage("Default monitor setting clear. Restart $APP_NAME to choose default monitor")
Mixpanel.postEventDualMonitorClearConfig()
}
}
addMenuItem("About") {
Platform.runLater {
alert(Alert.AlertType.INFORMATION, "About", "$APP_NAME $APP_VERSION \n\nSpecial thanks:\n" +
Expand All @@ -309,7 +328,7 @@ class TESLTracker : App(MainStageView::class) {
doExit()
}
if (File(DEBUG_FILE_NAME).exists()) {
addMenu("Test") {
addMenu("Tests") {
addMenuItem("Show Log") {
Platform.runLater {
Stage().apply {
Expand All @@ -319,8 +338,8 @@ class TESLTracker : App(MainStageView::class) {
title = "$APP_NAME Logs"
height = 200.0
width = 180.0
x = screenSize.width - width - 10.0
y = screenSize.height - height
x = screenSize.width - width - 10.0 + TESLTracker.graphicsDevice.defaultConfiguration.bounds.x
y = screenSize.height - height + TESLTracker.graphicsDevice.defaultConfiguration.bounds.y
}.show()
}
}
Expand Down Expand Up @@ -462,7 +481,7 @@ class TESLTracker : App(MainStageView::class) {
}
addMenuItem("Delete") {
Platform.runLater {
alert(Alert.AlertType.CONFIRMATION, "Are you sure?", "Delete ${deck.name}",
alertAlwaysOnTop(Alert.AlertType.CONFIRMATION, "Are you sure?", "Delete ${deck.name}",
ButtonType.YES, ButtonType.NO) { bt ->
if (bt == ButtonType.YES) {
TESLTrackerData.deleteDecks(deck) {
Expand Down Expand Up @@ -509,7 +528,7 @@ class TESLTracker : App(MainStageView::class) {
}
addMenuItem("Delete") {
Platform.runLater {
alert(Alert.AlertType.CONFIRMATION, "Are you sure?", "Delete ${deck.name}",
alertAlwaysOnTop(Alert.AlertType.CONFIRMATION, "Are you sure?", "Delete ${deck.name}",
ButtonType.YES, ButtonType.NO) { bt ->
if (bt == ButtonType.YES) {
decksImported.remove(deck)
Expand Down Expand Up @@ -580,9 +599,9 @@ class TESLTracker : App(MainStageView::class) {
}

private fun checkUpdate() {
TESLTrackerData.checkForUpdate { lastVersion ->
TESLTrackerData.checkForUpdate { lastVersion, changeLog ->
SwingUtilities.invokeLater {
trayIcon?.displayMessage(APP_NAME, "New version $lastVersion detected, downloading...", TrayIcon.MessageType.NONE)
trayIcon?.displayMessage(APP_NAME, "New version $lastVersion detected, downloading...\n$changeLog", TrayIcon.MessageType.NONE)
}
}
}
Expand All @@ -597,6 +616,7 @@ class TESLTracker : App(MainStageView::class) {
while (true) {
if (isTESLegendsScreenActive()) {
Logger.i("Elder scroll legends detected!")
Mixpanel.postEventGameDetected()
StateHandler.currentTESLState?.onResume()
startElderScrollRecognition()
Logger.i("Waiting Elder scroll legends..")
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/ediposouza/data/PHash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ object PHash {
// -- Game--

val GAME_ITEMS_LIST = mapOf(
"0001111010000011110111000110111111101101100101001100110101000011001001001001100111100100110011011010011110111111110111100" to PLAYER_GAME_FIRST,
"1101100000011011100000001011011000010011100011000011111010001111010100110101101000101011100101000101100010011100010010011" to PLAYER_GAME_SECOND,
"1101100000011011100000001011011000010011100011000011111010001111010100110101101000101011100101000101100010011100010010011" to PLAYER_GAME_FIRST,
"0001111010000011110111000110111111101101100101001100110101000011001001001001100111100100110011011010011110111111110111100" to PLAYER_GAME_SECOND,
"1101011101110011111000010100000110010011111111110000100110110101100010001000110000100000010000001101100000000100100001101" to GAME_WIN,
"0011110101000110101101110010100011011010110101001111010100100010100110001111011001101100001011001110100101010001011011011" to GAME_WIN2,
"0100011100000011011110001110011010001011101101110000010110100110101001000000111000100100010000001100111000001100100100100" to GAME_LOSS,
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/com/ediposouza/data/TESLTrackerData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ object TESLTrackerData {

private fun saveMatchAnonymous(newMatch: Match, retry: Int = 0) {
val matchIdUTC = LocalDateTime.now(ZoneOffset.UTC).toString().replace(".", "_")
val anonymousMatchesPath = "$NODE_WABBATRACK/$NODE_MATCHES/$matchIdUTC"
val modeName = newMatch.mode.name.toLowerCase()
val anonymousMatchesPath = "$NODE_WABBATRACK/$NODE_MATCHES/$modeName/${LocalDate.now()}/$matchIdUTC"
val newMatchData = Gson().toJson(FirebaseParsers.MatchParser().fromMatch(newMatch))
try {
firebaseDatabaseAPI.execute(Rest.Request.Method.PUT, "$anonymousMatchesPath.json",
Expand Down Expand Up @@ -319,7 +320,7 @@ object TESLTrackerData {
}
}

fun checkForUpdate(retry: Int = 0, onSuccess: (String) -> Unit) {
fun checkForUpdate(retry: Int = 0, onSuccess: (String, String) -> Unit) {
with(firebaseDatabaseAPI.get("$NODE_WABBATRACK.json").one()) {
val lastVersion = entries.find { it.key == "lastVersion" }?.value.toString().replace("\"", "")
if (lastVersion == TESLTracker.APP_VERSION) {
Expand All @@ -337,7 +338,8 @@ object TESLTrackerData {
}
}
Logger.i("New version detect, downloading version $lastVersion")
onSuccess(lastVersion)
val changeLog = entries.find { it.key == "changeLog" }?.value.toString().replace("\"", "")
onSuccess(lastVersion, changeLog)
val url = entries.find { it.key == "url" }?.value.toString()
val updaterUrl = entries.find { it.key == "updater" }?.value.toString()
downloadFile(updaterUrl, UPDATER_FILE_NAME) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ object DeckBuildExecutor {

private fun mouseMove(x: ReferenceConfig.() -> Int, y: ReferenceConfig.() -> Int) {
with(TESLTracker.referenceConfig) {
robot.mouseMove(x(), y())
robot.mouseMove(x() + TESLTracker.graphicsDevice.defaultConfiguration.bounds.x, y())
}
}

Expand Down
33 changes: 25 additions & 8 deletions src/main/kotlin/com/ediposouza/executor/DeckImportExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import com.ediposouza.model.Deck
import com.ediposouza.model.DeckClass
import com.ediposouza.model.DeckType
import com.ediposouza.util.Logger
import javafx.scene.control.ButtonType
import javafx.scene.control.TextInputDialog
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.javafx.JavaFx
import kotlinx.coroutines.experimental.launch
import org.jsoup.Jsoup
import java.util.*

/**
* Created by ediposouza on 12/05/17.
Expand All @@ -23,16 +25,31 @@ object DeckImportExecutor {

fun importDeckFromLegendsClick(onSuccess: (Deck) -> Unit) {
launch(JavaFx) {
val result = TextInputDialog("").apply {
val alert = TextInputDialog("").apply {
title = "${TESLTracker.Companion.APP_NAME} - Importing deck from Legends-Decks"
contentText = "Url:"
}.showAndWait()
if (result.isPresent) {
val url = result.get()
loading.show()
launch(CommonPool) {
importFromLegendsDeck(url) {
onSuccess(it)
}
with(alert.dialogPane) {
scene.root = javafx.scene.Group()
javafx.stage.Stage(javafx.stage.StageStyle.UTILITY).apply {
for (buttonType in buttonTypes) {
lookupButton(buttonType).setOnMouseClicked {
this@with.userData = buttonType
close()
}
}
initModality(javafx.stage.Modality.APPLICATION_MODAL)
isAlwaysOnTop = true
scene = javafx.scene.Scene(this@with)
}.showAndWait()
val button: Optional<ButtonType> = java.util.Optional.ofNullable(userData as? ButtonType)
if (button.isPresent && button.get() == ButtonType.OK) {
val url = alert.editor.characters.toString()
loading.show()
launch(CommonPool) {
importFromLegendsDeck(url) {
onSuccess(it)
}
}
}
}
Expand Down
23 changes: 18 additions & 5 deletions src/main/kotlin/com/ediposouza/executor/ScreenExecutor.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ediposouza.executor

import com.ediposouza.TESLTracker
import com.ediposouza.data.PHash
import com.ediposouza.extensions.*
import com.ediposouza.model.MatchMode
Expand All @@ -17,6 +18,8 @@ import java.awt.image.BufferedImage
*/
object ScreenExecutor {

private const val ARENA_GAME_STARTED_PREF = "ArenaGameStarted"

var screenRecognized = false
var lastScreenRecognized = ""

Expand Down Expand Up @@ -59,24 +62,34 @@ object ScreenExecutor {
launch(CommonPool) {
if (screenshot.getScreenGameCrop().matchScreen(PHash.SCREEN_GAME)) {
Logger.i("Game Screen Detected!", true)
StateHandler.currentTESLState = GameState
StateHandler.currentTESLState = GameState.apply {
if (matchMode == MatchMode.ARENA) {
TESLTracker.preferences.putBoolean(ARENA_GAME_STARTED_PREF, true)
}
}
screenRecognized = true
}
}
// Arena
launch(CommonPool) {
if (screenshot.getScreenArenaClassesCrop().matchScreen(PHash.SCREEN_ARENA_CLASSES)) {
Logger.i("Arena Classes Screen Detected!", true)
StateHandler.currentTESLState = ArenaState.apply {
pickNumber = 1
}
ArenaState.resetState()
screenRecognized = true
}
}
launch(CommonPool) {
if (screenshot.getScreenArenaPicksCrop().matchScreen(PHash.SCREEN_ARENA_PICKS)) {
Logger.i("Arena Picks Screen Detected!", true)
StateHandler.currentTESLState = ArenaState
StateHandler.currentTESLState = ArenaState.apply {
if (TESLTracker.preferences.getBoolean(ARENA_GAME_STARTED_PREF, false)) {
TESLTracker.preferences.remove(ARENA_GAME_STARTED_PREF)
pickNumber = 1
}
if (pickNumber == 0) {
pickNumber = 1
}
}
screenRecognized = true
}
}
Expand Down
37 changes: 36 additions & 1 deletion src/main/kotlin/com/ediposouza/extensions/AppExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ import com.ediposouza.ui.MainWidget
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import javafx.embed.swing.SwingFXUtils
import javafx.scene.Group
import javafx.scene.Scene
import javafx.scene.control.Alert
import javafx.scene.control.ButtonType
import javafx.scene.image.Image
import javafx.scene.image.ImageView
import javafx.stage.Modality
import javafx.stage.Stage
import javafx.stage.StageStyle
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.io.IOUtils
import tornadofx.Rest
Expand All @@ -15,6 +22,7 @@ import java.awt.PopupMenu
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
import java.util.*
import javax.imageio.ImageIO

fun String?.toIntSafely() = this?.toIntOrNull() ?: 0
Expand Down Expand Up @@ -109,4 +117,31 @@ fun File.getMD5(): String? {
fun Rest.Response.asJson(): JsonObject {
val text = text() ?: "{}"
return JsonParser().parse(text.takeIf { text != "null" } ?: "{}").asJsonObject
}
}

fun alertAlwaysOnTop(type: Alert.AlertType,
header: String,
content: String,
vararg buttons: ButtonType,
actionFn: (Alert.(ButtonType) -> Unit)? = null): Alert {

val alert = Alert(type, content, *buttons)
alert.headerText = header
with(alert.dialogPane) {
scene.root = Group()
Stage(StageStyle.UTILITY).apply {
for (buttonType in buttonTypes) {
lookupButton(buttonType).setOnMouseClicked {
this@with.userData = buttonType
close()
}
}
initModality(Modality.APPLICATION_MODAL)
isAlwaysOnTop = true
scene = Scene(this@with)
}.showAndWait()
val button: Optional<ButtonType> = Optional.ofNullable(userData as? ButtonType)
button.ifPresent { actionFn?.invoke(alert, button.get()) }
}
return alert
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/ediposouza/model/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ data class Card(
) : Serializable {
companion object {

val DUMMY = Card("Unknown", "", CardSet.UNKNOWN, CardAttribute.AGILITY, CardAttribute.AGILITY, CardAttribute.AGILITY,
val DUMMY = Card("Unknown", "", CardSet.UNKNOWN, CardAttribute.NEUTRAL, CardAttribute.NEUTRAL, CardAttribute.NEUTRAL,
CardRarity.COMMON, false, 0, 0, 0, CardType.UNKNOWN, CardRace.ARGONIAN, listOf(), "", CardArenaTier.NONE,
listOf(), false, "")

Expand Down
Loading

0 comments on commit f05f3a7

Please sign in to comment.