Add type to filter options

This commit is contained in:
Firenoo committed 2023-05-12 08:32:21 -07:00
1 parent 425c05b4b1
commit faec0bbeb8
4 files changed
+53 -24

No files matched your search

@@ -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=<name1>[;<name2>;]...§7 - " + I18n.format("gui.advanced_memory_card.sortinfo6"),
"§7" + I18n.format("gui.advanced_memory_card.sortinfo7")
)
}
@@ -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=<type1>;<type2>;...` 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<String>()
activeFilters.putIfAbsent(Filter.TYPE, l)
val types = result.groupValues[1].split(";")
types.forEach(l::add)
}
it.value.isBlank() -> {}
else -> {
}
}
} else {
val l = mutableListOf<String>()
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<String>?) -
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!!) {
@@ -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)
@@ -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.