4
0
Fork 0
mirror of https://github.com/Anvilcraft/modpacktools synced 2024-11-17 23:41:55 +01:00

Init is now creating modpack dev environment

This commit is contained in:
Timo Ley 2020-07-29 23:20:15 +02:00
parent 93cef01984
commit c03623dc38

View file

@ -1,11 +1,14 @@
package ley.anvil.modpacktools.commands
import ley.anvil.addonscript.v1.AddonscriptJSON
import ley.anvil.modpacktools.CONFIG
import ley.anvil.modpacktools.command.CommandReturn
import ley.anvil.modpacktools.command.CommandReturn.Companion.fail
import ley.anvil.modpacktools.command.CommandReturn.Companion.success
import ley.anvil.modpacktools.command.ICommand
import ley.anvil.modpacktools.command.LoadCommand
import ley.anvil.modpacktools.util.mergeTo
import java.io.File
import java.io.FileWriter
@LoadCommand
object Init : ICommand {
@ -15,9 +18,29 @@ object Init : ICommand {
override val needsModpackjson: Boolean = false
override fun execute(args: Array<out String>): CommandReturn {
if(CONFIG.exists)
return fail("Config exists")
if(!CONFIG.exists)
CONFIG.copyConfig()
return success("Config Created")
val srcDir = File(CONFIG.config.getPath<String>("Locations/src")!!)
val overrides = srcDir.mergeTo(File("overrides"))
if(!overrides.exists())
overrides.mkdirs()
val asjson = srcDir.mergeTo(File("modpack.json"))
if (!asjson.exists()) {
val writer = FileWriter(asjson)
val addsc = AddonscriptJSON.create()
addsc.type = "modpack"
val ver = AddonscriptJSON.Version()
addsc.versions = mutableListOf(ver)
ver.versionid = -1
val file = AddonscriptJSON.File()
ver.files = mutableListOf(file)
file.id = "overrides"
file.link = "file://overrides"
file.installer = "internal.overrides"
file.options = mutableListOf("client", "server", "required", "included")
addsc.write(writer)
writer.close()
}
return success("MPT dev environment created. Use the created modpack.json or use the import command to import a curse manifest (recommended)")
}
}