Module:GameData: Difference between revisions

Jump to navigation Jump to search
Vergir (talk | contribs)
Add Convar lookup mode to get_prop (Data:Convars.json), unwrapping the {value, description} form (with help from vergir-bot LLM)
Add public entity_matches() and refactor get_entities to reuse it, so ability-list membership can share one matching implementation (with help from vergir-bot LLM)
Line 1: Line 1:
-- Provides generic access to game data files
-- Provides generic access to game data files


Line 49: Line 50:
             -- Value match: prop string appears as a value (e.g. Scale.Type = "melee")
             -- Value match: prop string appears as a value (e.g. Scale.Type = "melee")
             if v == prop then return true end
             if v == prop then return true end
        end
    end
    return false
end
-- Returns true if a record matches at least one of the given properties,
-- using the same key-name-or-string-value semantics as get_entities.
-- Public so other modules (e.g. Module:AbilityTable membership) can reuse it.
function p.entity_matches(record, properties)
    for _, prop in ipairs(properties) do
        if record_matches_prop(record, prop) then
            return true
         end
         end
     end
     end
Line 66: Line 79:


     for _, record in pairs(data) do
     for _, record in pairs(data) do
         if is_active(record) then
         if is_active(record) and p.entity_matches(record, properties) then
            for _, prop in ipairs(properties) do
            table.insert(results, record)
                if record_matches_prop(record, prop) then
                    table.insert(results, record)
                    break
                end
            end
         end
         end
     end
     end