Remove util:lookup plugin

Behaviour moved into the api plugin.
This commit is contained in:
Major
2018-04-08 16:19:02 +01:00
parent fdabea8162
commit 8fe09880b7
11 changed files with 66 additions and 72 deletions
-3
View File
@@ -1,3 +0,0 @@
plugin {
name = "entity_lookup"
}
-37
View File
@@ -1,37 +0,0 @@
package org.apollo.game.plugin.util.lookup
import org.apollo.cache.def.ItemDefinition
import org.apollo.cache.def.NpcDefinition
import org.apollo.cache.def.ObjectDefinition
fun lookup_object(name: String): ObjectDefinition? {
return find_entity(ObjectDefinition::getDefinitions, ObjectDefinition::getName, name)
}
fun lookup_npc(name: String): NpcDefinition? {
return find_entity(NpcDefinition::getDefinitions, NpcDefinition::getName, name)
}
fun lookup_item(name: String): ItemDefinition? {
return find_entity(ItemDefinition::getDefinitions, ItemDefinition::getName, name)
}
/**
* The [Regex] used to match 'names' that have an id attached to the end.
*/
private val ID_REGEX = Regex(".+_[0-9]+$")
private fun <T : Any> find_entity(definitionsProvider: () -> Array<T>,
nameSupplier: T.() -> String,
name: String): T? {
val definitions = definitionsProvider.invoke()
if (ID_REGEX matches name) {
val id = name.substring(name.lastIndexOf('_') + 1, name.length).toInt()
return definitions.getOrNull(id)
}
val normalizedName = name.replace('_', ' ')
return definitions.firstOrNull { it.nameSupplier().equals(normalizedName, true) }
}
@@ -1,17 +0,0 @@
import org.apollo.cache.def.ItemDefinition
import org.apollo.game.plugin.testing.KotlinPluginTest
import org.apollo.game.plugin.util.lookup.lookup_item
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
class LookupTests : KotlinPluginTest() {
@Test
fun itemLookup() {
val testItem = ItemDefinition(0)
testItem.name = "sword"
ItemDefinition.init(arrayOf(testItem))
assertThat(lookup_item("sword")).isEqualTo(testItem)
}
}