Module:GameData: Difference between revisionsGive feedback
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) | if is_active(record) and p.entity_matches(record, properties) then | ||
table.insert(results, record) | |||
end | end | ||
end | end | ||