Skip to content

Commit 4b5af5d

Browse files
committed
ktlint
1 parent a3cd324 commit 4b5af5d

31 files changed

+69
-47
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[src/**/*.{kt,kts}]
2+
ktlint_code_style = intellij_idea
3+
max_line_length = 128
4+
ktlint_standard_no-wildcard-imports = disabled
5+
ktlint_standard_argument-list-wrapping = disabled
6+
ktlint_standard_multiline-if-else = disabled
7+
ktlint_standard_multiline-expression-wrapping = disabled
8+
ktlint_standard_argument-list-wrapping = disabled
9+
ktlint_standard_if-else-wrapping = disabled
10+
ktlint_standard_wrapping = disabled
11+
ktlint_standard_trailing-comma-on-call-site = disabled
12+
ktlint_standard_trailing-comma-on-declaration-site = disabled
13+
14+
[build/**]
15+
ktlint_standard = disabled

build.gradle.kts

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33
plugins {
44
kotlin("jvm") version "1.9.23"
55
application
6+
id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
67
}
78

89
group = "org.tfcc.bingo"
@@ -50,4 +51,8 @@ tasks.withType<Jar> {
5051
from({
5152
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
5253
})
53-
}
54+
}
55+
56+
ktlint {
57+
version.set("0.50.0")
58+
}

settings.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11

22
rootProject.name = "th-bingo"
3-

src/main/kotlin/BanPick.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ class BanPick(private val whoFirst: Int) {
128128
private val turn = arrayOf(listOf(1, 3, 5, 8, 9), listOf(2, 4, 6, 7, 10))
129129
private val games = listOf("6", "7", "8", "10", "11", "12", "13", "14", "15", "16", "17", "18")
130130
}
131-
}
131+
}

src/main/kotlin/Difficulty.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class Difficulty(val value: IntArray) {
1919
return Difficulty(intArrayOf(e, n, 20 - e - n))
2020
}
2121
}
22-
}
22+
}

src/main/kotlin/MainKt.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ open class MainKt {
99
Network.onInit()
1010
}
1111
}
12-
}
12+
}

src/main/kotlin/MiraiPusher.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ object MiraiPusher {
118118
throw RuntimeException(e)
119119
}
120120
}
121-
}
121+
}

src/main/kotlin/RoomType.kt

+1-8
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,5 @@ sealed interface RoomType {
2020
fun randSpells(games: Array<String>, ranks: Array<String>?, difficulty: Int): Array<Spell>
2121

2222
@Throws(HandlerException::class)
23-
fun handleUpdateSpell(
24-
room: Room,
25-
token: String,
26-
idx: Int,
27-
status: SpellStatus,
28-
now: Long,
29-
isReset: Boolean
30-
): SpellStatus
23+
fun handleUpdateSpell(room: Room, token: String, idx: Int, status: SpellStatus, now: Long, isReset: Boolean): SpellStatus
3124
}

src/main/kotlin/RoomTypeBP.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ object RoomTypeBP : RoomType {
144144
}
145145
}
146146
}
147-
}
147+
}

src/main/kotlin/RoomTypeLink.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ object RoomTypeLink : RoomType {
137137
val diff = abs(this - other)
138138
return diff == 1 || diff == 4 || diff == 5 || diff == 6
139139
}
140-
}
140+
}

src/main/kotlin/RoomTypeNormal.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ object RoomTypeNormal : RoomType {
3535
throw HandlerException("不支持的操作")
3636
if (room.pauseBeginMs != 0L && token != room.host)
3737
throw HandlerException("暂停中,不能操作")
38-
if (room.startMs <= now - room.gameTime.toLong() * 60000L - room.totalPauseMs && !room.isHost(token) && !room.scoreDraw())
38+
if (room.startMs <= now - room.gameTime.toLong() * 60000L - room.totalPauseMs &&
39+
!room.isHost(token) && !room.scoreDraw())
3940
throw HandlerException("游戏时间到")
4041
val isCountingDown = room.startMs > now - room.countDown.toLong() * 1000L
4142
if (isCountingDown) {
@@ -59,7 +60,8 @@ object RoomTypeNormal : RoomType {
5960

6061
LEFT_SELECT -> {
6162
val remainSelectTime =
62-
if (room.lastGetTime[0] == 0L) 0 else ((room.cdTime - 1) * 1000 - now + room.startMs + room.totalPauseMs + room.lastGetTime[0])
63+
if (room.lastGetTime[0] == 0L) 0
64+
else ((room.cdTime - 1) * 1000 - now + room.startMs + room.totalPauseMs + room.lastGetTime[0])
6365
if (remainSelectTime > 0)
6466
throw HandlerException("还有${remainSelectTime / 1000 + 1}秒才能选卡")
6567
if (st == RIGHT_SELECT) {
@@ -89,7 +91,8 @@ object RoomTypeNormal : RoomType {
8991

9092
RIGHT_SELECT -> {
9193
val remainSelectTime =
92-
if (room.lastGetTime[1] == 0L) 0 else ((room.cdTime - 1) * 1000 - now + room.startMs + room.totalPauseMs + room.lastGetTime[1])
94+
if (room.lastGetTime[1] == 0L) 0
95+
else ((room.cdTime - 1) * 1000 - now + room.startMs + room.totalPauseMs + room.lastGetTime[1])
9396
if (remainSelectTime > 0)
9497
throw HandlerException("还有${remainSelectTime / 1000 + 1}秒才能选卡")
9598
if (st == LEFT_SELECT) {
@@ -133,4 +136,4 @@ object RoomTypeNormal : RoomType {
133136
}
134137
return left == 0
135138
}
136-
}
139+
}

src/main/kotlin/SpellConfig.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,4 @@ object SpellConfig {
194194
}
195195

196196
private val isWindows = System.getProperty("os.name").lowercase().contains("windows")
197-
}
197+
}

src/main/kotlin/SpellFactory.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ object SpellFactory {
8585
idx[i] = i * 5 + j
8686
return idx
8787
}
88-
}
88+
}

src/main/kotlin/SpellLog.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ object SpellLog {
177177
}
178178

179179
enum class LogType {
180-
APPEAR, SELECT, GET
180+
APPEAR,
181+
SELECT,
182+
GET
181183
}
182184

183185
annotation class GameType {
@@ -227,4 +229,4 @@ object SpellLog {
227229
return this
228230
}
229231
}
230-
}
232+
}

src/main/kotlin/SpellStatus.kt

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ fun Int.toSpellStatus(): SpellStatus {
1818
}
1919

2020
enum class SpellStatus(val value: Int) {
21-
NONE(0), BANNED(-1),
22-
LEFT_SELECT(1), BOTH_SELECT(2), RIGHT_SELECT(3),
23-
LEFT_GET(5), BOTH_GET(6), RIGHT_GET(7);
21+
NONE(0),
22+
BANNED(-1),
23+
LEFT_SELECT(1),
24+
BOTH_SELECT(2),
25+
RIGHT_SELECT(3),
26+
LEFT_GET(5),
27+
BOTH_GET(6),
28+
RIGHT_GET(7);
2429

2530
fun isSelectStatus(): Boolean {
2631
return this == LEFT_SELECT || this == RIGHT_SELECT || this == BOTH_SELECT
@@ -37,4 +42,4 @@ enum class SpellStatus(val value: Int) {
3742
fun isRightStatus(): Boolean {
3843
return this == RIGHT_SELECT || this == RIGHT_GET || this == BOTH_SELECT || this == BOTH_GET
3944
}
40-
}
45+
}

src/main/kotlin/Store.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ object Store {
4343
for (f in players) {
4444
val name = f.name
4545
val player = getPlayer(name.substring("player-".length, name.length - ".0".length)) ?: continue
46-
if (now >= player.lastOperateMs + 6 * 60 * 60 * 1000 && (player.roomId == null || getRoom(player.roomId) == null)) {
46+
if (now >= player.lastOperateMs + 6 * 60 * 60 * 1000 &&
47+
(player.roomId == null || getRoom(player.roomId) == null)) {
4748
logger.info("玩家 ${player.token} 过期, 自动清除")
4849
removePlayer(player.token)
4950
}
@@ -209,4 +210,4 @@ object Store {
209210
roomConfig = RoomConfig.fromRoom(room),
210211
)
211212
}
212-
}
213+
}

src/main/kotlin/Supervisor.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ object Supervisor {
2929
fun getChannel(playerToken: String): Channel? {
3030
return playerTokenToChannel[playerToken]
3131
}
32-
}
32+
}

src/main/kotlin/message/BanPickInfoSc.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ class BanPickInfoSc(
99
val bBan: Array<String>,
1010
val aOpenEx: Int,
1111
val bOpenEx: Int,
12-
)
12+
)

src/main/kotlin/message/Dispatcher.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,4 @@ object Dispatcher {
133133
}
134134
return sb.toString()
135135
}
136-
}
136+
}

src/main/kotlin/message/ErrorSc.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package org.tfcc.bingo.message
22

3-
class ErrorSc(val code: Int, val msg: String?)
3+
class ErrorSc(val code: Int, val msg: String?)

src/main/kotlin/message/GetSpellsCs.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ class GetSpellsCs : Handler {
3333
)
3434
)
3535
}
36-
}
36+
}

src/main/kotlin/message/Handler.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ open class HandlerException(msg: String) : Exception(msg)
77
interface Handler {
88
@Throws(HandlerException::class)
99
fun handle(ctx: ChannelHandlerContext, token: String, protoName: String)
10-
}
10+
}

src/main/kotlin/message/LoginCs.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ class LoginCs(val token: String?) : Handler {
3030
}
3131
}
3232
}
33-
}
33+
}

src/main/kotlin/message/Message.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ data class Message(
55
val reply: String? = null,
66
val trigger: String? = null,
77
val data: Any? = null
8-
)
8+
)

src/main/kotlin/message/NextRoundCs.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ class NextRoundCs : Handler {
1818
Message(data = NextRoundSc(room.bpData?.whoseTurn ?: 0, room.bpData?.banPick ?: 0))
1919
)
2020
}
21-
}
21+
}

src/main/kotlin/message/ResetRoomCs.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ class ResetRoomCs : Handler {
3838
Store.putRoom(room)
3939
Store.notifyPlayerInfo(token, protoName)
4040
}
41-
}
41+
}

src/main/kotlin/message/RoomConfig.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ class RoomConfig(
5959
reservedType = room.reservedType,
6060
)
6161
}
62-
}
62+
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package org.tfcc.bingo.message
22

3-
class WarnPlayerSc(val fromName: String, val toName: String)
3+
class WarnPlayerSc(val fromName: String, val toName: String)

src/main/kotlin/network/Network.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ object Network {
3434
workGroup.shutdownGracefully()
3535
}
3636
}
37-
}
37+
}

src/main/kotlin/network/WebSocketServerChannelHandler.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import org.tfcc.bingo.message.HandlerException
1313
import org.tfcc.bingo.message.LeaveRoomCs
1414
import java.net.SocketException
1515

16-
1716
class WebSocketServerChannelHandler : SimpleChannelInboundHandler<WebSocketFrame>() {
1817
@Throws(Exception::class)
1918
override fun channelRead0(ctx: ChannelHandlerContext, msg: WebSocketFrame) {
@@ -22,13 +21,13 @@ class WebSocketServerChannelHandler : SimpleChannelInboundHandler<WebSocketFrame
2221

2322
@Throws(Exception::class)
2423
override fun channelActive(ctx: ChannelHandlerContext) {
25-
//添加连接
24+
// 添加连接
2625
logger.debug("客户端加入连接:${ctx.channel()}")
2726
}
2827

2928
@Throws(Exception::class)
3029
override fun channelInactive(ctx: ChannelHandlerContext) {
31-
//断开连接
30+
// 断开连接
3231
logger.debug("客户端断开连接:${ctx.channel()}")
3332
val token = Supervisor.removeChannel(ctx.channel()) ?: return
3433
Dispatcher.pool.submit {

src/main/kotlin/network/WebSocketServerInitializer.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ class WebSocketServerInitializer : ChannelInitializer<SocketChannel>() {
1717
pipeline.addLast("ws-handler", WebSocketServerProtocolHandler("/ws"))
1818
pipeline.addLast("webSocketServerHandler", WebSocketServerChannelHandler())
1919
}
20-
}
20+
}

0 commit comments

Comments
 (0)