17,105
edits
(getEntityByProperty: Extend to allow first property to be a table of entities) |
(Implement p.skillData as an easy way to reference skill data by local ID/skill name) |
||
Line 9: | Line 9: | ||
-- Expose underlying data should other modules require it | -- Expose underlying data should other modules require it | ||
p.rawData = GameData | p.rawData = GameData | ||
-- Given a namespace & local ID, returns a namespaced ID | -- Given a namespace & local ID, returns a namespaced ID | ||
Line 55: | Line 32: | ||
end | end | ||
return namespace, localID | return namespace, localID | ||
end | |||
local function populateSkillData() | |||
local skillData = {} | |||
for i, skillObj in ipairs(GameData.skillData) do | |||
local _, localID = p.getLocalID(skillObj.skillID) | |||
if localID ~= nil then | |||
skillData[localID] = skillObj.data | |||
end | |||
end | |||
return skillData | |||
end | |||
-- Expose an easy way to reference skill data by skill local ID | |||
p.skillData = populateSkillData() | |||
function p.skillDataTest() | |||
for localID, data in pairs(p.skillData) do | |||
mw.log(localID) | |||
end | |||
end | |||
-- If the entity ID is within the cache for the given entity type, then return it. | |||
-- Otherwise, returns nil | |||
local function getCache(entityType, ID) | |||
if type(entityType) == 'string' and type(ID) == 'string' then | |||
local cacheCat = indexCache[entityType] | |||
if cacheCat ~= nil then | |||
return cacheCat[ID] | |||
end | |||
end | |||
end | |||
-- Sets the cache for entity ID within the given entity type to idx. | |||
local function setCache(entityType, ID, idx) | |||
if type(entityType) == 'string' and type(ID) == 'string' and type(idx) == 'number' and idx == math.floor(idx) then | |||
if indexCache[entityType] == nil then | |||
indexCache[entityType] = {} | |||
end | |||
if indexCache[entityType][ID] == nil then | |||
indexCache[entityType][ID] = idx | |||
end | |||
end | |||
end | end | ||