Module:Compatibility status counter PS1

From PS3 Developer wiki
Revision as of 20:11, 25 January 2025 by Derf (talk | contribs) (WIP)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Compatibility status counter PS1/doc

-- This module counts table rows in wikitext 

local p = {}
local getArgs

function p.main(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	return p._main(getArgs(frame, {wrappers = 'Template:Table row counter'}))
end

function p._main(args)
	-- Get the title object
	local titleObj
	do
		local success
		success, titleObj = pcall(mw.title.new, args.page)
		if not success or not titleObj then
			titleObj = mw.title.getCurrentTitle()
		end
	end

	-- Get the page content
	local content = titleObj:getContent()
	if not content then
		return nil
	end

	-- Find the wikitables on that page
	local wikitables = {}
	do
		local iWikitable = 0
		local s1 = content:match('^({|.-\n|})')
		if s1 then
			iWikitable = iWikitable + 1
			wikitables[iWikitable] = s1
		end
		for s in content:gmatch('\n({|.-\n|})') do
			iWikitable = iWikitable + 1
			wikitables[iWikitable] = s
		end
	end

    local totalcount = 0
    local officialcount = 0
    local unplayablecount = 0
    local majorcount = 0
    local minorcount = 0
    local playablecount = 0

    -- Iterate all tables on the calling page
    for i, wikitable in ipairs(wikitables) do
        -- Count rows depending on playable status
        for row in wikitable:gmatch("|%-%s*\n(.-)\n") do
            row = string.lower(row)
            totalcount = totalcount + 1
            if row:find('{{ps1classic}}') then
                officialcount = officialcount + 1
            elseif row:find('<center>PS1 Classics</center>') then
                officialcount = officialcount + 1
            elseif row:find('{{unplayable}}') then
                unplayablecount = unplayablecount + 1
            elseif row:find('{{majorissues}}') then
                majorcount = majorcount + 1
            elseif row:find('{{minorissues}}') then
                minorcount = minorcount  + 1
            elseif row:find('{{playable}}') then
                playablecount = playablecount + 1
            else
                totalcount = totalcount - 1
            end
        end
    end

    return '<span class="compatibility-tag" style=" background:#ddd; color:#888; display:inline-block; width:8.4em; line-height:1.3em; border-radius:0.4em; box-shadow: 2px 4px 6px hsla(0,0%,99%,.3)inset, -2px -4px 6px rgba(0,0,0,.2)inset, 1px 1px 2px rgba(0,0,0,.4); border: 1px rgba(127,127,127,.5)outset " title="Total of all games on this page.">Total</span> = ' .. totalcount .. '&nbsp;&nbsp;<span class="compatibility-tag" style="background:#08e; color:#fff; display:inline-block; width:8.4em; line-height:1.3em; border-radius:0.4em; box-shadow: 2px 4px 6px hsla(0,0%,99%,.3)inset, -2px -4px 6px rgba(0,0,0,.3)inset, 1px 1px 2px rgba(0,0,0,.4); border:  1px rgba(127,127,127,.5)outset" title="{{tagtexts|ps1classic}}">PS1 Classic</span> = ' .. officialcount .. '&nbsp;&nbsp;<span class="compatibility-tag" style="background:#9d9; color:#05b; display:inline-block; width:8.4em; line-height:1.3em; border-radius:0.4em; box-shadow: 2px 4px 6px hsla(0,0%,99%,.5)inset, -2px -4px 6px rgba(0,0,0,.2)inset, 1px 1px 2px rgba(0,0,0,.4); border: 1px rgba(127,127,127,.5)outset " title="{{tagtexts|playable}}" > Playable </span> = ' .. playablecount .. '&nbsp;&nbsp;<span class="compatibility-tag" style="background:#ee8; color:#05b; display:inline-block; width:8.4em; line-height:1.3em; border-radius:0.4em; box-shadow: 2px 4px 6px hsla(0,0%,99%,.5)inset, -2px -4px 6px rgba(0,0,0,.2)inset, 1px 1px 2px rgba(0,0,0,.4); border: 1px rgba(127,127,127,.5)outset "title="{{tagtexts|minorissues}}">Minor Issues</span> = ' .. minorcount .. '&nbsp;&nbsp;<span class="compatibility-tag" style="background:#e93; color:#722; display:inline-block; width:8.4em; line-height:1.3em; border-radius:0.4em; box-shadow: 2px 4px 6px hsla(0,0%,99%,.5)inset, -2px -4px 6px rgba(0,0,0,.2)inset, 1px 1px 2px rgba(0,0,0,.4); border: 1px rgba(127,127,127,.5)outset" title="{{tagtexts|majorissues}}">Major Issues</span> = ' .. majorcount  .. '&nbsp;&nbsp;<span class="compatibility-tag" style="background:#e44; color:#722; display:inline-block; width:8.4em; line-height:1.3em; border-radius:0.4em; box-shadow: 2px 4px 6px hsla(0,0%,99%,.5)inset, -2px -4px 6px rgba(0,0,0,.2)inset, 1px 1px 2px rgba(0,0,0,.4); border: 1px rgba(127,127,127,.5)outset "title="{{tagtexts|unplayable}}">Unplayable</span> = ' .. unplayablecount

end

return p