fix: id oob

This commit is contained in:
aro 2023-01-12 18:45:33 +01:00
parent bce3e0d9f1
commit 11dbe77448
2 changed files with 13 additions and 5 deletions

View file

@ -10,6 +10,7 @@ import androidx.compose.ui.unit.dp
import xyz.atnrch.wrench.json.JsonLayout import xyz.atnrch.wrench.json.JsonLayout
import xyz.atnrch.wrench.json.SerializedWatcherEntry import xyz.atnrch.wrench.json.SerializedWatcherEntry
import xyz.atnrch.wrench.watcher.WatcherEntry import xyz.atnrch.wrench.watcher.WatcherEntry
import xyz.atnrch.wrench.watcher.WatcherManager
@Composable @Composable
fun TopBarButtons( fun TopBarButtons(
@ -17,13 +18,18 @@ fun TopBarButtons(
values: MutableCollection<WatcherEntry> values: MutableCollection<WatcherEntry>
) { ) {
Button(onClick = { Button(onClick = {
println(values.toList().joinToString(","))
jsonLayout.writeLayout(SerializedWatcherEntry.fromUnserializedEntries(values.toList())) jsonLayout.writeLayout(SerializedWatcherEntry.fromUnserializedEntries(values.toList()))
}) { }) {
Text("Save") Text("Save")
} }
Spacer(Modifier.width(10.dp)) Spacer(Modifier.width(10.dp))
Button(onClick = { Button(onClick = {
values.clear()
// not the cleanest way of doing things
// but tbh I'm tired after working on serialization
// for the past 2 hrs
// TODO: Make it cleaner maybe?
WatcherManager.CURRENT_ID = 0
jsonLayout.readLayout() jsonLayout.readLayout()
}) { }) {
Text("Load") Text("Load")

View file

@ -5,16 +5,18 @@ import java.io.File
import java.nio.file.Path import java.nio.file.Path
class WatcherManager(private val entries: MutableMap<Int, WatcherEntry>) { class WatcherManager(private val entries: MutableMap<Int, WatcherEntry>) {
private var currentId: Int = -1 companion object {
var CURRENT_ID: Int = -1
}
fun addFile(file: File, outputs: ArrayList<Path>) { fun addFile(file: File, outputs: ArrayList<Path>) {
val watcherEntry = WatcherEntry(file, outputs) val watcherEntry = WatcherEntry(file, outputs)
currentId += 1 CURRENT_ID += 1
entries[currentId] = watcherEntry entries[CURRENT_ID] = watcherEntry
Logger.info( Logger.info(
""" """
Tracking new file: Tracking new file:
ID: $currentId ID: $CURRENT_ID
Name: ${file.name} Name: ${file.name}
Path: ${file.absolutePath} Path: ${file.absolutePath}
""".trimIndent() """.trimIndent()