mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-19 06:54:05 +09:00
console command loading from command list on the module directory
This commit is contained in:
@@ -41,22 +41,11 @@ object CommandDict {
|
||||
val packageConsole = "$packageRoot.console"
|
||||
|
||||
printdbg(this, "Loading console commands from '${packageConsole}'")
|
||||
// printdbg(this, commandsList.joinToString())
|
||||
|
||||
|
||||
// TODO load commands using commandsList
|
||||
|
||||
|
||||
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 {
|
||||
commandsList.forEach { commandName ->
|
||||
val canonicalName = "$packageConsole.$commandName"
|
||||
val it = Class.forName(canonicalName)
|
||||
|
||||
printdbg(this, "> Trying to instantiate ${it.canonicalName}")
|
||||
|
||||
@@ -88,8 +77,6 @@ object CommandDict {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -64,7 +64,6 @@ internal object CommandInterpreter {
|
||||
}
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
e.printStackTrace()
|
||||
echoUnknownCmd(single_command.name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,9 @@ class ConsoleWindow : UICanvas() {
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ class UIItemTextLineInput(
|
||||
val maxLen: InputLenCap = InputLenCap(1000, InputLenCap.CharLenUnit.CODEPOINTS),
|
||||
// val enablePasteButton: Boolean = true,
|
||||
// val enableIMEButton: Boolean = true
|
||||
var keyFilter: (TerrarumKeyboardEvent) -> Boolean = { true }
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
init {
|
||||
@@ -203,6 +204,7 @@ class UIItemTextLineInput(
|
||||
|
||||
val (eventType, char, headkey, repeatCount, keycodes) = e
|
||||
|
||||
if (keyFilter(e)) {
|
||||
try {
|
||||
if (eventType == InputStrober.KEY_DOWN || eventType == InputStrober.KEY_CHANGE) {
|
||||
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)) {
|
||||
|
||||
// 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.config.mode == TerrarumIMEMode.CANDIDATES) {
|
||||
@@ -279,7 +281,7 @@ class UIItemTextLineInput(
|
||||
else if (keycodes.containsSome(Input.Keys.ENTER, Input.Keys.NUMPAD_ENTER)) {
|
||||
endComposing()
|
||||
|
||||
// println("END COMPOSING!!")
|
||||
// println("END COMPOSING!!")
|
||||
}
|
||||
// accept:
|
||||
// - literal "<"
|
||||
@@ -299,11 +301,11 @@ class UIItemTextLineInput(
|
||||
candidates = listOf()
|
||||
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()) {
|
||||
if (textbuf.isNotEmpty()) {
|
||||
// printdbg(this, "<del 1>")
|
||||
// printdbg(this, "<del 1>")
|
||||
inputBackspaceOnce(3)
|
||||
}
|
||||
}
|
||||
@@ -314,7 +316,7 @@ class UIItemTextLineInput(
|
||||
}
|
||||
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)) {
|
||||
textbuf.addAll(cursorX, codepoints)
|
||||
@@ -337,6 +339,7 @@ class UIItemTextLineInput(
|
||||
currentPlaceholderText = CodepointSequence(placeholder().toCodePoints())
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (oldActive) { // just became deactivated
|
||||
endComposing()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user