summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorSho Sakuma <me@m1sk9.dev>2026-08-02 19:45:33 +0900
committerSho Sakuma <me@m1sk9.dev>2026-08-02 19:45:33 +0900
commit7bcaaf9a305c2a8608a420c8f05521bd2de089dd (patch)
tree8e7332ea740900284752a5f754c9d8286e073f67 /engine
parentbc8010bc1b5401f11c80b565ba9a4de7d969a0a9 (diff)
downloadLunaticChat-7bcaaf9a305c2a8608a420c8f05521bd2de089dd.tar.gz
LunaticChat-7bcaaf9a305c2a8608a420c8f05521bd2de089dd.tar.bz2
LunaticChat-7bcaaf9a305c2a8608a420c8f05521bd2de089dd.zip
refactor: fold the remaining small duplications
- MessageFormatter built the same prefix component in three functions. - LanguageManager copied kaml's YamlNode into a private YamlValue tree before flattening it, so the map case was written twice and the list-of-maps case rendered a Kotlin data class toString into a player facing string. It now folds YamlNode directly. - StatusCommand inlined `if (enabled) "toggle.on" else "toggle.off"`, which is the body of LanguageManager.getToggleText. - The three chat formats each spelled out their own chain of String.replace, with the valid placeholder names documented only in a config.yml comment. - ChannelContext carried a channelId that both construction sites filled with channel.id; it is now derived, so the two cannot disagree. - ChannelInfo and ChannelStatus each declared MAX_MEMBERS_DISPLAY = 10 and built the same truncated member line, differing only in indent. A divergence between the two constants would have been invisible. Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'engine')
-rw-r--r--engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelContext.kt9
-rw-r--r--engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelDataClassesTest.kt6
2 files changed, 10 insertions, 5 deletions
diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelContext.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelContext.kt
index 02dc1d3..54b98e0 100644
--- a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelContext.kt
+++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelContext.kt
@@ -1,7 +1,12 @@
package dev.m1sk9.lunaticChat.engine.chat.channel
+/**
+ * A player's active channel together with its member list.
+ */
data class ChannelContext(
- val channelId: String,
val channel: Channel,
val members: List<ChannelMember>,
-)
+) {
+ /** Shorthand for the channel's id, which callers ask for far more often than the channel. */
+ val channelId: String get() = channel.id
+}
diff --git a/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelDataClassesTest.kt b/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelDataClassesTest.kt
index 4684432..de514b1 100644
--- a/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelDataClassesTest.kt
+++ b/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelDataClassesTest.kt
@@ -114,7 +114,7 @@ class ChannelDataClassesTest {
fun `ChannelContext should store all fields`() {
val channel = Channel(id = "ch-1", name = "Test", ownerId = testOwnerId)
val member = ChannelMember(channelId = "ch-1", playerId = testPlayerId, role = ChannelRole.MEMBER)
- val context = ChannelContext(channelId = "ch-1", channel = channel, members = listOf(member))
+ val context = ChannelContext(channel = channel, members = listOf(member))
assertEquals("ch-1", context.channelId)
assertEquals(channel, context.channel)
@@ -125,8 +125,8 @@ class ChannelDataClassesTest {
@Test
fun `ChannelContext copy should create independent instance`() {
val channel = Channel(id = "ch-1", name = "Test", ownerId = testOwnerId)
- val original = ChannelContext(channelId = "ch-1", channel = channel, members = emptyList())
- val copied = original.copy(channelId = "ch-2")
+ val original = ChannelContext(channel = channel, members = emptyList())
+ val copied = original.copy(channel = channel.copy(id = "ch-2"))
assertEquals("ch-2", copied.channelId)
assertNotEquals(original.channelId, copied.channelId)