Module:Mapcheck: Difference between revisions

From Heroes 3 wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
return ''
return ''
end
end
-- if mw.title.getCurrentTitle() == 'Maps' then
if mw.title.getCurrentTitle() == 'Maps' then
if true then
return 'bananananananana'
return mw.title.getCurrentTitle()
end
end
maplink = ''
maplink = ''

Revision as of 21:52, 5 January 2024

Usage

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

local p = {} --p stands for package

function p.mapcheck(frame)
	if not mw.site.server:find('heroes.thelazy.net') then
		return ''
	end
	if mw.title.getCurrentTitle() == 'Maps' then
		return 'bananananananana'
	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'}) 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='https://heroes.thelazy.net/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 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