Skip to content

Commit 1ba569e

Browse files
committed
Add debug page option to allow installing all possible installations to selected launcher.
1 parent 82d6f5f commit 1ba569e

File tree

1 file changed

+91
-0
lines changed
  • installer/src/main/kotlin/gg/essential/installer/gui/page

1 file changed

+91
-0
lines changed

installer/src/main/kotlin/gg/essential/installer/gui/page/DebugPage.kt

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,31 @@ import gg.essential.elementa.constraints.*
2121
import gg.essential.elementa.dsl.*
2222
import gg.essential.elementa.effects.ScissorEffect
2323
import gg.essential.elementa.layoutdsl.*
24+
import gg.essential.elementa.state.v2.combinators.map
25+
import gg.essential.elementa.state.v2.memo
2426
import gg.essential.elementa.state.v2.mutableStateOf
27+
import gg.essential.elementa.state.v2.stateOf
2528
import gg.essential.elementa.state.v2.toV1
2629
import gg.essential.elementa.util.onAnimationFrame
2730
import gg.essential.installer.exitInstaller
2831
import gg.essential.installer.gui.*
2932
import gg.essential.installer.gui.component.*
33+
import gg.essential.installer.install.InstallStep
34+
import gg.essential.installer.install.InstallSteps
35+
import gg.essential.installer.install.start
3036
import gg.essential.installer.launchInMainCoroutineScope
37+
import gg.essential.installer.launcher.InstallInfo
38+
import gg.essential.installer.launcher.Launcher
39+
import gg.essential.installer.launcher.Launchers
3140
import gg.essential.installer.logging.Logging.logger
41+
import gg.essential.installer.mod.ModManager
3242
import gg.essential.installer.platform.Platform
3343
import gg.essential.universal.UDesktop
3444
import gg.essential.universal.UScreen
3545
import kotlinx.coroutines.Dispatchers
3646
import kotlinx.coroutines.withContext
3747
import java.awt.Color
48+
import gg.essential.installer.launcher.Installation as LInstallation
3849

3950
/**
4051
* Debug page, of random things I need(ed) during testing
@@ -58,6 +69,9 @@ object DebugPage : InstallerPage() {
5869
textButton("No Launchers page", ButtonStyle.GRAY, Modifier.width(200f).height(48f)) {
5970
PageHandler.navigateTo(NoLauncherFoundPage)
6071
}
72+
textButton("Install Everything", ButtonStyle.GRAY, Modifier.width(200f).height(48f)) {
73+
PageHandler.navigateTo(InstallEverything)
74+
}
6175
textButton("Restart", ButtonStyle.GRAY, Modifier.width(200f).height(48f)) {
6276
exitInstaller(true)
6377
}
@@ -82,4 +96,81 @@ object DebugPage : InstallerPage() {
8296
scroller.setVerticalScrollBarComponent(scrollbar)
8397
}
8498

99+
object InstallEverything : InstallerPage() {
100+
101+
private val map = memo {
102+
ModManager.getAvailableMCVersions()().associateWith { ModManager.getAvailableModloaders(stateOf(it))() }
103+
}
104+
private val count = map.map { m -> m.entries.sumOf { it.value.size } }
105+
106+
private val installation = mutableStateOf<InstallStep<*, *>?>(null)
107+
108+
override fun LayoutScope.layoutPage() {
109+
110+
titleAndBody(
111+
"Install everything",
112+
"""
113+
This page allows you to install every single supported version & modloader in bulk.
114+
This will create ${count.getUntracked()} profiles/installs!
115+
Select a modloader on the right to install all possible profiles to it.
116+
""",
117+
modifier = Modifier.alignTopLeft()
118+
)
119+
column(Modifier.width(320f).alignTopRight(), Arrangement.spacedBy(8f, FloatPosition.START)) {
120+
forEach(Launchers.launchers) { launcher ->
121+
launcherButton(launcher)
122+
}
123+
}
124+
val desc = memo {
125+
val inst = installation() ?: return@memo "Not installing..."
126+
val currentStep = inst.currentStep()
127+
val stepsCompleted = inst.stepsCompleted()
128+
val numberOfSteps = inst.numberOfSteps()
129+
"Installing: ${currentStep.id} ($stepsCompleted/$numberOfSteps)"
130+
}
131+
box(Modifier.alignBottomRight()) {
132+
installerText(desc)
133+
}
134+
}
135+
136+
private fun <I : LInstallation, NI : InstallInfo.New, EI : InstallInfo.Edit<I>> LayoutScope.launcherButton(launcher: Launcher<I, NI, EI>) {
137+
button(stateOf(ButtonStyle.GRAY), disabled = installation.map { it != null }, modifier = Modifier.fillWidth().height(96f)) {
138+
row(Modifier.fillWidth(padding = 24f), Arrangement.spacedBy(24f, FloatPosition.START)) {
139+
box(Modifier.width(64f).heightAspect(1f)) {
140+
image(launcher.type.icon, Modifier.fillParent().color(Color.WHITE))
141+
}
142+
installerBoldText(launcher.type.displayName, Modifier.color(InstallerPalette.TEXT))
143+
}
144+
}.onLeftClick {
145+
if (installation.getUntracked() != null) return@onLeftClick
146+
val installationInfos = map.getUntracked().flatMap { (mcVersion, modloaders) ->
147+
modloaders.mapNotNull { modloader ->
148+
val installInfo = launcher.getNewInstallInfo(
149+
"Debug - $mcVersion ${modloader.type.displayName}",
150+
ModManager.getBestModVersion(mcVersion, modloader.type).getUntracked() ?: return@mapNotNull null,
151+
mcVersion,
152+
modloader,
153+
modloader.getBestModloaderVersion(mcVersion).getUntracked() ?: return@mapNotNull null
154+
)
155+
InstallSteps.merge(
156+
modloader.getInstallSteps(installInfo),
157+
launcher.getNewInstallationInstallSteps(installInfo),
158+
)
159+
}
160+
}
161+
val inst = InstallSteps.merge(*installationInfos.toTypedArray()).convertToSingleInstallStep()
162+
163+
installation.set(inst)
164+
165+
launchInMainCoroutineScope {
166+
logger.info("Starting Install")
167+
inst.start()
168+
installation.set(null)
169+
}
170+
}
171+
}
172+
173+
174+
}
175+
85176
}

0 commit comments

Comments
 (0)