Skip to content

Commit

Permalink
Added support for searching by id instead of just name
Browse files Browse the repository at this point in the history
  • Loading branch information
dosier committed Oct 20, 2023
1 parent 20690b3 commit bf2fb1c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/kotlin/stan/qodat/util/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import stan.qodat.scene.control.SplitSceneDividerDragRegion
import stan.qodat.scene.paint.ColorMaterial
import stan.qodat.scene.paint.TextureMaterial
import stan.qodat.scene.provider.TreeItemProvider
import stan.qodat.scene.runescape.entity.Entity
import stan.qodat.scene.shape.PolygonMeshView

//fun Qodat.Companion.addTo3DScene(node: Node) {
Expand Down Expand Up @@ -72,10 +73,14 @@ fun<S : Searchable> TextField.configureSearchFilter(filteredList: FilteredList<S
if (newValue != null && newValue.isEmpty())
filteredList.setPredicate { true }
else {
filteredList.setPredicate { it.getName().contains(newValue, ignoreCase = true) }
val id = newValue?.toIntOrNull()
filteredList.setPredicate { containsName<S>(it, newValue) || (containsId<S>(it, id, newValue)) }
}
}
}
private fun <S : Searchable> containsName(it: S, newValue: String) = it.getName().contains(newValue, ignoreCase = true)
private fun <S : Searchable> containsId(it: S, id: Int?, newValue: String) =
it is Entity<*> && id != null && it.definition.getOptionalId().orElse(-1).toString().contains(newValue)


fun<M : Material> PolygonMeshView.setAndBindMaterial(materialProperty: ObjectProperty<M>){
Expand Down

0 comments on commit bf2fb1c

Please sign in to comment.