From c03623dc3804607b3fa83584b5e19768034ffe87 Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Wed, 29 Jul 2020 23:20:15 +0200 Subject: [PATCH] Init is now creating modpack dev environment --- .../ley/anvil/modpacktools/commands/Init.kt | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/ley/anvil/modpacktools/commands/Init.kt b/src/main/kotlin/ley/anvil/modpacktools/commands/Init.kt index aa31714..f0a102f 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/commands/Init.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/commands/Init.kt @@ -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): CommandReturn { - if(CONFIG.exists) - return fail("Config exists") - CONFIG.copyConfig() - return success("Config Created") + if(!CONFIG.exists) + CONFIG.copyConfig() + val srcDir = File(CONFIG.config.getPath("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)") } } \ No newline at end of file