From 50cd5d3b9bf5a809cb4f458aefc5f68b8fb2efb3 Mon Sep 17 00:00:00 2001 From: way-zer Date: Sat, 6 Sep 2025 18:49:13 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E9=80=9A=E8=BF=87=E4=B8=8D=E5=90=8C=E5=AD=90?= =?UTF-8?q?=E6=A0=91=E8=AE=BF=E9=97=AE/=E4=BF=AE=E6=94=B9=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/cf/wayzer/contentsTweaker/CTNode.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/cf/wayzer/contentsTweaker/CTNode.kt b/src/main/kotlin/cf/wayzer/contentsTweaker/CTNode.kt index fa30683..7193065 100644 --- a/src/main/kotlin/cf/wayzer/contentsTweaker/CTNode.kt +++ b/src/main/kotlin/cf/wayzer/contentsTweaker/CTNode.kt @@ -6,6 +6,7 @@ import arc.util.serialization.JsonWriter import cf.wayzer.contentsTweaker.CTNode.* import cf.wayzer.contentsTweaker.util.ExtendableClass import cf.wayzer.contentsTweaker.util.ExtendableClassDSL +import java.util.* /** * 所有节点都是[CTNode] @@ -45,8 +46,10 @@ class CTNode private constructor() : ExtendableClass() { val node = children[name] ?: getAll().firstNotNullOfOrNull { it.resolve(name) } ?: error("Not found child $name") - node.collectAll() - return node + //If it's a duplicate Node for object, only Modifiers are accessible. + if (get>()?.isDuplicated == true && node.get() == null) + error("Duplicated Object Node, cannot visit children") + return node.collectAll() } /** 供[ContentsTweaker.NodeCollector]使用,解析清使用[resolve]*/ @@ -61,7 +64,13 @@ class CTNode private constructor() : ExtendableClass() { val elementType: Class<*>? = null, // List.T or Map.V val keyType: Class<*>? = null // Map.K ) : CTExtInfo { + val isDuplicated = duplicatedObjects.put(obj, Unit) != null + constructor(obj: T & Any) : this(obj, obj::class.java) + + companion object { + val duplicatedObjects = IdentityHashMap() + } } fun interface Resettable : CTExtInfo { @@ -184,6 +193,7 @@ class CTNode private constructor() : ExtendableClass() { Root.children.clear() Root.collected = false + ObjInfo.duplicatedObjects.clear() } fun handle(json: JsonValue, node: CTNode = Root.collectAll()) {