Skip to content

Commit

Permalink
refresh creations
Browse files Browse the repository at this point in the history
  • Loading branch information
ManApart committed Jun 22, 2024
1 parent bb3d656 commit 0892a42
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
47 changes: 33 additions & 14 deletions src/main/kotlin/commands/Creation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ private fun listCreations() {
val columns = listOf(
Column("Creation Id", 42),
Column("Mod File Id", 15),
Column("Managed", 15),
Column("Title", 22),
)
val data = parseCreationCatalog().values.map { creation ->
mapOf(
"Creation Id" to (creation.creationId ?: ""),
"Mod File Id" to (creation.modFileId ?: ""),
"Managed" to (creation.creationId?.let { toolData.byCreationId(it) } != null),
"Title" to creation.title,
)
}
Expand All @@ -105,9 +107,14 @@ private fun listCreations() {
}

private fun addAllCreations(force: Boolean = false) {
val creations = parseCreationCatalog().values.filter { it.creationId == null || toolData.byCreationId(it.creationId!!) != null }
confirm(force, yellow("Add unmanaged creations? ") + creations.joinToString(", ") { it.title }) {
creations.forEach { addCreation(it) }
val creations = parseCreationCatalog().values.filter { it.creationId == null || toolData.byCreationId(it.creationId!!) == null }
if (creations.isEmpty()) {
println("No creations found")
} else {
confirm(force, yellow("Add unmanaged creations? ") + creations.joinToString(", ") { it.title }) {
creations.forEach { addCreation(it) }
println("Added Creations")
}
}
}

Expand Down Expand Up @@ -151,25 +158,37 @@ fun addCreation(creation: Creation) {

private fun rmAllCreations(force: Boolean = false) {
val creations = toolData.mods.filter { it.creationId != null }
confirm(force, yellow("Remove Creations? ") + creations.joinToString(", ") { it.name }) {
confirm(force, yellow("Remove All Creations? ") + creations.joinToString(", ") { it.name }) {
creations.forEach { rmCreation(it, true) }
}
}

private fun rmCreation(creation: Mod, force: Boolean = false) {
confirm(force, yellow("Remove Creations? ")) {
creation.getModFiles().forEach { file ->

}
private fun rmCreation(mod: Mod, force: Boolean = false) {
confirm(force, yellow("Remove Creation ${mod.description()} ")) {
val modRoot = File(mod.filePath).absolutePath + "/"
mod.getModFiles()
.forEach { file ->
val linkFile = file.absolutePath.replace(modRoot, "")
deleteLink(linkFile, mapOf())
val destFile = File(file.absolutePath.replace(modRoot, toolConfig.gamePath!! +"/"))
if (!destFile.exists()) {
Files.move(file.toPath(), destFile.toPath())
}
}
delete(mod)
}
}

private fun refreshAllCreations() {
rmAllCreations(true)
addAllCreations(true)
confirm(false, "Refresh All Creations?") {
rmAllCreations(true)
addAllCreations(true)
}
}

private fun refreshCreation(creation: Mod) {
rmCreation(creation)
creation.creationId?.let { addCreation(it) }
private fun refreshCreation(mod: Mod) {
confirm(false, yellow("Refresh Creation ${mod.description()} ")) {
rmCreation(mod)
mod.creationId?.let { addCreation(it) }
}
}
16 changes: 9 additions & 7 deletions src/main/kotlin/commands/Deploy.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package commands

import Mod
import cyan
import toolConfig
import toolData
Expand Down Expand Up @@ -48,15 +49,17 @@ private fun getDisabledModPaths(): List<String> {

private fun getAllModFiles(): Map<String, File> {
val mappings = mutableMapOf<String, File>()
toolData.mods.filter { it.enabled }.sortedBy { it.loadOrder }.forEach { mod ->
val modRoot = File(mod.filePath).absolutePath + "/"
mod.getModFiles().forEach { file ->
mappings[file.absolutePath.replace(modRoot, "")] = file
}
}
toolData.mods.filter { it.enabled }.sortedBy { it.loadOrder }.forEach { mappings.addModFiles(it) }
return mappings
}

private fun MutableMap<String, File>.addModFiles(mod: Mod) {
val modRoot = File(mod.filePath).absolutePath + "/"
mod.getModFiles().forEach { file ->
this[file.absolutePath.replace(modRoot, "")] = file
}
}

fun makeLink(gamePath: String, modFile: File) {
val gameFile = File(toolConfig.usedGamePath(gamePath) + "/$gamePath")
gameFile.parentFile.mkdirs()
Expand Down Expand Up @@ -95,4 +98,3 @@ fun deleteLink(gamePath: String, modFiles: Map<String, File>) {
}
}
}

3 changes: 2 additions & 1 deletion src/main/kotlin/commands/RemoveMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ private fun removeMod(index: Int) {
}

fun delete(mod: Mod) {
val desc = mod.name
val existing = File(mod.filePath)
if (existing.exists()) existing.deleteRecursively()
toolData.mods.remove(mod)
toolData.mods.filter { it.loadOrder > mod.loadOrder }.map { it.loadOrder -= 1 }
toolData.mods.filter { it.index > mod.index }.map { it.index -= 1 }
save()
println(red("Mod deleted"))
println(red("Mod '$desc' deleted"))
}

0 comments on commit 0892a42

Please sign in to comment.