Skip to content

Commit

Permalink
Codechange: Do not store tilelog strings
Browse files Browse the repository at this point in the history
KIV for interactor
  • Loading branch information
zxtej committed Dec 30, 2024
1 parent da1f3bd commit 5b173b6
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions core/src/mindustry/client/antigrief/TileLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ private fun String.shorten() = take(MAX_NAME_LENGTH).let {
}

abstract class AbstractTileLog(tile: Tile, cause: Interactor, val block: Block) : TileLog(tile, cause) {
protected val eventPlayer: String = cause.shortName.stripColors().shorten()
protected val eventTarget: String = if (Core.settings.getBool("useiconslogs")) Fonts.getUnicodeStr(block.name) else block.localizedName
protected fun eventPlayer(): String = cause.shortName.stripColors().shorten()
protected fun eventTarget(): String = if (Core.settings.getBool("useiconslogs")) Fonts.getUnicodeStr(block.name) else block.localizedName
}

open class ConfigureTileLog(tile: Tile, cause: Interactor, block: Block, val rotation: Int, var configuration: Any?) : AbstractTileLog(tile, cause, block) {
Expand All @@ -196,23 +196,23 @@ open class ConfigureTileLog(tile: Tile, cause: Interactor, block: Block, val rot
previous.configuration = configuration
}

override fun toString() = "$eventPlayer ${Core.bundle.get("client.configured")} $eventTarget"
override fun toString() = "${eventPlayer()} ${Core.bundle.get("client.configured")} ${eventTarget()}"
override fun add(sequence: TileLogSequence) {
Core.app.post {
configuration = Vars.world.tile(position.x, position.y)?.build?.config()
super.add(sequence)
}
}

private val eventName: String = Core.bundle.get("client.configured").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }
private fun eventName(): String = Core.bundle.get("client.configured").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
override fun toShortString() = "${eventPlayer()} ${eventName()} ${eventTarget()}"
}

class NodeLinkAddedTileLog(tile: Tile, cause: Interactor, block: Block, rotation: Int, configuration: Any?) : ConfigureTileLog(tile, cause, block, rotation, configuration) {
override fun toString() = "$eventTarget ${Core.bundle.get("client.configurednodelink")}"
private val eventName: String = Core.bundle.get("client.configurednodelink").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }
override fun toShortString() = "$eventTarget $eventName"
override fun toString() = "${eventTarget()} ${Core.bundle.get("client.configurednodelink")}"
private fun eventName(): String = Core.bundle.get("client.configurednodelink").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }
override fun toShortString() = "${eventTarget()} ${eventName()}"
}

open class TilePlacedLog(tile: Tile, cause: Interactor, block: Block, var rotation: Int = tile.build?.rotation ?: 0, var configuration: Any?, val isRootTile: Boolean) : AbstractTileLog(tile, cause, block) {
Expand All @@ -232,19 +232,19 @@ open class TilePlacedLog(tile: Tile, cause: Interactor, block: Block, var rotati
return "${cause.name.stripColors()} ${Core.bundle.get("client.built")} ${block.localizedName}"
}

private val eventName: String = Core.bundle.get("client.built").let { if(Core.settings.getBool("colorizelogs")) "[green]$it[]" else it }
private fun eventName(): String = Core.bundle.get("client.built").let { if(Core.settings.getBool("colorizelogs")) "[green]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
override fun toShortString() = "${eventPlayer()} ${eventName()} ${eventTarget()}"
}

class BlockPayloadDropLog(tile: Tile, cause: Interactor, block: Block, rotation: Int, configuration: Any?, origin: Boolean) : TilePlacedLog(tile, cause, block, rotation, configuration, origin) {
override fun toString(): String {
return "${cause.name.stripColors()} ${Core.bundle.get("client.putdown")} ${block.localizedName}"
}

private val eventName: String = Core.bundle.get("client.putdown").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }
private fun eventName(): String = Core.bundle.get("client.putdown").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
override fun toShortString() = "${eventPlayer()} ${eventName()} ${eventTarget()}"
}

open class TileBreakLog(tile: Tile, cause: Interactor, block: Block) : AbstractTileLog(tile, cause, block) {
Expand All @@ -259,28 +259,28 @@ open class TileBreakLog(tile: Tile, cause: Interactor, block: Block) : AbstractT
return "${cause.name.stripColors()} ${Core.bundle.get("client.broke")} ${block.localizedName}"
}

private val eventName: String = Core.bundle.get("client.broke").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }
private fun eventName(): String = Core.bundle.get("client.broke").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
override fun toShortString() = "${eventPlayer()} ${eventName()} ${eventTarget()}"
}

class BlockPayloadPickupLog(tile: Tile, cause: Interactor, block: Block) : TileBreakLog(tile, cause, block) {
override fun toString(): String {
return "${cause.name.stripColors()} ${Core.bundle.get("client.pickedup")} ${block.localizedName}"
}

private val eventName: String = Core.bundle.get("client.pickedup").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }
private fun eventName(): String = Core.bundle.get("client.pickedup").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
override fun toShortString() = "${eventPlayer()} ${eventName()} ${eventTarget()}"
}
class TileDestroyedLog(tile: Tile, block: Block) : TileBreakLog(tile, NoInteractor(), block) {
override fun toString(): String {
return "${block.localizedName} ${Core.bundle.get("client.destroyed")}"
}

private val eventName: String = Core.bundle.get("client.destroyed").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }
private fun eventName(): String = Core.bundle.get("client.destroyed").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }

override fun toShortString() = "$eventTarget $eventName"
override fun toShortString() = "${eventTarget()} ${eventName()}"
}

class UnitDestroyedLog(val tile: Tile, cause: Interactor, unit: Unit, val isPlayer: Boolean) : TileLog(tile, cause) {
Expand All @@ -293,13 +293,13 @@ class UnitDestroyedLog(val tile: Tile, cause: Interactor, unit: Unit, val isPlay
return if(isPlayer) "${cause.name.stripColors()} ${Core.bundle.get("client.playerunitdeath")} ${unitType?.localizedName ?: "null unit"}" else "${cause.name.stripColors()} ${Core.bundle.get("client.unitdeath")}"
}

private val eventController: String = "${cause.shortName.stripColors().take(16)}${if (cause.shortName.stripColors().length > 16) "..." else ""}"
private val eventNamePlayer: String = Core.bundle.get("client.playerunitdeath").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }
private val eventNameLogic: String = Core.bundle.get("client.unitdeath").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }
private val eventUnit: String = if(Core.settings.getBool("useiconslogs") && unitType.name.isNotEmpty()) Fonts.getUnicodeStr(unitType.name) else unitType?.localizedName ?: "null unit"
private fun eventController(): String = "${cause.shortName.stripColors().take(16)}${if (cause.shortName.stripColors().length > 16) "..." else ""}"
private fun eventNamePlayer(): String = Core.bundle.get("client.playerunitdeath").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }
private fun eventNameLogic(): String = Core.bundle.get("client.unitdeath").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }
private fun eventUnit(): String = if(Core.settings.getBool("useiconslogs") && unitType.name.isNotEmpty()) Fonts.getUnicodeStr(unitType.name) else unitType?.localizedName ?: "null unit"

override fun toShortString(): String {
return if(isPlayer) "$eventController $eventNamePlayer $eventUnit" else "$eventController $eventNameLogic"
return if(isPlayer) "${eventController()} ${eventNamePlayer()} ${eventUnit()}" else "${eventController()} ${eventNameLogic()}"
}
}

Expand All @@ -312,7 +312,7 @@ class RotateTileLog(tile: Tile, cause: Interactor, block: Block, val rotation: I
return "${cause.name.stripColors()} ${Core.bundle.get("client.rotated")} ${block.localizedName} ${Core.bundle.get(if (direction) "client.counterclockwise" else "client.clockwise")}"
}

private val eventName: String = Core.bundle.get("client.rotated").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }
private fun eventName(): String = Core.bundle.get("client.rotated").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
override fun toShortString() = "${eventPlayer()} ${eventName()} ${eventTarget()}"
}

0 comments on commit 5b173b6

Please sign in to comment.