×
Create a new article
Write your page title here:
We currently have 22 articles on The Grand Library of Hylia. Type your article name above or click on one of the titles below and start writing!



The Grand Library of Hylia

Module:TextToZonaiRunes: Difference between revisions

No edit summary
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo
local function starts_with(str, start)
    return str:sub(1, #start) == start
end


function p.textToZonaiRunes(frame)
function p.textToZonaiRunes(frame)
Line 6: Line 10:
     local args = getArgs(frame);
     local args = getArgs(frame);
     local phrase = args[1]
     local phrase = args[1]
    local mode = args[2]
    local tableName = "ZonaiRunes"
    if mode ~= nil and mode == "dark" then
        tableName = "ZonaiRunesWhite"
    end
    if phrase == nil or phrase == "" then
        return ""
    end
    if (starts_with(phrase, "{{{")) then
        return ""
    end


     local result = ""
     local result = ""
     for i = 1, #phrase do
     for i = 1, #phrase do
         local c = phrase:sub(i,i)
         local c = phrase:sub(i,i)
         local queryFields = 'cipherCharacter=cipherCharacter,imageName=imageName'
         if c == " " then
        local args = {
            result = result .. c
            where = string.format('ZonaiRunes.cipherCharacter="%s"', c),
        else
            format = 'table',
            local queryFields = 'cipherCharacter=cipherCharacter,imageName=imageName'
            limit = 1
            local args = {
        }
                where = string.format('%s.cipherCharacter="%s"', tableName, c),
        local items = cargo.query("ZonaiRunes", queryFields, args)
                format = 'table',
        for r = 1, #items do
                limit = 1
            local item = items[r]
            }
            result = result .. string.format("[[File:%s]]", item.imageName)
            local items = cargo.query(tableName, queryFields, args)
            for r = 1, #items do
                local item = items[r]
                result = result .. string.format("[[File:%s|75px]]", item.imageName)
            end
         end
         end
     end
     end

Latest revision as of 07:59, 12 January 2024

Documentation for this module may be created at Module:TextToZonaiRunes/doc

local p = {}
local cargo = mw.ext.cargo

local function starts_with(str, start)
    return str:sub(1, #start) == start
end

function p.textToZonaiRunes(frame)
    local getArgs = require('Module:Arguments').getArgs
    local args = getArgs(frame);
    local phrase = args[1]
    local mode = args[2]
    local tableName = "ZonaiRunes"

    if mode ~= nil and mode == "dark" then
        tableName = "ZonaiRunesWhite"
    end
    if phrase == nil or phrase == "" then
        return ""
    end
    if (starts_with(phrase, "{{{")) then
        return ""
    end

    local result = ""
    for i = 1, #phrase do
        local c = phrase:sub(i,i)
        if c == " " then
            result = result .. c
        else
            local queryFields = 'cipherCharacter=cipherCharacter,imageName=imageName'
            local args = {
                where = string.format('%s.cipherCharacter="%s"', tableName, c),
                format = 'table',
                limit = 1
            }
            local items = cargo.query(tableName, queryFields, args)
            for r = 1, #items do
                local item = items[r]
                result = result .. string.format("[[File:%s|75px]]", item.imageName)
            end
        end
    end

    return result
end

return p