Skip to content

Commit efe7802

Browse files
committed
⬆️ (loader) 核心库v1.10.1.1
1 parent 1373c1f commit efe7802

13 files changed

Lines changed: 138 additions & 144 deletions

File tree

build.gradle.kts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sourceSets {
3434
}
3535

3636
repositories {
37-
mavenLocal()
37+
// mavenLocal()
3838
mavenCentral()
3939
maven(url = "https://www.jitpack.io") {
4040
content {
@@ -56,14 +56,14 @@ repositories {
5656
}
5757

5858
dependencies {
59-
val libraryVersion = "1.10.0.2"
59+
val libraryVersion = "1.10.1.1"
6060
val mindustryVersion = "v140.101"
6161
val pluginImplementation by configurations
6262
pluginImplementation("cf.wayzer:ScriptAgent:$libraryVersion")
63-
pluginImplementation("cf.wayzer:LibraryManager:1.4.1")
6463
// pluginImplementation("com.github.Anuken.Mindustry:core:$mindustryVersion")
6564
pluginImplementation("com.github.TinyLake.MindustryX:core:$mindustryVersion")
6665

66+
implementation(sourceSets.getByName("plugin").output)
6767
implementation(kotlin("script-runtime"))
6868
implementation("cf.wayzer:ScriptAgent:$libraryVersion")
6969
kotlinScriptDef("cf.wayzer:ScriptAgent:$libraryVersion")
@@ -132,7 +132,7 @@ tasks {
132132
archiveVersion.set(rootProject.version.toString().substringBeforeLast('.'))
133133
configurations = listOf(project.configurations.getByName("pluginCompileClasspath"))
134134
manifest.attributes(
135-
"Main-Class" to "cf.wayzer.scriptAgent.GenerateMain"
135+
"Main-Class" to "cf.wayzer.scriptAgent.mindustry.GenerateMain"
136136
)
137137
dependencies {
138138
include(dependency("cf.wayzer:ScriptAgent"))
@@ -149,9 +149,6 @@ tasks {
149149
outputs.files("scripts/cache")
150150

151151
classpath(buildPlugin.outputs.files)
152-
mainClass.set("cf.wayzer.scriptAgent.GenerateMain")
153-
if (javaVersion >= JavaVersion.VERSION_16)
154-
jvmArgs("--add-opens java.base/java.net=ALL-UNNAMED")
155152
}
156153
val precompileZip = create<Zip>("precompileZip") {
157154
dependsOn(precompile)

plugin/res/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ScriptAgent4Mindustry",
33
"author": "WayZer",
4-
"main": "cf.wayzer.ScriptAgent4Mindustry",
4+
"main": "cf.wayzer.scriptAgent.mindustry.Loader",
55
"description": "More commands and features.",
66
"version": "@version@",
77
"minGameVersion": 136

plugin/src/cf/wayzer/ConfigExt.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@file:Suppress("UnusedReceiverParameter")
2+
3+
package cf.wayzer.scriptAgent
4+
5+
import arc.util.CommandHandler
6+
import cf.wayzer.scriptAgent.util.DSLBuilder
7+
8+
var Config.version by DSLBuilder.lateInit<String>()
9+
internal set
10+
var Config.mainScript by DSLBuilder.lateInit<String>()
11+
internal set
12+
var Config.clientCommands by DSLBuilder.lateInit<CommandHandler>()
13+
internal set
14+
var Config.serverCommands by DSLBuilder.lateInit<CommandHandler>()
15+
internal set

plugin/src/cf/wayzer/scriptAgent/GenerateMain.kt renamed to plugin/src/cf/wayzer/scriptAgent/mindustry/GenerateMain.kt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
package cf.wayzer.scriptAgent
1+
package cf.wayzer.scriptAgent.mindustry
22

3+
import cf.wayzer.scriptAgent.Config
4+
import cf.wayzer.scriptAgent.ScriptAgent
5+
import cf.wayzer.scriptAgent.ScriptManager
6+
import cf.wayzer.scriptAgent.ScriptRegistry
37
import cf.wayzer.scriptAgent.define.LoaderApi
48
import cf.wayzer.scriptAgent.define.ScriptState
59
import cf.wayzer.scriptAgent.util.DependencyManager
@@ -18,7 +22,7 @@ object GenerateMain {
1822
"[%1\$tF | %1\$tT | %4\$s] [%3\$s] %5\$s%6\$s%n"
1923
)
2024
ScriptAgent.loadUseClassLoader()
21-
?.loadClass("cf.wayzer.scriptAgent.GenerateMain")
25+
?.loadClass(GenerateMain::class.java.name)
2226
?.getDeclaredMethod("afterLoad", Array<String>::class.java)?.invoke(null, args)
2327
?: exitProcess(-1)
2428
}
@@ -35,27 +39,22 @@ object GenerateMain {
3539
Config.rootDir = File("scripts")
3640
ScriptRegistry.scanRoot()
3741

38-
var notFound = 0
3942
runBlocking {
40-
if (args.isEmpty())
41-
ScriptManager.loadAll(false)
42-
else
43-
args.forEach {
44-
val script = ScriptManager.getScriptNullable(it)
45-
if (script == null) {
46-
println("找不到脚本: $it")
47-
notFound++
48-
return@forEach
49-
}
50-
}
43+
ScriptManager.transaction {
44+
if (args.isEmpty())
45+
addAll()
46+
else
47+
args.forEach { add(it) }
48+
load()
49+
}
5150
}
52-
val fail = ScriptRegistry.allScripts { it.scriptState == ScriptState.ToLoad && it.failReason != null }
53-
if (notFound != 0)
54-
println("${notFound}个输入脚本未找到")
55-
println("共加载${ScriptRegistry.allScripts { it.scriptState != ScriptState.ToLoad }.size}个脚本,失败${fail.size}")
51+
val fail = ScriptRegistry.allScripts { it.failReason != null }
52+
println(
53+
"共加载${ScriptRegistry.allScripts { it.scriptState != ScriptState.Found }.size}个脚本,失败${fail.size}"
54+
)
5655
fail.forEach {
5756
println("\t${it.id}: ${it.failReason}")
5857
}
59-
exitProcess(notFound + fail.size)
58+
exitProcess(fail.size)
6059
}
6160
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cf.wayzer.scriptAgent.mindustry
2+
3+
import arc.util.CommandHandler
4+
import cf.wayzer.scriptAgent.*
5+
import cf.wayzer.scriptAgent.define.LoaderApi
6+
import mindustry.mod.Plugin
7+
8+
@Suppress("unused")//ref by plugin.json
9+
class Loader : Plugin() {
10+
private val impl: Plugin
11+
12+
init {
13+
if (System.getProperty("java.util.logging.SimpleFormatter.format") == null)
14+
System.setProperty(
15+
"java.util.logging.SimpleFormatter.format",
16+
"[%1\$tF | %1\$tT | %4\$s] [%3\$s] %5\$s%6\$s%n"
17+
)
18+
@OptIn(LoaderApi::class)
19+
impl = ScriptAgent.loadUseClassLoader()
20+
?.loadClass(Main::class.java.name)
21+
?.getConstructor(Plugin::class.java)
22+
?.newInstance(this) as Plugin?
23+
?: error("Fail newInstance")
24+
}
25+
26+
override fun registerClientCommands(handler: CommandHandler?) {
27+
impl.registerClientCommands(handler)
28+
}
29+
30+
override fun registerServerCommands(handler: CommandHandler?) {
31+
impl.registerServerCommands(handler)
32+
}
33+
34+
override fun init() {
35+
impl.init()
36+
}
37+
}

plugin/src/cf/wayzer/ScriptAgent4Mindustry.kt renamed to plugin/src/cf/wayzer/scriptAgent/mindustry/Main.kt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
1-
package cf.wayzer
1+
package cf.wayzer.scriptAgent.mindustry
22

33
import arc.ApplicationListener
44
import arc.Core
5+
import arc.files.Fi
56
import arc.util.CommandHandler
67
import arc.util.Log
7-
import cf.wayzer.ConfigExt.clientCommands
8-
import cf.wayzer.ConfigExt.mainScript
9-
import cf.wayzer.ConfigExt.serverCommands
10-
import cf.wayzer.ConfigExt.version
118
import cf.wayzer.scriptAgent.*
129
import cf.wayzer.scriptAgent.define.LoaderApi
1310
import kotlinx.coroutines.runBlocking
1411
import mindustry.Vars
15-
import mindustry.plugin.Plugin
12+
import mindustry.mod.Plugin
1613
import java.io.File
1714

1815
@OptIn(LoaderApi::class)
19-
class ScriptAgent4Mindustry : Plugin() {
20-
init {
21-
if (System.getProperty("java.util.logging.SimpleFormatter.format") == null)
22-
System.setProperty(
23-
"java.util.logging.SimpleFormatter.format",
24-
"[%1\$tF | %1\$tT | %4\$s] [%3\$s] %5\$s%6\$s%n"
25-
)
26-
ScriptAgent.load()
27-
}
16+
class Main(private val loader: Plugin) : Plugin() {
17+
override fun getConfig(): Fi = loader.config
2818

2919
override fun registerClientCommands(handler: CommandHandler) {
30-
Config.clientCommands = handler
20+
//after init() is too late
21+
// Config.clientCommands = handler
3122
}
3223

3324
override fun registerServerCommands(handler: CommandHandler) {
@@ -36,13 +27,17 @@ class ScriptAgent4Mindustry : Plugin() {
3627

3728
override fun init() {
3829
val defaultMain = "main/bootStrap"
39-
val version = Vars.mods.getMod(javaClass).meta.version
30+
val version = Vars.mods.getMod(loader.javaClass).meta.version
4031
val main = System.getenv("SAMain") ?: defaultMain
4132
Log.info("SAMain=$main")
4233

4334
Config.version = version
4435
Config.mainScript = main
4536
Config.rootDir = Vars.dataDirectory.child("scripts").file()
37+
Config.clientCommands = Vars.netServer?.clientCommands ?: CommandHandler("/")
38+
if (!Vars.headless) {
39+
Config.serverCommands = CommandHandler("")
40+
}
4641

4742
tryExtract("/res/$defaultMain.kts", Config.rootDir.resolve("$defaultMain.kts"))
4843
tryExtract("/res/$defaultMain.ktc", Config.cacheFile(defaultMain, false))

plugin/src/mindustry/plugin/Plugin.kt

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

scripts/coreLibrary/lib/ConfigExt.kt

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

scripts/coreMindustry/lib/CommandImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package coreMindustry.lib
44

55
import arc.struct.Seq
66
import arc.util.CommandHandler
7-
import cf.wayzer.scriptAgent.Config
7+
import cf.wayzer.scriptAgent.*
88
import cf.wayzer.scriptAgent.thisContextScript
99
import cf.wayzer.scriptAgent.util.DSLBuilder
1010
import coreLibrary.lib.*

0 commit comments

Comments
 (0)