~jordanreger/cc

bfe6059601b2a01c9560b244f2f101d08d933797 — Jordan Reger a month ago 70925ad
feat: "multi-threading" and better functions
2 files changed, 94 insertions(+), 24 deletions(-)

M xOS/.x
M xOS/startup.lua
M xOS/.x => xOS/.x +84 -21
@@ 1,8 1,6 @@
local width, height = term.getSize()
local background_color = colors.lightGray

local window = window.create(term.current(), 1, 1, width, height)

local page = "home"

function setup()


@@ 18,26 16,60 @@ end
function render()
    if page == "home" then
        render_home()
    elseif page == "xOrder" then
        render_xOrder()
    elseif page == "xGPS" then
        render_xGPS()
    end
end

    if page == "ring" then
        ring()
        page = "home"
function writeCentered(str, y)
    if (math.fmod(string.len(str), 2) ~= 1) then
        window.setCursorPos(width / 2 - ((string.len(str) - 2) / 2), y)
        window.write(str)
    else
        window.setCursorPos(width / 2 - ((string.len(str) - 1) / 2), y)
        window.write(str)
    end
end

function render_home()
    window.clear()

    window.setCursorPos(width / 2 - 1, height / 2)
    window.write("Ring")
    window.setCursorPos(width / 2 - 3, height / 2 + 1)
    window.write("Shutdown")
    -- time
    local time = textutils.formatTime(os.time())

    if (string.len(time) < 8) then
        time = "0" .. time
    end

    writeCentered(time, 1)

    -- menu
    writeCentered("xOrder", height / 2)
    writeCentered("xGPS", height / 2 + 1)
    writeCentered("Shutdown", height / 2 + 2)
end

function ring()
    rednet.open("back")
function render_xOrder()
    window.clear()
    writeCentered("Coming soon!", height / 2)
    writeCentered("<-- back", height / 2 + 2)
end

function render_xGPS()
    -- local x, y, z = gps.locate()
    -- x, y, z = math.floor(x), math.floor(y), math.floor(z)
    -- writeCentered(x .. " " .. y .. " " .. z, height / 2)

    window.clear()
    writeCentered("Coming soon!", height / 2)
    writeCentered("<-- back", height / 2 + 2)
end

-- background tasks

function automatic_doors()
    local receiver_id = 17

    rednet.send(receiver_id, "gps")


@@ 67,25 99,56 @@ function ring()
    end
end

-- function location()
--     while true do
--         local x, y, z = gps.locate()
--         x, y, z = math.floor(x), math.floor(y), math.floor(z)
--         rednet.send(21, x .. " " .. y .. " " .. z)
--         sleep(30)
--     end
-- end

-- prerender tasks

function on_click()
    local e, id, x, y = os.pullEvent("mouse_click")
    if e then
        if (x >= width / 2 - 1 and x <= width / 2 + 2 and y == height / 2) then
            page = "ring"
        else
            return
    while true do
        local e, id, x, y = os.pullEvent("mouse_click")
        if e then
            if page == "home" then
                -- get clicks on *centered* text
                if (x >= width / 2 - 2 and x <= width / 2 + 2 and y == height / 2) then
                    page = "xOrder"
                elseif (x >= width / 2 - 1 and x <= width / 2 + 1 and y == height / 2 + 1) then
                    page = "xGPS"
                elseif (x >= width / 2 - 3 and x <= width / 2 + 4 and y == height / 2 + 2) then
                    os.shutdown()
                else
                    return
                end
            end
            
            if page == "xOrder" then
                if (x >= width / 2 - 3 and x <= width / 2 + 3 and y == height / 2 + 2) then
                    page = "home"
                end
            end

            if page == "xGPS" then
                if (x >= width / 2 - 3 and x <= width / 2 + 3 and y == height / 2 + 2) then
                    page = "home"
                end
            end
        end
    end
end

function main()
    setup()
    
    render()
    on_click()

    sleep(0.25)
    main()
end

main()
\ No newline at end of file
setup()

parallel.waitForAll(main, on_click, automatic_doors)
\ No newline at end of file

M xOS/startup.lua => xOS/startup.lua +10 -3
@@ 3,10 3,17 @@ rednet.open("back")
local width, height = term.getSize()

term.clear()
term.setCursorPos(width / 2 - 3, height / 2)
term.setCursorPos(width / 2 - 1, height / 2 - 2)
print("x  x")
term.setCursorPos(width / 2 - 1, height / 2 - 1)
print("  x ")
term.setCursorPos(width / 2 - 1, height / 2)
print(" x  ")
term.setCursorPos(width / 2 - 1, height / 2 + 1)
print("x  x")
term.setCursorPos(width / 2 - 3, height / 2 + 3)
print("xOS v0.1")
sleep(1)
term.setCursorPos(width / 2 - 4, height / 2 + 1)
term.setCursorPos(width / 2 - 4, height / 2 + 4)
textutils.slowPrint("xxxxxxxxxx")
sleep(1)
shell.run(".x")
\ No newline at end of file