Skip to content

Commit

Permalink
Merge pull request #11 from way-zer/fix-techTree
Browse files Browse the repository at this point in the history
修复`逻辑常量`和`科技树`问题
  • Loading branch information
way-zer authored Feb 22, 2022
2 parents a23f482 + 48c5379 commit 5c4acc5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions loaderMod/src/main/kotlin/cf/wayzer/contentsMod/ContentsLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cf.wayzer.contentsMod

import arc.func.Cons
import arc.func.Prov
import arc.struct.ObjectIntMap
import arc.struct.ObjectMap
import arc.struct.Seq
import arc.util.Log
Expand All @@ -11,6 +12,7 @@ import mindustry.ctype.ContentList
import mindustry.ctype.ContentType
import mindustry.gen.Call
import mindustry.gen.ClientPacketReliableCallPacket
import mindustry.logic.LExecutor
import mindustry.mod.Mod
import mindustry.net.Net
import mindustry.net.Packet
Expand Down Expand Up @@ -69,6 +71,18 @@ class ContentsLoader : Mod() {
val time = measureTimeMillis { it.load() }
Log.infoTag("ContentsLoader", "Loaded ${it.lastContent!!::class.qualifiedName} costs ${time}ms")
}
val timeReloadConstants = measureTimeMillis {
Vars.constants.apply {
javaClass.getDeclaredField("namesToIds")
.apply { isAccessible = true }
.set(this, ObjectIntMap<String>())
javaClass.getDeclaredField("vars")
.apply { isAccessible = true }
.set(this, Seq<LExecutor.Var>(LExecutor.Var::class.java))
init()
}
}
Log.infoTag("ContentsLoader", "Reload Vars.constants costs ${timeReloadConstants}ms")
if (!Vars.headless) {
val timeLoadColors = measureTimeMillis {
MyContentLoader.loadColors()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import mindustry.io.SaveVersion
import mindustry.mod.Mods

object MyContentLoader : ContentLoader() {
class ContentContainer(val type: ContentType, val default: ContentList) {
class ContentContainer(val type: ContentType?, val default: ContentList) {
var content: ContentList = default
var lastContent: ContentList? = null
private set
val contentMap: Seq<Content> = Vars.content.getBy<Content>(type).copy()
val contentMap: Seq<Content> = if (type == null) Seq() else Vars.content.getBy<Content>(type).copy()
val nameMap = contentMap.filterIsInstance<MappableContent>().associateByTo(mutableMapOf()) { it.name }

fun maskChanged() {
Expand Down Expand Up @@ -54,8 +54,10 @@ object MyContentLoader : ContentLoader() {
ContentContainer(ContentType.bullet, Bullets()),
ContentContainer(ContentType.unit, UnitTypes()),
ContentContainer(ContentType.block, Blocks()),
ContentContainer(null, Loadouts()),
ContentContainer(null, TechTree()),
)
val contentMap = contents.associateBy { it.type }
val contentMap = contents.filter { it.type != null }.associateBy { it.type }

override fun clear() = Unit/*throw NotImplementedError()*/
override fun createBaseContent() = throw NotImplementedError()
Expand Down

0 comments on commit 5c4acc5

Please sign in to comment.