no buttons for the 'X' cells

Also stop representing them in the data.
This commit is contained in:
Kartik K. Agaram 2023-10-17 15:23:46 -07:00
parent 3f18490c49
commit 08875d0094
2 changed files with 44 additions and 37 deletions

View File

@ -59,34 +59,41 @@ draw_data = function()
for y,t1 in ipairs(Rows) do
l = left+rside
for x,t2 in ipairs(Rows) do
button(Global_state, t1..t2, {
x=l, y=top+y*c,
w=cx[x] - l,
h=c,
bg = {r=0,g=0,b=0, a=0}, -- nothing
icon = function(params)
make_button_pop(params)
if Data[t1][t2] then
local px = (params.w - App.width(Data[t1][t2])) / 2
App.color{r=0, g=0, b=0}
love.graphics.print(Data[t1][t2], params.x+px, params.y+py)
end
end,
onpress1 = function()
local v = Data[t1][t2]
if v == 'X' then
return
elseif v == nil then
Data[t1][t2] = 0 Data[t2][t1] = 2
elseif v == 0 then
Data[t1][t2] = 2 Data[t2][t1] = 0
elseif v == 2 then
Data[t1][t2] = nil Data[t2][t1] = nil
else
error('invalid value')
end
end,
})
if t1 == t2 then
-- no button
local px = (cx[x] - l - App.width('X')) / 2
App.color{r=0, g=0, b=0}
love.graphics.print('X', l+px, top+y*c+py)
else
button(Global_state, t1..t2, {
x=l, y=top+y*c,
w=cx[x] - l,
h=c,
bg = {r=0,g=0,b=0, a=0}, -- nothing
icon = function(params)
make_button_pop(params)
if Data[t1][t2] then
local px = (params.w - App.width(Data[t1][t2])) / 2
App.color{r=0, g=0, b=0}
love.graphics.print(Data[t1][t2], params.x+px, params.y+py)
end
end,
onpress1 = function()
local v = Data[t1][t2]
if v == 'X' then
return
elseif v == nil then
Data[t1][t2] = 0 Data[t2][t1] = 2
elseif v == 0 then
Data[t1][t2] = 2 Data[t2][t1] = 0
elseif v == 2 then
Data[t1][t2] = nil Data[t2][t1] = nil
else
error('invalid value')
end
end,
})
end
l = cx[x]
end
local total = score(Data, t1)
@ -94,4 +101,4 @@ draw_data = function()
App.color{r=0, g=0, b=0}
love.graphics.print(score(Data, t1), l+px, top+y*c+py)
end
end
end

View File

@ -1,9 +1,9 @@
Data = {
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}
}
Ind={Pak=2, Aus=2},
NZ={Eng=2},
SA={Aus=2, SL=2},
Pak={Ind=0, SL=2},
Aus={Ind=0, SA=0, SL=2},
SL={SA=0, Pak=0, Aus=0},
Eng={NZ=0}
}