diff --git a/src/main/kotlin/de/steamwar/data/Groups.kt b/src/main/kotlin/de/steamwar/data/Groups.kt index 9d978af..6a71b76 100644 --- a/src/main/kotlin/de/steamwar/data/Groups.kt +++ b/src/main/kotlin/de/steamwar/data/Groups.kt @@ -15,7 +15,14 @@ data class GroupData(val name: String, val fights: MutableList) @OptIn(ExperimentalSerializationApi::class) class Groups { companion object { - private var groups: GroupsData = Cbor.decodeFromByteArray(kGroupsFile.readBytes()) + private var groups: GroupsData = if (kGroupsFile.exists()) { + Cbor.decodeFromByteArray(kGroupsFile.readBytes()) + } else { + kGroupsFile.createNewFile() + kGroupsFile.writeBytes(Cbor.encodeToByteArray(GroupsData(mutableListOf()))) + + GroupsData(mutableListOf()) + } fun getGroup(name: String): GroupData? { return groups.groups.find { it.name == name }