11package bootStrap
22
3- import cf.wayzer.scriptAgent.events.ScriptStateChangeEvent
3+ import cf.wayzer.scriptAgent.state.ConditionState
44import cf.wayzer.scriptAgent.util.CASScriptPacker
55import cf.wayzer.scriptAgent.util.DependencyManager
66import cf.wayzer.scriptAgent.util.maven.Dependency
@@ -12,66 +12,37 @@ fun prepareBuiltin(outputFile: File = File("build/tmp/builtin.packed.zip")) {
1212 val scripts = ScriptRegistry .allScripts { it.scriptState.loaded }
1313 .mapNotNull { it.compiledScript }
1414 println (" prepare Builtin for ${scripts.size} scripts." )
15- @OptIn(SAExperimentalApi ::class )
1615 CASScriptPacker (outputFile.outputStream())
1716 .use { scripts.forEach(it::add) }
1817}
1918
20- suspend fun compileOnlyLoad (script : ScriptInfo ) {
21- Config .logger.info(" 编译脚本 ${script.id} " )
22- val compiled = try {
23- @OptIn(SAExperimentalApi ::class )
24- ScriptManager .compileScript(script.source)
25- } catch (e: Exception ) {
26- val msg = if (e is IllegalStateException ) e.message else e.toString()
27- script.failReason = " 编译失败: $msg "
28- return
29- }
30- try {
31- compiled.loadLibraries()
32- } catch (e: Exception ) {
33- script.failReason = " 依赖下载失败:$e "
34- return
35- }
36- script.compiledScript = compiled
37- script.stateUpdateForce(ScriptState .Loaded ).join()
38- }
39-
40- // Replaced with compileOnlyLoad
41- listenTo<ScriptStateChangeEvent .Cancellable > {
42- if (next == ScriptState .Loading ) {
43- cancelled = true
44- compileOnlyLoad(script)
45- }
46- }
47-
4819onEnable {
4920 if (id != Config .mainScript)
5021 return @onEnable ScriptManager .disableScript(this , " 仅可通过SAMAIN启用" )
51- // so we can use `listenTo` in main
52- launch { main() }
22+ ScriptManager .afterTransaction { main() }
5323}
5424suspend fun main () {
5525 DependencyManager {
5626 addRepository(" https://www.jitpack.io/" )
5727 require(Dependency .parse(" com.github.TinyLake.MindustryX:core:v2025.10.X21" ))
5828 loadToClassLoader(Config .mainClassloader)
5929 }
60- ScriptManager .transaction {
30+ ScriptManager .transactionV2 {
31+ // Load Kcp
32+ enable(" kcp" )
33+ execute().printResult()
34+
6135 if (Config .args.isEmpty())
62- addAll( )
36+ compileOnly( " " )
6337 else
64- Config .args.forEach { add(it) }
65-
66- load()
67- }
68- val fail = ScriptRegistry .allScripts { it.failReason != null }
69- println (" 共加载${ScriptRegistry .allScripts { it.scriptState != ScriptState .Found }.size} 个脚本,失败${fail.size} 个" )
70- fail.forEach {
71- println (" \t ${it.id} : ${it.failReason} " )
72- }
73- if (System .getProperty(" ScriptAgent.PreparePack" ) != null ) {
74- println (" Finish pack in ${measureTimeMillis { prepareBuiltin() }} ms" )
38+ Config .args.forEach { compileOnly(it) }
39+ }.run {
40+ val fail = conditions.values.filter { it.status == ConditionState .Status .Success }
41+ println (" 共加载${conditions.size} 个脚本,失败${fail.size} 个" )
42+ printResult()
43+ if (System .getProperty(" ScriptAgent.PreparePack" ) != null ) {
44+ println (" Finish pack in ${measureTimeMillis { prepareBuiltin() }} ms" )
45+ }
46+ exitProcess(fail.size)
7547 }
76- exitProcess(fail.size)
7748}
0 commit comments