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
@@ -220,7 +222,7 @@ class UIItemTextLineInput(
} }
else if (keycodes.contains(Input.Keys.BACKSPACE) || (keycodes.contains(Input.Keys.CAPS_LOCK) && lowLayer.capsMode == TerrarumKeyCapsMode.BACK)) { else if (keycodes.contains(Input.Keys.BACKSPACE) || (keycodes.contains(Input.Keys.CAPS_LOCK) && lowLayer.capsMode == TerrarumKeyCapsMode.BACK)) {
// printdbg(this, "BACKSPACE hit; ime.composing=${ime?.composing?.invoke()}; buflen=${textbuf.size}") // printdbg(this, "BACKSPACE hit; ime.composing=${ime?.composing?.invoke()}; buflen=${textbuf.size}")
if (ime != null && ime.composing()) { if (ime != null && ime.composing()) {
if (ime.config.mode == TerrarumIMEMode.CANDIDATES) { if (ime.config.mode == TerrarumIMEMode.CANDIDATES) {
@@ -279,7 +281,7 @@ class UIItemTextLineInput(
else if (keycodes.containsSome(Input.Keys.ENTER, Input.Keys.NUMPAD_ENTER)) { else if (keycodes.containsSome(Input.Keys.ENTER, Input.Keys.NUMPAD_ENTER)) {
endComposing() endComposing()
// println("END COMPOSING!!") // println("END COMPOSING!!")
} }
// accept: // accept:
// - literal "<" // - literal "<"
@@ -299,11 +301,11 @@ class UIItemTextLineInput(
candidates = listOf() candidates = listOf()
val op = ime.acceptChar(headkey, shiftin, altgrin, char) val op = ime.acceptChar(headkey, shiftin, altgrin, char)
// printdbg(this, "delcount: ${op.first[0].toInt()}, rewrite: '${op.second}'") // printdbg(this, "delcount: ${op.first[0].toInt()}, rewrite: '${op.second}'")
repeat(op.first[0].toInt()) { repeat(op.first[0].toInt()) {
if (textbuf.isNotEmpty()) { if (textbuf.isNotEmpty()) {
// printdbg(this, "<del 1>") // printdbg(this, "<del 1>")
inputBackspaceOnce(3) inputBackspaceOnce(3)
} }
} }
@@ -314,7 +316,7 @@ class UIItemTextLineInput(
} }
else char.toCodePoints() else char.toCodePoints()
// printdbg(this, "textinput codepoints: ${codepoints.map { it.toString(16) }.joinToString()}") // printdbg(this, "textinput codepoints: ${codepoints.map { it.toString(16) }.joinToString()}")
if (!maxLen.exceeds(textbuf, codepoints)) { if (!maxLen.exceeds(textbuf, codepoints)) {
textbuf.addAll(cursorX, codepoints) textbuf.addAll(cursorX, codepoints)
@@ -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()
} }