mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 20:44:05 +09:00
replacing min/max usage with kotlin's
This commit is contained in:
@@ -20,6 +20,7 @@ import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.max
|
||||
import kotlin.math.sign
|
||||
|
||||
/**
|
||||
@@ -117,7 +118,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
||||
val windowWidth = Toolkit.drawWidth
|
||||
val player = ingame?.actorNowPlaying
|
||||
val hitbox = player?.hitbox
|
||||
val updateCount = maxOf(1L, (App.debugTimers["Ingame.UpdateCounter"] ?: 1L) as Long)
|
||||
val updateCount = max(1L, (App.debugTimers["Ingame.UpdateCounter"] ?: 1L))
|
||||
|
||||
/**
|
||||
* Top Left
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
@@ -346,7 +347,7 @@ abstract class UICanvas(
|
||||
const val OPENCLOSE_GENERIC = 0.0666f
|
||||
|
||||
fun doOpeningFade(ui: UICanvas, openCloseTime: Second) {
|
||||
ui.handler.opacity = maxOf(0f, ui.handler.openCloseCounter - 0.02f) / openCloseTime // fade start 1/50 sec late, it's intended
|
||||
ui.handler.opacity = max(0f, ui.handler.openCloseCounter - 0.02f) / openCloseTime // fade start 1/50 sec late, it's intended
|
||||
}
|
||||
fun doClosingFade(ui: UICanvas, openCloseTime: Second) {
|
||||
ui.handler.opacity = (openCloseTime - ui.handler.openCloseCounter) / openCloseTime
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.ceilInt
|
||||
import net.torvald.terrarum.ceilToInt
|
||||
|
||||
/**
|
||||
* Internal properties, namely initialValue, min, max, step; have the type of [Double] regardless of their input type.
|
||||
@@ -44,7 +44,7 @@ class UIItemSpinner(
|
||||
var selectionChangeListener: (Number) -> Unit = {}
|
||||
|
||||
// to alleviate floating point errors adding up as the spinner is being used
|
||||
private val values = DoubleArray(1 + ((max.toDouble() - min.toDouble()).div(step.toDouble())).ceilInt()) {
|
||||
private val values = DoubleArray(1 + ((max.toDouble() - min.toDouble()).div(step.toDouble())).ceilToInt()) {
|
||||
// printdbg(this, "$min..$max step $step; index [$it] = ${min.toDouble() + (step.toDouble() * it)}")
|
||||
min.toDouble() + (step.toDouble() * it)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ package net.torvald.terrarum.ui
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.floor
|
||||
import net.torvald.terrarum.roundToFloat
|
||||
import net.torvald.terrarum.ui.UIItemTextButton.Companion.Alignment
|
||||
import kotlin.math.min
|
||||
|
||||
class UIItemTextArea(
|
||||
parentUI: UICanvas,
|
||||
@@ -33,14 +34,14 @@ class UIItemTextArea(
|
||||
}
|
||||
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
for (i in scrollPos until minOf(lineCount + scrollPos, entireText.size)) {
|
||||
for (i in scrollPos until min(lineCount + scrollPos, entireText.size)) {
|
||||
val yPtr = i - scrollPos
|
||||
|
||||
val textWidth = App.fontGame.getWidth(entireText[i])
|
||||
|
||||
when (align) {
|
||||
Alignment.LEFT -> App.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (App.fontGame.lineHeight + lineGap))
|
||||
Alignment.CENTRE -> App.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).floor(), posY + yPtr * (App.fontGame.lineHeight + lineGap))
|
||||
Alignment.CENTRE -> App.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).roundToFloat(), posY + yPtr * (App.fontGame.lineHeight + lineGap))
|
||||
Alignment.RIGHT -> App.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (App.fontGame.lineHeight + lineGap))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.torvald.terrarum.gamecontroller.*
|
||||
import net.torvald.terrarum.utils.Clipboard
|
||||
import net.torvald.terrarumsansbitmap.gdx.CodepointSequence
|
||||
import net.torvald.unicode.toJavaString
|
||||
import kotlin.math.min
|
||||
import kotlin.streams.toList
|
||||
|
||||
data class InputLenCap(val count: Int, val unit: CharLenUnit) {
|
||||
@@ -194,7 +195,7 @@ class UIItemTextLineInput(
|
||||
private fun moveCursorBack(delta: Int) {
|
||||
cursorDrawX -= delta
|
||||
if (cursorDrawX < 0) {
|
||||
val stride = -cursorDrawX + minOf(256, fbo.width * 40 / 100) // + lookbehind term
|
||||
val stride = -cursorDrawX + min(256, fbo.width * 40 / 100) // + lookbehind term
|
||||
cursorDrawX += stride
|
||||
cursorDrawScroll -= stride
|
||||
}
|
||||
@@ -610,7 +611,7 @@ class UIItemTextLineInput(
|
||||
|
||||
val textWidths = localCandidates.map { App.fontGame.getWidth(CodepointSequence(it)) }
|
||||
val candidatesMax = ime.config.candidates.toInt()
|
||||
val candidatesCount = minOf(candidatesMax, localCandidates.size)
|
||||
val candidatesCount = min(candidatesMax, localCandidates.size)
|
||||
val isOnecolumn = (candidatesCount <= 3)
|
||||
val halfcount = if (isOnecolumn) candidatesCount else FastMath.ceil(candidatesCount / 2f)
|
||||
val candidateWinH = halfcount * 20 // using hard-coded 20 instead of the actual font height of 24
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import kotlin.math.max
|
||||
|
||||
/**
|
||||
* Nextstep-themed menu bar with mandatory title line
|
||||
@@ -38,7 +39,7 @@ class UINSMenu(
|
||||
val tree = treeRepresentation.parseAsYamlInvokable()
|
||||
override var width = 0
|
||||
override var height = 0
|
||||
//override var width = maxOf(minimumWidth, tree.getLevelData(1).map { AppLoader.fontGame.getWidth(it ?: "") }.max() ?: 0)
|
||||
//override var width = max(minimumWidth, tree.getLevelData(1).map { AppLoader.fontGame.getWidth(it ?: "") }.max() ?: 0)
|
||||
//override var height = LINE_HEIGHT * (tree.children.size + 1)
|
||||
|
||||
|
||||
@@ -90,8 +91,8 @@ class UINSMenu(
|
||||
tree.children[it].data?.first + if (tree.children[it].children.isNotEmpty()) " $CHILD_ARROW" else ""
|
||||
}
|
||||
|
||||
val listWidth = maxOf(
|
||||
App.fontGame.getWidth(menuTitle), minimumWidth,
|
||||
val listWidth = max(
|
||||
max(App.fontGame.getWidth(menuTitle), minimumWidth),
|
||||
stringsFromTree.map { App.fontGame.getWidth(it) }.maxOrNull() ?: 0
|
||||
)
|
||||
val uiWidth = listWidth + (2 * TEXT_OFFSETX.toInt())
|
||||
|
||||
Reference in New Issue
Block a user