diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt index ae9cfac..e58b98f 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt @@ -81,7 +81,8 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { "§6@out§7 - " + I18n.format("gui.advanced_memory_card.sortinfo3"), "§a@b§7 - " + I18n.format("gui.advanced_memory_card.sortinfo4"), "§c@u§7 - " + I18n.format("gui.advanced_memory_card.sortinfo5"), - "§7" + I18n.format("gui.advanced_memory_card.sortinfo6") + "§e@type=[;;]...§7 - " + I18n.format("gui.advanced_memory_card.sortinfo6"), + "§7" + I18n.format("gui.advanced_memory_card.sortinfo7") ) } diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/InfoFilter.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/InfoFilter.kt index a2e7a6a..da59cb5 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/InfoFilter.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/InfoFilter.kt @@ -1,11 +1,14 @@ package com.projecturanus.betterp2p.client.gui +import com.projecturanus.betterp2p.BetterP2P + /** * Extend the default filtering. Holds information about the search filter. * - * There are 3 modes of filtering: + * There are 4 modes of filtering: * - By input/output: Using `@in/@out` filters by input/output respectively. - * - By bound/unbound: Use `@b` or `@u` filters by input/output respectively. + * - By bound/unbound: Using `@b` or `@u` filters by bound/unbound respectively. + * - By type: Using `@types=;;...` filters by type. * - By name: Use the name * If someone comes and says "sort by freq pls" then we can add it at that time */ @@ -23,28 +26,42 @@ class InfoFilter { fun updateFilter(query: String) { val tokens = SEARCH_REGEX.findAll(query) activeFilters.clear() + var bind: String tokens.forEach { - when { - it.value.matches(Filter.INPUT.pattern) -> { - activeFilters.putIfAbsent(Filter.INPUT, null) - } - it.value.matches(Filter.OUTPUT.pattern) -> { - activeFilters.putIfAbsent(Filter.OUTPUT, null) - } - it.value.matches(Filter.BOUND.pattern) -> { - activeFilters.putIfAbsent(Filter.BOUND, null) - } - it.value.matches(Filter.UNBOUND.pattern) -> { - activeFilters.putIfAbsent(Filter.UNBOUND, null) - } - it.value.isBlank() -> {} - else -> { - activeFilters.putIfAbsent(Filter.NAME, mutableListOf()) - when { - it.groups[1] != null -> activeFilters[Filter.NAME]!!.add(it.groups[1]!!.value) - it.groups[2] != null -> activeFilters[Filter.NAME]!!.add(it.groups[2]!!.value) - else -> activeFilters[Filter.NAME]!!.add(it.value) + val token = it.value + // If we don't start with a tag, skip all these regexes + if (token.startsWith("@")) { + when { + it.value.matches(Filter.INPUT.pattern) -> { + activeFilters.putIfAbsent(Filter.INPUT, null) } + it.value.matches(Filter.OUTPUT.pattern) -> { + activeFilters.putIfAbsent(Filter.OUTPUT, null) + } + it.value.matches(Filter.BOUND.pattern) -> { + activeFilters.putIfAbsent(Filter.BOUND, null) + } + it.value.matches(Filter.UNBOUND.pattern) -> { + activeFilters.putIfAbsent(Filter.UNBOUND, null) + } + it.value.matches(Filter.TYPE.pattern) -> { + val result = Filter.TYPE.pattern.find(it.value)!! + val l = mutableListOf() + activeFilters.putIfAbsent(Filter.TYPE, l) + val types = result.groupValues[1].split(";") + types.forEach(l::add) + } + it.value.isBlank() -> {} + else -> { + } + } + } else { + val l = mutableListOf() + activeFilters.putIfAbsent(Filter.NAME, l) + when { + it.groups[1] != null -> l.add(it.groups[1]!!.value) + it.groups[2] != null -> l.add(it.groups[2]!!.value) + else -> activeFilters[Filter.NAME]!!.add(it.value) } } } @@ -60,6 +77,15 @@ enum class Filter(val pattern: Regex, val filter: (InfoWrapper, List?) - OUTPUT("\\A@out\\z".toRegex(), { it, _ -> it.output }), BOUND("\\A@b\\z".toRegex(), { it, _ -> it.frequency != 0L }), UNBOUND("\\A@u\\z".toRegex(), { it, _ -> it.frequency == 0L || it.error }), + TYPE("\\A@types*=(.+)\\z".toRegex(), filter@{ it, strs -> + val tags = BetterP2P.proxy.getP2PFromIndex(it.type)!!.dispName.lowercase() + for (f in strs!!) { + if (tags.contains(f.lowercase())) { + return@filter true + } + } + false + }), NAME("\"?.+\"?".toRegex(), filter@{ it, strs -> val name = it.name.lowercase() for (f in strs!!) { diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/InfoWrapper.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/InfoWrapper.kt index f1c2301..5c5a37f 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/InfoWrapper.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/InfoWrapper.kt @@ -31,6 +31,7 @@ class InfoWrapper(info: P2PInfo) { val dim: Int = info.world val facing: ForgeDirection = info.facing val output: Boolean = info.output + val type: Int = info.type /** * The backing icon (quartz, iron, etc) diff --git a/src/main/resources/assets/betterp2p/lang/en_US.lang b/src/main/resources/assets/betterp2p/lang/en_US.lang index 5014ab2..12656e6 100644 --- a/src/main/resources/assets/betterp2p/lang/en_US.lang +++ b/src/main/resources/assets/betterp2p/lang/en_US.lang @@ -12,7 +12,8 @@ gui.advanced_memory_card.sortinfo2=Show Input P2Ps only gui.advanced_memory_card.sortinfo3=Show Output P2Ps only gui.advanced_memory_card.sortinfo4=Show Bound P2Ps only gui.advanced_memory_card.sortinfo5=Show Unbound P2Ps only -gui.advanced_memory_card.sortinfo6=Tags are space separated and are combined w/ the AND operator. +gui.advanced_memory_card.sortinfo6=Filter by type name(s) +gui.advanced_memory_card.sortinfo7=Tags are space separated and are combined w/ the AND operator. gui.advanced_memory_card.extra.channel=Channels used: %s gui.advanced_memory_card.mode.input=Current Mode: Bind to §9Input gui.advanced_memory_card.mode.input.desc.1=• Before binding, the §aselected §aP2P §7and §bbind §btarget §7have their connections removed.