From 664ef63455183b21657c7a409dc6a06300dca975 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Mon, 26 Nov 2018 11:56:44 +0800 Subject: [PATCH] Move files --- auto_crafting.lua | 101 ------------ auto_crafting_robot.lua | 14 -- cross_3.lua => programs/station/cross_3.lua | 0 .../station/crossing3.lua | 0 .../transport/transport_center.lua | 0 .../transport/transport_client.lua | 0 .../transport/transport_repo.lua | 0 storage_manager.lua | 154 ------------------ teleport_calc.lua | 2 +- 9 files changed, 1 insertion(+), 270 deletions(-) delete mode 100644 auto_crafting.lua delete mode 100644 auto_crafting_robot.lua rename cross_3.lua => programs/station/cross_3.lua (100%) rename crossing3.lua => programs/station/crossing3.lua (100%) rename transport_center.lua => programs/transport/transport_center.lua (100%) rename transport_client.lua => programs/transport/transport_client.lua (100%) rename transport_repo.lua => programs/transport/transport_repo.lua (100%) delete mode 100644 storage_manager.lua diff --git a/auto_crafting.lua b/auto_crafting.lua deleted file mode 100644 index 485c9e1..0000000 --- a/auto_crafting.lua +++ /dev/null @@ -1,101 +0,0 @@ --- Storage Center and Auto Crafting --- Requires: --- Computer with wireless network card --- Robot with craft upgrade and inventory upgrade, wireless network card --- Transposer - -require("libevent") -require("util") -local component=require("component") - -local modem=component.list("modem") -if(modem==nil) then - error("Modem is required") -else - modem=component.proxy("modem") -end - --- Config -local craft_trans=proxy("transposer","") -local craft_trans_side_in=sides.west -local craft_trans_side_out=sides.east -local craft_trans_side_interface=sides.south - --- End of Config - -local craft_db={} - -local function readCraftTable() - local tb={} - tb.input={} - for i=1,3,1 do - for j=1,3,1 do - local p=craft_trans.getStackInSlot(sides.up,(i-1)*9+j) - if(p~=nil) then - table.insert(tb.input,{ - ["i"]=i, - ["j"]=j, - ["name"]=p.name, - ["size"]=p.size}) - end - end - end - - local xp=craft_trans.getStackInSlot(sides.up,2*9+5) - if(p~=nil) then - tb.output=xp.name - else - return false,"No craft target found. Invalid Plan." - end - - return true,tb -end - -local function netRobotCraft() - if(not modem.isOpen(2801)) then - if(not modem.open(2801)) then - return false,"Port can't be opened." - end - end - - local bus=CreateEventBus() - bus:listen("modem_message") - local craft_started=false - modem.broadcast(2802,"robotCraft") - local e=bus:next(3) -- Wait for 3 second - if(e~=nil) then - if(e.data[1]=="craft_started") then - craft_started=true - break - end - end - - if(not craft_started) then - return false,"Cannot tell robot to start craft" - end - - local e=bus:next() - if(e.data[1]~="craft_finished") then - return false,"Craft Failed" - end -end - -local function doCraftOnce(craft_table) - for k,v in pairs(craft_table) do - transferFromBaseToInterface(v.name,v.size,(v.i-1)*9+j) - end - local ret,msg=netRobotCraft() - if(not ret) then - return false,"Craft Failed. " .. msg - end -end - -local function craftOnce(name) - for k,v in pairs(craft_tb) do - if(v.output==name) then - doCraftOnce(v.input) - return - end - end - error("Craft table not found") -end diff --git a/auto_crafting_robot.lua b/auto_crafting_robot.lua deleted file mode 100644 index 633cba7..0000000 --- a/auto_crafting_robot.lua +++ /dev/null @@ -1,14 +0,0 @@ --- Auto Crafting Robot Client --- Requires: --- Craft upgrade and inventory upgrade --- Wireless network card - -require("libevent") -local component=require("component") -local modem=component.list("modem") -if(modem==nil) then - error("Modem is required") -else - modem=component.proxy("modem") -end - diff --git a/cross_3.lua b/programs/station/cross_3.lua similarity index 100% rename from cross_3.lua rename to programs/station/cross_3.lua diff --git a/crossing3.lua b/programs/station/crossing3.lua similarity index 100% rename from crossing3.lua rename to programs/station/crossing3.lua diff --git a/transport_center.lua b/programs/transport/transport_center.lua similarity index 100% rename from transport_center.lua rename to programs/transport/transport_center.lua diff --git a/transport_client.lua b/programs/transport/transport_client.lua similarity index 100% rename from transport_client.lua rename to programs/transport/transport_client.lua diff --git a/transport_repo.lua b/programs/transport/transport_repo.lua similarity index 100% rename from transport_repo.lua rename to programs/transport/transport_repo.lua diff --git a/storage_manager.lua b/storage_manager.lua deleted file mode 100644 index 0d8c37c..0000000 --- a/storage_manager.lua +++ /dev/null @@ -1,154 +0,0 @@ --- Storage Manager --- Designed for survival mode playing - -require("libevent") -local component=require("component") -local sides=require("sides") -local term=require("term") - -local gpu=component.proxy(component.list("gpu")()) - -local function fullScan() - local device_gate=component.list("transposer") - if(device_gate==nil) then return {} end - local devices={} - while true do - local addr=device_gate() - if(addr==nil) then break end - table.insert(devices,addr) - end - - local allprog=(#devices)*4 - - local db={} - local allsides={ sides.north, sides.east, sides.south, sides.west } - - local done=0 - - for _,addr in pairs(devices) do - local dev=component.proxy(addr) - for _,cside in pairs(allsides) do - local x=dev.getAllStacks(cside) - local cnt=x.count() - for i=1,cnt,1 do - local t=x() - if(t.name~=nil) then - if(db[t.name]~=nil) then - db[t.name]=db[t.name]+t.size - else - db[t.name]=t.size - end - end - end - done=done+1 - PushEvent("scan_progress",done/allprog) - end - end - - return db -end - -local item_db={} - -local function ui_clear() - local w,h=gpu.getResolution() - gpu.fill(1,1,w,h,' ') -end - -local function ui_show(page_id) - local w,h=gpu.getResolution() - gpu.fill(1,1,w,1,'=') - gpu.set(5,1,"Storage Manager v0.1") - gpu.fill(1,h,w,1,' ') - gpu.set(1,h,"Status: Loading...") - local item_to_skip=(page_id-1)*(h-2) - local skipped=0 - local now=2 - for k,v in pairs(item_db) do - if(skipped>=item_to_skip) then - gpu.set(1,now,k .. " -- Count: " .. v) - now=now+1 - if(now==h) then break end - else - skipped=skipped+1 - end - end - gpu.fill(1,h-3,w,1,' ') - gpu.set(1,h-3,"") - gpu.fill(1,h-2,w,1,' ') - gpu.set(1,h-2,"") - gpu.fill(1,h-1,w,1,' ') - gpu.set(1,h-1,"") - gpu.fill(1,h,w,1,' ') - gpu.set(1,h,"Status: Ready. Page " .. page_id) -end - -local function ui_fullscan() - ui_clear() - gpu.set(1,1,"Please wait while full scanning...") - local w,h=gpu.getResolution() - - local id=AddEventListener("scan_progress",function(e) - gpu.fill(1,2,w,1,' ') - gpu.fill(1,2,e.data[1]*w,1,'=') - gpu.set(1,2,"[" .. math.ceil(e.data[1]*100) .. "%>") - end) - - item_db=fullScan() - RemoveEventListener(id) -end - -local current_page=1 - -local function ui_view() - while true do - local e=WaitEvent("touch") - local w,h=gpu.getResolution() - - if(e.y==h-3) then - ui_fullscan() - return - end - - if(e.y==h-2) then - if(current_page>1) then - current_page=current_page-1 - return - end - end - - if(e.y==h-1) then - current_page=current_page+1 - return - end - if(e.y~=1 and e.y~=h) then - -- Selected one row - local count=1 - while true do - term.setCursor(1,h) - term.clearLine() - io.write("Input number here:") - term.setCursorBlink(true) - count=io.read("n") - if(count~=nil) then - break - end - end - end - end -end - -local function ui_main() - while true do - ui_clear() - ui_show(current_page) - ui_view() - end -end - -local function main() - ui_fullscan() - ui_main() -end - -main() \ No newline at end of file diff --git a/teleport_calc.lua b/teleport_calc.lua index 5bf3211..2bc5f9a 100644 --- a/teleport_calc.lua +++ b/teleport_calc.lua @@ -1,7 +1,7 @@ -- Teleport Calculator local function getEUStr(eu) if(eu<1000) then - return '' .. math.ceil(eu) + return string.format( elseif(eu<1000*1000) then return '' .. math.ceil(eu/1000) .. 'K,' .. getEUStr(eu%1000) else