Developer Assistant

by plexpt

A mod to assist developers with debugging and testing. View entity information. Demonstrates all GUI element types

Utilities
28 days ago
2.0
108

i textboxes instead of labels

a month ago

Could you use text fields instead of labels? Then we could copy the names directly. That would be helpful.

a month ago

updated

a month ago

Can the prototype of each entity be transferred from the data stage to the runtime stage for use? I am a little confused.

a month ago

yes. use global prototypes. see https://lua-api.factorio.com/latest/classes/LuaPrototypes.html
or what do you mean?
but if you want the data.raw 1:1 then it is more complex and time consuming. see my mod https://mods.factorio.com/mod/Kux-RawDataProvider

a month ago

Thank you, can I use your code?

a month ago

Excerpts yes, but don't copy them completely and make your own mod out of them!
But i still use a old technique
there is a new technique for data transfer, see
https://mods.factorio.com/mod/big-data-string

a month ago

But I see this was updated 3 years ago

a month ago
(updated a month ago)

it's not about the mod, but about the technology how to transfer the data ;-)
here is was I have extracted (but not yet used)

---@class KuxCoreLib.BigData
local BigData ={
    __class  = "BigData",
    __origin = "Kux-CoreLib/lib/data/BigData.lua",
}


local MAX = 10 * 20 ^ 21 -- 20 parameters * 20 recursion depth
local suffix = "Kux-CoreLib_BigData_"

if(KuxCoreLib.ModInfo.current_stage:match("^data")) then

    local function depth(n)
        return math.ceil(math.log(n / 10) / math.log(20)) - 1
    end

    local function insert(nodes, node, value)
        table.insert(node, value) -- store as parameter
        if 21 == #node then
            node = {""}
            table.insert(nodes, node)
        end
        return node
    end

    local function encode(data)
        local node = {""}
        local root = {node}
        local n = string.len(data)
        for i = 1,n,200 do
            local value = string.sub(data, i, i+199)
            node = insert(root, node, value)
        end
        while #root > 20 do
            local nodes,node = {},{""}
            for _, value in ipairs(root) do
                node = insert(nodes, node, value)
            end
            root = nodes
        end
        if #root == 1 then root = root[1] else
            table.insert(root, 1, "") -- no locale template
        end
        return #root < 3 and (root[2] or "") or root
    end

    function BigData.pack(name, stringdata)
        assert(type(name) == "string", "missing name!")
        assert(type(stringdata) == "string", "not a string!")
        local len = string.len(stringdata)
        assert(len <= MAX, "string too long!")
        if depth(len) > 4 then -- 10*20^(1+4) = 32MB
            log(string.format("WARNING! '%s' exceeds reasonable recursion depth of 4 (32MB). Expect performance degradation!", name))
        end
        data:extend{{
            -- type = "item",
            type = "flying-text", time_to_live = 0, speed = 1, -- reqired for a valid prototype
            name = "Kux-CoreLib_BigData_" .. name,
            icon = "__core__/graphics/empty.png",
            icon_size = 1,
            stack_size = 1,
            -- flags = {"hidden","hide-from-bonus-gui","hide-from-fuel-tooltip"},
            flags = {"hidden"},
            localised_name = string.format("BIGDATA[%s]", name),
            localised_description = encode(stringdata),
            order = "z",
        }}
    end
end

if(KuxCoreLib.ModInfo.current_stage:match("^control")) then

    local function decode(data)
        if type(data) == "string" then return data end
        local str = {}
        for i = 2, #data do
            str[i-1] = decode(data[i])
        end
        return table.concat(str, "")
    end

    function BigData.unpack(name)
        assert(type(name) == "string", "missing name!")
        -- local prototype = assert(game.item_prototypes[suffix ..  name],
        --              string.format("big data '%s' not defined!", name))
        local prototype = assert(prototypes.entity[suffix ..  name],
                        string.format("big data '%s' not defined!", name))
        return decode(prototype.localised_description)
    end

end


---------------------------------------------------------------------------------------------------
return BigData
a month ago

it is work

a month ago

then go ahead. I love developer tools that make my work easier

a month ago

updated

New response