Changes

no edit summary
Line 2: Line 2:     
local template = {
 
local template = {
top_header = [[{|style="text-align:center"
+
footer = "|}",
 +
header = [[{|style="text-align:center;width:100%"
 
!colspan="5" style="background-color:#3baef5;color:white"|Rewards]],
 
!colspan="5" style="background-color:#3baef5;color:white"|Rewards]],
footer = [[|}]],
+
ship_row = [=[|-
ship = [=[|-
+
!style="background-color:#3baef5;color:white;width:40%%"|Ship
!style="background-color:#3baef5;color:white"|Ship
   
|colspan="4" style="background-color:#eef2f7"|%s<br>[[%s]]]=],
 
|colspan="4" style="background-color:#eef2f7"|%s<br>[[%s]]]=],
header = [[|-
+
item_header = [[{|style="text-align:center;width:100%" class="sortable"
!style="background-color:#3baef5;color:white"|Equipment/Item
+
!style="background-color:#3baef5;color:white;width:40%"|Item/Equipment
!style="background-color:#3baef5;color:white;width:15%"|丁<br>Casual
+
!class="unsortable" style="background-color:#3baef5;color:white;width:15%"|丁<br>Casual
!style="background-color:#3baef5;color:white;width:15%"|丙<br>Easy
+
!class="unsortable" style="background-color:#3baef5;color:white;width:15%"|丙<br>Easy
!style="background-color:#3baef5;color:white;width:15%"|乙<br>Medium
+
!class="unsortable" style="background-color:#3baef5;color:white;width:15%"|乙<br>Medium
!style="background-color:#3baef5;color:white;width:15%"|甲<br>Hard]],
+
!class="unsortable" style="background-color:#3baef5;color:white;width:15%"|甲<br>Hard]],
row = [=[|-
+
item_row = [=[|-
|style="background-color:#eef2f7;font-size:12px"|%s<br>[[%s]]
+
|data-sort-value="%s" style="background-color:#eef2f7;font-size:12px"|%s<br>[[%s]]
 
|style="background-color:#eef2f7;font-size:18px"|%s
 
|style="background-color:#eef2f7;font-size:18px"|%s
 
|style="background-color:#eef2f7;font-size:18px"|%s
 
|style="background-color:#eef2f7;font-size:18px"|%s
Line 52: Line 52:  
end
 
end
 
local function getCount(name, diff)
 
local function getCount(name, diff)
return ((tbl[name] or {})[diff] or {}).count or ''
+
return ((tbl[name] or {})[diff] or {}).count or 0
 
end
 
end
 
local function getLevel(name, diff)
 
local function getLevel(name, diff)
Line 59: Line 59:  
end
 
end
 
local function getCell(name, diff)
 
local function getCell(name, diff)
return getCount(name, diff) .. getLevel(name, diff)
+
local count = getCount(name, diff)
 +
return (count == 0 and '' or count) .. getLevel(name, diff)
 
end
 
end
 
local function getAsset(name)
 
local function getAsset(name)
Line 68: Line 69:  
setData('Easy')
 
setData('Easy')
 
setData('Casual')
 
setData('Casual')
local result = { template.top_header }
+
local result = { template.header }
 
if ship then
 
if ship then
table.insert(result, string.format(template.ship, getAsset(ship), ship))
+
table.insert(result, string.format(template.ship_row, getAsset(ship), ship))
 
end
 
end
table.insert(result, template.header)
+
table.insert(result, template.footer)
for _, name in ipairs(index) do
+
table.insert(result, template.item_header)
table.insert(result, string.format(template.row, getAsset(name), name, getCell(name, 'Casual'), getCell(name, 'Easy'), getCell(name, 'Medium'), getCell(name, 'Hard')))
+
local sortedIndex = U.imap(index, function(name, i) return { name = name, i = i, typ = types[name] } end)
 +
table.sort(sortedIndex, function (x, y)
 +
if x.typ ~= y.typ then return x.typ > y.typ end
 +
if getCount(x.name, 'Casual') ~= getCount(y.name, 'Casual') then return getCount(x.name, 'Casual') > getCount(y.name, 'Casual') end
 +
if getCount(x.name, 'Easy') ~= getCount(y.name, 'Easy') then return getCount(x.name, 'Easy') > getCount(y.name, 'Easy') end
 +
if getCount(x.name, 'Medium') ~= getCount(y.name, 'Medium') then return getCount(x.name, 'Medium') > getCount(y.name, 'Medium') end
 +
if getCount(x.name, 'Hard') ~= getCount(y.name, 'Hard') then return getCount(x.name, 'Hard') > getCount(y.name, 'Hard') end
 +
return x.i < y.i
 +
end)
 +
local sortValues = {}
 +
for i, e in ipairs(sortedIndex) do sortValues[e.name] = i end
 +
for i, name in ipairs(index) do
 +
table.insert(result, string.format(template.item_row, sortValues[name], getAsset(name), name,
 +
getCell(name, 'Casual'), getCell(name, 'Easy'), getCell(name, 'Medium'), getCell(name, 'Hard')))
 
end
 
end
 
table.insert(result, template.footer)
 
table.insert(result, template.footer)
cssedit, gkautomate
7,064

edits