Module:Mapcheck: Difference between revisions

From Heroes 3 wiki
Jump to navigation Jump to search
(Created page with "local p = {} --p stands for package function p.mapcheck(frame) compile = '' for _, filetype in pairs({'png', 'gif', 'jpg'}) do for _, filesize in pairs({'tiny', 'small', 'medium', 'large', 'huge'}) do for _, filelevel in pairs({' ', ' underground '}) do filename = frame.args.scenario..filelevel..'map '..filesize..'.'..filetype fileresult = frame:expandTemplate{title = 'exist', args = {'file:'..filename, 'yes'}} if fileresult == 'yes' then compile...")
 
No edit summary
 
(45 intermediate revisions by the same user not shown)
Line 2: Line 2:


function p.mapcheck(frame)
function p.mapcheck(frame)
if not frame:expandTemplate{title = 'project:EnabledTabs'} == 'true' then
return ''
end
if mw.title.getCurrentTitle().text:find('Maps/') then
return previewOnly(frame)
end
if mw.title.getCurrentTitle().text == 'Minimaps' then
return previewMinimapOnly(frame)
end
maplink = ''
if frame.args.map_link then
maplink = frame.args.map_link..'|'
end
imagelink = frame.args.name
if frame.args.imagelink then
imagelink = frame.args.imagelink
end
mapsize = ''
if frame.args.size then
mapsize = ' ('..frame.args.size..')'
end
compile = ''
compile = ''
for _, filetype in pairs({'png', 'gif', 'jpg'}) do
none = '**'
for _, filesize in pairs({'tiny', 'small', 'medium', 'large', 'huge'}) do
none_u = ''
for _, filelevel in pairs({' ', ' underground '}) do
filelevels = {' '}
filename = frame.args.scenario..filelevel..'map '..filesize..'.'..filetype
if not frame.args.underground or frame.args.underground == 'enabled' or frame.args.underground == '' then
fileresult = frame:expandTemplate{title = 'exist', args = {'file:'..filename, 'yes'}}
table.insert(filelevels, ' underground ')
if fileresult == 'yes' then
none_u = '**'
compile = compile..filename..' : '..getDimensions(filename)..'<br>'
end
for _, filelevel in pairs(filelevels) do
for _, filesize in pairs({'tiny', 'small', 'medium', 'large', 'huge', 'auto', 'fullauto'}) do
for _, filetype in pairs({'png', 'gif', 'jpg'}) do
filename = imagelink..filelevel..'map '..filesize..'.'..filetype
filename = string.gsub(filename, ' ', '_')
fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..filename, 'yes'}}
underground = ''
if filelevel == ' underground ' then
underground = '(u)'
end
if fileexists == 'yes' then
if filelevel == ' underground ' then
underground = '(u)'
none_u = ''
else
none = ''
end
-- dimensions = getDimensions(filename)
dimensions = 'view'
compile = compile..'[[:file:'..filename..'|'..filesize..underground..'('..dimensions..')'..']], '
elseif filetype == 'png' then
compile = compile..frame:expandTemplate{title='extLink', args={link=mw.site.server..'index.php?title=Special:Upload&wpDestFile='..filename, title=filesize..underground}}..', '
end
end
end
end
end
end
end
end
if compile == '' then
compile = mw.ustring.sub(compile, 0, string.len(compile)-2)
compile = frame.args.scenario..' : none <br>'
compile = '[['..maplink..frame.args.name..']]'..mapsize..none..none_u..': '..compile
return compile
end
 
function previewOnly(frame)
imagelink = frame.args.name
if frame.args.imagelink then
imagelink = frame.args.imagelink
end
compile = ''
filelevels = {' '}
if not frame.args.underground or frame.args.underground == 'enabled' or frame.args.underground == '' then
table.insert(filelevels, ' underground ')
end
for _, filelevel in pairs(filelevels) do
for _, filesize in pairs({'tiny', 'small', 'medium', 'large', 'huge', 'auto', 'fullauto'}) do
for _, filetype in pairs({'png', 'gif', 'jpg'}) do
filename = imagelink..filelevel..'map '..filesize..'.'..filetype
filename = string.gsub(filename, ' ', '_')
fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..filename, 'yes'}}
if fileexists == 'yes' then
compile = compile..'[[file:'..filename..'|'..'66px'..']]'
end
end
end
end
return compile
end
 
function previewMinimapOnly(frame)
imagelink = frame.args.name
if frame.args.imagelink then
imagelink = frame.args.imagelink
end
compile = ''
filelevels = {' '}
if not frame.args.underground or frame.args.underground == 'enabled' or frame.args.underground == '' then
table.insert(filelevels, ' underground ')
end
for _, filelevel in pairs(filelevels) do
for _, filetype in pairs({'png', 'gif', 'jpg'}) do
filename = imagelink..filelevel..'minimap.'..filetype
filename = string.gsub(filename, ' ', '_')
fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..filename, 'yes'}}
if fileexists == 'yes' then
compile = compile..'[[file:'..filename..'|'..'66px'..']]'
end
end
end
end
return compile
return compile
Line 24: Line 114:
-- if map.file.width then
-- if map.file.width then
-- if map.file.height then
-- if map.file.height then
     return map.file.height..'x'..map.file.width
     return map.file.width..'x'..map.file.height
-- end
-- end
-- end
-- end

Latest revision as of 09:06, 4 September 2024

Usage[edit | hide]

{{#invoke:mapcheck|mapcheck|name=A New Day Tomorrow}}

local p = {} --p stands for package

function p.mapcheck(frame)
	if not frame:expandTemplate{title = 'project:EnabledTabs'} == 'true' then
		return ''
	end
	if mw.title.getCurrentTitle().text:find('Maps/') then
		return previewOnly(frame)
	end
	if mw.title.getCurrentTitle().text == 'Minimaps' then
		return previewMinimapOnly(frame)
	end
	maplink = ''
	if frame.args.map_link then
		maplink = frame.args.map_link..'|'
	end
	imagelink = frame.args.name
	if frame.args.imagelink then
		imagelink = frame.args.imagelink
	end
	mapsize = ''
	if frame.args.size then
		mapsize = ' ('..frame.args.size..')'
	end
	compile = ''
	none = '**'
	none_u = ''
	filelevels = {' '}
	if not frame.args.underground or frame.args.underground == 'enabled' or frame.args.underground == '' then
		table.insert(filelevels, ' underground ')
		none_u = '**'
	end
	for _, filelevel in pairs(filelevels) do
		for _, filesize in pairs({'tiny', 'small', 'medium', 'large', 'huge', 'auto', 'fullauto'}) do
			for _, filetype in pairs({'png', 'gif', 'jpg'}) do
				filename = imagelink..filelevel..'map '..filesize..'.'..filetype
				filename = string.gsub(filename, ' ', '_')
				fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..filename, 'yes'}}
				underground = ''
				if filelevel == ' underground ' then
					underground = '(u)'
				end
				if fileexists == 'yes' then
					if filelevel == ' underground ' then
						underground = '(u)'
						none_u = ''
					else
						none = ''
					end
					-- dimensions = getDimensions(filename)
					dimensions = 'view'
					compile = compile..'[[:file:'..filename..'|'..filesize..underground..'('..dimensions..')'..']], '
				elseif filetype == 'png' then
					compile = compile..frame:expandTemplate{title='extLink', args={link=mw.site.server..'index.php?title=Special:Upload&wpDestFile='..filename, title=filesize..underground}}..', '
				end
			end
		end
	end
	compile = mw.ustring.sub(compile, 0, string.len(compile)-2)
	compile = '[['..maplink..frame.args.name..']]'..mapsize..none..none_u..': '..compile
	return compile
end

function previewOnly(frame)
	imagelink = frame.args.name
	if frame.args.imagelink then
		imagelink = frame.args.imagelink
	end
	compile = ''
	filelevels = {' '}
	if not frame.args.underground or frame.args.underground == 'enabled' or frame.args.underground == '' then
		table.insert(filelevels, ' underground ')
	end
	for _, filelevel in pairs(filelevels) do
		for _, filesize in pairs({'tiny', 'small', 'medium', 'large', 'huge', 'auto', 'fullauto'}) do
			for _, filetype in pairs({'png', 'gif', 'jpg'}) do
				filename = imagelink..filelevel..'map '..filesize..'.'..filetype
				filename = string.gsub(filename, ' ', '_')
				fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..filename, 'yes'}}
				if fileexists == 'yes' then
					compile = compile..'[[file:'..filename..'|'..'66px'..']]'
				end
			end
		end
	end
	return compile	
end

function previewMinimapOnly(frame)
	imagelink = frame.args.name
	if frame.args.imagelink then
		imagelink = frame.args.imagelink
	end
	compile = ''
	filelevels = {' '}
	if not frame.args.underground or frame.args.underground == 'enabled' or frame.args.underground == '' then
		table.insert(filelevels, ' underground ')
	end
	for _, filelevel in pairs(filelevels) do
		for _, filetype in pairs({'png', 'gif', 'jpg'}) do
			filename = imagelink..filelevel..'minimap.'..filetype
			filename = string.gsub(filename, ' ', '_')
			fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..filename, 'yes'}}
			if fileexists == 'yes' then
				compile = compile..'[[file:'..filename..'|'..'66px'..']]'
			end
		end
	end
	return compile
end

function getDimensions(filename)
	map = mw.title.makeTitle(6, filename)
	-- if map.file.width then
		-- if map.file.height then
    		return map.file.width..'x'..map.file.height
		-- end
	-- end
	-- return ''
end

return p