Fix: 修复ArachnaeLog无限递归和CompProperties_HediffGiver的Dictionary问题

This commit is contained in:
2025-12-21 15:02:59 +08:00
parent 2825ef4e97
commit 1c0a701672
4 changed files with 21 additions and 12 deletions

Binary file not shown.

View File

@@ -15,7 +15,7 @@ namespace ArachnaeSwarm
{ {
if (DebugEnabled) if (DebugEnabled)
{ {
ArachnaeLog.Debug(message); Log.Message(message);
} }
} }
} }

View File

@@ -3,6 +3,15 @@ using Verse;
namespace ArachnaeSwarm namespace ArachnaeSwarm
{ {
/// <summary>
/// Hediff与身体部位的映射关系用于XML序列化
/// </summary>
public class HediffBodyPartMapping
{
public HediffDef hediff;
public BodyPartDef bodyPart;
}
public class CompProperties_HediffGiver : CompProperties public class CompProperties_HediffGiver : CompProperties
{ {
// 要添加的hediff列表 // 要添加的hediff列表
@@ -15,37 +24,37 @@ namespace ArachnaeSwarm
public bool allowDuplicates = false; public bool allowDuplicates = false;
// === 新增:优先应用部位设置 === // === 新增:优先应用部位设置 ===
public bool useDefaultInstallPart = true; // 是否使用HediffDef的defaultInstallPart public bool useDefaultInstallPart = true;
// === 新增:自定义部位映射 === // === 新增:自定义部位映射使用List替代Dictionary ===
public Dictionary<HediffDef, BodyPartDef> customBodyPartMapping = null; public List<HediffBodyPartMapping> customBodyPartMapping = null;
public CompProperties_HediffGiver() public CompProperties_HediffGiver()
{ {
this.compClass = typeof(CompHediffGiver); this.compClass = typeof(CompHediffGiver);
} }
/// <summary>
/// 获取Hediff应该应用的部位
/// </summary>
public BodyPartDef GetBodyPartForHediff(HediffDef hediffDef) public BodyPartDef GetBodyPartForHediff(HediffDef hediffDef)
{ {
if (hediffDef == null) if (hediffDef == null)
return null; return null;
// 首先检查自定义映射 if (customBodyPartMapping != null)
if (customBodyPartMapping != null && customBodyPartMapping.ContainsKey(hediffDef))
{ {
return customBodyPartMapping[hediffDef]; foreach (var mapping in customBodyPartMapping)
{
if (mapping.hediff == hediffDef)
return mapping.bodyPart;
}
} }
// 然后检查是否使用默认安装部位
if (useDefaultInstallPart && hediffDef.defaultInstallPart != null) if (useDefaultInstallPart && hediffDef.defaultInstallPart != null)
{ {
return hediffDef.defaultInstallPart; return hediffDef.defaultInstallPart;
} }
return null; // 没有指定部位 return null;
} }
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 337 KiB

After

Width:  |  Height:  |  Size: 528 KiB