js cannot be accessed concurrently

This commit is contained in:
minjaesong
2021-11-09 14:38:47 +09:00
parent 16272e76f6
commit 3c43aeec9d
10 changed files with 236 additions and 174 deletions

View File

@@ -12,6 +12,7 @@ import net.torvald.terrarum.ccE
import net.torvald.terrarum.console.Authenticator
import net.torvald.terrarum.console.CommandInterpreter
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
import net.torvald.terrarum.langpack.Lang
import net.torvald.util.CircularArray
@@ -32,14 +33,16 @@ class ConsoleWindow : UICanvas() {
private var messageDisplayPos: Int = 0
private var messagesCount: Int = 0
private var commandInputPool: StringBuilder? = null
// private var commandInputPool: StringBuilder? = null
private var commandHistory = CircularArray<String>(COMMAND_HISTORY_MAX, true)
private val LINE_HEIGHT = 20
private val MESSAGES_DISPLAY_COUNT = 11
private val inputToMsgboxGap = 3
override var width: Int = App.scr.width
override var height: Int = LINE_HEIGHT * (MESSAGES_DISPLAY_COUNT + 1)
override var height: Int = LINE_HEIGHT * (MESSAGES_DISPLAY_COUNT + 1) + inputToMsgboxGap
override var openCloseTime = 0f
@@ -51,8 +54,12 @@ class ConsoleWindow : UICanvas() {
private var iMadeTheGameToPause = false
private val textinput = UIItemTextLineInput(this, 0, 0, this.width)
init {
reset()
addUIitem(textinput)
textinput.isActive = false
}
private val lb = ArrayList<String>()
@@ -73,6 +80,8 @@ class ConsoleWindow : UICanvas() {
it.setTooltipMessage(null)
}
}
uiItems.forEach { it.update(delta) }
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
@@ -81,65 +90,75 @@ class ConsoleWindow : UICanvas() {
Toolkit.fillArea(batch, drawOffX, drawOffY, width.toFloat(), height.toFloat())
Toolkit.fillArea(batch, drawOffX, drawOffY, width.toFloat(), LINE_HEIGHT.toFloat())
val input = commandInputPool!!.toString()
val inputDrawWidth = App.fontGame.getWidth(input)
val inputDrawHeight = App.fontGame.lineHeight
// text and cursor
batch.color = Color.WHITE
App.fontGame.draw(batch, input, 1f + drawOffX, drawOffY)
batch.color = Color(0x7f7f7f_ff)
Toolkit.fillArea(batch, inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 2f, inputDrawHeight)
batch.color = Color.WHITE
Toolkit.fillArea(batch, inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 1f, inputDrawHeight - 1)
// val input = commandInputPool!!.toString()
// val inputDrawWidth = App.fontGame.getWidth(input)
// val inputDrawHeight = App.fontGame.lineHeight
//
// text and cursor
// batch.color = Color.WHITE
// App.fontGame.draw(batch, input, 1f + drawOffX, drawOffY)
//
// batch.color = Color(0x7f7f7f_ff)
// Toolkit.fillArea(batch, inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 2f, inputDrawHeight)
// batch.color = Color.WHITE
// Toolkit.fillArea(batch, inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 1f, inputDrawHeight - 1)
// messages
batch.color = Color.WHITE
for (i in 0 until MESSAGES_DISPLAY_COUNT) {
val message = messages[messageDisplayPos + i] ?: ""
App.fontGame.draw(batch, message, 1f + drawOffX, (LINE_HEIGHT * (MESSAGES_DISPLAY_COUNT - i)).toFloat() + drawOffY)
App.fontGame.draw(batch, message, 1f + drawOffX, (LINE_HEIGHT * (MESSAGES_DISPLAY_COUNT - i)).toFloat() + drawOffY + inputToMsgboxGap)
}
uiItems.forEach { it.render(batch, camera) }
}
override fun inputStrobed(e: TerrarumKeyboardEvent) {
uiItems.forEach { it.inputStrobed(e) }
}
override fun keyDown(key: Int): Boolean {
// history
if (key == Input.Keys.UP && historyIndex < commandHistory.elemCount)
historyIndex++
else if (key == Input.Keys.DOWN && historyIndex >= 0)
historyIndex--
else if (key != Input.Keys.UP && key != Input.Keys.DOWN)
historyIndex = -1
try {
val textOnBuffer = textinput.getText()
// execute
if (key == Input.Keys.ENTER && commandInputPool!!.isNotEmpty()) {
commandHistory.appendHead(commandInputPool!!.toString())
executeCommand()
commandInputPool = StringBuilder()
// history
if (key == Input.Keys.UP && historyIndex < commandHistory.elemCount)
historyIndex++
else if (key == Input.Keys.DOWN && historyIndex >= 0)
historyIndex--
else if (key != Input.Keys.UP && key != Input.Keys.DOWN)
historyIndex = -1
// execute
if (key == Input.Keys.ENTER && textOnBuffer.isNotEmpty()) {
commandHistory.appendHead(textOnBuffer)
executeCommand(textOnBuffer)
textinput.clearText()
}
// scroll
else if (key == Input.Keys.UP || key == Input.Keys.DOWN) {
// create new stringbuilder
textinput.clearText()
if (historyIndex >= 0) // just leave blank if index is -1
textinput.setText(commandHistory[historyIndex] ?: "")
}
// delete input
// else if (key == Input.Keys.BACKSPACE) {
// commandInputPool = StringBuilder()
// }
// message scroll up
else if (key == Input.Keys.PAGE_UP) {
setDisplayPos(-MESSAGES_DISPLAY_COUNT + 1)
}
// message scroll down
else if (key == Input.Keys.PAGE_DOWN) {
setDisplayPos(MESSAGES_DISPLAY_COUNT - 1)
}
}
// erase last letter
else if (key == Input.Keys.BACKSPACE && commandInputPool!!.isNotEmpty()) {
commandInputPool!!.deleteCharAt(commandInputPool!!.length - 1)
}
// scroll
else if (key == Input.Keys.UP || key == Input.Keys.DOWN) {
// create new stringbuilder
commandInputPool = StringBuilder()
if (historyIndex >= 0) // just leave blank if index is -1
commandInputPool!!.append(commandHistory[historyIndex])
}
// delete input
else if (key == Input.Keys.BACKSPACE) {
commandInputPool = StringBuilder()
}
// message scroll up
else if (key == Input.Keys.PAGE_UP) {
setDisplayPos(-MESSAGES_DISPLAY_COUNT + 1)
}
// message scroll down
else if (key == Input.Keys.PAGE_DOWN) {
setDisplayPos(MESSAGES_DISPLAY_COUNT - 1)
catch (e: ConcurrentModificationException) {
System.err.println("[ConsoleWindow] ConcurrentModificationException")
}
@@ -148,7 +167,7 @@ class ConsoleWindow : UICanvas() {
val acceptedChars = "1234567890-=qwfpgjluy;[]\\arstdhneio'zxcvbkm,./!@#$%^&*()_+QWFPGJLUY:{}|ARSTDHNEIO\"ZXCVBKM<>? ".toSet()
override fun keyTyped(character: Char): Boolean {
/*override fun keyTyped(character: Char): Boolean {
if (character in acceptedChars) {
commandInputPool!!.append(character)
inputCursorPos += 1
@@ -158,14 +177,14 @@ class ConsoleWindow : UICanvas() {
else {
return false
}
}
}*/
override fun keyUp(keycode: Int): Boolean {
return false
}
private fun executeCommand() {
CommandInterpreter.execute(commandInputPool!!.toString())
private fun executeCommand(s: String) {
CommandInterpreter.execute(s)
}
fun sendMessage(msg: String) {
@@ -200,7 +219,7 @@ class ConsoleWindow : UICanvas() {
messagesCount = 0
inputCursorPos = 0
commandHistory = CircularArray<String>(COMMAND_HISTORY_MAX, true)
commandInputPool = StringBuilder()
textinput.clearText()
if (Authenticator.b()) {
sendMessage("$ccE${TerrarumAppConfiguration.GAME_NAME} ${App.getVERSION_STRING()} $EMDASH ${TerrarumAppConfiguration.COPYRIGHT_DATE_NAME}")
@@ -232,11 +251,13 @@ class ConsoleWindow : UICanvas() {
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
0f, -height.toFloat()
)*/
textinput.isActive = false
}
override fun endOpening(delta: Float) {
drawOffY = 0f
openingTimeCounter = 0f
textinput.isActive = true
}
override fun endClosing(delta: Float) {
@@ -252,5 +273,6 @@ class ConsoleWindow : UICanvas() {
}
override fun dispose() {
uiItems.forEach { it.dispose() }
}
}