Skip to content

Commit

Permalink
outsource minosoft boot process from main class to external class
Browse files Browse the repository at this point in the history
That will make it much easier to use a custom main class, maybe useful on android
  • Loading branch information
Bixilon committed Nov 23, 2023
1 parent a2cb6b6 commit 56f26db
Show file tree
Hide file tree
Showing 22 changed files with 159 additions and 99 deletions.
51 changes: 8 additions & 43 deletions src/main/java/de/bixilon/minosoft/Minosoft.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import de.bixilon.kutil.concurrent.pool.runnable.ForcePooledRunnable
import de.bixilon.kutil.concurrent.worker.task.TaskWorker
import de.bixilon.kutil.concurrent.worker.task.WorkerTask
import de.bixilon.kutil.latch.AbstractLatch
import de.bixilon.kutil.latch.CallbackLatch
import de.bixilon.kutil.latch.SimpleLatch
import de.bixilon.kutil.observer.DataObserver.Companion.observe
import de.bixilon.kutil.os.OSTypes
Expand All @@ -31,50 +30,35 @@ import de.bixilon.kutil.shutdown.ShutdownManager
import de.bixilon.kutil.time.TimeUtil.nanos
import de.bixilon.kutil.unit.UnitFormatter.formatNanos
import de.bixilon.minosoft.assets.IntegratedAssets
import de.bixilon.minosoft.assets.meta.MinosoftMeta
import de.bixilon.minosoft.assets.properties.version.AssetsVersionProperties
import de.bixilon.minosoft.config.StaticConfiguration
import de.bixilon.minosoft.config.profile.manager.ProfileManagers
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
import de.bixilon.minosoft.data.entities.event.EntityEvents
import de.bixilon.minosoft.data.language.LanguageUtil
import de.bixilon.minosoft.data.language.manager.MultiLanguageManager
import de.bixilon.minosoft.data.registries.fallback.FallbackRegistries
import de.bixilon.minosoft.data.registries.fallback.tags.FallbackTags
import de.bixilon.minosoft.data.registries.identified.Namespaces
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
import de.bixilon.minosoft.data.language.IntegratedLanguage
import de.bixilon.minosoft.data.text.formatting.FormattingCodes
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.datafixer.DataFixer
import de.bixilon.minosoft.gui.eros.Eros
import de.bixilon.minosoft.gui.eros.crash.ErosCrashReport
import de.bixilon.minosoft.gui.eros.crash.ErosCrashReport.Companion.crash
import de.bixilon.minosoft.gui.eros.dialog.StartingDialog
import de.bixilon.minosoft.gui.eros.util.JavaFXInitializer
import de.bixilon.minosoft.main.BootTasks
import de.bixilon.minosoft.main.MinosoftBoot
import de.bixilon.minosoft.modding.event.events.FinishBootEvent
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
import de.bixilon.minosoft.modding.loader.LoadingPhases
import de.bixilon.minosoft.modding.loader.ModLoader
import de.bixilon.minosoft.properties.MinosoftPropertiesLoader
import de.bixilon.minosoft.protocol.protocol.LANServerListener
import de.bixilon.minosoft.protocol.versions.VersionLoader
import de.bixilon.minosoft.terminal.AutoConnect
import de.bixilon.minosoft.terminal.CommandLineArguments
import de.bixilon.minosoft.terminal.RunConfiguration
import de.bixilon.minosoft.terminal.cli.CLI
import de.bixilon.minosoft.util.DesktopUtil
import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.json.Jackson
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
import de.bixilon.minosoft.util.yggdrasil.YggdrasilUtil


object Minosoft {
val LANGUAGE_MANAGER = MultiLanguageManager()
val BOOT_LATCH = CallbackLatch(1)


private fun preBoot(args: Array<String>) {
Expand Down Expand Up @@ -104,15 +88,8 @@ object Minosoft {
private fun boot() {
val taskWorker = TaskWorker(errorHandler = { _, error -> error.printStackTrace(); error.crash() }, forcePool = true)

taskWorker += WorkerTask(identifier = BootTasks.VERSIONS, priority = ThreadPool.HIGHER, executor = VersionLoader::load)
taskWorker += WorkerTask(identifier = BootTasks.PROFILES, priority = ThreadPool.HIGHEST, executor = ProfileManagers::load)

MinosoftBoot.register(taskWorker)
taskWorker += WorkerTask(identifier = BootTasks.LANGUAGE_FILES, dependencies = arrayOf(BootTasks.PROFILES), executor = this::loadLanguageFiles)
taskWorker += WorkerTask(identifier = BootTasks.ASSETS_PROPERTIES, dependencies = arrayOf(BootTasks.VERSIONS), executor = AssetsVersionProperties::load)
taskWorker += WorkerTask(identifier = BootTasks.DEFAULT_REGISTRIES, dependencies = arrayOf(BootTasks.VERSIONS), executor = { MinosoftMeta.load(); FallbackTags.load(); FallbackRegistries.load(); EntityEvents.load() })


taskWorker += WorkerTask(identifier = BootTasks.LAN_SERVERS, dependencies = arrayOf(BootTasks.PROFILES), executor = LANServerListener::listen)

if (!RunConfiguration.DISABLE_EROS) {
javafx(taskWorker)
Expand All @@ -121,17 +98,10 @@ object Minosoft {
// eros is disabled, but rendering not, force initialize the desktop, otherwise eros will do so
DefaultThreadPool += { DesktopUtil.initialize() }
}
taskWorker += WorkerTask(identifier = BootTasks.YGGDRASIL, executor = { YggdrasilUtil.load() })

taskWorker += WorkerTask(identifier = BootTasks.ASSETS_OVERRIDE, executor = { IntegratedAssets.OVERRIDE.load(it) })
taskWorker += WorkerTask(identifier = BootTasks.MODS, executor = { ModLoader.load(LoadingPhases.BOOT, it) })
taskWorker += WorkerTask(identifier = BootTasks.DATA_FIXER, executor = { DataFixer.load() })
taskWorker += WorkerTask(identifier = BootTasks.CLI, priority = ThreadPool.LOW, executor = CLI::startThread)


taskWorker.work(BOOT_LATCH)
BOOT_LATCH.dec() // initial count
BOOT_LATCH.await()
taskWorker.work(MinosoftBoot.LATCH)
MinosoftBoot.LATCH.dec() // initial count
MinosoftBoot.LATCH.await()
}

private fun postBoot() {
Expand All @@ -150,7 +120,7 @@ object Minosoft {
private fun javafx(taskWorker: TaskWorker) {
taskWorker += WorkerTask(identifier = BootTasks.JAVAFX, executor = { JavaFXInitializer.start(); async(ThreadPool.HIGHER) { javafx.scene.text.Font.getDefault() } })

taskWorker += WorkerTask(identifier = BootTasks.STARTUP_PROGRESS, executor = { StartingDialog(BOOT_LATCH).show() }, dependencies = arrayOf(BootTasks.LANGUAGE_FILES, BootTasks.JAVAFX))
taskWorker += WorkerTask(identifier = BootTasks.STARTUP_PROGRESS, executor = { StartingDialog(MinosoftBoot.LATCH).show() }, dependencies = arrayOf(BootTasks.LANGUAGE_FILES, BootTasks.JAVAFX))
taskWorker += WorkerTask(identifier = BootTasks.EROS, dependencies = arrayOf(BootTasks.JAVAFX, BootTasks.PROFILES, BootTasks.MODS, BootTasks.VERSIONS, BootTasks.LANGUAGE_FILES), executor = { DefaultThreadPool += { Eros.preload() } })

DefaultThreadPool += ForcePooledRunnable { Eros::class.java.forceInit() }
Expand Down Expand Up @@ -185,12 +155,7 @@ object Minosoft {
}

private fun loadLanguageFiles(latch: AbstractLatch?) {
val language = ErosProfileManager.selected.general.language
ErosProfileManager.selected.general::language.observe(this, true) {
Log.log(LogMessageType.OTHER, LogLevels.VERBOSE) { "Loading language files (${language})" }
LANGUAGE_MANAGER.translators[Namespaces.MINOSOFT] = LanguageUtil.load(it, null, IntegratedAssets.DEFAULT, minosoft("language/"))
Log.log(LogMessageType.OTHER, LogLevels.VERBOSE) { "Language files loaded!" }
}
ErosProfileManager.selected.general::language.observe(this, true) { IntegratedLanguage.load(it) }
}

private fun checkMacOS() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/

package de.bixilon.minosoft.data.language

import de.bixilon.minosoft.assets.IntegratedAssets
import de.bixilon.minosoft.data.language.manager.MultiLanguageManager
import de.bixilon.minosoft.data.registries.identified.Namespaces
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType

object IntegratedLanguage {
val LANGUAGE = MultiLanguageManager()


fun load(name: String) {
Log.log(LogMessageType.LOADING, LogLevels.VERBOSE) { "Loading language files (${name})" }
val language = LanguageUtil.load(name, null, IntegratedAssets.DEFAULT, minosoft("language/"))
LANGUAGE.translators[Namespaces.MINOSOFT] = language
}
}
4 changes: 2 additions & 2 deletions src/main/java/de/bixilon/minosoft/data/text/ChatComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package de.bixilon.minosoft.data.text

import com.fasterxml.jackson.core.JacksonException
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.language.IntegratedLanguage
import de.bixilon.minosoft.data.language.translate.Translatable
import de.bixilon.minosoft.data.language.translate.Translator
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
Expand Down Expand Up @@ -103,7 +103,7 @@ interface ChatComponent {
return raw
}
if (raw is Translatable && raw !is ResourceLocation) {
return (translator ?: Minosoft.LANGUAGE_MANAGER).forceTranslate(raw.translationKey, parent, restricted = restricted)
return (translator ?: IntegratedLanguage.LANGUAGE).forceTranslate(raw.translationKey, parent, restricted = restricted)
}

when (raw) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

package de.bixilon.minosoft.data.text

import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.AbstractServer
import de.bixilon.minosoft.data.accounts.Account
import de.bixilon.minosoft.data.language.IntegratedLanguage
import de.bixilon.minosoft.util.KUtil.toResourceLocation

object TranslatableComponents {
Expand All @@ -27,8 +27,15 @@ object TranslatableComponents {
val GENERAL_EXIT = "minosoft:general.exit".toResourceLocation()
val GENERAL_REFRESH = "minosoft:general.refresh".toResourceLocation()

val EROS_DELETE_SERVER_CONFIRM_DESCRIPTION = { name: ChatComponent, address: String -> Minosoft.LANGUAGE_MANAGER.forceTranslate("minosoft:server_info.delete.dialog.description".toResourceLocation(), name, address) }
val ACCOUNT_CARD_CONNECTION_COUNT = { count: Int -> Minosoft.LANGUAGE_MANAGER.forceTranslate("minosoft:main.account.card.connection_count".toResourceLocation(), count) }
val CONNECTION_KICK_DESCRIPTION = { server: AbstractServer, account: Account -> Minosoft.LANGUAGE_MANAGER.forceTranslate("minosoft:connection.kick.description".toResourceLocation(), server.name, account.username) }
val CONNECTION_LOGIN_KICK_DESCRIPTION = { server: AbstractServer, account: Account -> Minosoft.LANGUAGE_MANAGER.forceTranslate("minosoft:connection.login_kick.description".toResourceLocation(), server.name, account.username) }
@Deprecated("yah")
val EROS_DELETE_SERVER_CONFIRM_DESCRIPTION = { name: ChatComponent, address: String -> IntegratedLanguage.LANGUAGE.forceTranslate("minosoft:server_info.delete.dialog.description".toResourceLocation(), name, address) }

@Deprecated("yah")
val ACCOUNT_CARD_CONNECTION_COUNT = { count: Int -> IntegratedLanguage.LANGUAGE.forceTranslate("minosoft:main.account.card.connection_count".toResourceLocation(), count) }

@Deprecated("yah")
val CONNECTION_KICK_DESCRIPTION = { server: AbstractServer, account: Account -> IntegratedLanguage.LANGUAGE.forceTranslate("minosoft:connection.kick.description".toResourceLocation(), server.name, account.username) }

@Deprecated("yah")
val CONNECTION_LOGIN_KICK_DESCRIPTION = { server: AbstractServer, account: Account -> IntegratedLanguage.LANGUAGE.forceTranslate("minosoft:connection.login_kick.description".toResourceLocation(), server.name, account.username) }
}
4 changes: 2 additions & 2 deletions src/main/java/de/bixilon/minosoft/gui/eros/Eros.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import de.bixilon.kutil.collections.CollectionUtil.toSynchronizedSet
import de.bixilon.kutil.exception.ExceptionUtil.catchAll
import de.bixilon.kutil.latch.SimpleLatch
import de.bixilon.kutil.observer.DataObserver.Companion.observe
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
import de.bixilon.minosoft.gui.eros.main.MainErosController
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.forceInit
import de.bixilon.minosoft.main.MinosoftBoot
import de.bixilon.minosoft.modding.event.events.FinishBootEvent
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
Expand Down Expand Up @@ -100,7 +100,7 @@ object Eros {
mainErosController = it
catchAll { it.stage.forceInit() }
latch.dec()
if (Minosoft.BOOT_LATCH.count == 0) {
if (MinosoftBoot.LATCH.count == 0) {
start()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package de.bixilon.minosoft.gui.eros.dialog

import de.bixilon.kutil.exception.ExceptionUtil.toStackTrace
import de.bixilon.kutil.reflection.ReflectionUtil.realName
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.language.IntegratedLanguage
import de.bixilon.minosoft.data.text.TranslatableComponents.GENERAL_IGNORE
import de.bixilon.minosoft.gui.eros.controller.DialogController
import de.bixilon.minosoft.gui.eros.crash.ErosCrashReport.Companion.crash
Expand Down Expand Up @@ -66,7 +66,7 @@ class ErosErrorReport : DialogController() {

companion object {
private val LAYOUT = "minosoft:eros/dialog/error.fxml".toResourceLocation()
private val TITLE = { exception: Throwable? -> Minosoft.LANGUAGE_MANAGER.forceTranslate("minosoft:error.title".toResourceLocation(), exception?.let { it::class.java.realName }) }
private val TITLE = { exception: Throwable? -> IntegratedLanguage.LANGUAGE.forceTranslate("minosoft:error.title".toResourceLocation(), exception?.let { it::class.java.realName }) }
private val HEADER = "minosoft:error.header".toResourceLocation()
private val DESCRIPTION = "minosoft:error.description".toResourceLocation()
private val FATAL_CRASH = "minosoft:error.fatal_crash".toResourceLocation()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
Expand All @@ -14,7 +14,7 @@
package de.bixilon.minosoft.gui.eros.dialog

import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.language.IntegratedLanguage
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.data.text.TranslatableComponents
import de.bixilon.minosoft.gui.eros.controller.DialogController
Expand Down Expand Up @@ -49,10 +49,10 @@ class SimpleErosConfirmationDialog(
}

override fun init() {
headerFX.text = Minosoft.LANGUAGE_MANAGER.translate(header)
descriptionFX.text = description?.let { Minosoft.LANGUAGE_MANAGER.translate(it) } ?: ChatComponent.EMPTY
cancelButtonFX.text = Minosoft.LANGUAGE_MANAGER.translate(cancelButtonText).message
confirmButtonFX.text = Minosoft.LANGUAGE_MANAGER.translate(confirmButtonText).message
headerFX.text = IntegratedLanguage.LANGUAGE.translate(header)
descriptionFX.text = description?.let { IntegratedLanguage.LANGUAGE.translate(it) } ?: ChatComponent.EMPTY
cancelButtonFX.text = IntegratedLanguage.LANGUAGE.translate(cancelButtonText).message
confirmButtonFX.text = IntegratedLanguage.LANGUAGE.translate(confirmButtonText).message
}

override fun postInit() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
Expand All @@ -14,7 +14,7 @@
package de.bixilon.minosoft.gui.eros.dialog

import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.language.IntegratedLanguage
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.gui.eros.controller.DialogController
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
Expand Down Expand Up @@ -47,9 +47,9 @@ class SimpleErosWarningDialog(
}

override fun init() {
headerFX.text = Minosoft.LANGUAGE_MANAGER.translate(header)
descriptionFX.text = description?.let { Minosoft.LANGUAGE_MANAGER.translate(it) } ?: ChatComponent.EMPTY
ignoreButtonFX.text = Minosoft.LANGUAGE_MANAGER.translate(ignoreButtonText).message
headerFX.text = IntegratedLanguage.LANGUAGE.translate(header)
descriptionFX.text = description?.let { IntegratedLanguage.LANGUAGE.translate(it) } ?: ChatComponent.EMPTY
ignoreButtonFX.text = IntegratedLanguage.LANGUAGE.translate(ignoreButtonText).message
}

override fun postInit() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
Expand All @@ -13,7 +13,7 @@

package de.bixilon.minosoft.gui.eros.dialog.connection

import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.language.IntegratedLanguage
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.gui.eros.controller.DialogController
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
Expand Down Expand Up @@ -44,8 +44,8 @@ class KickDialog(


override fun init() {
headerFX.text = Minosoft.LANGUAGE_MANAGER.translate(header)
descriptionFX.text = description?.let { Minosoft.LANGUAGE_MANAGER.translate(it) } ?: ChatComponent.EMPTY
headerFX.text = IntegratedLanguage.LANGUAGE.translate(header)
descriptionFX.text = description?.let { IntegratedLanguage.LANGUAGE.translate(it) } ?: ChatComponent.EMPTY
reasonFX.text = reason

reconnectButtonFX.isDisable = true // ToDo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ package de.bixilon.minosoft.gui.eros.dialog.profiles

import de.bixilon.kutil.cast.CastUtil.nullCast
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.profile.ProfileType
import de.bixilon.minosoft.config.profile.manager.ProfileManagers
import de.bixilon.minosoft.data.language.IntegratedLanguage
import de.bixilon.minosoft.data.language.translate.Translatable
import de.bixilon.minosoft.data.registries.identified.Identified
import de.bixilon.minosoft.data.registries.identified.Namespaces.i18n
Expand Down Expand Up @@ -57,7 +57,7 @@ class ProfileSelectDialog(
}

override fun init() {
headerFX.text = Minosoft.LANGUAGE_MANAGER.forceTranslate(HEADER)
headerFX.text = IntegratedLanguage.LANGUAGE.forceTranslate(HEADER)

typeColumnFX.ctext = TYPE_COLUMN_TITLE
profileColumnFX.ctext = PROFILE_COLUMN_TITLE
Expand Down
Loading

0 comments on commit 56f26db

Please sign in to comment.