Module:Illustration: Difference between revisions

From Terra Invicta Official Wiki
Llamageddon (talk | contribs)
mNo edit summary
Llamageddon (talk | contribs)
mNo edit summary
 
(23 intermediate revisions by the same user not shown)
Line 14: Line 14:
-- Currently just trying to get this to output all entries for a key into a readable string, to test the basics work.
-- Currently just trying to get this to output all entries for a key into a readable string, to test the basics work.
function p.Illusnametest (frame)
function p.Illusnametest (frame)
-- This just checks matching dataName. More useful within other modules/templates.
-- Next function planned will convert displayName to dataName first. More useful for humans.
local illusdataName = frame.args[1]
local illusdataName = frame.args[1]
-- Check input makes sense
-- Check input makes sense
Line 31: Line 29:
end
end
if illusdataName[illusData] then
local returnString = 'Illustrations: '
-- Am just infering that "j" counts entries for a key (no idea about correct syntax here really).
if illusData[illusdataName] then
local Illustrations = {}
        for j, file in ipairs(illusData[illusdataName]) do
            if file ~= '' then
                tinsert(Illustrations, file)
            end
        end
    returnString = returnString .. tconcat( Illustrations, ' , ')
        returnString = returnString .. '<br />Did this work?'
end
    return returnString
end
 
-- This will output illustrations as file links, horizontally.
function p.Illus (frame)
local illusdataName = frame.args[1]
-- Check input makes sense
if not illusdataName then
return 'No illustration data name specified.'
end
if not illusData[illusdataName] then
illusdataName = slower(illusdataName)
end
if not illusData[illusdataName] then
illusdataName = mw.text.trim(illusdataName)
end
if not illusData[illusdataName] then
return 'Data name not recognized.'
end
local returnString = '[[File:'
if illusData[illusdataName] then
local Illustrations = {}
local Illustrations = {}
for j = 0, 5 do
        for j, file in ipairs(illusData[illusdataName]) do
local illusFile = {}
            if file ~= '' then
if illusData[illusdataName][j] and illusData[illusdataName][j] ~= '' then
                tinsert(Illustrations, file)
tinsert(Illustrations,illusData[illusFile][j])
            end
end
        end
    returnString = returnString .. tconcat( Illustrations, '|256px]] [[File:')
        returnString = returnString .. '|256px]]'
end
    return returnString
end
 
-- This will return just the illustration file name(s) as strings with a new line between multiple entries
-- Mainly intended for quickly adding images to galleries (until better functionality added, anyway)
function p.Illuslist (frame)
local illusdataName = frame.args[1]
if not illusdataName then
return 'No illustration data name specified.'
end
if not illusData[illusdataName] then
illusdataName = slower(illusdataName)
end
if not illusData[illusdataName] then
illusdataName = mw.text.trim(illusdataName)
end
if not illusData[illusdataName] then
return 'Data name not recognized.'
end
local returnString = ''
if illusData[illusdataName] then
local Illustrations = {}
        for j, file in ipairs(illusData[illusdataName]) do
            if file ~= '' then
                tinsert(Illustrations, file)
            end
        end
    returnString = returnString .. tconcat( Illustrations, '<br />')
end
    return returnString
end
 
-- Test function trying to create and use dynamic variables
function p.IllusCountTest (frame)
local illusdataName = frame.args[1]
if not illusdataName then
return 'No illustration data name specified.'
end
if not illusData[illusdataName] then
illusdataName = slower(illusdataName)
end
if not illusData[illusdataName] then
illusdataName = mw.text.trim(illusdataName)
end
if not illusData[illusdataName] then
return 'Data name not recognized.'
end
local returnString = ''
if illusData[illusdataName] then
local illusCount = #illusData[illusdataName]
-- count entries and create variable for each one
for i, value in ipairs(myArray) do
-- Not sure how to do this with local variables...
            _G["illusNum_" .. i] = value
end
end
-- Emulated this from NationLister and hoping it will just work with the table formatting stripped...
   
local returnString = 'Illustrations: '
local Illustrations = {}
returnString = returnString .. tconcat(Illustrations, ' , ')
        for j, file in ipairs(illusData[illusdataName]) do
returnString = returnString .. 'Did this work?'
            if file ~= '' then
return returnString
                tinsert(Illustrations, file)
            end
        end
    returnString = returnString .. tconcat( Illustrations, '<br />')
end
end
    return returnString
end
end


return p
return p

Latest revision as of 20:43, 9 December 2025

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

-- This is meant to be a way to reference and use the illustrations in the game easily on the wiki and inside other templates.
-- No idea what I'm doing really, and need a break, so just leaving whatever this is here for now.

local p = {}

-- Almost 1500 lines, probably want to split into categories for more specific functions to use efficiently?
local illusData = mw.loadData('Module:Illustration/data')
-- Syntax borrowed from modules this one is emulating.
-- Commenting out for use later ##local ssub = string.sub
local tinsert = table.insert
local tconcat = table.concat
local slower = string.lower

-- Currently just trying to get this to output all entries for a key into a readable string, to test the basics work.
function p.Illusnametest (frame)
	local illusdataName = frame.args[1]
	-- Check input makes sense
	if not illusdataName then
		return 'No illustration data name specified.'	
	end
	if not illusData[illusdataName] then
		illusdataName = slower(illusdataName)	
	end
	if not illusData[illusdataName] then
		illusdataName = mw.text.trim(illusdataName)	
	end
	if not illusData[illusdataName] then
		return 'Data name not recognized.'	
	end
	
	local returnString = 'Illustrations: '
	if illusData[illusdataName] then
		local Illustrations = {}
        for j, file in ipairs(illusData[illusdataName]) do
            if file ~= '' then
                tinsert(Illustrations, file)
            end
        end
	    returnString = returnString .. tconcat( Illustrations, ' , ')
        returnString = returnString .. '<br />Did this work?'
	end
    return returnString
end

-- This will output illustrations as file links, horizontally.
function p.Illus (frame)
	local illusdataName = frame.args[1]
	-- Check input makes sense
	if not illusdataName then
		return 'No illustration data name specified.'	
	end
	if not illusData[illusdataName] then
		illusdataName = slower(illusdataName)	
	end
	if not illusData[illusdataName] then
		illusdataName = mw.text.trim(illusdataName)	
	end
	if not illusData[illusdataName] then
		return 'Data name not recognized.'	
	end
	
	local returnString = '[[File:'
	if illusData[illusdataName] then
		local Illustrations = {}
        for j, file in ipairs(illusData[illusdataName]) do
            if file ~= '' then
                tinsert(Illustrations, file)
            end
        end
	    returnString = returnString .. tconcat( Illustrations, '|256px]] [[File:')
        returnString = returnString .. '|256px]]'
	end
    return returnString
end

-- This will return just the illustration file name(s) as strings with a new line between multiple entries
-- Mainly intended for quickly adding images to galleries (until better functionality added, anyway)
function p.Illuslist (frame)
	local illusdataName = frame.args[1]
	if not illusdataName then
		return 'No illustration data name specified.'	
	end
	if not illusData[illusdataName] then
		illusdataName = slower(illusdataName)	
	end
	if not illusData[illusdataName] then
		illusdataName = mw.text.trim(illusdataName)	
	end
	if not illusData[illusdataName] then
		return 'Data name not recognized.'	
	end
	
	local returnString = ''
	if illusData[illusdataName] then
		local Illustrations = {}
        for j, file in ipairs(illusData[illusdataName]) do
            if file ~= '' then
                tinsert(Illustrations, file)
            end
        end
	    returnString = returnString .. tconcat( Illustrations, '<br />')
	end
    return returnString
end

-- Test function trying to create and use dynamic variables
function p.IllusCountTest (frame)
	local illusdataName = frame.args[1]
	if not illusdataName then
		return 'No illustration data name specified.'	
	end
	if not illusData[illusdataName] then
		illusdataName = slower(illusdataName)	
	end
	if not illusData[illusdataName] then
		illusdataName = mw.text.trim(illusdataName)	
	end
	if not illusData[illusdataName] then
		return 'Data name not recognized.'	
	end
	
	local returnString = ''
	if illusData[illusdataName] then
		local illusCount = #illusData[illusdataName]
		-- count entries and create variable for each one
		for i, value in ipairs(myArray) do
			-- Not sure how to do this with local variables...
            _G["illusNum_" .. i] = value
		end
    
		local Illustrations = {}
        for j, file in ipairs(illusData[illusdataName]) do
            if file ~= '' then
                tinsert(Illustrations, file)
            end
        end
	    returnString = returnString .. tconcat( Illustrations, '<br />')
	end
    return returnString
end

return p