More ATM work.

This commit is contained in:
Andrew Lalis 2023-08-29 17:18:23 -04:00
parent a9a6c34ba8
commit 2d458615ec
1 changed files with 21 additions and 5 deletions

26
atm.lua
View File

@ -21,19 +21,33 @@ end
local function showLoginUI() local function showLoginUI()
drawFrame() drawFrame()
g.drawTextCenter(term, W/2, 3, "Welcome to HandieBank ATM!", colors.green, colors.white) g.drawTextCenter(term, W/2, 3, "Welcome to HandieBank ATM!", colors.green, colors.white)
g.drawTextCenter(term, W/2, 4, "Insert your card below, or click to login.", colors.black, colors.white) g.drawTextCenter(term, W/2, 5, "Insert your card below, or click to login.", colors.black, colors.white)
g.fillRect(term, W/2 - 3, 7, 7, 3, colors.lightGray) g.fillRect(term, W/2 - 3, 7, 9, 3, colors.green)
g.drawTextCenter(term, W/2, 8, "Login", colors.green, colors.lightGray) g.drawTextCenter(term, W/2, 8, "Login", colors.white, colors.green)
while true do while true do
local event, p1, p2, p3 = os.pullEvent() local event, p1, p2, p3 = os.pullEvent()
if event == "disk" then if event == "disk" then
print("Disk: "..p1) local side = p1
return {username = "bleh", password = "bleh"} if disk.hasData(side) then
local mountPath = disk.getMountPath(side)
local dataFile = fs.combine(disk.getMountPath(side), "bank-credentials.json")
if fs.exists(dataFile) then
local f = io.open(dataFile, "r")
local content = f:read("*a")
f:close()
return textutils.unserializeJSON(content)
else
disk.eject(side)
end
else
disk.eject(side)
end
elseif event == "mouse_click" then elseif event == "mouse_click" then
local button = p1 local button = p1
local x = p2 local x = p2
local y = p3 local y = p3
if button == 1 and x >= (W/2 - 3) and x <= (W/2 + 4) and y >= 7 and y <= 9 then if button == 1 and x >= (W/2 - 3) and x <= (W/2 + 4) and y >= 7 and y <= 9 then
-- TODO: Show login input elements.
return {username = "bleh", password = "bleh"} return {username = "bleh", password = "bleh"}
end end
end end
@ -42,4 +56,6 @@ end
while true do while true do
local credentials = showLoginUI() local credentials = showLoginUI()
g.clear(term, colors.black)
return
end end