Skip to content

Commit 3366a24

Browse files
committed
👽️ (mapScript/*) 适配新版本
1 parent 0da9177 commit 3366a24

7 files changed

Lines changed: 66 additions & 41 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package coreMindustry.util
2+
3+
import cf.wayzer.scriptAgent.Event
4+
import cf.wayzer.scriptAgent.thisContextScript
5+
import coreLibrary.lib.util.ReceivedEvent
6+
import coreLibrary.lib.util.nextEvent
7+
import kotlinx.coroutines.withTimeoutOrNull
8+
import mindustry.gen.Player
9+
10+
data class OnChat(val player: Player, val text: String) : Event, ReceivedEvent {
11+
override var received: Boolean = false
12+
13+
companion object : Event.Handler()
14+
}
15+
16+
suspend fun nextChat(player: Player, timeoutMillis: Int): String? = withTimeoutOrNull(timeoutMillis.toLong()) {
17+
thisContextScript().nextEvent<OnChat> { it.player == player }.text
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package coreMindustry.util
2+
3+
import mindustry.gen.SendChatMessageCallPacket
4+
5+
listenPacket2ServerAsync<SendChatMessageCallPacket> { con, p ->
6+
con.player?.let { OnChat(it, p.message).emitAsync().received.not() } ?: true
7+
}
8+
export(::nextChat)

scripts/coreMindustry/utilNextChat.kts

Lines changed: 0 additions & 18 deletions
This file was deleted.

scripts/mapScript/lib/PosMark.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package mapScript.lib
2+
3+
import mindustry.game.Team
4+
import mindustry.gen.Call
5+
import mindustry.world.Tile
6+
7+
//定义一种标记格式
8+
//放置世界信息版,每行可设置一个标记,形如
9+
// @zone w=5 h=5
10+
//地图加载后,将存储在@zone类型信息中
11+
12+
data class PosMark(val type: String, val tile: Tile, val team: Team, val arg: Map<String, String>) {
13+
fun error(msg: String, duration: Float = 10f) {
14+
Call.labelReliable(msg, duration, tile.worldx(), tile.worldy())
15+
}
16+
17+
//@file:Depends("mapScript/shared/PosMark")
18+
interface Service {
19+
fun getPoses(type: String): List<PosMark>
20+
fun registerCommand(type: String, handler: (PosMark) -> Unit)
21+
}
22+
}
Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1+
@file:Implement(PosMark.Service::class)
2+
13
package mapScript.shared
24

3-
import mindustry.game.Team
45
import mindustry.world.Tile
56

6-
//定义一种标记格式
7-
//放置世界信息版,每行可设置一个标记,形如
8-
// @zone w=5 h=5
9-
//地图加载后,将存储在@zone类型信息中
10-
11-
data class Pos(val type: String, val tile: Tile, val team: Team, val arg: Map<String, String>) {
12-
fun error(msg: String, duration: Float = 10f) {
13-
Call.labelReliable(msg, duration, tile.worldx(), tile.worldy())
14-
}
15-
}
16-
17-
fun parse(tile: Tile): List<Pos>? {
7+
fun parse(tile: Tile): List<PosMark>? {
188
if (tile.block() != Blocks.worldMessage) return null
199
val lines = tile.build.config().toString().lines()
2010
if (lines.any { it.firstOrNull() != '@' }) return null
2111
val team = tile.team()
2212
return lines.map { line ->
2313
val sp = line.split(" ").filter { it.isNotBlank() }
24-
Pos(sp[0], tile, team,
14+
PosMark(
15+
sp[0], tile, team,
2516
sp.drop(1).associate { it.substringBefore('=') to it.substringAfter('=', "") })
2617
}
2718
}
@@ -39,7 +30,7 @@ val posMap by autoInit {
3930
all.groupBy { it.type }
4031
}
4132

42-
fun getPoses(type: String) = posMap[type].orEmpty()
33+
/*override*/ fun getPoses(type: String) = posMap[type].orEmpty()
4334

4435
//动态地图标记
4536
listen<EventType.TileChangeEvent> { event ->
@@ -53,8 +44,8 @@ listen<EventType.TileChangeEvent> { event ->
5344
}
5445
}
5546
}
56-
val commands = mutableMapOf<String, (pos: Pos) -> Unit>()
47+
val commands = mutableMapOf<String, (pos: PosMark) -> Unit>()
5748
onDisable { commands.clear() }
58-
fun registerCommand(type: String, handler: (pos: Pos) -> Unit) {
49+
/*override*/ fun registerCommand(type: String, handler: (pos: PosMark) -> Unit) {
5950
commands[type] = handler
6051
}

scripts/metadata/coreMindustry.metadata

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ ID coreMindustry/scoreboard
2828
FQ_NAME coreMindustry.Scoreboard
2929
+DEPENDS coreMindustry module
3030

31+
ID coreMindustry/util/newContent
32+
FQ_NAME coreMindustry.util.NewContent
33+
+DEPENDS coreMindustry module
34+
35+
ID coreMindustry/util/nextChat
36+
FQ_NAME coreMindustry.util.NextChat
37+
+DEPENDS coreMindustry module
38+
3139
ID coreMindustry/util/packetHelper
3240
FQ_NAME coreMindustry.util.PacketHelper
3341
+DEPENDS coreMindustry module
@@ -44,10 +52,6 @@ ID coreMindustry/util/trackBuilding
4452
FQ_NAME coreMindustry.util.TrackBuilding
4553
+DEPENDS coreMindustry module
4654

47-
ID coreMindustry/utilMapRule
48-
FQ_NAME coreMindustry.UtilMapRule
49-
+DEPENDS coreMindustry module
50-
5155
ID coreMindustry/utilNextChat
5256
FQ_NAME coreMindustry.UtilNextChat
5357
+DEPENDS coreMindustry module

settings.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ include("scripts")
22

33
file("scripts").listFiles()?.forEach {
44
if (it.isDirectory && it.name.startsWith("@")) {
5-
include("scripts:${it.name.substring(1)}")
6-
project(":scripts:${it.name.substring(1)}").projectDir = it
5+
include("scripts:@${it.name.substring(1)}")
6+
project(":scripts:@${it.name.substring(1)}").projectDir = it
77
}
88
}

0 commit comments

Comments
 (0)