This commit is contained in:
DBotThePony 2023-09-04 09:43:36 +07:00
parent 595b1c5e69
commit 7a69dee5ca
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -38,21 +38,47 @@ data class RenderRuleList(
val matchHue: Boolean = false,
val inverse: Boolean = false,
) {
private fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
return when (type) {
"EqualsSelf" -> equalityTester.test(getter.getTile(thisPos), getter.getTile(thisPos + offsetPos))
"Connects" -> getter.getTile(thisPos + offsetPos).material != null
private fun interface ActualTester {
fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean
}
private object EqualsSelf : ActualTester {
override fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
return equalityTester.test(getter.getTile(thisPos), getter.getTile(thisPos + offsetPos))
}
}
private object Conntects : ActualTester {
override fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
return getter.getTile(thisPos + offsetPos).material != null
}
}
private object Never : ActualTester {
override fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
return false
}
}
private val actualTester by lazy {
when (type) {
"EqualsSelf" -> EqualsSelf
"Connects" -> Conntects
else -> {
if (LOGGED.add(type)) {
LOGGER.error("Unknown render rule test $type!")
}
false
Never
}
}
}
private fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
return actualTester.doTest(getter, equalityTester, thisPos, offsetPos)
}
fun test(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
if (inverse) {
return !doTest(getter, equalityTester, thisPos, offsetPos)