mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 00:38:18 +00:00
Use symbols instead of strings in name-util.
This commit is contained in:
@@ -2,38 +2,39 @@ require 'java'
|
|||||||
|
|
||||||
# Looks up the id of the npc with the specified name.
|
# Looks up the id of the npc with the specified name.
|
||||||
def lookup_npc(name)
|
def lookup_npc(name)
|
||||||
return lookup_entity('npc', name)
|
return lookup_entity(:npc, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Looks up the id of the item with the specified name.
|
# Looks up the id of the item with the specified name.
|
||||||
def lookup_item(name)
|
def lookup_item(name)
|
||||||
return lookup_entity('item', name)
|
return lookup_entity(:item, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Looks up the id of the object with the specified name.
|
# Looks up the id of the object with the specified name.
|
||||||
def lookup_object(name)
|
def lookup_object(name)
|
||||||
return lookup_entity('object', name)
|
return lookup_entity(:object, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Looks up the id of an entity of the specified type (either 'npc', 'item', or 'object')
|
# Looks up the id of an entity of the specified type (either :npc, :item, or :object)
|
||||||
def lookup_entity(type, symbol)
|
def lookup_entity(type, name)
|
||||||
symbol = symbol.to_s
|
type = type.to_s
|
||||||
cached = NAME_CACHE[type + symbol]
|
name = name.to_s.gsub('_', ' ')
|
||||||
|
|
||||||
|
cached = NAME_CACHE[type + name]
|
||||||
return cached unless cached.nil?
|
return cached unless cached.nil?
|
||||||
|
|
||||||
name = symbol.to_s.gsub('_', ' ')
|
|
||||||
id = name[name.rindex(' ') + 1, name.length - 1].to_i if name.include?(' ')
|
id = name[name.rindex(' ') + 1, name.length - 1].to_i if name.include?(' ')
|
||||||
id = find_entities(type, name, 1).first if (id .nil? || id.zero?)
|
id = find_entities(type, name, 1).first if (id .nil? || id.zero?)
|
||||||
|
|
||||||
raise "The #{type} called #{name} could not be identified." if id.nil?
|
raise "The #{type} called #{name} could not be identified." if id.nil?
|
||||||
|
|
||||||
NAME_CACHE[type + symbol] = id
|
NAME_CACHE[type + name] = id
|
||||||
return id
|
return id
|
||||||
end
|
end
|
||||||
|
|
||||||
# Finds entities with the specified type (e.g. npc) and name, returning possible ids as an array.
|
# Finds entities with the specified type (e.g. npc) and name, returning possible ids as an array.
|
||||||
def find_entities(type, name, limit=5)
|
def find_entities(type, name, limit=5)
|
||||||
ids = [];
|
ids = []
|
||||||
name.downcase!
|
name.downcase!
|
||||||
|
|
||||||
Kernel.const_get("#{type.capitalize}Definition").definitions.each do |definition|
|
Kernel.const_get("#{type.capitalize}Definition").definitions.each do |definition|
|
||||||
|
|||||||
Reference in New Issue
Block a user