Editing Module:GameData

Jump to navigation Jump to search
Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 12: Line 12:
     CONVARS  = "Data:Convars.json",
     CONVARS  = "Data:Convars.json",
}
}
-- Street Brawl ships a partial overlay of ability properties rather than a full
-- dataset, so it is deliberately kept out of p.Dataset: its top-level keys are
-- sections ("ability-changes", "item-buckets"), not entity records, and it is
-- not usable with get_entities. Only get_prop consults it.
local STREET_BRAWL = "Data:StreetBrawlData.json"


-- Returns true if a record represents an active, usable entity.
-- Returns true if a record represents an active, usable entity.
Line 214: Line 208:
-- Find an entity by display name or internal key.
-- Find an entity by display name or internal key.
-- Uses ResourceLookup type field to go directly to the right dataset.
-- Uses ResourceLookup type field to go directly to the right dataset.
-- Returns (entity_record, type_string, internal_key) or (nil, nil, nil).
-- Returns (entity_record, type_string) or (nil, nil).
local function find_entity(identifier)
local function find_entity(identifier)
     local resource = mw.loadJsonData("Data:ResourceLookup.json")[identifier:lower()]
     local resource = mw.loadJsonData("Data:ResourceLookup.json")[identifier:lower()]
Line 227: Line 221:
         end
         end
         if data and data[resource.key] then
         if data and data[resource.key] then
             return data[resource.key], resource.type, resource.key
             return data[resource.key], resource.type
         end
         end
     end
     end
Line 239: Line 233:
     for _, ds in ipairs(datasets) do
     for _, ds in ipairs(datasets) do
         local data = mw.loadJsonData(ds[1])
         local data = mw.loadJsonData(ds[1])
         if data[identifier] then return data[identifier], ds[2], identifier end
         if data[identifier] then return data[identifier], ds[2] end
     end
     end


     return nil, nil, nil
     return nil, nil
end
end


Line 288: Line 282:
-- {{#invoke:GameData|get_prop|...}}
-- {{#invoke:GameData|get_prop|...}}
-- Two modes:
-- Two modes:
--  Entity:  {{#invoke:GameData|get_prop|ENTITY_NAME|PROPERTY|VARIANT}}
--  Entity:  {{#invoke:GameData|get_prop|ENTITY_NAME|PROPERTY}}
--            Finds entity via ResourceLookup, returns the raw value (no
--            Finds entity via ResourceLookup, returns the raw value (no
--            formatting). Supports dot notation for nested properties
--            formatting). Supports dot notation for nested properties
--            (e.g. "Scale.Value"); tables with a .Value field are unwrapped.
--            (e.g. "Scale.Value"); tables with a .Value field are unwrapped.
--            The optional VARIANT selects a game mode variant. "Street Brawl"
--            (case and spacing insensitive) returns the value changed for
--            Street Brawl, falling back to the base value when Street Brawl
--            does not change that property.
--  Convar:  {{#invoke:GameData|get_prop|Convar|CONVAR_NAME}}
--  Convar:  {{#invoke:GameData|get_prop|Convar|CONVAR_NAME}}
--            Looks up the convar in Data:Convars.json and returns its value,
--            Looks up the convar in Data:Convars.json and returns its value,
Line 302: Line 292:
     local arg1 = frame.args[1]
     local arg1 = frame.args[1]
     local arg2 = frame.args[2]
     local arg2 = frame.args[2]
    local arg3 = frame.args[3]
     if not arg1 then return "" end
     if not arg1 then return "" end


Line 321: Line 310:
     if not prop then return "" end
     if not prop then return "" end


     local entity, etype, ekey = find_entity(name)
     local entity, etype = find_entity(name)
     if not entity then
     if not entity then
         return '<span style="color:red;">Entity not found: ' .. name .. '</span>'
         return '<span style="color:red;">Entity not found: ' .. name .. '</span>'
    end
    -- Street Brawl changes a handful of ability properties. The overlay lists
    -- only what changed, so a miss here just means "unchanged" and the base
    -- record answers instead. That includes the empty string resolve_prop
    -- returns for a table with no Value field: the overlay records are partial,
    -- so an overridden table often holds nothing but a nested Scale.
    if arg3 and arg3 ~= "" then
        local mode = mw.ustring.lower(mw.text.trim(arg3))
        mode = mode:gsub("%s+", "")
        if mode ~= "streetbrawl" then
            return '<span style="color:red;">Unknown variant: ' .. arg3 .. '</span>'
        end
        if etype == "ability" then
            local changed = mw.loadJsonData(STREET_BRAWL)["ability-changes"][ekey]
            if changed then
                local value = resolve_prop(changed, prop)
                if value ~= nil and value ~= "" then return value end
            end
        end
     end
     end


Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Page included on this page: