diff --git a/assets/locales/en/terrarum.json b/assets/locales/en/terrarum.json index bfb4ffeef..9f438b41a 100644 --- a/assets/locales/en/terrarum.json +++ b/assets/locales/en/terrarum.json @@ -32,6 +32,7 @@ "MENU_OPTIONS_BLUR": "Blur", "MENU_OPTIONS_DEBUG_CONSOLE": "Debug Console", "MENU_OPTIONS_DITHER": "Dithering", + "MENU_OPTIONS_ENABLE_SCRIPT_MODS": "Enable Script Mods", "MENU_OPTIONS_JVM_HEAP_MAX": "Max Heap Memory", "MENU_OPTIONS_LIGHT_UPDATE_PASSES": "Light Calculation Depth", "MENU_OPTIONS_NOTIFICATION_DISPLAY_DURATION": "Show notification for", diff --git a/assets/locales/en/terrarum_sentences.json b/assets/locales/en/terrarum_sentences.json index 9a434cbaa..09a172c58 100644 --- a/assets/locales/en/terrarum_sentences.json +++ b/assets/locales/en/terrarum_sentences.json @@ -21,4 +21,5 @@ "MENU_LABEL_KEYCONFIG_HELP1": "Click On the Keycap to Assign Actions", "MENU_LABEL_SAVE_WILL_BE_DELETED": "The selected save file will be deleted.", "MENU_LABEL_UNSAVED_PROGRESS_WILL_BE_LOST": "Unsaved progress will be lost.", + "MENU_LABEL_WARN_ACE": "Script mods may damage your game or result in other unexpected behaviour.\nOnly use the mods you know they can be trusted." } \ No newline at end of file diff --git a/assets/locales/koKR/terrarum.json b/assets/locales/koKR/terrarum.json index 00480da80..4aac0ae1f 100644 --- a/assets/locales/koKR/terrarum.json +++ b/assets/locales/koKR/terrarum.json @@ -32,6 +32,7 @@ "MENU_OPTIONS_BLUR": "흐림", "MENU_OPTIONS_DEBUG_CONSOLE": "디버그 콘솔", "MENU_OPTIONS_DITHER": "디더링", + "MENU_OPTIONS_ENABLE_SCRIPT_MODS": "스크립트 모드 활성화", "MENU_OPTIONS_JVM_HEAP_MAX": "최대 힙 메모리", "MENU_OPTIONS_LIGHT_UPDATE_PASSES": "빛 계산 반복 횟수", "MENU_OPTIONS_NOTIFICATION_DISPLAY_DURATION": "알림 표시 시간", diff --git a/assets/locales/koKR/terrarum_sentences.json b/assets/locales/koKR/terrarum_sentences.json index ccde55552..66f2b19b4 100644 --- a/assets/locales/koKR/terrarum_sentences.json +++ b/assets/locales/koKR/terrarum_sentences.json @@ -8,11 +8,18 @@ "GAME_APPLE_ROSETTA_WARNING2": "최적의 성능과 게임 경험을 위해 Apple Silicon용 빌드의 게임을 이용해 주십시오.", "APP_NOMODULE_1": "현재 불러와진 모듈이 없습니다.", "APP_NOMODULE_2": "다음의 파일에서 불러오기 순서를 설정하고 게임을 재시작하십시오.", - "MENU_LABEL_KEYCONFIG_HELP1": "키캡을 클릭해 컨트롤을 배정하십시오", "GAME_PREV_SAVE_WAS_LOADED1": "가장 최근에 저장된 게임이 손상되었습니다.", "GAME_PREV_SAVE_WAS_LOADED2": "이전에 저장된 게임을 불러왔습니다.", "GAME_MORE_RECENT_AUTOSAVE1": "자동 저장된 게임이 수동으로 저장한 게임보다 더 최신입니다.", "GAME_MORE_RECENT_AUTOSAVE2": "불러올 게임을 선택해 주십시오.", + "MENU_IO_LOAD_UPDATING_BLOCK_MAPPINGS": "Updating Block Mappings...", + "MENU_IO_WORLDGEN_CARVING_EARTH": "Carving Earth...", + "MENU_IO_WORLDGEN_PAINTING_GREEN": "Painting Green...", + "MENU_IO_WORLDGEN_GROWING_MINERALS": "Growing Minerals...", + "MENU_IO_WORLDGEN_POSITIONING_ROCKS": "Positioning Rocks...", + "MENU_IO_WORLDGEN_RETICULATING_SPLINES": "Reticulating Splines...", + "MENU_LABEL_KEYCONFIG_HELP1": "키캡을 클릭해 컨트롤을 배정하십시오", "MENU_LABEL_SAVE_WILL_BE_DELETED": "선택된 세이브가 삭제됩니다.", - "MENU_LABEL_UNSAVED_PROGRESS_WILL_BE_LOST": "저장하지 않은 진행 상황을 잃게 됩니다." + "MENU_LABEL_UNSAVED_PROGRESS_WILL_BE_LOST": "저장하지 않은 진행 상황을 잃게 됩니다.", + "MENU_LABEL_WARN_ACE": "스크립트 모드는 게임을 손상시키거나 다른 예상치 못한 결과를 가져올 수 있습니다.\n신뢰할 수 있는 모드만을 사용하십시오." } diff --git a/assets/mods/basegame/configplan.csv b/assets/mods/basegame/configplan.csv index d6b19915e..0e0431317 100644 --- a/assets/mods/basegame/configplan.csv +++ b/assets/mods/basegame/configplan.csv @@ -1,2 +1,3 @@ +->Lang:MENU_OPTIONS_GAMEPLAY->h1 gameplay_max_crafting->Lang:MENU_OPTIONS_MAX_CRAFTING->spinner,100,1000,100 showpickaxetooltip->Lang:MENU_OPTIONS_SHOW_ORES_TOOLTIP_WHEN_MINING->toggle \ No newline at end of file diff --git a/assets/mods/basegame/metadata.properties b/assets/mods/basegame/metadata.properties index 357ed5af2..80c4be0f4 100644 --- a/assets/mods/basegame/metadata.properties +++ b/assets/mods/basegame/metadata.properties @@ -47,7 +47,7 @@ entrypoint=net.torvald.terrarum.modulebasegame.EntryPoint releasedate=2023-10-06 # The version, must follow Semver 2.0.0 scheme (https://semver.org/) -version=0.3.3 +version=0.4.0 # External JAR that the module is compiled. If your module requires yet another library, the JAR must be compiled as a "Fatjar"; # Due to security reasons, loading an arbitrary JAR is not allowed. diff --git a/src/net/torvald/terrarum/AudioManager.kt b/src/net/torvald/terrarum/AudioManager.kt index 6bd0208d7..16d55adba 100644 --- a/src/net/torvald/terrarum/AudioManager.kt +++ b/src/net/torvald/terrarum/AudioManager.kt @@ -5,7 +5,7 @@ package net.torvald.terrarum */ object AudioManager { - /** Returns a companded master volume */ + /** Returns a master volume */ val masterVolume: Float get() = App.getConfigDouble("mastervolume").toFloat() diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt index 379c1874c..258474938 100644 --- a/src/net/torvald/terrarum/DefaultConfig.kt +++ b/src/net/torvald/terrarum/DefaultConfig.kt @@ -130,6 +130,8 @@ object DefaultConfig { "lightpasses" to 3, + "enablescriptmods" to false, + // settings regarding debugger diff --git a/src/net/torvald/terrarum/ModMgr.kt b/src/net/torvald/terrarum/ModMgr.kt index d8af1953d..f2def82cc 100644 --- a/src/net/torvald/terrarum/ModMgr.kt +++ b/src/net/torvald/terrarum/ModMgr.kt @@ -140,6 +140,10 @@ object ModMgr { loadOrder.forEachIndexed { index, it -> + + val loadScriptMod = if (App.getConfigBoolean("enablescriptmods")) true else (index == 0) + + val moduleName = it[0] this.loadOrder.add(moduleName) printmsg(this, "Loading module $moduleName") @@ -250,6 +254,11 @@ object ModMgr { // run entry script in entry point if (entryPoint.isNotBlank()) { + if (!loadScriptMod) { + throw ScriptModDisallowedException() + } + + var newClass: Class<*>? = null try { // for modules that has JAR defined @@ -329,6 +338,14 @@ object ModMgr { moduleInfo.remove(moduleName) if (module != null) moduleInfoErrored[moduleName] = module } + catch (noScriptModule: ScriptModDisallowedException) { + printmsgerr(this, noScriptModule.message) + + logError(LoadErrorType.MY_FAULT, moduleName, noScriptModule) + + moduleInfo.remove(moduleName) + if (module != null) moduleInfoErrored[moduleName] = module + } catch (e: Throwable) { // TODO: Instead of skipping module with error, just display the error message onto the face? @@ -352,6 +369,8 @@ object ModMgr { private class ModuleDependencyNotSatisfied(want: String, have: String) : RuntimeException("Required: $want, Installed: $have") + private class ScriptModDisallowedException : RuntimeException("Script Mods disabled") + operator fun invoke() { } /*fun reloadModules() { diff --git a/src/net/torvald/terrarum/ModOptionsHost.kt b/src/net/torvald/terrarum/ModOptionsHost.kt index f3633d5c1..677b1b635 100644 --- a/src/net/torvald/terrarum/ModOptionsHost.kt +++ b/src/net/torvald/terrarum/ModOptionsHost.kt @@ -22,7 +22,7 @@ class ModOptionsHost(val remoCon: UIRemoCon) : UICanvas() { private val moduleAreaHMargin = 48 private val moduleAreaBorder = 8 - override var width = App.scr.width - UIRemoCon.remoConWidth - moduleAreaHMargin + override var width = 560 override var height = App.scr.height - moduleAreaHMargin * 2 private val drawX = (Toolkit.drawWidth - width) / 2 @@ -78,7 +78,10 @@ class ModOptionsHost(val remoCon: UIRemoCon) : UICanvas() { else { { options[1] } } - arrayOf("$modname:${options[0]}", labelfun, options[2]) + if (options[0].isBlank()) + arrayOf("", labelfun, options[2]) + else + arrayOf("$modname:${options[0]}", labelfun, options[2]) }.toTypedArray() ControlPanelCommon.register(this, width, "basegame.modcontrolpanel.$modname", modOptions) diff --git a/src/net/torvald/terrarum/console/Authenticator.kt b/src/net/torvald/terrarum/console/Authenticator.kt index 8308e1a4d..8e5595619 100644 --- a/src/net/torvald/terrarum/console/Authenticator.kt +++ b/src/net/torvald/terrarum/console/Authenticator.kt @@ -33,14 +33,14 @@ internal object Authenticator : ConsoleCommand { val pwd = args[1] val hashedPwd = DigestUtils.sha256Hex(pwd) - println("auth passwd: '$pwd'") - println("hash: $hashedPwd") +// println("auth passwd: '$pwd'") +// println("hash: $hashedPwd") - if ("2d962f949f55906ac47f16095ded190c9e44d95920259b8f36c2e54bd75df173".equals(hashedPwd, ignoreCase = true)) { + if ("c40232ae7b8020da3ab1449a015e7cc23f249a790856b63b1b69c6a5de019fed".equals(hashedPwd, ignoreCase = true)) { // beedle val msg = if (a) "Locked" else "Authenticated" Echo(msg) - println("[Authenticator] " + msg) + println("[Authenticator] $msg") a = !a INGAME.consoleHandler.reset() } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt b/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt index 08ef62dbe..62be789d2 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt @@ -36,7 +36,7 @@ object ControlPanelCommon { val optionName = optionNames.first() val arg = args.split(',') - return if (args.equals("h1") || args.equals("p")) { + return if (args == "h1" || args == "p" || args == "emph") { (object : UIItem(parent, x, y) { override val width = 1 override val height = 1 @@ -201,10 +201,13 @@ object ControlPanelCommon { else throw IllegalArgumentException(args) } + private fun String.countLines() = this.count { it == '\n' } + 1 + private val linegap = 14 private val panelgap = 20 - private val rowheight = 20 + linegap + private val textLineHeight = App.fontGame.lineHeight.toInt() + private val rowheightDiff = textLineHeight - panelgap private val h1MarginTop = 16 private val h1MarginBottom = 4 @@ -225,9 +228,11 @@ object ControlPanelCommon { optionsYpos[index] = akku + val realRowHeight = (row[1] as () -> String).invoke().countLines() * textLineHeight - rowheightDiff + akku += when (option) { - "h1" -> rowheight + h1MarginBottom - else -> rowheight + "h1" -> realRowHeight + linegap + h1MarginBottom + else -> realRowHeight + linegap } } optionsYpos[optionsYpos.lastIndex] = akku @@ -264,20 +269,23 @@ object ControlPanelCommon { val font = if (mode == "h1") App.fontUITitle else App.fontGame - val label = (args[1] as () -> String).invoke() - val labelWidth = font.getWidth(label) + val label = (args[1] as () -> String).invoke().lines() + val labelWidth = label.maxOf { font.getWidth(it) } batch.color = when (mode) { "h1" -> Toolkit.Theme.COL_MOUSE_UP "p" -> Color.LIGHT_GRAY + "emph" -> Toolkit.Theme.COL_RED else -> Color.WHITE } - val xpos = if (mode == "p" || mode == "h1") + val xpos = if (mode == "p" || mode == "h1" || mode == "emph") drawX + (width - labelWidth)/2 // centre-aligned else - drawX + width/2 - panelgap - labelWidth // right aligned at the middle of the panel, offsetted by panelgap + drawX + width/2 - panelgap - labelWidth // right aligned at the middle of the panel, offset by panelgap - font.draw(batch, label, xpos.toFloat(), drawY + optionsYpos[index] - 2f) + label.forEachIndexed { rows, s -> + font.draw(batch, s, xpos.toFloat(), drawY + optionsYpos[index] - 2f + textLineHeight * rows) + } // draw hrule if (mode == "h1") { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt index 99092cd04..de6830201 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt @@ -1,19 +1,9 @@ package net.torvald.terrarum.modulebasegame.ui -import com.badlogic.gdx.Gdx -import com.badlogic.gdx.Input -import com.badlogic.gdx.graphics.Camera -import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.terrarum.App -import net.torvald.terrarum.CommonResourcePool -import net.torvald.terrarum.ceilToInt import net.torvald.terrarum.langpack.Lang -import net.torvald.terrarum.modulebasegame.ui.ControlPanelCommon.makeButton import net.torvald.terrarum.ui.* -import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack -import net.torvald.unicode.TIMES /** * Created by minjaesong on 2023-06-22. @@ -32,6 +22,10 @@ class UIPerformanceControlPanel(remoCon: UIRemoCon?) : UICanvas() { arrayOf("", { Lang["MENU_LABEL_GRAPHICS"] }, "h1"), arrayOf("atlastexsize", { Lang["MENU_OPTIONS_ATLAS_TEXTURE_SIZE"] }, "spinnersel,1024,2048,4096,8192"), arrayOf("lightpasses", { Lang["MENU_OPTIONS_LIGHT_UPDATE_PASSES"] }, "spinner,2,4,1"), + arrayOf("", { Lang["MENU_MODULES"] }, "h1"), + arrayOf("enablescriptmods", { Lang["MENU_OPTIONS_ENABLE_SCRIPT_MODS"] }, "toggle"), + arrayOf("", { "(${Lang["MENU_LABEL_RESTART_REQUIRED"]})" }, "p"), + arrayOf("", { "${Lang["MENU_LABEL_WARN_ACE"]}" }, "emph"), arrayOf("", { Lang["MENU_LABEL_JVM_DNT"] }, "h1"), arrayOf("jvm_xmx", { Lang["MENU_OPTIONS_JVM_HEAP_MAX"] + " (GB)" }, "spinner,2,32,1"), arrayOf("jvm_extra_cmd", { Lang["MENU_LABEL_EXTRA_JVM_ARGUMENTS"] }, "typein"),