Move files

This commit is contained in:
Kirigaya Kazuto 2018-11-26 11:56:44 +08:00
parent a18770896f
commit 664ef63455
9 changed files with 1 additions and 270 deletions

View File

@ -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

View File

@ -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

View File

@ -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,"<REFRESH>")
gpu.fill(1,h-2,w,1,' ')
gpu.set(1,h-2,"<PREV>")
gpu.fill(1,h-1,w,1,' ')
gpu.set(1,h-1,"<NEXT>")
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()

View File

@ -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