fixed some more stuff
This commit is contained in:
		
							parent
							
								
									4762e216d9
								
							
						
					
					
						commit
						e175f78431
					
				| 
						 | 
				
			
			@ -48,6 +48,18 @@ local function attemptItemExport(name, count)
 | 
			
		|||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function playNotes(instrument, pitches, delay)
 | 
			
		||||
    local speaker = peripheral.find("speaker")
 | 
			
		||||
    if speaker == nil then return end
 | 
			
		||||
    delay = delay or 0.25
 | 
			
		||||
    for i, pitch in pairs(pitches) do
 | 
			
		||||
        speaker.playNote(instrument, 3, pitch)
 | 
			
		||||
        if i < #pitches then
 | 
			
		||||
            os.sleep(delay)
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function drawProgress(p)
 | 
			
		||||
    local discreteWidth = W - 2
 | 
			
		||||
    local filled = p * discreteWidth
 | 
			
		||||
| 
						 | 
				
			
			@ -126,12 +138,14 @@ local function exportItem(name, count)
 | 
			
		|||
    -- Check for flags and do different stuff if so.
 | 
			
		||||
    if EXPORT_REPORT then
 | 
			
		||||
        -- Report the item issue to the schematic site.
 | 
			
		||||
        g.drawText(mon, 1, 10, "Reporting item. Skipping to next one.", colors.orange, colors.black)
 | 
			
		||||
        os.sleep(2)
 | 
			
		||||
        g.drawText(mon, 1, 10, "Reporting item. Skipping to next one.", colors.yellow, colors.black)
 | 
			
		||||
        http.post("https://schematics.andrewlalis.com/item-reports", name)
 | 
			
		||||
        g.drawText(mon, 1, 11, "Contact an admin if urgent.", colors.yellow, colors.black)
 | 
			
		||||
        os.sleep(3)
 | 
			
		||||
        return count
 | 
			
		||||
    elseif EXPORT_SKIP then
 | 
			
		||||
        -- Skip this item.
 | 
			
		||||
        g.drawText(mon, 1, 10, "Skipping this item.", colors.orange, colors.black)
 | 
			
		||||
        g.drawText(mon, 1, 10, "Skipping this item.", colors.yellow, colors.black)
 | 
			
		||||
        os.sleep(2)
 | 
			
		||||
        return count
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			@ -140,7 +154,7 @@ local function exportItem(name, count)
 | 
			
		|||
    if me == nil then
 | 
			
		||||
        g.drawText(mon, 1, 10, "Error: No \"meBridge\" peripheral.", colors.red, colors.black)
 | 
			
		||||
        g.drawText(mon, 1, 11, "Attach one please.", colors.red, colors.black)
 | 
			
		||||
        os.sleep(1)
 | 
			
		||||
        os.sleep(0.5)
 | 
			
		||||
        return 0
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -148,7 +162,7 @@ local function exportItem(name, count)
 | 
			
		|||
    if allItems == nil or #allItems < 5 then
 | 
			
		||||
        g.drawText(mon, 1, 10, "Error: Couldn't list AE items.", colors.red, colors.black)
 | 
			
		||||
        g.drawText(mon, 1, 11, "Msg: " .. err, colors.red, colors.black)
 | 
			
		||||
        os.sleep(1)
 | 
			
		||||
        os.sleep(0.5)
 | 
			
		||||
        return 0
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -159,17 +173,19 @@ local function exportItem(name, count)
 | 
			
		|||
            if exported == 0 then
 | 
			
		||||
                g.drawText(mon, 1, 10, "Exported 0 items. Make sure there is", colors.yellow, colors.black)
 | 
			
		||||
                g.drawText(mon, 1, 11, "space in the output container.", colors.yellow, colors.black)
 | 
			
		||||
                os.sleep(0.5)
 | 
			
		||||
            else
 | 
			
		||||
                g.drawText(mon, 1, 10, "Exported " .. exported .. " items.", colors.white, colors.black)
 | 
			
		||||
            end
 | 
			
		||||
            os.sleep(0.5)
 | 
			
		||||
            return exported
 | 
			
		||||
        end
 | 
			
		||||
        g.drawText(mon, 1, 10, "Transfer failed: " .. err, colors.red, colors.black)
 | 
			
		||||
        os.sleep(1)
 | 
			
		||||
        os.sleep(0.5)
 | 
			
		||||
        return 0
 | 
			
		||||
    else
 | 
			
		||||
        g.drawText(mon, 1, 10, "Item isn't present in the AE system.", colors.yellow, colors.black)
 | 
			
		||||
        g.drawText(mon, 1, 11, "Please add some, craft, or skip.", colors.yellow, colors.black)
 | 
			
		||||
        os.sleep(1)
 | 
			
		||||
        os.sleep(0.5)
 | 
			
		||||
        return 0
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -220,10 +236,15 @@ local function exportSchematics(itemLists)
 | 
			
		|||
    end
 | 
			
		||||
    -- Done! Show a small message, then set the EXPORTING flag to false.
 | 
			
		||||
    EXPORTING = false
 | 
			
		||||
    RUNNING = false -- Exit back to the desktop.
 | 
			
		||||
    for i = 1, 3 do -- Queue up some no-op touch events make sure the event handler quits.
 | 
			
		||||
        os.queueEvent("monitor_touch", "monitor_24", 1, 1)
 | 
			
		||||
    end
 | 
			
		||||
    g.drawText(mon, 1, H-4, "Export complete!", colors.lime, colors.black)
 | 
			
		||||
    clearMainPanel()
 | 
			
		||||
    g.drawText(mon, 1, 8, "Export complete!", colors.lime, colors.black)
 | 
			
		||||
    g.drawText(mon, 1, 10, totalItemsExported .. " items exported.", colors.white, colors.black)
 | 
			
		||||
    playNotes("bell", {8, 12, 16, 20}, 0.5)
 | 
			
		||||
    os.sleep(3)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function handleExportEvents()
 | 
			
		||||
| 
						 | 
				
			
			@ -232,10 +253,13 @@ local function handleExportEvents()
 | 
			
		|||
        if monName == "monitor_24" and y >= H-2 then
 | 
			
		||||
            if x >= 27 then
 | 
			
		||||
                EXPORTING = false
 | 
			
		||||
                playNotes("harp", {12, 8})
 | 
			
		||||
            elseif x >= 14 then
 | 
			
		||||
                EXPORT_REPORT = true
 | 
			
		||||
                playNotes("hat", {14, 10})
 | 
			
		||||
            else
 | 
			
		||||
                EXPORT_SKIP = true
 | 
			
		||||
                playNotes("snare", {12})
 | 
			
		||||
            end
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			@ -257,26 +281,63 @@ local function handleSchematicUrl(url)
 | 
			
		|||
        os.sleep(3)
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
    g.drawText(mon, 1, 9, "Got lists for "..(#itemLists).." schematics.", colors.white, colors.black)
 | 
			
		||||
 | 
			
		||||
    g.drawText(mon, 1, 9, "Got lists for "..(#itemLists).." schematics:", colors.white, colors.black)
 | 
			
		||||
    local y = 10
 | 
			
		||||
    for i, itemList in pairs(itemLists) do
 | 
			
		||||
        local count = itemList.__COUNT__
 | 
			
		||||
        local name = itemList.__NAME__
 | 
			
		||||
        g.drawText(mon, 2, y, count.."x "..name, colors.white, colors.black)
 | 
			
		||||
        y = y+1
 | 
			
		||||
        if y == H and i < #itemLists then
 | 
			
		||||
        if y == H-3 and i < #itemLists then
 | 
			
		||||
            local numRemaining = #itemLists - i
 | 
			
		||||
            g.drawText(mon, 2, y, "... and "..numRemaining.." more.")
 | 
			
		||||
            break
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    os.sleep(3)
 | 
			
		||||
    -- Draw continue and cancel buttons and wait for user input.
 | 
			
		||||
    g.fillRect(mon, 1, H-2, 18, 3, colors.gray)
 | 
			
		||||
    g.drawTextCenter(mon, 9, H-1, "Cancel", colors.white)
 | 
			
		||||
    g.fillRect(mon, 19, H-2, 20, 3, colors.green)
 | 
			
		||||
    g.drawTextCenter(mon, 29, H-1, "Continue", colors.white)
 | 
			
		||||
    local waiting = true
 | 
			
		||||
    while waiting do
 | 
			
		||||
        local event, monName, x, y = os.pullEvent("monitor_touch")
 | 
			
		||||
        if monName == "monitor_24" and y >= H-2 then
 | 
			
		||||
            if x <= 18 then
 | 
			
		||||
                playNotes("harp", {12, 8})
 | 
			
		||||
                return
 | 
			
		||||
            else
 | 
			
		||||
                playNotes("bell", {12, 16})
 | 
			
		||||
                waiting = false
 | 
			
		||||
            end
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    -- Write instructions
 | 
			
		||||
    clearMainPanel()
 | 
			
		||||
    g.drawText(mon, 1, 8, "Export beginning shortly. Please read", colors.white, colors.black)
 | 
			
		||||
    g.drawText(mon, 1, 9, "these instructions beforehand:", colors.white, colors.black)
 | 
			
		||||
    
 | 
			
		||||
    g.drawText(mon, 1, 10, "Press", colors.white, colors.black)
 | 
			
		||||
    g.drawText(mon, 7, 10, "Skip", colors.white, colors.blue)
 | 
			
		||||
    g.drawText(mon, 13, 10, "to skip an item.", colors.white, colors.black)
 | 
			
		||||
    
 | 
			
		||||
    g.drawText(mon, 1, 11, "Press", colors.white, colors.black)
 | 
			
		||||
    g.drawText(mon, 7, 11, "Report", colors.white, colors.orange)
 | 
			
		||||
    g.drawText(mon, 14, 11, "to report an invalid item.", colors.white, colors.black)
 | 
			
		||||
 | 
			
		||||
    g.drawText(mon, 1, 12, "Press", colors.white, colors.black)
 | 
			
		||||
    g.drawText(mon, 7, 12, "Quit", colors.white, colors.red)
 | 
			
		||||
    g.drawText(mon, 12, 12, "to stop the export.", colors.white, colors.black)
 | 
			
		||||
    -- Draw control buttons.
 | 
			
		||||
    g.fillRect(mon, 1, H-2, 13, 3, colors.blue)
 | 
			
		||||
    g.drawText(mon, 5, H-1, "Skip", colors.white)
 | 
			
		||||
    g.fillRect(mon, 14, H-2, 13, 3, colors.yellow)
 | 
			
		||||
    g.drawText(mon, 14, H-1, "Report Error", colors.lightBlue)
 | 
			
		||||
    g.fillRect(mon, 14, H-2, 13, 3, colors.orange)
 | 
			
		||||
    g.drawText(mon, 17, H-1, "Report", colors.white)
 | 
			
		||||
    g.fillRect(mon, 27, H-2, 13, 3, colors.red)
 | 
			
		||||
    g.drawText(mon, 31, H-1, "Quit", colors.white)
 | 
			
		||||
    os.sleep(3)
 | 
			
		||||
    EXPORTING = true
 | 
			
		||||
    local fExport = function() exportSchematics(itemLists) end
 | 
			
		||||
    local fHandleEvents = function() handleExportEvents() end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue