Модуль:Prototypes/Хранилище/Предмет: различия между версиями

мНет описания правки
мНет описания правки
Строка 56: Строка 56:
     local amount = (amountNumber and amountNumber ~= 1) and string.format(" [%d]", amountNumber) or ""
     local amount = (amountNumber and amountNumber ~= 1) and string.format(" [%d]", amountNumber) or ""
      
      
    local prob = ""
local prob = ""
    local probValue = nil
local probValue = nil
    if content.weight then
if content.prob then
        probValue = content.weight / 100
    -- Если значение вероятности указано в формате десятичной дроби (например, 0.5)
    end
    probValue = content.prob * 100  -- перевод в проценты
 
elseif content.weight then
    if probValue then
    probValue = content.weight
        prob = string.format(" <div>%s%%</div>", probValue * 100 >= 1 and math.floor(probValue * 100) or probValue * 100)
end
    end
if probValue then
    prob = string.format(" <div>%s%%</div>", probValue >= 1 and math.floor(probValue) or probValue)
end


     return string.format(
     return string.format(
    -- <span></span> - костыль, без него ломается все почему-то
         '{{#invoke:Предмет|main|%s|%s<span>%s</span>|repository=1|wrapper=1}}',
         '{{#invoke:Предмет|main|%s|%s<span>%s</span>|repository=1|wrapper=1}}',
         id, amount, prob
         id, amount, prob
Строка 376: Строка 380:
             return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}')
             return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}')
         elseif subMode == "slot" then
         elseif subMode == "slot" then
            local itemDataEntry = findDataById(itemSlotsData, id)
local itemDataEntry = findDataById(itemSlotsData, id)
            if not itemDataEntry then return "" end
if not itemDataEntry then return "" end
            local startingItem = nil
local startingItem = nil
            if itemDataEntry.ItemSlots and itemDataEntry.ItemSlots.slots then
if itemDataEntry.ItemSlots and itemDataEntry.ItemSlots.slots then
                for _, slot in ipairs(itemDataEntry.ItemSlots.slots) do
    for _, slot in pairs(itemDataEntry.ItemSlots.slots) do
                    if slot.startingItem and slot.startingItem ~= "" then
        if slot.startingItem and slot.startingItem ~= "" then
                        startingItem = slot.startingItem
            startingItem = slot.startingItem
                        break
            break
                    end
        end
                end
    end
            end
end
            if not startingItem then return "" end
if not startingItem then return "" end
            return frame:preprocess('{{СollapsibleMenu|color=#71702a|' .. formatContent(startingItem) .. '}}')
return frame:preprocess('{{СollapsibleMenu|color=#71702a|' .. formatContent(startingItem) .. '}}')
         elseif subMode == "stack" then
         elseif subMode == "stack" then
             local count = getStackCount(id)
             local count = getStackCount(id)