Skip to content

Commit

Permalink
refactor to have file service
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Smart <derek@grindaga.com>
  • Loading branch information
mcred committed Mar 2, 2019
1 parent 510a32d commit 1dcb24e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/com/grindaga/crissaegrim/Maps/Stats.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.grindaga.crissaegrim.maps

import com.grindaga.crissaegrim.objects.Location

data class Stats(
data class Stats (
val HP: Location = Location(0x474, 1, true),
val HPMax: Location = Location(0x478, 1, true),
val Hearts: Location = Location(0x47C, 1, true),
Expand All @@ -14,4 +14,4 @@ data class Stats(
val INT: Location = Location(0x494),
val LCK: Location = Location(0x498),
val ATTBonus: Location = Location(0x49)
)
)
17 changes: 17 additions & 0 deletions src/main/kotlin/com/grindaga/crissaegrim/objects/Stats.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.grindaga.crissaegrim.objects

import tornadofx.*

data class Stats (
val HP: Int,
val HPMax: Int,
val Hearts: Int,
val HeartsMax: Int,
val MP: Int,
val MPMax: Int,
val STR: Int,
val CON: Int,
val INT: Int,
val LCK: Int,
val ATTBonus: Int
): ViewModel()
40 changes: 40 additions & 0 deletions src/main/kotlin/com/grindaga/crissaegrim/service/FileService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.grindaga.crissaegrim.service

import com.grindaga.crissaegrim.objects.Card
import javafx.stage.FileChooser
import tornadofx.*
import java.io.File

object FileService {
private val mcrFilter = FileChooser.ExtensionFilter("mednafen files (*.mcr)", "*.mcr")
private val allFilter = FileChooser.ExtensionFilter("all files (*.*)", "*.*")

fun openFile(targetFile: File? = null) {
val file: File

if (targetFile == null) {
// If the user didn't select, then finish this method.
file = getFile() ?: return
} else {
file = targetFile
}

try {
val saveFile = File(file.toString()).inputStream()
val card = Card.load(file.toString(), saveFile)
println(card.slots[1])
//ModelManager.textModel.textProperty.set(text)
//ModelManager.fileModel.fileProperty.set(file)
} catch (e: Exception) {
println(e)
}
}

private fun getFile(): File? {
val fileList = chooseFile("Select PS1 Memory Card", arrayOf(mcrFilter, allFilter), FileChooserMode.Single)
return when (fileList.isEmpty()) {
true -> null
else -> fileList.first()
}
}
}
18 changes: 18 additions & 0 deletions src/main/kotlin/com/grindaga/crissaegrim/utils/Loader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.grindaga.crissaegrim.utils

import com.grindaga.crissaegrim.objects.*
import com.grindaga.crissaegrim.maps.*
import com.grindaga.crissaegrim.objects.Stats as StatObj
import java.io.File

class Loader {
Expand All @@ -11,6 +12,23 @@ class Loader {
return Card.load(fileLocation, saveFile)
}

fun getStats(slot: Slot): StatObj{
val statMap = Stats()
return StatObj(
Numeric(slot.getValueByRange(statMap.HP.getRange())).output(),
Numeric(slot.getValueByRange(statMap.HPMax.getRange())).output(),
Numeric(slot.getValueByRange(statMap.Hearts.getRange())).output(),
Numeric(slot.getValueByRange(statMap.HeartsMax.getRange())).output(),
Numeric(slot.getValueByRange(statMap.MP.getRange())).output(),
Numeric(slot.getValueByRange(statMap.MPMax.getRange())).output(),
Numeric(slot.getValueByRange(statMap.STR.getRange())).output(),
Numeric(slot.getValueByRange(statMap.CON.getRange())).output(),
Numeric(slot.getValueByRange(statMap.INT.getRange())).output(),
Numeric(slot.getValueByRange(statMap.LCK.getRange())).output(),
Numeric(slot.getValueByRange(statMap.ATTBonus.getRange())).output()
)
}

/*
val stats: Stats = Stats()
println("HP: ${stats.HP}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.grindaga.crissaegrim.views

import tornadofx.*
import tornadofx.Form

class CharacterView : View("My View") {
override val root = form {

override val root = form {
fieldset("Character Stats") {
field("HP") {
textfield()
}
}
}

}
12 changes: 2 additions & 10 deletions src/main/kotlin/com/grindaga/crissaegrim/views/MenuBarView.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.grindaga.crissaegrim.views

import com.grindaga.crissaegrim.service.FileService
import javafx.application.Platform
import tornadofx.*
import javafx.scene.input.KeyCombination
import javafx.stage.FileChooser
import java.io.File
import com.grindaga.crissaegrim.objects.*
import com.grindaga.crissaegrim.utils.*
import com.grindaga.crissaegrim.utils.Loader

class MenuBarView : View("My View") {
override val root = menubar{
Expand All @@ -18,11 +14,7 @@ class MenuBarView : View("My View") {
menu("File") {
item("Open", KeyCombination.valueOf("Shortcut+O")) {
setOnAction {
val filters = arrayOf(FileChooser.ExtensionFilter("Memory Card Files", "*.mcr"))
val files: List<File> = chooseFile("Select PS1 Memory Card", filters, FileChooserMode.Single)
val loader = Loader()
val card = loader.loadCard(files[0].toString())
println(card.slots[1])
FileService.openFile()
}
}
item("Save", KeyCombination.valueOf("Shortcut+S")) {
Expand Down

0 comments on commit 1dcb24e

Please sign in to comment.