flatBlockedBy

This commit is contained in:
DBotThePony 2022-08-23 23:05:11 +07:00
parent 65dd7cead9
commit 017e9dee7f
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 40 additions and 4 deletions

View File

@ -141,8 +141,8 @@ abstract class AndroidResearch(val type: AndroidResearchType<*>, val capability:
isResearched = nbt.getBoolean("researched") isResearched = nbt.getBoolean("researched")
} }
inline val prerequisites get() = type.definedPrerequisites inline val prerequisites get() = type.flatPrerequisites
inline val unlocks get() = type.flatUnlocks inline val unlocks get() = type.flatUnlocks
inline val blockedBy get() = type.definedBlockedBy inline val blockedBy get() = type.flatBlockedBy
inline val blocking get() = type.flatBlocking inline val blocking get() = type.flatBlocking
} }

View File

@ -354,7 +354,7 @@ class AndroidResearchBuilder(
)) ))
} }
for (value in this.type.definedBlockedBy) { for (value in this.type.flatBlockedBy) {
builder.add(TranslatableComponent("android_research.status.blocked_by", capability.getResearch(value).screenTooltipHeader).withStyle(ChatFormatting.DARK_RED)) builder.add(TranslatableComponent("android_research.status.blocked_by", capability.getResearch(value).screenTooltipHeader).withStyle(ChatFormatting.DARK_RED))
} }

View File

@ -132,7 +132,7 @@ open class AndroidResearchType<R : AndroidResearch>(
/** /**
* Prerequisites as-is. * Prerequisites as-is.
* *
* Please avoid having more than one prerequisite as this case don't have proper research tree * Please avoid having more than one prerequisite, as this case doesn't have proper research tree
* rendering code (yet). * rendering code (yet).
*/ */
open val definedPrerequisites: List<AndroidResearchType<*>> get() = emptyList() open val definedPrerequisites: List<AndroidResearchType<*>> get() = emptyList()
@ -217,6 +217,42 @@ open class AndroidResearchType<R : AndroidResearch>(
ListSet(list.build()) ListSet(list.build())
} }
/**
* Flat list of research blocking this research.
*
* This list won't contain any research blocked by this' research parents.
*
* E.g.
*
* * C depends on B
* * B is blocked by A
* * C is blocked by A
*
* Both B and C are blocked by A, but C requires B, so C's [flatBlockedBy] will not contain A, but B's will.
*
* Returns list which also doubles as set (for contains method).
*/
val flatBlockedBy: List<AndroidResearchType<*>> by lazy {
val list = ImmutableList.builder<AndroidResearchType<*>>()
for (blocker in definedBlockedBy) {
var hit = false
for (research in allPrerequisites) {
if (blocker in research.flatBlockedBy) {
hit = true
break
}
}
if (!hit) {
list.add(blocker)
}
}
ListSet(list.build())
}
/** /**
* All research directly unlocked by this research. * All research directly unlocked by this research.
* *