console command loading from command list on the module directory

This commit is contained in:
minjaesong
2022-01-28 09:50:05 +09:00
parent a301ec57ae
commit e3b82ae5b6
4 changed files with 141 additions and 150 deletions

View File

@@ -41,22 +41,11 @@ object CommandDict {
val packageConsole = "$packageRoot.console" val packageConsole = "$packageRoot.console"
printdbg(this, "Loading console commands from '${packageConsole}'") printdbg(this, "Loading console commands from '${packageConsole}'")
// printdbg(this, commandsList.joinToString())
commandsList.forEach { commandName ->
// TODO load commands using commandsList val canonicalName = "$packageConsole.$commandName"
val it = Class.forName(canonicalName)
val stream = ClassLoader.getSystemClassLoader().getResourceAsStream(packageConsole.replace('.', '/'))
if (stream != null) { // not all modules have extra console commands
val reader = BufferedReader(InputStreamReader(stream))
reader.lines()
.filter { it.endsWith(".class") && !it.contains('$') }
.map { Class.forName("$packageConsole.${it.substring(0, it.lastIndexOf('.'))}") }
.forEach {
printdbg(this, "> Trying to instantiate ${it.canonicalName}") printdbg(this, "> Trying to instantiate ${it.canonicalName}")
@@ -88,8 +77,6 @@ object CommandDict {
} }
} }
}
} }

View File

@@ -64,7 +64,6 @@ internal object CommandInterpreter {
} }
} }
catch (e: NullPointerException) { catch (e: NullPointerException) {
e.printStackTrace()
echoUnknownCmd(single_command.name) echoUnknownCmd(single_command.name)
} }
} }

View File

@@ -55,7 +55,9 @@ class ConsoleWindow : UICanvas() {
private var iMadeTheGameToPause = false private var iMadeTheGameToPause = false
private val textinput = UIItemTextLineInput(this, 0, 0, this.width) private val textinput = UIItemTextLineInput(this, 0, 0, this.width, keyFilter = { e ->
!e.keycodes.contains(Input.Keys.GRAVE)
})
private var clickLatched = false private var clickLatched = false

View File

@@ -64,6 +64,7 @@ class UIItemTextLineInput(
val maxLen: InputLenCap = InputLenCap(1000, InputLenCap.CharLenUnit.CODEPOINTS), val maxLen: InputLenCap = InputLenCap(1000, InputLenCap.CharLenUnit.CODEPOINTS),
// val enablePasteButton: Boolean = true, // val enablePasteButton: Boolean = true,
// val enableIMEButton: Boolean = true // val enableIMEButton: Boolean = true
var keyFilter: (TerrarumKeyboardEvent) -> Boolean = { true }
) : UIItem(parentUI, initialX, initialY) { ) : UIItem(parentUI, initialX, initialY) {
init { init {
@@ -203,6 +204,7 @@ class UIItemTextLineInput(
val (eventType, char, headkey, repeatCount, keycodes) = e val (eventType, char, headkey, repeatCount, keycodes) = e
if (keyFilter(e)) {
try { try {
if (eventType == InputStrober.KEY_DOWN || eventType == InputStrober.KEY_CHANGE) { if (eventType == InputStrober.KEY_DOWN || eventType == InputStrober.KEY_CHANGE) {
fboUpdateLatch = true fboUpdateLatch = true
@@ -337,6 +339,7 @@ class UIItemTextLineInput(
currentPlaceholderText = CodepointSequence(placeholder().toCodePoints()) currentPlaceholderText = CodepointSequence(placeholder().toCodePoints())
} }
} }
}
else if (oldActive) { // just became deactivated else if (oldActive) { // just became deactivated
endComposing() endComposing()
} }