show team scores and sort by them
This commit is contained in:
parent
d50960e61f
commit
8aabfc63d1
|
@ -1,6 +1,11 @@
|
|||
on.draw = function()
|
||||
draw_table({
|
||||
Ind={Ind='X', NZ=2},
|
||||
NZ={Ind=0, NZ='X'}
|
||||
Ind={Ind='X', Pak=2, Aus=2},
|
||||
NZ={NZ='X', Eng=2},
|
||||
SA={SA='X', Aus=2, SL=2},
|
||||
Pak={Pak='X', Ind=0, SL=2},
|
||||
Aus={Aus='X', Ind=0, SA=0, SL=2},
|
||||
SL={SL='X', SA=0, Pak=0, Aus=0},
|
||||
Eng={Eng='X', NZ=0}
|
||||
})
|
||||
end
|
|
@ -7,7 +7,7 @@ draw_table = function(t)
|
|||
local rside = max_row_width(t) + namepx*2 -- width of name column
|
||||
local nt = table.size(t)
|
||||
local hrow = total_row_width(t) + namepx*2*nt
|
||||
local width = rside + hrow
|
||||
local width = rside + hrow + App.width('Total') + namepx*2
|
||||
local height = (nt+1)*c
|
||||
local top, left = 30,30
|
||||
local rows = ordered_keys(t)
|
||||
|
@ -19,7 +19,7 @@ draw_table = function(t)
|
|||
local hx = left+rside
|
||||
love.graphics.line(hx, top, hx, top+height)
|
||||
-- remaining columns
|
||||
for i=1,#cx-1 do
|
||||
for i=1,#cx do
|
||||
love.graphics.line(cx[i], top, cx[i], top+height)
|
||||
end
|
||||
end
|
||||
|
@ -41,13 +41,19 @@ draw_table = function(t)
|
|||
love.graphics.print(rows[i], l+px, top+py)
|
||||
l = r
|
||||
end
|
||||
love.graphics.print('Total', l+namepx, top+py)
|
||||
-- print out cells
|
||||
l = left+rside
|
||||
for x,row in ipairs(t) do
|
||||
for y,cell in ipairs(row) do
|
||||
local px = (cx[x] - l - App.width(t[x][y])) / 2
|
||||
love.graphics.print(t[x][y], l+px, top+y*c+py)
|
||||
for y,t1 in ipairs(rows) do
|
||||
l = left+rside
|
||||
for x,t2 in ipairs(rows) do
|
||||
if t[t1][t2] then
|
||||
local px = (cx[x] - l - App.width(t[t1][t2])) / 2
|
||||
love.graphics.print(t[t1][t2], l+px, top+y*c+py)
|
||||
end
|
||||
l = cx[x]
|
||||
end
|
||||
l = cx[x]
|
||||
local total = score(t, t1)
|
||||
local px = (App.width('Total') - App.width(total)) / 2
|
||||
love.graphics.print(score(t, t1), l+px, top+y*c+py)
|
||||
end
|
||||
end
|
|
@ -1,7 +1,10 @@
|
|||
ordered_keys = function(t)
|
||||
local result = {}
|
||||
for k in pairs(t) do
|
||||
table.insert(result, k)
|
||||
local s = {}
|
||||
for team in pairs(t) do
|
||||
table.insert(result, team)
|
||||
s[team] = score(t, team)
|
||||
end
|
||||
table.sort(result, function(t1, t2) return s[t1] > s[t2] end)
|
||||
return result
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
score = function(t, team)
|
||||
local result = 0
|
||||
for opp, score in pairs(t[team]) do
|
||||
if type(score) == 'number' then
|
||||
result = result + score
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
Loading…
Reference in New Issue