Module:NFSWCar

local p, _data = {}, mw.loadData("Module:NFSWCar/data")

do local metamethods = getmetatable(mw.html.create("T")).__index metamethods.addnodes = function(self, ...) if self.selfClosing then error("Self-closing tags can't have child nodes") end local nodes = self.nodes local nodecount = #nodes for i=1,#arg do			if arg[i] ~= nil then nodecount = nodecount + 1 nodes[nodecount]=arg[i] end end return self end metamethods.title = function(self, title) if type(title) ~= "string" then error("Invalid title given: The title must be a string") end local attributes = self.attributes attributes[#attributes+1] = { name = "title", val = title } return self end end

local function splitperfpartname(name) local raritylist = {"improved", "sport", "tuned", "custom", "ultimate"}

for i=1,#raritylist do 		local make, hit = name:gsub(raritylist[i].."$", "") if hit == 1 then return make, i end end return name, 1 end

local function car_perfpart(name, type) local parttype = _data.perfparts._partlist[type]

if name then local _make, rarity = splitperfpartname(name) local make = _data.perfparts[_make] local part, partstats = make[parttype[2]], make[parttype[2]][rarity]

if make and part and partstats then local rarity = _data.perfparts._raritylist[rarity]

return mw.html.create("div") :addClass("world-cardata-part custom-tooltip-worldcarpart") :attr({					["data-type"]="perfpart",					["data-image"]=make.image,					["data-title"]=make.make,					["data-desc"]=rarity[1].." "..parttype[1],					["data-accent"]=rarity[2],					["data-stars"]=make.stars,					["data-topspeed"]=partstats[1],					["data-acceleration"]=partstats[2],					["data-handling"]=partstats[3] }) :wikitext(" "..parttype[1]..": "..make.make.." ("..rarity[1]..")") end end return ' '..parttype[1]..': Stock ' end

local function car_aftermarketpart(name, type) local parttype = _data.aftermarketparts._partlist[type]

if name then local part = _data.aftermarketparts[parttype[2]][name] if part then local fallback = _data.aftermarketparts[parttype[2]]._default

return mw.html.create("div") :addClass("world-cardata-part custom-tooltip-worldcarpart") :attr({					["data-image"]=part.image or fallback.image,					["data-title"]=part.name or fallback.name,					["data-desc"]=part.description or fallback.description}) :wikitext(" "..parttype[1]..": "..(part.name or fallback.name).." "..(part.description or fallback.description)) end end

return ''..parttype[1]..": "..parttype[4]..' ' end

local function car_skillmod(name, slot) if name then local _skill, level = name:match("^(%a+)(%d)$") local skill = _data.skillmods[_skill or name]

if skill then if slot == 0 then return mw.html.create("div") :addClass("world-cardata-part") :attr({					["data-image"]=skill.image,					["data-title"]=skill.name,					["data-desc"]=skill.desc,					["data-accent"]=skill.accent}) :wikitext(" Special Slot: "..skill.name) else return mw.html.create("div") :addClass("world-cardata-part custom-tooltip-worldcarpart") :attr({					["data-type"]="skillmod",					["data-image"]=skill.image,					["data-title"]=skill.name,					["data-desc"]=skill.desc,					["data-accent"]=skill.accent,					["data-stars"]=level,					["data-value"]=skill.levels[tonumber(level)]}) :wikitext(" Slot "..slot..": "..skill.name.." ("..level.." Star Rating)") end end end

return slot ~= 0 and ' Slot '..slot..': None ' end

function p.perfpartstable local data, table = _data.perfparts, mw.html.create("table"):addClass("world world-perfparts"):css("width", "100%")

do local thead1 = table:tag("tr"):wikitext(' ') local thead2 = table:tag("tr") local thead_stats = '   '

for i=1,5 do 			thead1:wikitext(''..data._raritylist[i][1]..' ') thead2.nodes[i] = thead_stats end end

local makelist = {"amerikon", "dawndraft", "nova", "omnia", "royal", "gromlen", "kestrel", "richter", "norset", "medion", "velocicom", "ventura", "ursa", "transtek", "zero", "attack", "speedsciens", "quartz", "stick", "tear", "dynamo"} local partlist = {"engines", "forcedinductions", "transmissions", "suspensions", "brakes", "tyres"} for i=1,#makelist do		local make = data[makelist[i]]

for i2=1,#partlist do			local parts = make[partlist[i2]] if parts then local row = table:tag("tr") row:wikitext(' ')

for i3=1,5 do					local part = parts[i3] if part then for i4=1,3 do							local stat = part[i4] if stat ~= 0 then row:wikitext('0% ') else row:wikitext(" 0% ") end end else row:wikitext("  ") end end end end end

return tostring(table) end

function p.car(f) local cardata = mw.html.create("div"):addClass("world-cardata"):wikitext("")

do local field = cardata:tag("div"):addClass("world-cardata-class") field:tag("b"):addClass("world-cardata-stathead"):wikitext("Car Class: ") if tonumber(f.args.ao) then for i, class in pairs(_data.carclasses) do				if tonumber(f.args.ao) < class[4] then field:title(class[1]):css("color", class[3]):wikitext(" "..f.args.ao) break end end else field:title("Unknown Class"):wikitext(" ???") end end

if f.args.type then local style = _data.carstyles[f.args.type] if style then cardata:wikitext(' Style: ') end end if f.args.extra then local field = cardata:tag("div"):addClass("world-cardata-mod") local mod = _data.carmods[f.args.type] if mod then cardata:tag("div"):addClass("world-cardata-mod"):title(mod[2]) :tag("span"):addClass("world-cardata-stathead"):wikitext("Mod: "):done :wikitext(" "..mod[2]) end end

cardata:wikitext(' Top Speed Rating: '..(f.args.ts or 0)..' ') cardata:wikitext(' Acceleration Rating: '..(f.args.acl or 0)..' ') cardata:wikitext(' Handling Rating: '..(f.args.hnd or 0)..' ')

if f.args.price1 then local formataward = function(a1, a2) return (a1 and " " or "")..""..(a2 or "Achievement Reward").."" end local format = { award = { "world-cardata-cost-award", function return "Award" end }, awardcollect = { "world-cardata-cost-awardcollect", formataward }, awardcomp = { "world-cardata-cost-awardcomp", formataward }, awardcustom = { "world-cardata-cost-awardcustom", formataward }, awarddriver = { "world-cardata-cost-awarddriver", formataward }, card = { "world-cardata-cost-card", function return "Car Prize Pack" end }, igc = { "world-cardata-cost-igc", function(a) return ""..(a or "0") end }, pend = { "world-cardata-cost-pend", function return "Pending Release" end }, promo = { "world-cardata-cost-promo", function(a) return a and "Promotional "..a.." " or "Promotional" end }, sb = { "world-cardata-cost-sb", function(a) return ""..(a or "0") end }, ur = { "world-cardata-cost-ur", function return "Unreleased" end }, _default = { "world-cardata-cost-retired", "Retired" } }

cardata:tag("div"):addClass("world-cardata-cost "..(format[f.args.price1][1] or format._default[1])):wikitext(' Cost: '..format[f.args.price1][2](f.args.price2, f.args.award) or format._default[2]) end

cardata:addnodes(		'Performance Parts ',		car_perfpart(f.args.eng , 1),		car_perfpart(f.args.ind   , 2),		car_perfpart(f.args.tran  , 3),		car_perfpart(f.args.sus   , 4),		car_perfpart(f.args.brakes, 5),		car_perfpart(f.args.tyres , 6),

--placeholder 'Aftermarket Parts ', car_aftermarketpart(f.args.body , 1), car_aftermarketpart(f.args.spoiler, 7), car_aftermarketpart(f.args.hood , 2), car_aftermarketpart(f.args.wheel, 6), car_aftermarketpart(f.args.neon , 5), car_aftermarketpart(f.args.glass, 8), car_aftermarketpart(f.args.lower, 4), car_aftermarketpart(f.args.plate, 3), 'Skill Mods ', car_skillmod(f.args.ms, 0), car_skillmod(f.args.m1, 1), car_skillmod(f.args.m2, 2), car_skillmod(f.args.m3, 3), car_skillmod(f.args.m4, 4), car_skillmod(f.args.m5, 5))

return tostring(cardata) end

function p.tooltip(f) local tooltip = mw.html.create("div"):addClass("world-cardata-tooltip")

tooltip:wikitext("") local tt_name = tooltip:tag("div"):wikitext(f.args.name) local tt_desc

if f.args.desc then tt_name:wikitext(" ") tt_desc = tt_name:tag("small"):wikitext(f.args.desc) end

if f.args.type == "perfpart" then tooltip:addClass("world-cardata-tooltip-ext")

if f.args.accent then tt_desc:css("color", f.args.accent) end

local tt_stars = tooltip:tag("div") if f.args.stars then for i=1,f.args.stars do tt_stars:wikitext("") end end

local tt_stats = tooltip:tag("div") if f.args.topspeed then local stat = tt_stats:tag("span"):wikitext(" "..f.args.topspeed.."%") if f.args.topspeed ~= 0 then stat:css("color", "#B5FF33") end end if f.args.acceleration then local stat = tt_stats:tag("span"):wikitext(" "..f.args.acceleration.."%") if f.args.acceleration ~= 0 then stat:css("color", "#B5FF33") end end if f.args.handling then local stat = tt_stats:tag("span"):wikitext(" "..f.args.handling.."%") if f.args.handling ~= 0 then stat:css("color", "#B5FF33") end end elseif f.args.type == "skillmod" then tooltip:addClass("world-cardata-tooltip-ext")

if f.args.accent then tt_name:css("color", f.args.accent) end local tt_stars = tooltip:tag("div") if f.args.stars then for i=1,f.args.stars do tt_stars:wikitext("") end end

local tt_stats = tooltip:tag("div") if f.args.value then tt_stats:wikitext(f.args.value) end if f.args.accent then tt_name:css("color", f.args.accent) tt_stats:css("color", f.args.accent) end end

return tostring(tooltip) end

return p