Compare commits
13 Commits
Kan18/deve
...
ui-enhance
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d17162b49d | ||
|
|
949c485539 | ||
|
|
3246579ab1 | ||
|
|
6b429a26e4 | ||
|
|
ef6cde3013 | ||
|
|
569dd5572d | ||
|
|
3321866ba3 | ||
|
|
1cbe87033d | ||
|
|
0a7ec352cc | ||
|
|
f655cc5965 | ||
|
|
6bb4149113 | ||
|
|
e2aac13e8f | ||
|
|
cdea6e4aed |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,2 @@
|
||||
/etc/fstab
|
||||
/etc/recipes2.db
|
||||
/.vscode
|
||||
|
||||
16
README.md
16
README.md
@@ -1,18 +1,2 @@
|
||||
# opus-apps
|
||||
Applications for Opus OS
|
||||
|
||||
## Installing an application
|
||||
To install an application, follow these steps
|
||||
1. Start your OpusOS Computer
|
||||
2. Go to the System tab on the main menu
|
||||
3. Find the packages app and open it
|
||||
4. Select the package you want
|
||||
5. Select the package and press the `+` button
|
||||
6. Your application should get installed!
|
||||
|
||||
## Updating your applications
|
||||
To update your applications, follow these steps
|
||||
1. Start your OpusOS Computer
|
||||
2. Go to the System tab on the main menu
|
||||
3. Find the packages app and open it
|
||||
4. Press the `Update All` button
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
title = 'busted',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/moonscript',
|
||||
description = [[WIP]],
|
||||
license = 'MIT',
|
||||
required = {
|
||||
'penlight',
|
||||
},
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
return {
|
||||
-- Returns the monotonic time the system has been up, in secconds.
|
||||
monotime = function()
|
||||
return os.clock()
|
||||
end,
|
||||
|
||||
-- Sleep for n seconds.
|
||||
sleep = function(n)
|
||||
os.sleep(n)
|
||||
end,
|
||||
|
||||
-- Returns the current system time, 1970 (UTC), in secconds.
|
||||
gettime = function()
|
||||
return os.epoch('utc') / 1000
|
||||
end,
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
return {
|
||||
isatty = function()
|
||||
return false
|
||||
end,
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
packages/busted/busted urlfs https://raw.githubusercontent.com/Olivine-Labs/busted/master/bin/busted
|
||||
rom/modules/main/busted gitfs Olivine-Labs/busted/master/busted
|
||||
rom/modules/main/mediator.lua urlfs https://raw.githubusercontent.com/Olivine-Labs/mediator_lua/master/src/mediator.lua
|
||||
rom/modules/main/cliargs gitfs amireh/lua_cliargs/master/src/cliargs
|
||||
rom/modules/main/luassert gitfs Olivine-Labs/luassert/master/src
|
||||
rom/modules/main/say.lua urlfs https://raw.githubusercontent.com/Olivine-Labs/say/master/src/init.lua
|
||||
rom/modules/main/term.lua linkfs packages/busted/depend/term.lua
|
||||
rom/modules/main/system.lua linkfs packages/busted/depend/system.lua
|
||||
@@ -21,4 +21,11 @@ Restorable history
|
||||
Partial CCKernel2 support
|
||||
Full compatibility with CraftOS shell.lua]],
|
||||
license = 'MIT',
|
||||
install = [[
|
||||
require('opus.alternate').set('shell', 'packages/cash/cash.lua')
|
||||
require('opus.util').writeFile('.cashrc', 'set TERMINATE_QUIT=yes')
|
||||
]],
|
||||
uninstall = [[
|
||||
require('opus.alternate').remove('shell', 'packages/cash/cash.lua')
|
||||
]],
|
||||
}
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
local ccemux = _G.ccemux
|
||||
local fs = _G.fs
|
||||
local textutils = _G.textutils
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
if ccemux then
|
||||
-- add a System setup tab
|
||||
fs.mount('sys/apps/system/ccemux.lua', 'linkfs', 'packages/ccemux/system/ccemux.lua')
|
||||
|
||||
_G.kernel.hook('clipboard_copy', function(_, args)
|
||||
local data = args[1]
|
||||
if type(data) == 'table' then
|
||||
local s, m = pcall(textutils.serialize, data)
|
||||
data = s and m or tostring(data)
|
||||
end
|
||||
local Config = require('opus.config')
|
||||
|
||||
if data then
|
||||
ccemux.setClipboard(data)
|
||||
for k,v in pairs(Config.load('ccemux')) do
|
||||
if not peripheral.getType(k) then
|
||||
ccemux.attach(k, v.type, v.args)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
local ccemux
|
||||
ccemux = _G.ccemux
|
||||
local fs
|
||||
fs = _G.fs
|
||||
local peripheral
|
||||
peripheral = _G.peripheral
|
||||
local unserialize
|
||||
unserialize = _G.textutils.unserialize
|
||||
local CONFIG = 'usr/config/ccemux'
|
||||
if ccemux and fs.exists(CONFIG) then
|
||||
local f = fs.open(CONFIG, 'r')
|
||||
local c = unserialize(f.readAll())
|
||||
f.close()
|
||||
for k, v in pairs(c) do
|
||||
if not peripheral.getType(k) then
|
||||
ccemux.attach(k, v.type, v.args)
|
||||
print(k)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,16 +0,0 @@
|
||||
import ccemux from _G
|
||||
import fs from _G
|
||||
import peripheral from _G
|
||||
import unserialize from _G.textutils
|
||||
|
||||
CONFIG = 'usr/config/ccemux'
|
||||
|
||||
if ccemux and fs.exists CONFIG
|
||||
f = fs.open(CONFIG, 'r')
|
||||
c = unserialize(f.readAll())
|
||||
f.close()
|
||||
|
||||
for k,v in pairs c
|
||||
if not peripheral.getType(k)
|
||||
ccemux.attach(k, v.type, v.args)
|
||||
print k
|
||||
@@ -1,13 +1,12 @@
|
||||
local Config = require('opus.config')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local ccemux = _G.ccemux
|
||||
|
||||
local sides = { 'bottom', 'top', 'back', 'front', 'right', 'left' }
|
||||
|
||||
local tab = UI.Tab {
|
||||
title = 'CCEmuX',
|
||||
tabTitle = 'CCEmuX',
|
||||
description = 'CCEmuX peripherals',
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 2, ey = 5,
|
||||
@@ -39,6 +38,7 @@ local tab = UI.Tab {
|
||||
add = UI.Button {
|
||||
x = -6, y = 3, width = 5,
|
||||
text = 'Add', event = 'form_ok',
|
||||
help = 'Add items to turtle to add to filter',
|
||||
},
|
||||
},
|
||||
grid = UI.Grid {
|
||||
@@ -46,7 +46,6 @@ local tab = UI.Tab {
|
||||
columns = {
|
||||
{ heading = 'Side', key = 'side', width = 8 },
|
||||
{ heading = 'Type', key = 'type' },
|
||||
{ heading = 'ID', key = 'args', width = 4 },
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -57,29 +56,13 @@ function tab:updatePeripherals(config)
|
||||
table.insert(self.grid.values, {
|
||||
side = k,
|
||||
type = v.type,
|
||||
args = v.args and v.args.id,
|
||||
args = v.args,
|
||||
})
|
||||
end
|
||||
self.grid:update()
|
||||
end
|
||||
|
||||
function tab.bootCheck()
|
||||
local startupFile = 'packages/ccemux/bin/emustartup.lua'
|
||||
|
||||
local c = Util.readTable('.startup.boot')
|
||||
if c then
|
||||
for _,v in pairs(c.preload) do
|
||||
if v == startupFile then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(c.preload, startupFile)
|
||||
Util.writeTable('.startup.boot', c)
|
||||
end
|
||||
|
||||
function tab:enable()
|
||||
self:bootCheck()
|
||||
local config = Config.load('ccemux')
|
||||
|
||||
local choices = { }
|
||||
@@ -100,6 +83,7 @@ function tab:eventHandler(event)
|
||||
self:emit({ type = 'error_message', message = 'Invalid drive ID' })
|
||||
else
|
||||
ccemux.detach(event.values.side)
|
||||
ccemux.attach(event.values.side, event.values.type)
|
||||
|
||||
local config = Config.load('ccemux')
|
||||
config[event.values.side] = {
|
||||
@@ -109,9 +93,6 @@ function tab:eventHandler(event)
|
||||
config[event.values.side].args = {
|
||||
id = event.values.drive_id
|
||||
}
|
||||
ccemux.attach(event.values.side, event.values.type, { id = event.values.drive_id })
|
||||
else
|
||||
ccemux.attach(event.values.side, event.values.type)
|
||||
end
|
||||
Config.update('ccemux', config)
|
||||
self:updatePeripherals(config)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
title = 'Collections',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/collections',
|
||||
description = [[Collections (rework)
|
||||
See: https://github.com/imliam/Lua-Collections
|
||||
|
||||
Collections are like tables on steroids. They are designed to act as a fluent wrapper when working with structured data, offering the developer convenience for common tasks.]],
|
||||
license = 'MIT',
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
||||
packages/collections/tests/tests.lua urlfs https://raw.githubusercontent.com/imliam/Lua-Collections/master/tests.lua
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,4 @@
|
||||
* and more...
|
||||
]],
|
||||
license = 'MIT',
|
||||
required = {
|
||||
'core',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ local function unregisterApp(key)
|
||||
end
|
||||
end
|
||||
|
||||
local sandboxEnv = Util.shallowCopy(_ENV)
|
||||
setmetatable(sandboxEnv, { __index = _G })
|
||||
|
||||
multishell.setTitle(multishell.getCurrent(), 'App Store')
|
||||
UI:configure('Appstore', ...)
|
||||
|
||||
@@ -57,7 +60,7 @@ local function downloadApp(app)
|
||||
end
|
||||
|
||||
local function runApp(app, checkExists, ...)
|
||||
local env = shell.makeEnv(_ENV)
|
||||
|
||||
local path, fn
|
||||
local args = { ... }
|
||||
|
||||
@@ -78,13 +81,14 @@ local function runApp(app, checkExists, ...)
|
||||
error('Failed to download')
|
||||
end
|
||||
|
||||
_G.setfenv(fn, env)
|
||||
_G.setfenv(fn, sandboxEnv)
|
||||
fn(table.unpack(args))
|
||||
end
|
||||
end
|
||||
|
||||
multishell.openTab(_ENV, {
|
||||
multishell.openTab({
|
||||
title = app.name,
|
||||
env = sandboxEnv,
|
||||
path = path,
|
||||
fn = fn,
|
||||
focused = true,
|
||||
|
||||
@@ -3,26 +3,26 @@ local Event = require('opus.event')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local device = _G.device
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
--[[ -- PeripheralsPage -- ]] --
|
||||
local peripheralsPage = UI.Page {
|
||||
grid = UI.ScrollingGrid {
|
||||
ey = -2,
|
||||
columns = {
|
||||
--{ heading = 'Name', key = 'name' },
|
||||
{ heading = 'Type', key = 'type' },
|
||||
{ heading = 'Side', key = 'side' },
|
||||
},
|
||||
sortColumn = 'type',
|
||||
autospace = true,
|
||||
enable = function(self)
|
||||
local sides = peripheral.getNames()
|
||||
|
||||
Util.clear(self.values)
|
||||
for _,v in pairs(device) do
|
||||
for _,side in pairs(sides) do
|
||||
table.insert(self.values, {
|
||||
type = v.type,
|
||||
side = v.side,
|
||||
name = v.name,
|
||||
type = peripheral.getType(side),
|
||||
side = side
|
||||
})
|
||||
end
|
||||
self:update()
|
||||
@@ -75,50 +75,49 @@ local methodsPage = UI.Page {
|
||||
[ 'control-q' ] = 'back',
|
||||
backspace = 'back',
|
||||
},
|
||||
enable = function(self, p)
|
||||
self.peripheral = p or self.peripheral
|
||||
|
||||
p = device[self.peripheral.name]
|
||||
if p.getDocs then
|
||||
-- plethora
|
||||
self.grid.values = { }
|
||||
for k,v in pairs(p.getDocs()) do
|
||||
table.insert(self.grid.values, {
|
||||
name = k,
|
||||
doc = v,
|
||||
})
|
||||
end
|
||||
elseif not p.getAdvancedMethodsData then
|
||||
-- computercraft
|
||||
self.grid.values = { }
|
||||
for k,v in pairs(p) do
|
||||
if type(v) == 'function' then
|
||||
table.insert(self.grid.values, {
|
||||
name = k,
|
||||
noext = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
else
|
||||
-- open peripherals
|
||||
self.grid.values = p.getAdvancedMethodsData()
|
||||
for name,f in pairs(self.grid.values) do
|
||||
f.name = name
|
||||
end
|
||||
end
|
||||
|
||||
self.grid:update()
|
||||
self.grid:setIndex(1)
|
||||
|
||||
self.doc:setText(self:getDocumentation())
|
||||
|
||||
self.statusBar:setStatus(self.peripheral.type)
|
||||
UI.Page.enable(self)
|
||||
|
||||
self:setFocus(self.grid)
|
||||
end,
|
||||
}
|
||||
|
||||
function methodsPage:enable(p)
|
||||
self.peripheral = p or self.peripheral
|
||||
|
||||
p = peripheral.wrap(self.peripheral.side)
|
||||
if p.getDocs then
|
||||
-- plethora
|
||||
self.grid.values = { }
|
||||
for k,v in pairs(p.getDocs()) do
|
||||
table.insert(self.grid.values, {
|
||||
name = k,
|
||||
doc = v,
|
||||
})
|
||||
end
|
||||
elseif not p.getAdvancedMethodsData then
|
||||
-- computercraft
|
||||
self.grid.values = { }
|
||||
for name in pairs(p) do
|
||||
table.insert(self.grid.values, {
|
||||
name = name,
|
||||
noext = true,
|
||||
})
|
||||
end
|
||||
else
|
||||
-- open peripherals
|
||||
self.grid.values = p.getAdvancedMethodsData()
|
||||
for name,f in pairs(self.grid.values) do
|
||||
f.name = name
|
||||
end
|
||||
end
|
||||
|
||||
self.grid:update()
|
||||
self.grid:setIndex(1)
|
||||
|
||||
self.doc:setText(self:getDocumentation())
|
||||
|
||||
self.statusBar:setStatus(self.peripheral.type)
|
||||
UI.Page.enable(self)
|
||||
|
||||
self:setFocus(self.grid)
|
||||
end
|
||||
|
||||
function methodsPage:eventHandler(event)
|
||||
if event.type == 'back' then
|
||||
UI:setPage(peripheralsPage)
|
||||
@@ -132,7 +131,7 @@ end
|
||||
function methodsPage:getDocumentation()
|
||||
local method = self.grid:getSelected()
|
||||
|
||||
if not method or method.noext then -- computercraft docs
|
||||
if method.noext then -- computercraft docs
|
||||
return 'No documentation'
|
||||
end
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ function page:enable()
|
||||
self.eject.value = config.eject
|
||||
self.automatic.value = config.automatic
|
||||
|
||||
self.dir:move(math.floor((self.width / 2) - 3) + 1, self.dir.y)
|
||||
self.dir.x = math.floor((self.width / 2) - 3) + 1
|
||||
|
||||
UI.Page.enable(self)
|
||||
end
|
||||
@@ -218,7 +218,7 @@ function page:copy()
|
||||
self.progress:sync()
|
||||
|
||||
self.progress.value = 0
|
||||
-- self.progress:clear()
|
||||
self.progress:clear()
|
||||
|
||||
self:scan()
|
||||
|
||||
|
||||
@@ -30,12 +30,23 @@ local page = UI.Page {
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
|
||||
local function tovalue(s)
|
||||
if type(s) == 'table' then
|
||||
return 'table'
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
for k,v in pairs(row) do
|
||||
row[k] = type(v) == 'table' and 'table' or v
|
||||
row[k] = tovalue(v)
|
||||
end
|
||||
|
||||
return row
|
||||
end,
|
||||
draw = function(self)
|
||||
self:adjustWidth()
|
||||
UI.Grid.draw(self)
|
||||
end,
|
||||
},
|
||||
accelerators = {
|
||||
f = 'filter',
|
||||
@@ -60,7 +71,7 @@ local page = UI.Page {
|
||||
self.menuBar:draw()
|
||||
|
||||
elseif event.type == 'grid_select' then
|
||||
multishell.openTab(_ENV, {
|
||||
multishell.openTab({
|
||||
path = 'sys/apps/Lua.lua',
|
||||
args = { event.selected },
|
||||
focused = true,
|
||||
@@ -88,25 +99,30 @@ local page = UI.Page {
|
||||
end,
|
||||
}
|
||||
|
||||
local updated = false
|
||||
local timerId = os.startTimer(1)
|
||||
|
||||
Event.addRoutine(function()
|
||||
while true do
|
||||
local _, id = os.pullEvent('timer')
|
||||
if id == timerId then
|
||||
while #page.grid.values > 100 do
|
||||
table.remove(page.grid.values)
|
||||
if updated then
|
||||
while #page.grid.values > 100 do -- page.grid.height do
|
||||
table.remove(page.grid.values, 100) -- #page.grid.values)
|
||||
end
|
||||
updated = false
|
||||
page.grid:update()
|
||||
page.grid:draw()
|
||||
page:sync()
|
||||
end
|
||||
timerId = nil
|
||||
page.grid:update()
|
||||
page.grid:draw()
|
||||
page:sync()
|
||||
timerId = os.startTimer(1)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local hookFunction = function(event, e)
|
||||
if not page.filtered[event] and not page.paused and not (event == 'timer' and e[1] == timerId) then
|
||||
updated = true
|
||||
table.insert(page.grid.values, 1, {
|
||||
event = event,
|
||||
p1 = e[1],
|
||||
@@ -115,7 +131,6 @@ local hookFunction = function(event, e)
|
||||
p4 = e[4],
|
||||
p5 = e[5],
|
||||
})
|
||||
timerId = timerId or os.startTimer(.1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ local Socket = require('opus.socket')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local colors = _G.colors
|
||||
local fs = _G.fs
|
||||
local multishell = _ENV.multishell
|
||||
local network = _G.network
|
||||
@@ -30,7 +31,7 @@ local socket, turtle, page
|
||||
|
||||
page = UI.Page {
|
||||
coords = UI.Window {
|
||||
backgroundColor = 'black',
|
||||
backgroundColor = colors.black,
|
||||
height = 3,
|
||||
marginTop = 1, marginLeft = 1,
|
||||
draw = function(self)
|
||||
@@ -49,149 +50,156 @@ page = UI.Page {
|
||||
},
|
||||
tabs = UI.Tabs {
|
||||
x = 1, y = 4, ey = -2,
|
||||
UI.Tab {
|
||||
title = 'Run',
|
||||
scripts = UI.ScrollingGrid {
|
||||
backgroundColor = 'primary',
|
||||
columns = {
|
||||
{ heading = '', key = 'label' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
local files = fs.list(SCRIPTS_PATH)
|
||||
for _,path in pairs(files) do
|
||||
table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) })
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
page:runScript(event.selected.label)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
scripts = UI.ScrollingGrid {
|
||||
tabTitle = 'Run',
|
||||
backgroundColor = colors.cyan,
|
||||
columns = {
|
||||
{ heading = '', key = 'label' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
local files = fs.list(SCRIPTS_PATH)
|
||||
for _,path in pairs(files) do
|
||||
table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) })
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
page:runScript(event.selected.label)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
UI.Tab {
|
||||
title = 'Select',
|
||||
turtles = UI.ScrollingGrid {
|
||||
backgroundColor = 'primary',
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
{ heading = 'Dist', key = 'distance' },
|
||||
{ heading = 'Status', key = 'status' },
|
||||
{ heading = 'Fuel', key = 'fuel' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
if row.fuel then
|
||||
row.fuel = Util.toBytes(row.fuel)
|
||||
turtles = UI.ScrollingGrid {
|
||||
tabTitle = 'Select',
|
||||
backgroundColor = colors.cyan,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
{ heading = 'Dist', key = 'distance' },
|
||||
{ heading = 'Status', key = 'status' },
|
||||
{ heading = 'Fuel', key = 'fuel' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
if row.fuel then
|
||||
row.fuel = Util.toBytes(row.fuel)
|
||||
end
|
||||
if row.distance then
|
||||
row.distance = Util.round(row.distance, 1)
|
||||
end
|
||||
return row
|
||||
end,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
for _,v in pairs(network) do
|
||||
if v.fuel then
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
if row.distance then
|
||||
row.distance = Util.round(row.distance, 1)
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
turtle = event.selected
|
||||
config.id = event.selected.id
|
||||
Config.update('Turtles', config)
|
||||
multishell.setTitle(multishell.getCurrent(), turtle.label)
|
||||
if socket then
|
||||
socket:close()
|
||||
socket = nil
|
||||
end
|
||||
return row
|
||||
end,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
for _,v in pairs(network) do
|
||||
if v.fuel then
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
inventory = UI.ScrollingGrid {
|
||||
backgroundColor = colors.cyan,
|
||||
tabTitle = 'Inv',
|
||||
columns = {
|
||||
{ heading = '', key = 'index', width = 2 },
|
||||
{ heading = '', key = 'count', width = 2 },
|
||||
{ heading = 'Inventory', key = 'key' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
getRowTextColor = function(self, row, selected)
|
||||
if turtle and row.selected then
|
||||
return colors.yellow
|
||||
end
|
||||
return UI.ScrollingGrid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
draw = function(self)
|
||||
local t = turtle
|
||||
Util.clear(self.values)
|
||||
if t then
|
||||
for k,v in pairs(t.inv or { }) do -- new method (less data)
|
||||
local index, count = k:match('(%d+),(%d+)')
|
||||
v = {
|
||||
index = tonumber(index),
|
||||
key = v,
|
||||
count = tonumber(count),
|
||||
}
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
|
||||
for _,v in pairs(t.inventory or { }) do
|
||||
if v.count > 0 then
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
turtle = event.selected
|
||||
config.id = event.selected.id
|
||||
Config.update('Turtles', config)
|
||||
multishell.setTitle(multishell.getCurrent(), turtle.label)
|
||||
if socket then
|
||||
socket:close()
|
||||
socket = nil
|
||||
end
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
},
|
||||
UI.Tab {
|
||||
title = 'Inv',
|
||||
inventory = UI.ScrollingGrid {
|
||||
backgroundColor = 'primary',
|
||||
columns = {
|
||||
{ heading = '', key = 'index', width = 2 },
|
||||
{ heading = '', key = 'count', width = 2 },
|
||||
{ heading = 'Inventory', key = 'key' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
getRowTextColor = function(self, row, selected)
|
||||
if turtle and row.selected then
|
||||
return 'yellow'
|
||||
end
|
||||
return UI.ScrollingGrid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
draw = function(self)
|
||||
local t = turtle
|
||||
Util.clear(self.values)
|
||||
if t then
|
||||
for k,v in pairs(t.inv or { }) do -- new method (less data)
|
||||
local index, count = k:match('(%d+),(%d+)')
|
||||
v = {
|
||||
index = tonumber(index),
|
||||
key = v,
|
||||
count = tonumber(count),
|
||||
}
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
|
||||
for _,v in pairs(t.inventory or { }) do
|
||||
if v.count > 0 then
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
for _,v in pairs(self.values) do
|
||||
if v.index == t.slotIndex then
|
||||
v.selected = true
|
||||
end
|
||||
|
||||
for _,v in pairs(self.values) do
|
||||
if v.index == t.slotIndex then
|
||||
v.selected = true
|
||||
end
|
||||
if v.key then
|
||||
v.key = itemDB:getName(v.key)
|
||||
end
|
||||
if v.key then
|
||||
v.key = itemDB:getName(v.key)
|
||||
end
|
||||
end
|
||||
self:adjustWidth()
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
local fn = string.format('turtle.select(%d)', event.selected.index)
|
||||
page:runFunction(fn)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
end
|
||||
self:adjustWidth()
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
local fn = string.format('turtle.select(%d)', event.selected.index)
|
||||
page:runFunction(fn)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
UI.Tab {
|
||||
title = 'Action',
|
||||
backgroundColor = 'primary',
|
||||
--[[
|
||||
policy = UI.ScrollingGrid {
|
||||
tabTitle = 'Mod',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
},
|
||||
values = policies,
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
},
|
||||
]]
|
||||
action = UI.Window {
|
||||
tabTitle = 'Action',
|
||||
backgroundColor = colors.cyan,
|
||||
moveUp = UI.Button {
|
||||
x = 5, y = 2,
|
||||
text = 'up',
|
||||
@@ -223,43 +231,10 @@ page = UI.Page {
|
||||
fn = 'turtle.turnRight',
|
||||
},
|
||||
info = UI.TextArea {
|
||||
x = 15, y = 1,
|
||||
x = 15, y = 2,
|
||||
inactive = true,
|
||||
},
|
||||
showBlocks = function(self)
|
||||
local script = [[
|
||||
local function inspect(direction)
|
||||
local s,b = turtle['inspect' .. (direction or '')]()
|
||||
if not s then
|
||||
return 'minecraft:air:0'
|
||||
end
|
||||
return string.format('%s:%d', b.name, b.metadata)
|
||||
end
|
||||
|
||||
local bu, bf, bd = inspect('Up'), inspect(), inspect('Down')
|
||||
return string.format('%s\n%s\n%s', bu, bf, bd)
|
||||
]]
|
||||
|
||||
local s, m = page:runFunction(script, true)
|
||||
self.info:setText(s or m)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'button_press' then
|
||||
if event.button.fn then
|
||||
page:runFunction(event.button.fn, event.button.nowrap)
|
||||
self:showBlocks()
|
||||
end
|
||||
return true
|
||||
end
|
||||
return UI.Tab.eventHandler(self, event)
|
||||
end,
|
||||
}
|
||||
},
|
||||
enable = function(self)
|
||||
if config.tab then
|
||||
self:selectTab(Util.find(self, 'title', config.tab))
|
||||
end
|
||||
UI.Tabs.enable(self)
|
||||
end
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
values = { },
|
||||
@@ -356,6 +331,24 @@ function page:runScript(scriptName)
|
||||
end
|
||||
end
|
||||
|
||||
function page:showBlocks()
|
||||
local script = [[
|
||||
local function inspect(direction)
|
||||
local s,b = turtle['inspect' .. (direction or '')]()
|
||||
if not s then
|
||||
return 'minecraft:air:0'
|
||||
end
|
||||
return string.format('%s:%d', b.name, b.metadata)
|
||||
end
|
||||
|
||||
local bu, bf, bd = inspect('Up'), inspect(), inspect('Down')
|
||||
return string.format('%s\n%s\n%s', bu, bf, bd)
|
||||
]]
|
||||
|
||||
local s, m = self:runFunction(script, true)
|
||||
self.tabs.action.info:setText(s or m)
|
||||
end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'quit' then
|
||||
UI:quit()
|
||||
@@ -364,6 +357,13 @@ function page:eventHandler(event)
|
||||
config.tab = event.button.text
|
||||
Config.update('Turtles', config)
|
||||
|
||||
elseif event.type == 'button_press' then
|
||||
if event.button.fn then
|
||||
self:runFunction(event.button.fn, event.button.nowrap)
|
||||
self:showBlocks()
|
||||
elseif event.button.script then
|
||||
self:runScript(event.button.script)
|
||||
end
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
@@ -393,5 +393,9 @@ Event.onInterval(1, function()
|
||||
end
|
||||
end)
|
||||
|
||||
if config.tab then
|
||||
page.tabs.tabBar:selectTab(config.tab)
|
||||
end
|
||||
|
||||
UI:setPage(page)
|
||||
UI:start()
|
||||
|
||||
@@ -6,49 +6,3 @@ end
|
||||
|
||||
_ENV.shell.setCompletionFunction("packages/common/edit.lua", c)
|
||||
_ENV.shell.setCompletionFunction("packages/common/hexedit.lua", c)
|
||||
|
||||
_ENV.shell.registerHandler(function(env, command, args)
|
||||
if command:match('^!') then
|
||||
return {
|
||||
title = 'lua',
|
||||
path = table.concat({ command:match('^!(.+)'), table.unpack(args) }, ' '),
|
||||
args = args,
|
||||
load = function(s)
|
||||
return function()
|
||||
local fn, m
|
||||
local wrapped
|
||||
|
||||
fn = load('return (' ..s.. ')', 'lua', nil, env)
|
||||
|
||||
if fn then
|
||||
fn = load('return {' ..s.. '}', 'lua', nil, env)
|
||||
wrapped = true
|
||||
end
|
||||
|
||||
if fn then
|
||||
fn, m = pcall(fn)
|
||||
if #m <= 1 and wrapped then
|
||||
m = m[1]
|
||||
end
|
||||
else
|
||||
fn, m = load(s, 'lua', nil, env)
|
||||
if fn then
|
||||
fn, m = pcall(fn)
|
||||
end
|
||||
end
|
||||
|
||||
if fn then
|
||||
if m or wrapped then
|
||||
require('opus.util').print(m or 'nil')
|
||||
else
|
||||
print()
|
||||
end
|
||||
else
|
||||
_G.printError(m)
|
||||
end
|
||||
end
|
||||
end,
|
||||
env = env,
|
||||
}
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
local Util = require('opus.util')
|
||||
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
local term = _G.term
|
||||
|
||||
local args = { ... }
|
||||
local mon = not args[1] and term.current() or
|
||||
device[args[1]] or
|
||||
peripheral.wrap(args[1]) or
|
||||
local mon = args[1] and peripheral.wrap(args[1]) or
|
||||
peripheral.find('monitor') or
|
||||
error('Syntax: debug <monitor>')
|
||||
|
||||
mon.clear()
|
||||
if mon.setTextScale then
|
||||
mon.setTextScale(.5)
|
||||
end
|
||||
mon.setTextScale(.5)
|
||||
mon.setCursorPos(1, 1)
|
||||
|
||||
local oldDebug = _G._syslog
|
||||
@@ -24,16 +19,13 @@ _G._syslog = function(...)
|
||||
local oldTerm = term.redirect(mon)
|
||||
Util.print(...)
|
||||
term.redirect(oldTerm)
|
||||
oldDebug(...)
|
||||
end
|
||||
|
||||
repeat
|
||||
local e, side = os.pullEventRaw('monitor_touch')
|
||||
if e == 'monitor_touch' and side == mon.side then
|
||||
mon.clear()
|
||||
if mon.setTextScale then
|
||||
mon.setTextScale(.5)
|
||||
end
|
||||
mon.setTextScale(.5)
|
||||
mon.setCursorPos(1, 1)
|
||||
end
|
||||
until e == 'terminate'
|
||||
|
||||
202
common/edit.lua
202
common/edit.lua
@@ -1,15 +1,15 @@
|
||||
local Array = require('opus.array')
|
||||
local Config = require('opus.config')
|
||||
local fuzzy = require('opus.fuzzy')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local device = _G.device
|
||||
local fs = _G.fs
|
||||
local keys = _G.keys
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
local shell = _ENV.shell
|
||||
local term = _G.term.current()
|
||||
local term = _G.term
|
||||
local textutils = _G.textutils
|
||||
|
||||
local _format = string.format
|
||||
@@ -202,6 +202,7 @@ local page = UI.Page {
|
||||
label = 'Find',
|
||||
search = UI.TextEntry {
|
||||
x = 7, ex = -3,
|
||||
limit = 512,
|
||||
accelerators = {
|
||||
[ 'enter' ] = 'accept',
|
||||
},
|
||||
@@ -231,6 +232,7 @@ local page = UI.Page {
|
||||
label = 'Save',
|
||||
filename = UI.TextEntry {
|
||||
x = 7, ex = -3,
|
||||
limit = 512,
|
||||
accelerators = {
|
||||
[ 'enter' ] = 'accept',
|
||||
},
|
||||
@@ -304,7 +306,7 @@ local page = UI.Page {
|
||||
x = 2, y = 2, ey = -4, ex = -2,
|
||||
columns = {
|
||||
{ key = 'name', heading = 'Name' },
|
||||
{ key = 'dir', heading = 'Directory', textColor = 'lightGray' },
|
||||
{ key = 'dir', heading = 'Directory' },
|
||||
},
|
||||
accelerators = {
|
||||
backspace = 'slide_hide',
|
||||
@@ -318,7 +320,7 @@ local page = UI.Page {
|
||||
show = function(self)
|
||||
local t = { }
|
||||
for _,v in pairs(config.recent or { }) do
|
||||
_insert(t, { name = fs.getName(v), dir = fs.getDir(v), path = v })
|
||||
table.insert(t, { name = fs.getName(v), dir = fs.getDir(v), path = v })
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
self.grid:setIndex(1)
|
||||
@@ -334,23 +336,102 @@ local page = UI.Page {
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
quick_open = UI.QuickSelect {
|
||||
modal = true,
|
||||
enable = function() end,
|
||||
quick_open = UI.SlideOut {
|
||||
filter_entry = UI.TextEntry {
|
||||
x = 2, y = 2, ex = -2,
|
||||
limit = 256,
|
||||
shadowText = 'File name',
|
||||
accelerators = {
|
||||
[ 'enter' ] = 'accept',
|
||||
[ 'up' ] = 'grid_up',
|
||||
[ 'down' ] = 'grid_down',
|
||||
},
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, y = 3, ex = -2, ey = -4,
|
||||
disableHeader = true,
|
||||
columns = {
|
||||
{ key = 'name' },
|
||||
{ key = 'dir', textColor = 'lightGray' },
|
||||
},
|
||||
accelerators = {
|
||||
grid_select = 'accept',
|
||||
},
|
||||
},
|
||||
cancel = UI.Button {
|
||||
x = -9, y = -2,
|
||||
text = 'Cancel',
|
||||
event = 'slide_hide',
|
||||
},
|
||||
apply_filter = function(self, filter)
|
||||
local t = { }
|
||||
if filter then
|
||||
filter = filter:lower()
|
||||
self.grid.sortColumn = 'score'
|
||||
self.grid.inverseSort = true
|
||||
|
||||
for _,v in pairs(self.listing) do
|
||||
v.score = fuzzy(v.lname, filter)
|
||||
if v.score then
|
||||
_insert(t, v)
|
||||
end
|
||||
end
|
||||
else
|
||||
self.grid.sortColumn = 'lname'
|
||||
self.grid.inverseSort = false
|
||||
t = self.listing
|
||||
end
|
||||
|
||||
self.grid:setValues(t)
|
||||
self.grid:setIndex(1)
|
||||
end,
|
||||
show = function(self)
|
||||
UI.QuickSelect.enable(self)
|
||||
self:focusFirst()
|
||||
self:draw()
|
||||
local listing = { }
|
||||
local function recurse(dir)
|
||||
local files = fs.list(dir)
|
||||
for _,f in ipairs(files) do
|
||||
local fullName = fs.combine(dir, f)
|
||||
if fs.native.isDir(fullName) then -- skip virtual dirs
|
||||
if f ~= '.git' then recurse(fullName) end
|
||||
else
|
||||
_insert(listing, {
|
||||
name = f,
|
||||
dir = dir,
|
||||
lname = f:lower(),
|
||||
fullName = fullName,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
recurse('')
|
||||
self.listing = listing
|
||||
self:apply_filter()
|
||||
self.filter_entry:reset()
|
||||
UI.SlideOut.show(self)
|
||||
self:addTransition('expandUp', { easing = 'outBounce', ticks = 12 })
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'select_cancel' then
|
||||
self:disable()
|
||||
elseif event.type == 'select_file' then
|
||||
self:disable()
|
||||
actions.process('open', event.file)
|
||||
if event.type == 'grid_up' then
|
||||
self.grid:emit({ type = 'scroll_up' })
|
||||
|
||||
elseif event.type == 'grid_down' then
|
||||
self.grid:emit({ type = 'scroll_down' })
|
||||
|
||||
elseif event.type == 'accept' then
|
||||
local sel = self.grid:getSelected()
|
||||
if sel then
|
||||
actions.process('open', sel.fullName)
|
||||
self:hide()
|
||||
end
|
||||
|
||||
elseif event.type == 'text_change' then
|
||||
self:apply_filter(event.text)
|
||||
self.grid:draw()
|
||||
|
||||
else
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
return UI.QuickSelect.eventHandler(self, event)
|
||||
return true
|
||||
end,
|
||||
},
|
||||
completions = UI.SlideOut {
|
||||
@@ -375,9 +456,10 @@ local page = UI.Page {
|
||||
event = 'slide_hide',
|
||||
},
|
||||
show = function(self, values)
|
||||
local m = Util.reduce(values, function(m, v)
|
||||
return #v.text > m and #v.text or m
|
||||
end, 12)
|
||||
local m = 12
|
||||
for _, v in pairs(values) do
|
||||
m = #v.text > m and #v.text or m
|
||||
end
|
||||
m = m + 3
|
||||
m = m > self.parent.width and self.parent.width or m
|
||||
self.ox = -m
|
||||
@@ -413,9 +495,7 @@ local page = UI.Page {
|
||||
scan = function(self)
|
||||
self.values = { }
|
||||
for k, v in pairs(device) do
|
||||
if type(v.side) == 'string' then
|
||||
_insert(self.values, { name = k, complete = 'peripheral.wrap("' .. v.side .. '")' })
|
||||
end
|
||||
table.insert(self.values, { name = k, complete = 'peripheral.wrap("' .. v.side .. '")' })
|
||||
end
|
||||
end,
|
||||
postInit = function(self)
|
||||
@@ -442,7 +522,7 @@ local page = UI.Page {
|
||||
for k, v in pairs(dev) do
|
||||
if type(v) == 'function' then
|
||||
local m = docs and docs[k] and docs[k]:match('^function%((.+)%).+')
|
||||
_insert(t, { method = k, complete = k .. '(' .. (m or '') .. ')' })
|
||||
table.insert(t, { method = k, complete = k .. '(' .. (m or '') .. ')' })
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -491,14 +571,10 @@ local page = UI.Page {
|
||||
UI.Window.resize(self)
|
||||
|
||||
w, h = self.width, self.height
|
||||
actions.set_cursor()
|
||||
actions.set_cursor(x, y)
|
||||
actions.dirty_all()
|
||||
actions.redraw()
|
||||
end,
|
||||
setCursorPos = function(self, cx, cy)
|
||||
self.cursorBlink = cy >= 1 and cy <= self.height
|
||||
UI.Window.setCursorPos(self, cx, cy)
|
||||
end,
|
||||
draw = function()
|
||||
actions.redraw()
|
||||
end,
|
||||
@@ -571,9 +647,9 @@ local function getFileInfo(path)
|
||||
config.recent = config.recent or { }
|
||||
|
||||
Array.removeByValue(config.recent, path)
|
||||
_insert(config.recent, 1, path)
|
||||
table.insert(config.recent, 1, path)
|
||||
while #config.recent > 10 do
|
||||
_remove(config.recent)
|
||||
table.remove(config.recent)
|
||||
end
|
||||
|
||||
Config.update('editor', config)
|
||||
@@ -639,7 +715,7 @@ local function redraw()
|
||||
if dirty.y > 0 then
|
||||
for dy = 1, h do
|
||||
local sLine = tLines[dy + scrollY]
|
||||
if sLine and #sLine > 0 then
|
||||
if sLine ~= nil then
|
||||
if dy + scrollY >= dirty.y and dy + scrollY <= dirty.ey then
|
||||
page.editor:clearLine(dy)
|
||||
writeHighlighted(sLine, dy + scrollY, dy)
|
||||
@@ -686,7 +762,7 @@ actions = {
|
||||
local last = _remove(undo.chain)
|
||||
if last then
|
||||
undo.active = true
|
||||
_insert(undo.redo, { })
|
||||
table.insert(undo.redo, { })
|
||||
for i = #last, 1, -1 do
|
||||
local u = last[i]
|
||||
actions[u.action](_unpack(u.args))
|
||||
@@ -700,14 +776,14 @@ actions = {
|
||||
undo_add = function(entry)
|
||||
if undo.active then
|
||||
local last = undo.redo[#undo.redo]
|
||||
_insert(last, entry)
|
||||
table.insert(last, entry)
|
||||
else
|
||||
if not undo.redo_active then
|
||||
undo.redo = { }
|
||||
end
|
||||
local last = undo.chain[#undo.chain]
|
||||
if last and undo.continue then
|
||||
_insert(last, entry)
|
||||
table.insert(last, entry)
|
||||
else
|
||||
_insert(undo.chain, { entry })
|
||||
end
|
||||
@@ -827,7 +903,7 @@ actions = {
|
||||
if not force and undo.chain[#undo.chain] ~= lastSave then
|
||||
page.unsaved:show('file_new')
|
||||
else
|
||||
actions.open('/untitled.lua')
|
||||
actions.open('/untitled.txt')
|
||||
end
|
||||
end,
|
||||
|
||||
@@ -901,7 +977,11 @@ actions = {
|
||||
if fs.isReadOnly(filename) then
|
||||
actions.error("access denied")
|
||||
else
|
||||
local s, m = pcall(Util.writeFile, filename, table.concat(tLines, '\n'))
|
||||
local s, m = pcall(function()
|
||||
if not Util.writeLines(filename, tLines) then
|
||||
error("Failed to open " .. filename)
|
||||
end
|
||||
end)
|
||||
|
||||
if s then
|
||||
lastSave = undo.chain[#undo.chain]
|
||||
@@ -932,40 +1012,29 @@ actions = {
|
||||
actions.error('open available with multishell')
|
||||
return
|
||||
end
|
||||
local routine = {
|
||||
focused = true,
|
||||
title = fs.getName(fileInfo.path),
|
||||
onExit = function(_, result)
|
||||
-- display results of process before closing window
|
||||
if result then -- clean exit
|
||||
-- any errors will be picked up by multishells
|
||||
-- error handling
|
||||
print('Press enter to exit')
|
||||
while true do
|
||||
local e, code = os.pullEventRaw('key')
|
||||
if e == 'terminate' or e == 'key' and code == keys.enter then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
}
|
||||
if undo.chain[#undo.chain] == lastSave then
|
||||
routine.path = 'sys/apps/shell.lua'
|
||||
routine.args = { fileInfo.path }
|
||||
local nTask = shell.openTab(fileInfo.path)
|
||||
if nTask then
|
||||
shell.switchTab(nTask)
|
||||
else
|
||||
actions.error("error starting Task")
|
||||
end
|
||||
else
|
||||
local fn, msg = load(_concat(tLines, '\n'), fileInfo.path)
|
||||
if not fn then
|
||||
if fn then
|
||||
multishell.openTab({
|
||||
fn = fn,
|
||||
focused = true,
|
||||
title = fs.getName(fileInfo.path),
|
||||
})
|
||||
else
|
||||
local ln = msg:match(':(%d+):')
|
||||
if ln and tonumber(ln) then
|
||||
actions.go_to(1, tonumber(ln))
|
||||
end
|
||||
actions.error(msg)
|
||||
return
|
||||
end
|
||||
routine.fn = fn
|
||||
end
|
||||
multishell.openTab(_ENV, routine)
|
||||
end,
|
||||
|
||||
status = function()
|
||||
@@ -1462,23 +1531,16 @@ actions = {
|
||||
end,
|
||||
}
|
||||
|
||||
local args, options = Util.parse( ... )
|
||||
local args = { ... }
|
||||
local filename = args[1] and shell.resolve(args[1])
|
||||
if not (actions.load(filename) or actions.load(config.filename) or actions.load('untitled.lua')) then
|
||||
if not (actions.load(filename) or actions.load(config.filename) or actions.load('untitled.txt')) then
|
||||
error('Error opening file')
|
||||
end
|
||||
|
||||
if tonumber(options.line) then
|
||||
scrollY = math.max(0, tonumber(options.line) - math.floor(h / 2))
|
||||
actions.go_to(1, tonumber(options.line))
|
||||
actions.set_cursor()
|
||||
actions.dirty_all()
|
||||
end
|
||||
|
||||
UI:setPage(page)
|
||||
local s, m = pcall(function() UI:start() end)
|
||||
if not s then
|
||||
actions.save('/crash.txt')
|
||||
print('Editor has crashed. File saved as /crash.txt')
|
||||
error(m, -1)
|
||||
error(m)
|
||||
end
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
category = "Apps",
|
||||
requires = "advancedComputer",
|
||||
iconExt = "\030 \031 \128\030d\159\030 \031d\140\030d\031 \155\030 \0315\140\0305\031 \155\030 \128\010\030 \031d\136\145\0315\136\145\031d\153\031 \128\0315\153\010\030 \031 \128\031d\130\140\134\0315\140\134\031 \128",
|
||||
run = "fileui --exec=hexedit.lua --title=hexedit",
|
||||
run = "fileui --exec=hexedit.lua",
|
||||
},
|
||||
[ "fb1c39e9f4f3c2628ad173ab401a6e4e4baf783d" ] = {
|
||||
title = "Sounds",
|
||||
@@ -78,9 +78,4 @@
|
||||
category = "Apps",
|
||||
run = "write",
|
||||
},
|
||||
[ "c543ece81605c7d202121c62080a0db4020fc2c75bfac35d101d7f3e93c93949" ] = {
|
||||
category = "Apps",
|
||||
run = "ascii",
|
||||
title = "Ascii",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
packages/common/ascii.lua urlfs https://pastebin.com/raw/U3KcNyJd
|
||||
packages/common/ascii.lua urlfs http://pastebin.com/raw/u3kcnyjd
|
||||
packages/common/hexedit.lua urlfs https://pastebin.com/raw/Ds9ajsp4
|
||||
packages/common/colors.lua urlfs https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/ignore/colors.lua
|
||||
packages/common/cowsay.lua urlfs https://pastebin.com/raw/n00VQJsw
|
||||
packages/common/calc.lua urlfs https://pastebin.com/raw/nAinUn1h
|
||||
packages/common/write.lua urlfs https://pastebin.com/raw/RSyhCjqv
|
||||
# pretty output
|
||||
rom/modules/main/inspect.lua urlfs https://raw.githubusercontent.com/kikito/inspect.lua/master/inspect.lua
|
||||
packages/common/write.lua urlfs https://pastebin.com/raw/RSyhCjqv
|
||||
@@ -1,3 +1,4 @@
|
||||
_G.requireInjector(_ENV)
|
||||
local config = require('opus.config').load('gps')
|
||||
if config.home then
|
||||
if turtle.enableGPS() then
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
local turtle = _G.turtle
|
||||
|
||||
turtle.run(function()
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local GPS = require('opus.gps')
|
||||
|
||||
if not turtle.enableGPS() then
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
_G.requireInjector(_ENV)
|
||||
local Config = require('opus.config')
|
||||
local pt = turtle.enableGPS()
|
||||
if pt then
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
local function summon(id)
|
||||
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local GPS = require('opus.gps')
|
||||
local Point = require('opus.point')
|
||||
local Socket = require('opus.socket')
|
||||
|
||||
@@ -89,7 +89,7 @@ local function hijackTurtle(remoteId)
|
||||
local socket, msg = Socket.connect(remoteId, 188)
|
||||
|
||||
if not socket then
|
||||
error(msg, 0)
|
||||
error(msg)
|
||||
end
|
||||
|
||||
socket:write('turtle')
|
||||
@@ -101,7 +101,7 @@ local function hijackTurtle(remoteId)
|
||||
socket:write({ method, ... })
|
||||
local resp = socket:read()
|
||||
if not resp then
|
||||
error('T/O: ' .. method, 0)
|
||||
error('timed out: ' .. method)
|
||||
end
|
||||
return table.unpack(resp)
|
||||
end
|
||||
@@ -308,7 +308,7 @@ local containerText = {
|
||||
}
|
||||
|
||||
local containTab = UI.Tab {
|
||||
title = 'Contain',
|
||||
tabTitle = 'Contain',
|
||||
button = UI.Button {
|
||||
x = 2, y = 2,
|
||||
text = 'Set corner',
|
||||
@@ -321,7 +321,7 @@ local containTab = UI.Tab {
|
||||
}
|
||||
|
||||
local blocksTab = UI.Tab {
|
||||
title = 'Blocks',
|
||||
tabTitle = 'Blocks',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 1,
|
||||
columns = {
|
||||
@@ -333,7 +333,7 @@ local blocksTab = UI.Tab {
|
||||
}
|
||||
|
||||
local turtlesTab = UI.Tab {
|
||||
title = 'Turtles',
|
||||
tabTitle = 'Turtles',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 1,
|
||||
values = pool,
|
||||
|
||||
@@ -23,7 +23,7 @@ local colours = _G.colors
|
||||
|
||||
local args, options = Util.parse(...)
|
||||
|
||||
local oldTerm, showInput, skipLast, lastDelay, curInput = Util.shallowCopy(_G.device.terminal), false, false, 2, ""
|
||||
local oldTerm, showInput, skipLast, lastDelay, curInput = Util.shallowCopy(multishell.term), false, false, 2, ""
|
||||
local curBlink, oldBlink, tTerm, buffer, colourNum, xPos, yPos, oldXPos, oldYPos, tCol, bCol, xSize, ySize = false, false, {}, {}, {}, 1, 1, 1, 1, colours.white, colours.black, oldTerm.getSize()
|
||||
local greys, buttons = {["0"] = true, ["7"] = true, ["8"] = true, ["f"] = true}, {"l", "r", "m"}
|
||||
local charW, charH, chars
|
||||
@@ -60,8 +60,8 @@ if options.help then
|
||||
end
|
||||
|
||||
if options.daemon then
|
||||
_G.device.keyboard.addHotkey('control-P', function()
|
||||
multishell.openTab(_ENV, {
|
||||
device.keyboard.addHotkey('control-P', function()
|
||||
multishell.openTab({
|
||||
path = 'sys/apps/shell.lua',
|
||||
args = { arg[0], '--noResize', '--rawOutput', 'recorder.gif' },
|
||||
})
|
||||
@@ -141,7 +141,7 @@ end
|
||||
|
||||
-- Build a terminal that records stuff:
|
||||
|
||||
local recTerm = _G.device.terminal
|
||||
local recTerm = multishell.term
|
||||
|
||||
for key, func in pairs(oldTerm) do
|
||||
if type(func) == 'function' then
|
||||
@@ -153,7 +153,7 @@ for key, func in pairs(oldTerm) do
|
||||
end
|
||||
callCount = callCount + 1
|
||||
curCalls[callCount] = { key, ... }
|
||||
return table.unpack(result)
|
||||
return unpack(result)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -196,7 +196,7 @@ end
|
||||
_G.device.keyboard.removeHotkey('control-p')
|
||||
|
||||
for k,fn in pairs(oldTerm) do
|
||||
_G.device.terminal[k] = fn
|
||||
multishell.term[k] = fn
|
||||
end
|
||||
|
||||
multishell.unhideTab(tabId)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
title = 'Compress',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/compress',
|
||||
description = [[untar / gunzip]],
|
||||
license = 'MIT',
|
||||
}
|
||||
@@ -1,530 +0,0 @@
|
||||
--[[
|
||||
see: https://github.com/davidm/lua-compress-deflatelua/
|
||||
for licensing / details
|
||||
--]]
|
||||
|
||||
local M = {_TYPE='module', _NAME='compress.deflatelua', _VERSION='0.3.20111128'}
|
||||
|
||||
local assert = assert
|
||||
local error = error
|
||||
local ipairs = ipairs
|
||||
local pairs = pairs
|
||||
local tostring = tostring
|
||||
local type = type
|
||||
local setmetatable = setmetatable
|
||||
local io = io
|
||||
local math = math
|
||||
local table_sort = table.sort
|
||||
local math_max = math.max
|
||||
local string_char = string.char
|
||||
local band = bit32.band
|
||||
local lshift = bit32.lshift
|
||||
local rshift = bit32.rshift
|
||||
|
||||
local function runtime_error(s, level)
|
||||
level = level or 1
|
||||
error(s, level+1)
|
||||
end
|
||||
|
||||
|
||||
local function make_outstate(outbs)
|
||||
local outstate = {}
|
||||
outstate.outbs = outbs
|
||||
outstate.window = {}
|
||||
outstate.window_pos = 1
|
||||
return outstate
|
||||
end
|
||||
|
||||
|
||||
local function output(outstate, byte)
|
||||
local window_pos = outstate.window_pos
|
||||
outstate.outbs(byte)
|
||||
outstate.window[window_pos] = byte
|
||||
outstate.window_pos = window_pos % 32768 + 1 -- 32K
|
||||
end
|
||||
|
||||
|
||||
local function noeof(val)
|
||||
return assert(val, 'unexpected end of file')
|
||||
end
|
||||
|
||||
|
||||
local function hasbit(bits, bit)
|
||||
return bits % (bit + bit) >= bit
|
||||
end
|
||||
|
||||
|
||||
local function memoize(f)
|
||||
local mt = {}
|
||||
local t = setmetatable({}, mt)
|
||||
function mt:__index(k)
|
||||
local v = f(k)
|
||||
t[k] = v
|
||||
return v
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
-- small optimization (lookup table for powers of 2)
|
||||
local pow2 = memoize(function(n) return 2^n end)
|
||||
|
||||
--local tbits = memoize(
|
||||
-- function(bits)
|
||||
-- return memoize( function(bit) return getbit(bits, bit) end )
|
||||
-- end )
|
||||
|
||||
|
||||
-- weak metatable marking objects as bitstream type
|
||||
local is_bitstream = setmetatable({}, {__mode='k'})
|
||||
|
||||
local function bytestream_from_file(fh)
|
||||
local o = {}
|
||||
function o.read()
|
||||
local sb = fh:read(1)
|
||||
if sb then return sb:byte() end
|
||||
end
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
local function bytestream_from_string(s)
|
||||
local i = 1
|
||||
local o = {}
|
||||
function o.read()
|
||||
local by
|
||||
if i <= #s then
|
||||
by = s:byte(i)
|
||||
i = i + 1
|
||||
end
|
||||
return by
|
||||
end
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
local function bytestream_from_function(f)
|
||||
local o = {}
|
||||
function o.read()
|
||||
return f()
|
||||
end
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
local function bitstream_from_bytestream(bys)
|
||||
local buf_byte = 0
|
||||
local buf_nbit = 0
|
||||
local o = {}
|
||||
|
||||
function o.nbits_left_in_byte()
|
||||
return buf_nbit
|
||||
end
|
||||
|
||||
function o:read(nbits)
|
||||
nbits = nbits or 1
|
||||
while buf_nbit < nbits do
|
||||
local byte = bys:read()
|
||||
if not byte then return end -- note: more calls also return nil
|
||||
buf_byte = buf_byte + lshift(byte, buf_nbit)
|
||||
buf_nbit = buf_nbit + 8
|
||||
end
|
||||
local bits
|
||||
if nbits == 0 then
|
||||
bits = 0
|
||||
elseif nbits == 32 then
|
||||
bits = buf_byte
|
||||
buf_byte = 0
|
||||
else
|
||||
bits = band(buf_byte, rshift(0xffffffff, 32 - nbits))
|
||||
buf_byte = rshift(buf_byte, nbits)
|
||||
end
|
||||
buf_nbit = buf_nbit - nbits
|
||||
return bits
|
||||
end
|
||||
|
||||
|
||||
is_bitstream[o] = true
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
local function get_bitstream(o)
|
||||
local bs
|
||||
if is_bitstream[o] then
|
||||
return o
|
||||
elseif io.type(o) == 'file' then
|
||||
bs = bitstream_from_bytestream(bytestream_from_file(o))
|
||||
elseif type(o) == 'string' then
|
||||
bs = bitstream_from_bytestream(bytestream_from_string(o))
|
||||
elseif type(o) == 'function' then
|
||||
bs = bitstream_from_bytestream(bytestream_from_function(o))
|
||||
else
|
||||
runtime_error 'unrecognized type'
|
||||
end
|
||||
return bs
|
||||
end
|
||||
|
||||
|
||||
local function get_obytestream(o)
|
||||
local bs
|
||||
if io.type(o) == 'file' then
|
||||
bs = function(sbyte) o:write(string_char(sbyte)) end
|
||||
elseif type(o) == 'function' then
|
||||
bs = o
|
||||
else
|
||||
runtime_error('unrecognized type: ' .. tostring(o))
|
||||
end
|
||||
return bs
|
||||
end
|
||||
|
||||
|
||||
local function HuffmanTable(init, is_full)
|
||||
local t = {}
|
||||
if is_full then
|
||||
for val,nbits in pairs(init) do
|
||||
if nbits ~= 0 then
|
||||
t[#t+1] = {val=val, nbits=nbits}
|
||||
end
|
||||
end
|
||||
else
|
||||
for i=1,#init-2,2 do
|
||||
local firstval, nbits, nextval = init[i], init[i+1], init[i+2]
|
||||
if nbits ~= 0 then
|
||||
for val=firstval,nextval-1 do
|
||||
t[#t+1] = {val=val, nbits=nbits}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
table_sort(t, function(a,b)
|
||||
return a.nbits == b.nbits and a.val < b.val or a.nbits < b.nbits
|
||||
end)
|
||||
|
||||
-- assign codes
|
||||
local code = 1 -- leading 1 marker
|
||||
local nbits = 0
|
||||
for _,s in ipairs(t) do
|
||||
if s.nbits ~= nbits then
|
||||
code = code * pow2[s.nbits - nbits]
|
||||
nbits = s.nbits
|
||||
end
|
||||
s.code = code
|
||||
code = code + 1
|
||||
end
|
||||
|
||||
local minbits = math.huge
|
||||
local look = {}
|
||||
for _,s in ipairs(t) do
|
||||
minbits = math.min(minbits, s.nbits)
|
||||
look[s.code] = s.val
|
||||
end
|
||||
|
||||
local msb = function(bits, nbits)
|
||||
local res = 0
|
||||
for _=1,nbits do
|
||||
res = lshift(res, 1) + band(bits, 1)
|
||||
bits = rshift(bits, 1)
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
local tfirstcode = memoize(
|
||||
function(bits) return pow2[minbits] + msb(bits, minbits) end)
|
||||
|
||||
function t:read(bs)
|
||||
local code = 1 -- leading 1 marker
|
||||
local nbits = 0
|
||||
while 1 do
|
||||
if nbits == 0 then -- small optimization (optional)
|
||||
code = tfirstcode[noeof(bs:read(minbits))]
|
||||
nbits = nbits + minbits
|
||||
else
|
||||
local b = noeof(bs:read())
|
||||
nbits = nbits + 1
|
||||
code = code * 2 + b -- MSB first
|
||||
end
|
||||
local val = look[code]
|
||||
if val then
|
||||
return val
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
local function parse_gzip_header(bs)
|
||||
-- local FLG_FTEXT = 2^0
|
||||
local FLG_FHCRC = 2^1
|
||||
local FLG_FEXTRA = 2^2
|
||||
local FLG_FNAME = 2^3
|
||||
local FLG_FCOMMENT = 2^4
|
||||
|
||||
local id1 = bs:read(8)
|
||||
local id2 = bs:read(8)
|
||||
if id1 ~= 31 or id2 ~= 139 then
|
||||
runtime_error 'not in gzip format'
|
||||
end
|
||||
bs:read(8) -- compression method
|
||||
local flg = bs:read(8) -- FLaGs
|
||||
local mtime = bs:read(32) -- Modification TIME
|
||||
local xfl = bs:read(8) -- eXtra FLags
|
||||
local os = bs:read(8) -- Operating System
|
||||
|
||||
if not os then runtime_error 'invalid header' end
|
||||
|
||||
if hasbit(flg, FLG_FEXTRA) then
|
||||
local xlen = bs:read(16)
|
||||
local extra = 0
|
||||
for i=1,xlen do
|
||||
extra = bs:read(8)
|
||||
end
|
||||
if not extra then runtime_error 'invalid header' end
|
||||
end
|
||||
|
||||
local function parse_zstring(bs)
|
||||
repeat
|
||||
local by = bs:read(8)
|
||||
if not by then runtime_error 'invalid header' end
|
||||
until by == 0
|
||||
end
|
||||
|
||||
if hasbit(flg, FLG_FNAME) then
|
||||
parse_zstring(bs)
|
||||
end
|
||||
|
||||
if hasbit(flg, FLG_FCOMMENT) then
|
||||
parse_zstring(bs)
|
||||
end
|
||||
|
||||
if hasbit(flg, FLG_FHCRC) then
|
||||
local crc16 = bs:read(16)
|
||||
if not crc16 then runtime_error 'invalid header' end
|
||||
-- IMPROVE: check CRC. where is an example .gz file that
|
||||
-- has this set?
|
||||
end
|
||||
end
|
||||
|
||||
local function parse_zlib_header(bs)
|
||||
local cm = bs:read(4) -- Compression Method
|
||||
local cinfo = bs:read(4) -- Compression info
|
||||
local fcheck = bs:read(5) -- FLaGs: FCHECK (check bits for CMF and FLG)
|
||||
local fdict = bs:read(1) -- FLaGs: FDICT (present dictionary)
|
||||
local flevel = bs:read(2) -- FLaGs: FLEVEL (compression level)
|
||||
local cmf = cinfo * 16 + cm -- CMF (Compresion Method and flags)
|
||||
local flg = fcheck + fdict * 32 + flevel * 64 -- FLaGs
|
||||
|
||||
if cm ~= 8 then -- not "deflate"
|
||||
runtime_error("unrecognized zlib compression method: " + cm)
|
||||
end
|
||||
if cinfo > 7 then
|
||||
runtime_error("invalid zlib window size: cinfo=" + cinfo)
|
||||
end
|
||||
local window_size = 2^(cinfo + 8)
|
||||
|
||||
if (cmf*256 + flg) % 31 ~= 0 then
|
||||
runtime_error("invalid zlib header (bad fcheck sum)")
|
||||
end
|
||||
|
||||
if fdict == 1 then
|
||||
runtime_error("FIX:TODO - FDICT not currently implemented")
|
||||
local dictid_ = bs:read(32)
|
||||
end
|
||||
|
||||
return window_size
|
||||
end
|
||||
|
||||
local function parse_huffmantables(bs)
|
||||
local hlit = bs:read(5) -- # of literal/length codes - 257
|
||||
local hdist = bs:read(5) -- # of distance codes - 1
|
||||
local hclen = noeof(bs:read(4)) -- # of code length codes - 4
|
||||
|
||||
local ncodelen_codes = hclen + 4
|
||||
local codelen_init = {}
|
||||
local codelen_vals = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}
|
||||
for i=1,ncodelen_codes do
|
||||
local nbits = bs:read(3)
|
||||
local val = codelen_vals[i]
|
||||
codelen_init[val] = nbits
|
||||
end
|
||||
local codelentable = HuffmanTable(codelen_init, true)
|
||||
|
||||
local function decode(ncodes)
|
||||
local init = {}
|
||||
local nbits
|
||||
local val = 0
|
||||
while val < ncodes do
|
||||
local codelen = codelentable:read(bs)
|
||||
--FIX:check nil?
|
||||
local nrepeat
|
||||
if codelen <= 15 then
|
||||
nrepeat = 1
|
||||
nbits = codelen
|
||||
elseif codelen == 16 then
|
||||
nrepeat = 3 + noeof(bs:read(2))
|
||||
-- nbits unchanged
|
||||
elseif codelen == 17 then
|
||||
nrepeat = 3 + noeof(bs:read(3))
|
||||
nbits = 0
|
||||
elseif codelen == 18 then
|
||||
nrepeat = 11 + noeof(bs:read(7))
|
||||
nbits = 0
|
||||
else
|
||||
error 'ASSERT'
|
||||
end
|
||||
for i=1,nrepeat do
|
||||
init[val] = nbits
|
||||
val = val + 1
|
||||
end
|
||||
end
|
||||
local huffmantable = HuffmanTable(init, true)
|
||||
return huffmantable
|
||||
end
|
||||
|
||||
local nlit_codes = hlit + 257
|
||||
local ndist_codes = hdist + 1
|
||||
|
||||
local littable = decode(nlit_codes)
|
||||
local disttable = decode(ndist_codes)
|
||||
|
||||
return littable, disttable
|
||||
end
|
||||
|
||||
|
||||
local tdecode_len_base
|
||||
local tdecode_len_nextrabits
|
||||
local tdecode_dist_base
|
||||
local tdecode_dist_nextrabits
|
||||
local function parse_compressed_item(bs, outstate, littable, disttable)
|
||||
local val = littable:read(bs)
|
||||
if val < 256 then -- literal
|
||||
output(outstate, val)
|
||||
elseif val == 256 then -- end of block
|
||||
return true
|
||||
else
|
||||
if not tdecode_len_base then
|
||||
local t = {[257]=3}
|
||||
local skip = 1
|
||||
for i=258,285,4 do
|
||||
for j=i,i+3 do t[j] = t[j-1] + skip end
|
||||
if i ~= 258 then skip = skip * 2 end
|
||||
end
|
||||
t[285] = 258
|
||||
tdecode_len_base = t
|
||||
end
|
||||
if not tdecode_len_nextrabits then
|
||||
local t = {}
|
||||
|
||||
for i=257,285 do
|
||||
local j = math_max(i - 261, 0)
|
||||
t[i] = rshift(j, 2)
|
||||
end
|
||||
|
||||
t[285] = 0
|
||||
tdecode_len_nextrabits = t
|
||||
end
|
||||
local len_base = tdecode_len_base[val]
|
||||
local nextrabits = tdecode_len_nextrabits[val]
|
||||
local extrabits = bs:read(nextrabits)
|
||||
local len = len_base + extrabits
|
||||
|
||||
if not tdecode_dist_base then
|
||||
local t = {[0]=1}
|
||||
local skip = 1
|
||||
for i=1,29,2 do
|
||||
for j=i,i+1 do t[j] = t[j-1] + skip end
|
||||
if i ~= 1 then skip = skip * 2 end
|
||||
end
|
||||
tdecode_dist_base = t
|
||||
end
|
||||
if not tdecode_dist_nextrabits then
|
||||
local t = {}
|
||||
|
||||
for i=0,29 do
|
||||
local j = math_max(i - 2, 0)
|
||||
t[i] = rshift(j, 1)
|
||||
end
|
||||
|
||||
tdecode_dist_nextrabits = t
|
||||
end
|
||||
local dist_val = disttable:read(bs)
|
||||
local dist_base = tdecode_dist_base[dist_val]
|
||||
local dist_nextrabits = tdecode_dist_nextrabits[dist_val]
|
||||
local dist_extrabits = bs:read(dist_nextrabits)
|
||||
local dist = dist_base + dist_extrabits
|
||||
|
||||
for i=1,len do
|
||||
local pos = (outstate.window_pos - 1 - dist) % 32768 + 1 -- 32K
|
||||
output(outstate, assert(outstate.window[pos], 'invalid distance'))
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
local function parse_block(bs, outstate, throttle)
|
||||
local bfinal = bs:read(1)
|
||||
local btype = bs:read(2)
|
||||
|
||||
local BTYPE_NO_COMPRESSION = 0
|
||||
local BTYPE_FIXED_HUFFMAN = 1
|
||||
local BTYPE_DYNAMIC_HUFFMAN = 2
|
||||
local BTYPE_RESERVED_ = 3
|
||||
|
||||
if btype == BTYPE_NO_COMPRESSION then
|
||||
bs:read(bs:nbits_left_in_byte())
|
||||
local len = bs:read(16)
|
||||
local nlen_ = noeof(bs:read(16))
|
||||
|
||||
for _=1,len do
|
||||
local by = noeof(bs:read(8))
|
||||
output(outstate, by)
|
||||
end
|
||||
elseif btype == BTYPE_FIXED_HUFFMAN or btype == BTYPE_DYNAMIC_HUFFMAN then
|
||||
local littable, disttable
|
||||
if btype == BTYPE_DYNAMIC_HUFFMAN then
|
||||
littable, disttable = parse_huffmantables(bs)
|
||||
else
|
||||
littable = HuffmanTable {0,8, 144,9, 256,7, 280,8, 288,nil}
|
||||
disttable = HuffmanTable {0,5, 32,nil}
|
||||
end
|
||||
|
||||
repeat
|
||||
local is_done = parse_compressed_item(
|
||||
bs, outstate, littable, disttable)
|
||||
throttle()
|
||||
until is_done
|
||||
else
|
||||
runtime_error 'unrecognized compression type'
|
||||
end
|
||||
|
||||
return bfinal ~= 0
|
||||
end
|
||||
|
||||
function M.inflate(t)
|
||||
local bs = get_bitstream(t.input)
|
||||
local outbs = get_obytestream(t.output)
|
||||
local outstate = make_outstate(outbs)
|
||||
|
||||
repeat
|
||||
local is_final = parse_block(bs, outstate, t.throttle)
|
||||
until is_final
|
||||
end
|
||||
local inflate = M.inflate
|
||||
|
||||
function M.gunzip(t)
|
||||
local bs = get_bitstream(t.input)
|
||||
local outbs = get_obytestream(t.output)
|
||||
|
||||
parse_gzip_header(bs)
|
||||
|
||||
inflate{input=bs, output=outbs, throttle=t.throttle or function() end}
|
||||
|
||||
bs:read(bs:nbits_left_in_byte())
|
||||
end
|
||||
|
||||
return M
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,29 +0,0 @@
|
||||
local LZW = require('opus.compress.lzw')
|
||||
local Tar = require('opus.compress.tar')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local shell = _ENV.shell
|
||||
|
||||
local args = { ... }
|
||||
|
||||
if not args[2] then
|
||||
error('Syntax: tar OUTFILE DIR')
|
||||
end
|
||||
|
||||
local file = shell.resolve(args[1])
|
||||
local dir = shell.resolve(args[2])
|
||||
|
||||
local filetype = 'tar'
|
||||
if file:match('(.+)%.tar$') then
|
||||
filetype = 'tar'
|
||||
elseif file:match('(.+)%.lzw$') then
|
||||
filetype = 'lzw'
|
||||
end
|
||||
|
||||
if filetype == 'tar' then
|
||||
Tar.tar(file, dir)
|
||||
|
||||
elseif filetype == 'lzw' then
|
||||
local c = Tar.tar_string(dir)
|
||||
Util.writeFile(file, LZW.compress(c), 'wb')
|
||||
end
|
||||
@@ -1,54 +0,0 @@
|
||||
local DEFLATE = require('compress.deflatelua')
|
||||
local LZW = require('opus.compress.lzw')
|
||||
local Tar = require('opus.compress.tar')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local io = _G.io
|
||||
local shell = _ENV.shell
|
||||
|
||||
local args = { ... }
|
||||
|
||||
if not args[2] then
|
||||
error('Syntax: tar FILE DESTDIR')
|
||||
end
|
||||
|
||||
local inFile = shell.resolve(args[1])
|
||||
local outDir = shell.resolve(args[2])
|
||||
|
||||
if inFile:match('(.+)%.[gG][zZ]$') then
|
||||
-- uncompress a file created with: tar czf ...
|
||||
local fh = io.open(inFile, 'rb') or error('Error opening ' .. inFile)
|
||||
|
||||
local t = { }
|
||||
local function writer(b)
|
||||
table.insert(t, b)
|
||||
end
|
||||
|
||||
DEFLATE.gunzip {input=fh, output=writer, disable_crc=true}
|
||||
|
||||
fh:close()
|
||||
|
||||
local s, m = Tar.untar_string(string.char(table.unpack(t)), outDir, true)
|
||||
|
||||
if not s then
|
||||
error(m)
|
||||
end
|
||||
|
||||
elseif inFile:match('(.+)%.tar%.lzw$') then
|
||||
local c = Util.readFile(inFile, 'rb')
|
||||
if not c then
|
||||
error('Unable to open ' .. inFile)
|
||||
end
|
||||
|
||||
local s, m = Tar.untar_string(LZW.decompress(c), outDir, true)
|
||||
|
||||
if not s then
|
||||
error(m)
|
||||
end
|
||||
|
||||
else
|
||||
local s, m = Tar.untar(inFile, outDir, true)
|
||||
if not s then
|
||||
error(m)
|
||||
end
|
||||
end
|
||||
@@ -33,19 +33,20 @@ end
|
||||
|
||||
function itemDB:makeKey(item)
|
||||
if not item then error('itemDB:makeKey: item is required', 2) end
|
||||
return table.concat({ item.name, item.nbt }, ':')
|
||||
return table.concat({ item.name, item.damage or '*', item.nbtHash }, ':')
|
||||
end
|
||||
|
||||
function itemDB:splitKey(key, item)
|
||||
item = item or { }
|
||||
|
||||
local t = Util.split(key, '(.-):')
|
||||
|
||||
if t[3] then
|
||||
item.nbt = t[3]
|
||||
t[3] = nil
|
||||
if #t[#t] > 8 then
|
||||
item.nbtHash = table.remove(t)
|
||||
end
|
||||
local damage = table.remove(t)
|
||||
if damage ~= '*' then
|
||||
item.damage = tonumber(damage)
|
||||
end
|
||||
|
||||
item.name = table.concat(t, ':')
|
||||
|
||||
return item
|
||||
@@ -81,20 +82,36 @@ function itemDB:_get(key)
|
||||
return item
|
||||
end
|
||||
|
||||
for k,item in pairs(self.data) do
|
||||
if key.name == item.name and
|
||||
key.nbt == item.nbt then
|
||||
-- try finding an item that has damage values
|
||||
if type(key.damage) == 'number' then
|
||||
item = TableDB.get(self, self:makeKey({ name = key.name, nbtHash = key.nbtHash }))
|
||||
if item and item.maxDamage then
|
||||
item = Util.shallowCopy(item)
|
||||
item.damage = key.damage
|
||||
if item.maxDamage > 0 and type(item.damage) == 'number' and item.damage > 0 then
|
||||
item.displayName = string.format('%s (damage: %s)', item.displayName, item.damage)
|
||||
end
|
||||
return item
|
||||
end
|
||||
else
|
||||
for k,item in pairs(self.data) do
|
||||
if key.name == item.name and
|
||||
key.nbtHash == key.nbtHash and
|
||||
item.maxDamage > 0 then
|
||||
item = Util.shallowCopy(item)
|
||||
item.nbtHash = key.nbtHash
|
||||
return item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if key.nbt then
|
||||
item = self:get({ name = key.name })
|
||||
if key.nbtHash then
|
||||
item = self:get({ name = key.name, damage = key.damage })
|
||||
|
||||
if item and item.ignoreNBT then
|
||||
item = Util.shallowCopy(item)
|
||||
item.nbt = key.nbt
|
||||
item.nbtHash = key.nbtHash
|
||||
item.damage = key.damage
|
||||
return item
|
||||
end
|
||||
end
|
||||
@@ -117,7 +134,8 @@ end
|
||||
function itemDB:add(baseItem)
|
||||
local nItem = {
|
||||
name = baseItem.name,
|
||||
nbt = baseItem.nbt,
|
||||
damage = baseItem.damage,
|
||||
nbtHash = baseItem.nbtHash,
|
||||
}
|
||||
-- if detail.maxDamage > 0 then
|
||||
-- nItem.damage = '*'
|
||||
@@ -125,6 +143,7 @@ function itemDB:add(baseItem)
|
||||
|
||||
nItem.displayName = safeString(baseItem.displayName)
|
||||
nItem.maxCount = baseItem.maxCount
|
||||
nItem.maxDamage = baseItem.maxDamage
|
||||
|
||||
-- enchanted items
|
||||
if baseItem.enchantments then
|
||||
@@ -137,7 +156,7 @@ function itemDB:add(baseItem)
|
||||
if k > 1 then
|
||||
nItem.displayName = nItem.displayName .. ', '
|
||||
end
|
||||
nItem.displayName = nItem.displayName .. v.displayName
|
||||
nItem.displayName = nItem.displayName .. v.fullName
|
||||
end
|
||||
|
||||
-- turtles / computers / etc
|
||||
@@ -173,8 +192,18 @@ function itemDB:add(baseItem)
|
||||
if nItem.name == item.name and
|
||||
nItem.displayName == item.displayName then
|
||||
|
||||
if nItem.nbt ~= item.nbt then
|
||||
nItem.nbt = nil
|
||||
if nItem.nbtHash ~= item.nbtHash and nItem.damage ~= item.damage then
|
||||
nItem.damage = '*'
|
||||
nItem.nbtHash = nil
|
||||
nItem.ignoreNBT = true
|
||||
self.data[k] = nil
|
||||
break
|
||||
elseif nItem.damage ~= item.damage then
|
||||
nItem.damage = '*'
|
||||
self.data[k] = nil
|
||||
break
|
||||
elseif nItem.nbtHash ~= item.nbtHash then
|
||||
nItem.nbtHash = nil
|
||||
nItem.ignoreNBT = true
|
||||
self.data[k] = nil
|
||||
break
|
||||
@@ -185,7 +214,8 @@ function itemDB:add(baseItem)
|
||||
|
||||
TableDB.add(self, self:makeKey(nItem), nItem)
|
||||
nItem = Util.shallowCopy(nItem)
|
||||
nItem.nbt = baseItem.nbt
|
||||
nItem.damage = baseItem.damage
|
||||
nItem.nbtHash = baseItem.nbtHash
|
||||
|
||||
return nItem
|
||||
end
|
||||
@@ -204,8 +234,8 @@ function itemDB:getName(item)
|
||||
-- fallback to nameDB
|
||||
local strId = self:makeKey(item)
|
||||
local name = nameDB.data[strId]
|
||||
if not name then
|
||||
name = nameDB.data[self:makeKey({ name = item.name, nbt = item.nbt })]
|
||||
if not name and not item.damage then
|
||||
name = nameDB.data[self:makeKey({ name = item.name, damage = 0, nbtHash = item.nbtHash })]
|
||||
end
|
||||
return name or strId
|
||||
end
|
||||
@@ -220,17 +250,24 @@ function itemDB:load()
|
||||
|
||||
for key,item in pairs(self.data) do
|
||||
self:splitKey(key, item)
|
||||
item.maxDamage = item.maxDamage or 0
|
||||
item.maxCount = item.maxCount or 64
|
||||
end
|
||||
end
|
||||
|
||||
function itemDB:flush()
|
||||
if self.dirty then
|
||||
|
||||
local t = { }
|
||||
for k,v in pairs(self.data) do
|
||||
v = Util.shallowCopy(v)
|
||||
v.name = nil
|
||||
v.nbt = nil
|
||||
v.damage = nil
|
||||
v.nbtHash = nil
|
||||
v.count = nil -- wipe out previously saved counts - temporary
|
||||
if v.maxDamage == 0 then
|
||||
v.maxDamage = nil
|
||||
end
|
||||
if v.maxCount == 64 then
|
||||
v.maxCount = nil
|
||||
end
|
||||
|
||||
@@ -23,10 +23,14 @@ function nameDB:loadDirectory(directory)
|
||||
error('Unable to read ' .. fs.combine(directory, file))
|
||||
end
|
||||
|
||||
for strId, blockName in pairs(blocks) do
|
||||
for strId, block in pairs(blocks) do
|
||||
strId = string.format('%s:%s', mod, strId)
|
||||
if type(blockName) == 'string' then
|
||||
self.data[strId] = blockName
|
||||
if type(block.name) == 'string' then
|
||||
self.data[strId .. ':0'] = block.name
|
||||
else
|
||||
for nid,name in pairs(block.name) do
|
||||
self.data[strId .. ':' .. (nid-1)] = name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,6 +0,0 @@
|
||||
{
|
||||
title = 'Lua Debugger',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/debugger',
|
||||
description = [[Lua interactive debugger]],
|
||||
license = 'MIT',
|
||||
}
|
||||
@@ -1,229 +0,0 @@
|
||||
-- this code is loaded into the code being debugged
|
||||
-- some portions from https://github.com/slembcke/debugger.lua
|
||||
|
||||
local fs = _G.fs
|
||||
|
||||
local dbg = {
|
||||
hooks = { },
|
||||
waits = { },
|
||||
breakpoints = nil,
|
||||
}
|
||||
|
||||
local function breakpointHook(depth, lineNo)
|
||||
if dbg.breakpoints then
|
||||
local info
|
||||
for _,v in ipairs(dbg.breakpoints) do
|
||||
if v.line == lineNo then
|
||||
if not info then
|
||||
info = debug.getinfo(depth)
|
||||
end
|
||||
if (v.file == info.short_src or v.bfile == info.short_src) then
|
||||
return not v.disabled
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function functionHook(fn)
|
||||
return function()
|
||||
return debug.getinfo(3).func == fn
|
||||
end
|
||||
end
|
||||
|
||||
local function stepHook()
|
||||
return function()
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function stackSizeHook(n)
|
||||
local i = 2
|
||||
while true do
|
||||
local info = debug.getinfo(i)
|
||||
if not info then
|
||||
break
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
return function(depth, lineNo)
|
||||
return not debug.getinfo(i - n)
|
||||
or breakpointHook(depth + 1, lineNo)
|
||||
end
|
||||
end
|
||||
|
||||
local function stepOutHook()
|
||||
return stackSizeHook(1)
|
||||
end
|
||||
|
||||
local function stepOverHook()
|
||||
return stackSizeHook(0)
|
||||
end
|
||||
|
||||
-- Create a table of all the locally accessible variables.
|
||||
local function local_bindings(offset, stack_inspect_offset)
|
||||
offset = offset + 1 + stack_inspect_offset -- add this function to the offset
|
||||
local func = debug.getinfo(offset).func
|
||||
local bindings = { }
|
||||
|
||||
-- Retrieve the upvalues
|
||||
do local i = 1; while true do
|
||||
local name, value = debug.getupvalue(func, i)
|
||||
if not name then break end
|
||||
bindings[name] = { type = 'U', raw = value }
|
||||
i = i + 1
|
||||
end end
|
||||
|
||||
-- Retrieve the locals (overwriting any upvalues)
|
||||
do local i = 1; while true do
|
||||
local name, value = debug.getlocal(offset, i)
|
||||
if not name then break end
|
||||
bindings[name] = { type = 'L', raw = value }
|
||||
i = i + 1
|
||||
end end
|
||||
|
||||
-- Retrieve the varargs (works in Lua 5.2 and LuaJIT)
|
||||
local varargs = { }
|
||||
do local i = 1; while true do
|
||||
local name, value = debug.getlocal(offset, -i)
|
||||
if not name then break end
|
||||
varargs[i] = value
|
||||
i = i + 1
|
||||
end end
|
||||
if #varargs > 0 then
|
||||
bindings["..."] = { type = 'V', value = varargs }
|
||||
end
|
||||
|
||||
local t = { }
|
||||
for k,v in pairs(bindings) do
|
||||
if k ~= '(*temporary)' then
|
||||
v.name = k
|
||||
v.value = tostring(v.raw)
|
||||
--if type(v.raw) == 'table' and not next(v.raw) then
|
||||
-- v.value = 'table: (empty)'
|
||||
--end
|
||||
table.insert(t, v)
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
local function get_trace(offset, stack_inspect_offset)
|
||||
local function format_loc(file, line) return file..":"..line end
|
||||
local function format_stack_frame_info(info)
|
||||
local filename = info.source:match("@(.*)")
|
||||
local source = filename and fs.getName(filename) or info.short_src
|
||||
local namewhat = (info.namewhat == "" and "chunk at" or info.namewhat)
|
||||
local name = (info.name and "'"..info.name.."'" or format_loc(source, info.linedefined))
|
||||
return format_loc(source, info.currentline).." in "..namewhat.." "..name
|
||||
end
|
||||
|
||||
offset = offset + 1 -- add this function to the offset
|
||||
local t = { }
|
||||
local i = 0
|
||||
while true do
|
||||
local info = debug.getinfo(offset + i)
|
||||
if not info then break end
|
||||
t[i] = {
|
||||
index = i,
|
||||
current = (i == stack_inspect_offset),
|
||||
desc = format_stack_frame_info(info),
|
||||
info = info,
|
||||
}
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
local function hook(_, lineNo)
|
||||
local h = dbg.hooks[coroutine.running()]
|
||||
|
||||
if h and h.eval(3, lineNo) then
|
||||
local inspectOffset = 0
|
||||
|
||||
repeat
|
||||
local done = true
|
||||
|
||||
local snapshot = {
|
||||
info = debug.getinfo(2 + inspectOffset),
|
||||
locals = local_bindings(2, inspectOffset),
|
||||
stack = get_trace(2, inspectOffset),
|
||||
}
|
||||
inspectOffset = 0 -- reset
|
||||
|
||||
table.insert(dbg.waits, h)
|
||||
while dbg.waits[1] ~= h do
|
||||
os.sleep(.1)
|
||||
end
|
||||
local cmd, param = dbg.read(snapshot)
|
||||
|
||||
table.remove(dbg.waits, 1)
|
||||
|
||||
if cmd == 's' then
|
||||
h.eval = stepHook()
|
||||
elseif cmd == 'n' then
|
||||
h.eval = stepOverHook()
|
||||
elseif cmd == 'f' then
|
||||
h.eval = stepOutHook()
|
||||
elseif cmd == 'c' then
|
||||
h.eval = breakpointHook
|
||||
elseif cmd == 'i' then
|
||||
-- get snapshot of stack at this offset
|
||||
inspectOffset = param
|
||||
done = false
|
||||
else
|
||||
done = false
|
||||
end
|
||||
until done
|
||||
end
|
||||
end
|
||||
|
||||
function dbg.call(fn, ...)
|
||||
local args = { ... }
|
||||
return xpcall(
|
||||
function()
|
||||
return fn(table.unpack(args))
|
||||
end,
|
||||
function(err)
|
||||
dbg.hooks[coroutine.running()].eval = stepHook()
|
||||
|
||||
-- An error has occurred
|
||||
return err
|
||||
end)
|
||||
end
|
||||
|
||||
dbg.stopIn = function(fn)
|
||||
dbg.hooks[coroutine.running()].eval = functionHook(fn)
|
||||
end
|
||||
|
||||
_ENV.coroutine = setmetatable({
|
||||
create = function(fn)
|
||||
local co = _G.coroutine.create(function(...)
|
||||
local r = { dbg.call(fn, ...) }
|
||||
|
||||
dbg.hooks[coroutine.running()] = nil
|
||||
if not r[1] then
|
||||
error(r[2], -1)
|
||||
end
|
||||
|
||||
return table.unpack(r, 2)
|
||||
end)
|
||||
|
||||
dbg.hooks[co] = {
|
||||
co = co,
|
||||
eval = breakpointHook,
|
||||
}
|
||||
debug.sethook(co, hook, 'l')
|
||||
return co
|
||||
end
|
||||
}, { __index = coroutine })
|
||||
|
||||
dbg.hooks[coroutine.running()] = {
|
||||
co = coroutine.running(),
|
||||
eval = function() return false end,
|
||||
}
|
||||
|
||||
debug.sethook(hook, 'l')
|
||||
return dbg
|
||||
@@ -1,4 +0,0 @@
|
||||
local completion = require('cc.shell.completion')
|
||||
|
||||
_ENV.shell.setCompletionFunction("packages/debugger/debug.lua",
|
||||
completion.build(completion.program))
|
||||
@@ -1,590 +0,0 @@
|
||||
local class = require('opus.class')
|
||||
local Config = require('opus.config')
|
||||
local Event = require('opus.event')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local fs = _G.fs
|
||||
local getfenv = _G.getfenv
|
||||
local kernel = _G.kernel
|
||||
local multishell = _ENV.multishell
|
||||
local shell = _ENV.shell
|
||||
|
||||
local args = { ... }
|
||||
local filename = shell.resolveProgram(table.remove(args, 1))
|
||||
|
||||
if not filename then
|
||||
error('file not found')
|
||||
end
|
||||
|
||||
UI:disableEffects()
|
||||
|
||||
local config = Config.load('debugger')
|
||||
if not config[filename] then
|
||||
config[filename] = { }
|
||||
end
|
||||
|
||||
local breakpoints = config[filename]
|
||||
local currentFile
|
||||
local debugFile, debugLine
|
||||
|
||||
local debugger = kernel.getCurrent()
|
||||
local client
|
||||
|
||||
local function startClient()
|
||||
local env = kernel.makeEnv(_ENV, fs.getDir(filename))
|
||||
currentFile = nil
|
||||
|
||||
local clientId = multishell.openTab(nil, {
|
||||
env = env,
|
||||
title = fs.getName(filename):match('([^%.]+)'),
|
||||
args = args,
|
||||
fn = function()
|
||||
local dbg = require('debugger')
|
||||
local fn, msg = loadfile(filename, env)
|
||||
|
||||
if not fn then
|
||||
error(msg, -1)
|
||||
end
|
||||
|
||||
dbg.read = function(snapshot)
|
||||
os.sleep(0) -- not sure why, but we need a sleep before :resume
|
||||
-- directly resuming debugger routine to prevent
|
||||
-- serialization of the snapshot
|
||||
dbg.debugger:resume('debuggerX', 'break', snapshot)
|
||||
local e, cmd, param
|
||||
repeat
|
||||
e, cmd, param = os.pullEvent('debugger')
|
||||
until e == 'debugger'
|
||||
return cmd, param
|
||||
end
|
||||
|
||||
_ENV.arg = { table.unpack(args) }
|
||||
_ENV.arg[0] = filename
|
||||
-- breakpoint table is shared across processes
|
||||
dbg.breakpoints = breakpoints
|
||||
dbg.debugger = debugger
|
||||
dbg.stopIn(fn)
|
||||
local s, m = dbg.call(fn, table.unpack(args))
|
||||
|
||||
dbg.debugger:resume('debuggerX', 'disconnect')
|
||||
|
||||
if not s then
|
||||
error(m, -1)
|
||||
end
|
||||
print('Process ended normally')
|
||||
print('Press enter to exit')
|
||||
while true do
|
||||
local e, code = os.pullEventRaw('key')
|
||||
if e == 'terminate' or e == 'key' and code == _G.keys.enter then
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
client = kernel.find(clientId)
|
||||
end
|
||||
|
||||
local romFiles = {
|
||||
files = { },
|
||||
load = function(self)
|
||||
local function recurse(dir)
|
||||
local files = fs.list(dir)
|
||||
for _,f in ipairs(files) do
|
||||
local fullName = fs.combine(dir, f)
|
||||
if fs.isDir(fullName) then
|
||||
recurse(fullName)
|
||||
else
|
||||
self.files[f] = fullName
|
||||
end
|
||||
end
|
||||
end
|
||||
recurse('rom/apis')
|
||||
self.reversed = Util.transpose(self.files)
|
||||
end,
|
||||
get = function(self, file)
|
||||
return self.files[file]
|
||||
end,
|
||||
lookup = function(self, file)
|
||||
return self.reversed[file]
|
||||
end,
|
||||
}
|
||||
romFiles:load()
|
||||
|
||||
local function loadSource(file)
|
||||
currentFile = romFiles:get(file) or file:match('@?(.*)')
|
||||
local src = { }
|
||||
local lines = Util.readLines(currentFile) or type(file) == 'string' and Util.split(file)
|
||||
|
||||
if lines then
|
||||
for i = 1, #lines do
|
||||
table.insert(src, { line = i, source = lines[i] })
|
||||
end
|
||||
end
|
||||
|
||||
return src
|
||||
end
|
||||
|
||||
local function message(...)
|
||||
client:resume('debugger', ...)
|
||||
end
|
||||
|
||||
UI.InverseButton = class(UI.Button)
|
||||
UI.InverseButton.defaults = {
|
||||
UIElement = 'InverseButton',
|
||||
backgroundColor = 'primary',
|
||||
backgroundFocusColor = 'gray',
|
||||
textFocusColor = 'primary',
|
||||
textColor = 'gray',
|
||||
}
|
||||
|
||||
local page = UI.Page {
|
||||
backgroundColor = 'gray',
|
||||
|
||||
container = UI.Window {
|
||||
y = 1, ey = '50%',
|
||||
tabs = UI.Tabs {
|
||||
ey = -2,
|
||||
barBackgroundColor = 'tertiary',
|
||||
locals = UI.Tab {
|
||||
title = 'Locals',
|
||||
index = 1,
|
||||
grid = UI.ScrollingGrid {
|
||||
disableHeader = true,
|
||||
unfocusedBackgroundSelectedColor = 'black',
|
||||
columns = {
|
||||
{ heading = 'localname', key = 'name' },
|
||||
{ heading = 'Value', key = 'value', textColor = 'yellow' },
|
||||
},
|
||||
autospace = true,
|
||||
accelerators = {
|
||||
grid_select = 'show_variable',
|
||||
},
|
||||
getRowTextColor = function(self, row, selected)
|
||||
return row.type == 'U' and 'cyan'
|
||||
or row.type == 'V' and 'lime'
|
||||
or UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
stack = UI.Tab {
|
||||
title = 'Stack',
|
||||
index = 3,
|
||||
grid = UI.ScrollingGrid {
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
unfocusedBackgroundSelectedColor = 'black',
|
||||
columns = {
|
||||
{ key = 'index', width = 2 },
|
||||
{ heading = 'heading', key = 'desc' },
|
||||
},
|
||||
getRowTextColor = function(self, row, selected)
|
||||
return row.current and 'yellow'
|
||||
or UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
message('i', event.selected.index)
|
||||
else
|
||||
return UI.Grid.eventHandler(self, event)
|
||||
end
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
env = UI.Tab {
|
||||
title = 'Env',
|
||||
index = 4,
|
||||
grid = UI.ScrollingGrid {
|
||||
disableHeader = true,
|
||||
autospace = true,
|
||||
unfocusedBackgroundSelectedColor = 'black',
|
||||
columns = {
|
||||
{ heading = 'Key', key = 'name' },
|
||||
{ heading = 'Value', key = 'value', textColor = 'yellow' },
|
||||
},
|
||||
accelerators = {
|
||||
grid_select = 'show_variable',
|
||||
},
|
||||
sortCompare = function() end,
|
||||
},
|
||||
},
|
||||
|
||||
breaks = UI.Tab {
|
||||
title = 'Breakpoints',
|
||||
index = 2,
|
||||
UI.MenuBar {
|
||||
buttons = {
|
||||
{ text = 'Toggle', event = 'toggle' },
|
||||
{ text = 'Remove', event = 'remove' },
|
||||
{ text = 'Clear', event = 'clear' },
|
||||
},
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
values = breakpoints,
|
||||
autospace = true,
|
||||
columns = {
|
||||
{ heading = 'Line', key = 'line', width = 5 },
|
||||
{ heading = 'Name', key = 'short' },
|
||||
{ heading = 'Path', key = 'path', textColor = 'lightGray' },
|
||||
},
|
||||
getDisplayValues = function(_, row)
|
||||
return {
|
||||
line = row.line,
|
||||
short = fs.getName(row.file),
|
||||
path = fs.getDir(row.file),
|
||||
}
|
||||
end,
|
||||
getRowTextColor = function(self, row, selected)
|
||||
return row.disabled and 'lightGray'
|
||||
or UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
},
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'clear' then
|
||||
Util.clear(self.grid.values)
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
|
||||
elseif event.type == 'toggle' then
|
||||
local bp = self.grid:getSelected()
|
||||
if bp then
|
||||
bp.disabled = not bp.disabled
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
end
|
||||
|
||||
elseif event.type == 'grid_select' then
|
||||
self:emit({
|
||||
type = 'open_file',
|
||||
file = event.selected.file,
|
||||
line = event.selected.line,
|
||||
})
|
||||
|
||||
elseif event.type == 'remove' then
|
||||
local bp = self.grid:getSelected()
|
||||
if bp then
|
||||
Util.removeByValue(self.grid.values, bp)
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
end
|
||||
|
||||
end
|
||||
return UI.Tab.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
UI.MenuBar {
|
||||
y = -1,
|
||||
backgroundColor = 'primary',
|
||||
buttonClass = 'InverseButton',
|
||||
buttons = {
|
||||
{ text = 'Continue', event = 'cmd', cmd = 'c' },
|
||||
{ text = 'Step', event = 'cmd', cmd = 's' },
|
||||
{ text = 'Over', event = 'cmd', cmd = 'n' },
|
||||
{ text = 'Out', event = 'cmd', cmd = 'f' },
|
||||
{ text = 'Restart', event = 'restart', width = 9, ex = -1 },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
source = UI.ScrollingGrid {
|
||||
y = '50%', ey = -2,
|
||||
disableHeader = true,
|
||||
backgroundColor = 'gray',
|
||||
backgroundSelectedColor = 'lightGray',
|
||||
unfocusedBackgroundSelectedColor = 'lightGray',
|
||||
columns = {
|
||||
{ key = 'marker', width = 1 },
|
||||
{ key = 'line', textColor = 'cyan', width = 4 },
|
||||
{ heading = 'heading', key = 'source' },
|
||||
},
|
||||
accelerators = {
|
||||
t = 'toggle_enabled'
|
||||
},
|
||||
getDisplayValues = function(_, row)
|
||||
for _,v in pairs(breakpoints) do
|
||||
if v.file == currentFile and v.line == row.line then
|
||||
return {
|
||||
marker = v.disabled and 'x' or '!',
|
||||
line = row.line,
|
||||
source = row.source,
|
||||
}
|
||||
end
|
||||
end
|
||||
return row
|
||||
end,
|
||||
getRowTextColor = function(self, row, selected)
|
||||
return row.line == debugLine and currentFile == debugFile and 'yellow'
|
||||
or UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
self:emit({
|
||||
type = 'toggle_breakpoint',
|
||||
file = currentFile,
|
||||
line = event.selected.line,
|
||||
})
|
||||
elseif event.type == 'toggle_enabled' then
|
||||
local line = self:getSelected() and self:getSelected().line
|
||||
if line then
|
||||
for _,v in pairs(breakpoints) do
|
||||
if v.file == currentFile and v.line == line then
|
||||
v.disabled = not v.disabled
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return UI.Grid.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
ex = -12, y = -1,
|
||||
backgroundColor = 'gray',
|
||||
textColor = 'orange',
|
||||
},
|
||||
UI.FlatButton {
|
||||
y = -1, x = -5,
|
||||
textColor = 'orange',
|
||||
event = 'open',
|
||||
text = 'Open',
|
||||
},
|
||||
UI.FlatButton {
|
||||
y = -1, x = -10,
|
||||
textColor = 'orange',
|
||||
event = 'edit_file',
|
||||
text = 'Edit',
|
||||
},
|
||||
|
||||
quick_open = UI.QuickSelect {
|
||||
y = '50%',
|
||||
modal = true,
|
||||
enable = function() end,
|
||||
getFiles = function()
|
||||
local paths = { }
|
||||
for _,v in pairs(Util.split(client.env.package.path, '(.-);')) do
|
||||
v = v:match('(.+)%?') or ''
|
||||
if v:sub(1, 1) ~= '/' then
|
||||
v = fs.combine(fs.getDir(filename), v)
|
||||
end
|
||||
if fs.exists(v) and fs.isDir(v) then
|
||||
paths[fs.combine(v, '')] = true
|
||||
end
|
||||
end
|
||||
|
||||
local t = { }
|
||||
for k in pairs(paths) do
|
||||
local function recurse(dir)
|
||||
local files = fs.list(dir)
|
||||
for _,f in ipairs(files) do
|
||||
local fullName = fs.combine(dir, f)
|
||||
if fs.isDir(fullName) then
|
||||
-- skip virtual dirs
|
||||
if f ~= '.git' and fs.native.isDir(fullName) then
|
||||
recurse(fullName)
|
||||
end
|
||||
elseif fullName:match('(.+)%.lua$') then
|
||||
table.insert(t, {
|
||||
name = f,
|
||||
dir = dir,
|
||||
lname = f:lower(),
|
||||
fullName = fullName,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
recurse(k)
|
||||
end
|
||||
return t
|
||||
end,
|
||||
show = function(self)
|
||||
UI.QuickSelect.enable(self)
|
||||
self:focusFirst()
|
||||
self:draw()
|
||||
self:addTransition('expandUp', { easing = 'outBounce', ticks = 12 })
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'select_cancel' then
|
||||
self:disable()
|
||||
elseif event.type == 'select_file' then
|
||||
self.parent:openFile(event.file)
|
||||
self:disable()
|
||||
end
|
||||
return UI.QuickSelect.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
|
||||
textDisplay = UI.SlideOut {
|
||||
ey = '50%',
|
||||
textArea = UI.TextArea {
|
||||
ey = -2,
|
||||
},
|
||||
UI.Button {
|
||||
x = '50%', y = -1,
|
||||
text = 'Ok',
|
||||
event = 'slide_hide',
|
||||
}
|
||||
},
|
||||
|
||||
openFile = function(self, file, line)
|
||||
if file ~= currentFile then
|
||||
local src = loadSource(file)
|
||||
self.source:setValues(src)
|
||||
end
|
||||
if line then
|
||||
self.source:setIndex(#self.source.values)
|
||||
self.source:setIndex(math.max(1, line - 4))
|
||||
end
|
||||
self.source:setIndex(line or 1)
|
||||
|
||||
if currentFile == debugFile then
|
||||
self.statusBar:setStatus(
|
||||
string.format('%s : %d', fs.getName(file), debugLine))
|
||||
else
|
||||
self.statusBar:setStatus(fs.getName(file))
|
||||
end
|
||||
self:draw()
|
||||
end,
|
||||
|
||||
editFile = function(self, file)
|
||||
if fs.exists(file) then
|
||||
local line = self.source:getSelected().line
|
||||
multishell.openTab(_ENV, {
|
||||
path = 'sys/apps/shell.lua',
|
||||
args = { ('edit --line=%d %s'):format(line , '/' .. file) },
|
||||
focused = true,
|
||||
})
|
||||
end
|
||||
end,
|
||||
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'cmd' then
|
||||
self.statusBar:setStatus('Running...')
|
||||
self:sync()
|
||||
message(event.element.cmd)
|
||||
|
||||
elseif event.type == 'restart' then
|
||||
if kernel.find(client.uid) then
|
||||
client:resume('terminate')
|
||||
end
|
||||
startClient()
|
||||
|
||||
elseif event.type == 'open' then
|
||||
self.quick_open:show()
|
||||
|
||||
elseif event.type == 'edit_file' then
|
||||
self:editFile(currentFile)
|
||||
|
||||
elseif event.type == 'open_file' then
|
||||
self:openFile(event.file, event.line)
|
||||
|
||||
elseif event.type == 'update_breakpoints' then
|
||||
self.container.tabs.breaks.grid:update()
|
||||
self.container.tabs.breaks.grid:draw()
|
||||
self.source:draw()
|
||||
Config.update('debugger', config)
|
||||
|
||||
elseif event.type == 'toggle_breakpoint' then
|
||||
for k,v in pairs(breakpoints) do
|
||||
if v.file == event.file and v.line == event.line then
|
||||
table.remove(breakpoints, k)
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(breakpoints, {
|
||||
file = event.file,
|
||||
line = event.line,
|
||||
bfile = romFiles:lookup(event.file),
|
||||
})
|
||||
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
|
||||
elseif event.type == 'show_variable' then
|
||||
if type(event.selected.raw) == 'table' then
|
||||
if event.selected.children then
|
||||
event.selected.children = nil
|
||||
else
|
||||
event.selected.children = { }
|
||||
local t = event.selected.raw
|
||||
for k,v in pairs(t) do
|
||||
local depth = event.selected.depth or 0
|
||||
table.insert(event.selected.children, {
|
||||
name = (' '):rep(depth + 2) .. tostring(k),
|
||||
value = tostring(v),
|
||||
raw = v,
|
||||
depth = depth + 2
|
||||
})
|
||||
end
|
||||
table.sort(event.selected.children, function(a, b) return a.name < b.name end)
|
||||
end
|
||||
local t = { }
|
||||
local function insert(values)
|
||||
for _,v in pairs(values) do
|
||||
table.insert(t, v)
|
||||
if v.children then
|
||||
insert(v.children)
|
||||
end
|
||||
end
|
||||
end
|
||||
insert(event.element.orig)
|
||||
event.element:setValues(t)
|
||||
event.element:draw()
|
||||
else
|
||||
self.textDisplay.textArea:setValue(event.selected.value)
|
||||
self.textDisplay:show()
|
||||
end
|
||||
end
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end,
|
||||
enable = function(self)
|
||||
UI.Page.enable(self)
|
||||
startClient()
|
||||
end,
|
||||
}
|
||||
|
||||
Event.on('debuggerX', function(_, cmd, data)
|
||||
if cmd == 'disconnect' then
|
||||
page.statusBar:setStatus('Finished')
|
||||
page:sync()
|
||||
|
||||
elseif cmd == 'break' then
|
||||
kernel.raise(debugger.uid)
|
||||
|
||||
-- local tab
|
||||
table.sort(data.locals, function(a, b) return a.name < b.name end)
|
||||
page.container.tabs.locals.grid:setValues(data.locals)
|
||||
page.container.tabs.locals.grid.orig = Util.shallowCopy(data.locals)
|
||||
|
||||
-- env tab
|
||||
local t = { }
|
||||
for k,v in pairs(getfenv(data.info.func)) do
|
||||
table.insert(t, { name = k, value = tostring(v), raw = v })
|
||||
end
|
||||
table.sort(t, function(a, b) return a.name < b.name end)
|
||||
page.container.tabs.env.grid:setValues(t)
|
||||
page.container.tabs.env.grid.orig = Util.shallowCopy(t)
|
||||
|
||||
debugLine = data.info.currentline
|
||||
debugFile = data.info.source:match('@?(.*)')
|
||||
|
||||
-- source tab
|
||||
page:openFile(debugFile, debugLine)
|
||||
|
||||
-- stack
|
||||
page.container.tabs.stack.grid:setValues(data.stack)
|
||||
|
||||
page:draw()
|
||||
page:sync()
|
||||
end
|
||||
end)
|
||||
|
||||
UI:setPage(page)
|
||||
UI:start()
|
||||
|
||||
if kernel.find(client.uid) then
|
||||
client:resume('terminate')
|
||||
end
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
[ "1a03bd2fd107c453f3183e30b9716f82200671e8270fbbefbe602f5a48705527" ] = {
|
||||
run = "fileui --exec=debug.lua --title=debug",
|
||||
title = "Debug",
|
||||
category = "Apps",
|
||||
iconExt = "\30\50\31\50\128\31\102\152\144\30\102\31\50\159\155\30\50\128\10\30\50\31\102\130\152\30\101\31\53\143\143\30\102\31\50\155\30\50\31\102\129\10\30\50\31\102\130\31\50\128\31\101\134\137\31\50\128\31\102\129",
|
||||
},
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
An interactive debugger for lua
|
||||
|
||||
debug must be enabled!
|
||||
|
||||
Run from a shell prompt
|
||||
> debug FILE [ARGS]
|
||||
@@ -246,35 +246,43 @@ local function server(mode)
|
||||
computers[computerId] = nil
|
||||
page.grid.values = positions
|
||||
page.grid:update()
|
||||
page.grid:draw()
|
||||
page.grid:sync()
|
||||
end
|
||||
end
|
||||
|
||||
Event.on('modem_message', function(_, side, channel, computerId, message, distance)
|
||||
local modem = modems[side]
|
||||
if distance and modem then
|
||||
if distance and modems[side] then
|
||||
if mode == 'gps' and channel == GPS.CHANNEL_GPS and message == "PING" then
|
||||
modem.transmit(computerId, GPS.CHANNEL_GPS, { modem.x, modem.y, modem.z })
|
||||
getPosition(computerId, modem, distance)
|
||||
for _, modem in pairs(modems) do
|
||||
modem.transmit(computerId, GPS.CHANNEL_GPS, { modem.x, modem.y, modem.z })
|
||||
end
|
||||
getPosition(computerId, modems[side], distance)
|
||||
end
|
||||
|
||||
if mode == 'snmp' and channel == 999 then
|
||||
getPosition(computerId, modem, distance, message)
|
||||
getPosition(computerId, modems[side], distance, message)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.onInterval(1, function()
|
||||
local resync = false
|
||||
for _, detail in pairs(positions) do
|
||||
if os.clock() - detail.lastChanged > 10 then
|
||||
detail.changed = false
|
||||
resync = true
|
||||
end
|
||||
if os.clock() - detail.timestamp > 60 and detail.alive then
|
||||
detail.alive = false
|
||||
detail.hbeat = false
|
||||
resync = true
|
||||
end
|
||||
end
|
||||
page:draw()
|
||||
page:sync()
|
||||
if resync then
|
||||
page:draw()
|
||||
page:sync()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -296,7 +304,6 @@ elseif args[1] == 'snmp' then
|
||||
table.insert(page.grid.columns,
|
||||
{ heading = 'Label', key = 'label', textColor = colors.cyan }
|
||||
)
|
||||
page.grid.sortColumn = 'label'
|
||||
page.grid:adjustWidth()
|
||||
server('snmp')
|
||||
|
||||
|
||||
15
ignore/chars.lua
Normal file
15
ignore/chars.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
local w, h = term.getSize()
|
||||
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
|
||||
local t = { }
|
||||
for i = 1, 8 do
|
||||
table.insert(t, '---')
|
||||
end
|
||||
|
||||
for i = 1, 255 do
|
||||
table.insert(t, string.format('%d %c', i, i))
|
||||
end
|
||||
|
||||
textutils.pagedTabulate(t)
|
||||
196
ignore/glasses.lua
Normal file
196
ignore/glasses.lua
Normal file
@@ -0,0 +1,196 @@
|
||||
local class = require('opus.class')
|
||||
local UI = require('opus.ui')
|
||||
local Event = require('opus.event')
|
||||
local Peripheral = require('opus.peripheral')
|
||||
|
||||
--[[-- Glasses device --]]--
|
||||
local Glasses = class()
|
||||
function Glasses:init(args)
|
||||
|
||||
local defaults = {
|
||||
backgroundColor = colors.black,
|
||||
textColor = colors.white,
|
||||
textScale = .5,
|
||||
backgroundOpacity = .5,
|
||||
multiplier = 2.6665,
|
||||
-- multiplier = 2.333,
|
||||
}
|
||||
defaults.width, defaults.height = term.getSize()
|
||||
|
||||
UI:setProperties(defaults, args)
|
||||
UI:setProperties(self, defaults)
|
||||
|
||||
self.bridge = Peripheral.get({
|
||||
type = 'openperipheral_bridge',
|
||||
method = 'addBox',
|
||||
})
|
||||
self.bridge.clear()
|
||||
|
||||
self.setBackgroundColor = function(...) end
|
||||
self.setTextColor = function(...) end
|
||||
|
||||
self.t = { }
|
||||
for i = 1, self.height do
|
||||
self.t[i] = {
|
||||
text = string.rep(' ', self.width+1),
|
||||
--text = self.bridge.addText(0, 40+i*4, string.rep(' ', self.width+1), 0xffffff),
|
||||
bg = { },
|
||||
textFields = { },
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function Glasses:setBackgroundBox(boxes, ax, bx, y, bgColor)
|
||||
local colors = {
|
||||
[ colors.black ] = 0x000000,
|
||||
[ colors.brown ] = 0x7F664C,
|
||||
[ colors.blue ] = 0x253192,
|
||||
[ colors.red ] = 0xFF0000,
|
||||
[ colors.gray ] = 0x272727,
|
||||
[ colors.lime ] = 0x426A0D,
|
||||
[ colors.green ] = 0x2D5628,
|
||||
[ colors.white ] = 0xFFFFFF
|
||||
}
|
||||
|
||||
local function overlap(box, ax, bx)
|
||||
if bx < box.ax or ax > box.bx then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
for _,box in pairs(boxes) do
|
||||
if overlap(box, ax, bx) then
|
||||
if box.bgColor == bgColor then
|
||||
ax = math.min(ax, box.ax)
|
||||
bx = math.max(bx, box.bx)
|
||||
box.ax = box.bx + 1
|
||||
elseif ax == box.ax then
|
||||
box.ax = bx + 1
|
||||
elseif ax > box.ax then
|
||||
if bx < box.bx then
|
||||
table.insert(boxes, { -- split
|
||||
ax = bx + 1,
|
||||
bx = box.bx,
|
||||
bgColor = box.bgColor
|
||||
})
|
||||
box.bx = ax - 1
|
||||
break
|
||||
else
|
||||
box.ax = box.bx + 1
|
||||
end
|
||||
elseif ax < box.ax then
|
||||
if bx > box.bx then
|
||||
box.ax = box.bx + 1 -- delete
|
||||
else
|
||||
box.ax = bx + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if bgColor ~= colors.black then
|
||||
table.insert(boxes, {
|
||||
ax = ax,
|
||||
bx = bx,
|
||||
bgColor = bgColor
|
||||
})
|
||||
end
|
||||
|
||||
local deleted
|
||||
repeat
|
||||
deleted = false
|
||||
for k,box in pairs(boxes) do
|
||||
if box.ax > box.bx then
|
||||
if box.box then
|
||||
box.box.delete()
|
||||
end
|
||||
table.remove(boxes, k)
|
||||
deleted = true
|
||||
break
|
||||
end
|
||||
if not box.box then
|
||||
box.box = self.bridge.addBox(
|
||||
math.floor(self.x + (box.ax - 1) * self.multiplier),
|
||||
self.y + y * 4,
|
||||
math.ceil((box.bx - box.ax + 1) * self.multiplier),
|
||||
4,
|
||||
colors[bgColor],
|
||||
self.backgroundOpacity)
|
||||
else
|
||||
box.box.setX(self.x + math.floor((box.ax - 1) * self.multiplier))
|
||||
box.box.setWidth(math.ceil((box.bx - box.ax + 1) * self.multiplier))
|
||||
end
|
||||
end
|
||||
until not deleted
|
||||
end
|
||||
|
||||
function Glasses:write(x, y, text, bg)
|
||||
|
||||
if x < 1 then
|
||||
error(' less ', 6)
|
||||
end
|
||||
if y <= #self.t then
|
||||
local line = self.t[y]
|
||||
local str = line.text
|
||||
str = str:sub(1, x-1) .. text .. str:sub(x + #text)
|
||||
self.t[y].text = str
|
||||
|
||||
for _,tf in pairs(line.textFields) do
|
||||
tf.delete()
|
||||
end
|
||||
line.textFields = { }
|
||||
|
||||
local function split(st)
|
||||
local words = { }
|
||||
local offset = 0
|
||||
while true do
|
||||
local b,e,w = st:find('(%S+)')
|
||||
if not b then
|
||||
break
|
||||
end
|
||||
table.insert(words, {
|
||||
offset = b + offset - 1,
|
||||
text = w,
|
||||
})
|
||||
offset = offset + e
|
||||
st = st:sub(e + 1)
|
||||
end
|
||||
return words
|
||||
end
|
||||
|
||||
local words = split(str)
|
||||
for _,word in pairs(words) do
|
||||
local tf = self.bridge.addText(self.x + word.offset * self.multiplier,
|
||||
self.y+y*4, '', 0xffffff)
|
||||
tf.setScale(self.textScale)
|
||||
tf.setZ(1)
|
||||
tf.setText(word.text)
|
||||
table.insert(line.textFields, tf)
|
||||
end
|
||||
|
||||
self:setBackgroundBox(line.bg, x, x + #text - 1, y, bg)
|
||||
end
|
||||
end
|
||||
|
||||
function Glasses:clear(bg)
|
||||
for _,line in pairs(self.t) do
|
||||
for _,tf in pairs(line.textFields) do
|
||||
tf.delete()
|
||||
end
|
||||
line.textFields = { }
|
||||
line.text = string.rep(' ', self.width+1)
|
||||
-- self.t[i].text.setText('')
|
||||
end
|
||||
end
|
||||
|
||||
function Glasses:reset()
|
||||
self:clear()
|
||||
self.bridge.clear()
|
||||
self.bridge.sync()
|
||||
end
|
||||
|
||||
function Glasses:sync()
|
||||
self.bridge.sync()
|
||||
end
|
||||
|
||||
return Glasses
|
||||
@@ -1,77 +0,0 @@
|
||||
local pals = {
|
||||
{ -- molokai
|
||||
0x101010,
|
||||
0x960050,
|
||||
0x66aa11,
|
||||
0xc47f2c,
|
||||
0x30309b,
|
||||
0x7e40a5,
|
||||
0x3579a8,
|
||||
0x9999aa,
|
||||
0x303030,
|
||||
0xff0090,
|
||||
0x80ff00,
|
||||
0xffba68,
|
||||
0x5f5fee,
|
||||
0xbb88dd,
|
||||
0x4eb4fa,
|
||||
0xd0d0d0,
|
||||
},
|
||||
{ -- solarized
|
||||
0xffffd7,
|
||||
0xd75f00, -- orange
|
||||
0x585858,
|
||||
0x0087ff, -- light blue
|
||||
0x1c1c1c,
|
||||
0x8a8a8a,
|
||||
0xd70000, -- light red
|
||||
0x808080, -- gray
|
||||
0xe4e4e4, -- light gray
|
||||
0x00afaf, -- cyan
|
||||
0x626262,
|
||||
0x5f5faf, -- blue
|
||||
0xaf8700, -- brown
|
||||
0x5f8700, -- green
|
||||
0xaf005f, -- dark red
|
||||
0x262626, -- black
|
||||
},
|
||||
{
|
||||
0xf7f7f7,
|
||||
0xc4a500, -- mustard
|
||||
0xf79aff, -- magenta
|
||||
0x8dcff0, -- light blue
|
||||
0xfee14d, -- yellow
|
||||
0xc4f137, -- lime
|
||||
0x207383, -- dark green
|
||||
0x7a7a7a,
|
||||
0xa1a1a1,
|
||||
0x6ad9cf, -- greenish blue
|
||||
0xba8acc, -- purple
|
||||
0x62a3c4, -- blue gray
|
||||
0xd6837c, -- orange/brown
|
||||
0x7da900, -- green
|
||||
0xb84131, -- redish brown
|
||||
0x1b1b1b,
|
||||
}
|
||||
}
|
||||
term.setPaletteColor(2^0,0xFFFFFF)
|
||||
term.setPaletteColor(2^1,0xFF6300)
|
||||
term.setPaletteColor(2^2,0xFF00DE)
|
||||
term.setPaletteColor(2^3,0x00C3FF)
|
||||
term.setPaletteColor(2^4,0xFFFF00)
|
||||
term.setPaletteColor(2^5,0x91FF00)
|
||||
term.setPaletteColor(2^6,0xFF6DA8)
|
||||
term.setPaletteColor(2^7,0x585757)
|
||||
term.setPaletteColor(2^8,0xA9A9A9)
|
||||
term.setPaletteColor(2^9,0x00FFFF)
|
||||
term.setPaletteColor(2^10,0x7700FF)
|
||||
term.setPaletteColor(2^11,0x0000FF)
|
||||
term.setPaletteColor(2^12,0x4C2700)
|
||||
term.setPaletteColor(2^13,0x00FF00)
|
||||
term.setPaletteColor(2^14,0xFF0000)
|
||||
term.setPaletteColor(2^15,0x000000)
|
||||
|
||||
local pal = pals[tonumber(({...})[1])]
|
||||
for k,v in pairs(pal) do
|
||||
term.setPaletteColour(2^(k - 1), v)
|
||||
end
|
||||
173
ignore/rabbitRancher.lua
Normal file
173
ignore/rabbitRancher.lua
Normal file
@@ -0,0 +1,173 @@
|
||||
--[[
|
||||
Breed rabbits with a rabbit.
|
||||
]]
|
||||
|
||||
local neural = require('neural.interface')
|
||||
local Point = require('point')
|
||||
local Sound = require('sound')
|
||||
local Util = require('util')
|
||||
|
||||
local os = _G.os
|
||||
|
||||
local BREEDING = 'Rabbit'
|
||||
local WALK_SPEED = 1.3
|
||||
local MAX_GROWN = 100
|
||||
local BREED_DELAY = 120
|
||||
|
||||
neural.assertModules({
|
||||
'plethora:sensor',
|
||||
'plethora:scanner',
|
||||
'plethora:laser',
|
||||
'plethora:kinetic',
|
||||
'plethora:introspection',
|
||||
})
|
||||
|
||||
local ID = neural.getID()
|
||||
local fed = { }
|
||||
|
||||
local function resupply()
|
||||
local slot = neural.getEquipment().list()[1]
|
||||
if slot and slot.count > 32 then
|
||||
return
|
||||
end
|
||||
print('resupplying')
|
||||
|
||||
local dispenser = Util.find(neural.scan(), 'name', 'minecraft:wooden_pressure_plate')
|
||||
if dispenser then
|
||||
if math.abs(dispenser.x) > 1 or math.abs(dispenser.z) > 1 then
|
||||
neural.walkTo({ x = dispenser.x, y = 0, z = dispenser.z }, WALK_SPEED)
|
||||
end
|
||||
neural.lookAt(dispenser)
|
||||
neural.getEquipment().suck(1, 64)
|
||||
end
|
||||
end
|
||||
|
||||
local function breed(entity)
|
||||
print('breeding')
|
||||
entity.lastFed = os.clock()
|
||||
fed[entity.id] = entity
|
||||
|
||||
neural.walkTo(entity, WALK_SPEED, .5)
|
||||
entity = neural.getMetaByID(entity.id)
|
||||
if entity and not entity.isChild then
|
||||
neural.lookAt(entity)
|
||||
neural.use(1)
|
||||
os.sleep(.1)
|
||||
end
|
||||
end
|
||||
|
||||
local function kill(entity)
|
||||
print('killing')
|
||||
neural.walkTo(entity, WALK_SPEED, 2)
|
||||
entity = neural.getMetaByID(entity.id)
|
||||
if entity and not entity.isChild then
|
||||
neural.lookAt(entity)
|
||||
neural.fireAt({ x = entity.x, y = 0, z = entity.z })
|
||||
Sound.play('entity.firework.launch')
|
||||
os.sleep(.2)
|
||||
end
|
||||
end
|
||||
|
||||
local function getEntities()
|
||||
return Util.filter(neural.sense(), function(entity)
|
||||
if entity.name == BREEDING and entity.y > -.5 and entity.id ~= ID then
|
||||
return true
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function getHungry(entities)
|
||||
for _,v in pairs(entities) do
|
||||
if not fed[v.id] or
|
||||
os.clock() - fed[v.id].lastFed > BREED_DELAY then
|
||||
return v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function randomEntity(entities)
|
||||
local r = math.random(1, Util.size(entities))
|
||||
local i = 1
|
||||
for _, v in pairs(entities) do
|
||||
i = i + 1
|
||||
if i > r then
|
||||
return v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function dropOff()
|
||||
print('dropping')
|
||||
|
||||
if neural.getEquipment().list()[2] then
|
||||
local b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
|
||||
if b then
|
||||
neural.walkTo({ x = b.x, y = 0, z = b.z }, 2)
|
||||
|
||||
b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
|
||||
if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then
|
||||
print('dropped')
|
||||
neural.getEquipment().drop(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function pickup(id)
|
||||
local b = neural.getMetaByID(id)
|
||||
if b then
|
||||
neural.walkTo(b, 2)
|
||||
|
||||
local main = neural.getEquipment().list()[1]
|
||||
local amount = neural.getEquipment().suck(not main and 2 or nil)
|
||||
print('sucked: ' .. amount)
|
||||
if amount > 0 then
|
||||
Sound.play('entity.item.pickup')
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function drops()
|
||||
local sensed = Util.reduce(neural.sense(), function(acc, s)
|
||||
if Util.round(s.y) == 0 and s.name == 'Item' then
|
||||
acc[s.id] = s
|
||||
end
|
||||
return acc
|
||||
end, { })
|
||||
|
||||
local pt = { x = 0, y = 0, z = 0 }
|
||||
while true do
|
||||
local b = Point.closest(pt, sensed)
|
||||
if not b then
|
||||
break
|
||||
end
|
||||
sensed[b.id] = nil
|
||||
|
||||
if pickup(b.id) then
|
||||
pt = b
|
||||
else
|
||||
dropOff()
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
resupply()
|
||||
|
||||
local entities = getEntities()
|
||||
|
||||
if Util.size(entities) > MAX_GROWN then
|
||||
kill(randomEntity(entities))
|
||||
else
|
||||
local entity = getHungry(entities)
|
||||
if entity then
|
||||
breed(entity)
|
||||
else
|
||||
print('sleeping')
|
||||
os.sleep(5)
|
||||
end
|
||||
drops()
|
||||
end
|
||||
end
|
||||
11
lfs/.package
11
lfs/.package
@@ -1,11 +0,0 @@
|
||||
{
|
||||
title = 'LuaFileSystem',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/lfs',
|
||||
description = [[LuaFileSystem port for computercraft
|
||||
See: https://github.com/keplerproject/luafilesystem
|
||||
|
||||
LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution.
|
||||
|
||||
LuaFileSystem offers a portable way to access the underlying directory structure and file attributes. LuaFileSystem is free software and uses the same license as Lua 5.x (MIT).]],
|
||||
license = 'MIT',
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
-- a port of LuaFileSystem
|
||||
-- https://keplerproject.github.io/luafilesystem/manual.html
|
||||
|
||||
local fs = _G.fs
|
||||
local shell = _ENV.shell
|
||||
|
||||
local lfs = {
|
||||
_VERSION = '1.8.0.computercraft'
|
||||
}
|
||||
|
||||
-- lfs.attributes (filepath [, request_name | result_table])
|
||||
-- Returns a table with the file attributes corresponding to filepath (or nil followed
|
||||
-- by an error message and a system-dependent error code in case of error). If the second
|
||||
-- optional argument is given and is a string, then only the value of the named attribute
|
||||
-- is returned (this use is equivalent to lfs.attributes(filepath)[request_name], but the
|
||||
-- table is not created and only one attribute is retrieved from the O.S.). if a table is
|
||||
-- passed as the second argument, it (result_table) is filled with attributes and returned
|
||||
-- instead of a new table. The attributes are described as follows; attribute mode is a
|
||||
-- string, all the others are numbers, and the time related attributes use the same time
|
||||
-- reference of os.time:
|
||||
function lfs.attributes(path, request_name)
|
||||
path = shell.resolve(path)
|
||||
|
||||
local s, fsattr = pcall(fs.attributes, path)
|
||||
if not s then
|
||||
return nil, fsattr, 1
|
||||
end
|
||||
|
||||
local attributes = type(request_name) == 'table' and request_name or { }
|
||||
|
||||
-- on Unix systems, this represents the device that the inode resides on.
|
||||
-- On Windows systems, represents the drive number of the disk containing the file
|
||||
attributes.dev = fs.getDrive(path)
|
||||
|
||||
-- on Unix systems, this represents the inode number.
|
||||
-- On Windows systems this has no meaning
|
||||
attributes.ino = nil
|
||||
|
||||
--string representing the associated protection mode
|
||||
-- (the values could be file, directory, link, socket, named pipe,
|
||||
-- char device, block device or other)
|
||||
attributes.mode = fsattr.isDir and 'directory' or 'file'
|
||||
|
||||
-- number of hard links to the file
|
||||
attributes.nlink = 0
|
||||
|
||||
-- user-id of owner (Unix only, always 0 on Windows)
|
||||
attributes.uid = 0
|
||||
|
||||
-- group-id of owner (Unix only, always 0 on Windows)
|
||||
attributes.gid = 0
|
||||
|
||||
-- on Unix systems, represents the device type, for special file inodes.
|
||||
-- On Windows systems represents the same as dev
|
||||
attributes.rdev = attributes.dev
|
||||
|
||||
-- time of last access
|
||||
attributes.access = fsattr.modification
|
||||
|
||||
-- time of last data modification
|
||||
attributes.modification = fsattr.modification
|
||||
|
||||
-- time of last file status change
|
||||
attributes.change = fsattr.modification
|
||||
|
||||
-- file size, in bytes
|
||||
attributes.size = fsattr.size
|
||||
|
||||
-- file permissions string
|
||||
local perm = (fs.isDir or fs.isReadOnly(path)) and 'r-x' or 'rwx'
|
||||
attributes.permissions = perm .. perm .. perm
|
||||
|
||||
-- block allocated for file; (Unix only)
|
||||
attributes.blocks = nil
|
||||
|
||||
-- optimal file system I/O blocksize; (Unix only)
|
||||
attributes.blksize = nil
|
||||
|
||||
return type(request_name) ~= 'string' and attributes or attributes[request_name]
|
||||
end
|
||||
|
||||
-- lfs.chdir (path)
|
||||
-- Changes the current working directory to the given path.
|
||||
-- Returns true in case of success or nil plus an error string.
|
||||
function lfs.chdir(path)
|
||||
path = shell.resolve(path)
|
||||
if fs.isDir(path) then
|
||||
shell.setDir(path)
|
||||
return true
|
||||
end
|
||||
return nil, path .. ': No such directory'
|
||||
end
|
||||
|
||||
-- lfs.currentdir ()
|
||||
-- Returns a string with the current working directory or nil plus an error string.
|
||||
function lfs.currentdir()
|
||||
return '/' .. shell.dir()
|
||||
end
|
||||
|
||||
-- iter, dir_obj = lfs.dir (path)
|
||||
-- Lua iterator over the entries of a given directory.
|
||||
-- Each time the iterator is called with dir_obj it returns a directory
|
||||
-- entry's name as a string, or nil if there are no more entries.
|
||||
-- You can also iterate by calling dir_obj:next(), and explicitly close the
|
||||
-- directory before the iteration finished with dir_obj:close().
|
||||
-- Raises an error if path is not a directory.
|
||||
function lfs.dir(path)
|
||||
path = shell.resolve(path)
|
||||
local set = fs.list(path)
|
||||
local iter = function()
|
||||
local key, value = next(set)
|
||||
set[key or false] = nil
|
||||
return value
|
||||
end
|
||||
return iter, {
|
||||
valid = true,
|
||||
closed = false,
|
||||
next = function(self)
|
||||
if not self.valid then
|
||||
error('file iterator invalid')
|
||||
end
|
||||
local n = iter()
|
||||
if not n then
|
||||
self.valid = false
|
||||
end
|
||||
return n
|
||||
end,
|
||||
close = function(self)
|
||||
if self.closed then
|
||||
error('file iterator invalid')
|
||||
end
|
||||
self.closed = true
|
||||
self.valid = false
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
-- lfs.link (old, new[, symlink])
|
||||
-- Creates a link. The first argument is the object to link to and the second is the
|
||||
-- name of the link. If the optional third argument is true, the link will by a symbolic
|
||||
-- link (by default, a hard link is created).
|
||||
function lfs.link(old, new, symlink)
|
||||
if not symlink then
|
||||
return false
|
||||
end
|
||||
-- hard links are not supported in vfs :(
|
||||
old = shell.resolve(old)
|
||||
new = shell.resolve(new)
|
||||
return not not fs.mount(new, 'linkfs', old)
|
||||
end
|
||||
|
||||
-- lfs.mkdir (dirname)
|
||||
-- Creates a new directory. The argument is the name of the new directory.
|
||||
-- Returns true in case of success or nil, an error message and a system-dependent
|
||||
-- error code in case of error.
|
||||
function lfs.mkdir(dirname)
|
||||
dirname = shell.resolve(dirname)
|
||||
if fs.exists(fs.getDir(dirname)) then
|
||||
fs.makeDir(dirname)
|
||||
if fs.isDir(dirname) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return nil, dirname .. ': Unable to create directory', 1
|
||||
end
|
||||
|
||||
-- lfs.rmdir (dirname)
|
||||
-- Removes an existing directory. The argument is the name of the directory.
|
||||
-- Returns true in case of success or nil, an error message and a system-dependent
|
||||
-- error code in case of error.
|
||||
function lfs.rmdir(dirname)
|
||||
dirname = shell.resolve(dirname)
|
||||
if not fs.exists(dirname) or not fs.isDir(dirname) then
|
||||
return false, dirname .. ': Not a directory', 1
|
||||
end
|
||||
pcall(fs.delete, dirname)
|
||||
return not fs.exists(dirname) or false, dirname .. ': Unable to remove directory', 1
|
||||
end
|
||||
|
||||
-- lfs.setmode (file, mode)
|
||||
-- Sets the writing mode for a file. The mode string can be either "binary" or "text".
|
||||
-- Returns true followed the previous mode string for the file, or nil followed by an
|
||||
-- error string in case of errors. On non-Windows platforms, where the two modes are
|
||||
-- identical, setting the mode has no effect, and the mode is always returned as binary.
|
||||
function lfs.setmode(file)
|
||||
if tostring(file) == 'file (closed)' then
|
||||
error('closed file')
|
||||
end
|
||||
return true, 'binary'
|
||||
end
|
||||
|
||||
-- lfs.symlinkattributes (filepath [, request_name])
|
||||
-- Identical to lfs.attributes except that it obtains information about the link itself
|
||||
-- (not the file it refers to). It also adds a target field, containing the file name that
|
||||
-- the symlink points to. On Windows this function does not yet support links, and is
|
||||
-- identical to lfs.attributes.
|
||||
function lfs.symlinkattributes(filepath, request_name)
|
||||
filepath = shell.resolve(filepath)
|
||||
|
||||
local target = fs.resolve(filepath)
|
||||
local attribs = lfs.attributes('/' .. target)
|
||||
if filepath ~= target then
|
||||
attribs.target = '/' .. target
|
||||
attribs.mode = 'link'
|
||||
end
|
||||
|
||||
return request_name and attribs[request_name] or attribs
|
||||
end
|
||||
|
||||
-- lfs.touch (filepath [, atime [, mtime]])
|
||||
-- Set access and modification times of a file. This function is a bind to utime function.
|
||||
-- The first argument is the filename, the second argument (atime) is the access time, and
|
||||
-- the third argument (mtime) is the modification time. Both times are provided in seconds
|
||||
-- (which should be generated with Lua standard function os.time). If the modification time
|
||||
-- is omitted, the access time provided is used; if both times are omitted, the current time
|
||||
-- is used.
|
||||
-- Returns true in case of success or nil, an error message and a system-dependent error
|
||||
-- code in case of error.
|
||||
function lfs.touch(filename, atime, mtime)
|
||||
mtime = mtime or atime
|
||||
filename = shell.resolve(filename)
|
||||
|
||||
if atime or mtime then
|
||||
error('setting access/modification time is not supported')
|
||||
end
|
||||
|
||||
-- cc does not suport setting atime/mtime
|
||||
-- error('lfs.touch not supported')
|
||||
if not fs.exists(filename) then
|
||||
local f = fs.open(filename, 'w')
|
||||
if f then
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return lfs
|
||||
@@ -1 +0,0 @@
|
||||
packages/lfs/tests/test.lua urlfs https://raw.githubusercontent.com/keplerproject/luafilesystem/master/tests/test.lua
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
title = 'LPeg',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/lpeg',
|
||||
description = [[A pure Lua port of LPeg, Roberto Ierusalimschy's Parsing Expression Grammars library.
|
||||
|
||||
This version of LuLPeg emulates LPeg v0.12.
|
||||
see: https://github.com/pygy/LuLPeg/]],
|
||||
license = 'MIT',
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
rom/modules/main/lpeg.lua urlfs https://raw.githubusercontent.com/pygy/LuLPeg/master/lulpeg.lua
|
||||
334
lzwfs/lzwfs.lua
334
lzwfs/lzwfs.lua
@@ -19,9 +19,9 @@ local SIGC = 'LZWC'
|
||||
local basedictcompress = {}
|
||||
local basedictdecompress = {}
|
||||
for i = 0, 255 do
|
||||
local ic, iic = char(i), char(i, 0)
|
||||
basedictcompress[ic] = iic
|
||||
basedictdecompress[iic] = ic
|
||||
local ic, iic = char(i), char(i, 0)
|
||||
basedictcompress[ic] = iic
|
||||
basedictdecompress[iic] = ic
|
||||
end
|
||||
|
||||
local native = { open = fs.open }
|
||||
@@ -29,123 +29,123 @@ local enabled = false
|
||||
local filters = { }
|
||||
|
||||
local function dictAddA(str, dict, a, b)
|
||||
if a >= 256 then
|
||||
a, b = 0, b+1
|
||||
if b >= 256 then
|
||||
dict = {}
|
||||
b = 1
|
||||
end
|
||||
end
|
||||
dict[str] = char(a,b)
|
||||
a = a+1
|
||||
return dict, a, b
|
||||
if a >= 256 then
|
||||
a, b = 0, b+1
|
||||
if b >= 256 then
|
||||
dict = {}
|
||||
b = 1
|
||||
end
|
||||
end
|
||||
dict[str] = char(a,b)
|
||||
a = a+1
|
||||
return dict, a, b
|
||||
end
|
||||
|
||||
local function compress(input)
|
||||
if type(input) ~= "string" then
|
||||
error ("string expected, got "..type(input))
|
||||
end
|
||||
local len = #input
|
||||
if len <= 1 then
|
||||
return input
|
||||
end
|
||||
if type(input) ~= "string" then
|
||||
error ("string expected, got "..type(input))
|
||||
end
|
||||
local len = #input
|
||||
if len <= 1 then
|
||||
return input
|
||||
end
|
||||
|
||||
local dict = {}
|
||||
local a, b = 0, 1
|
||||
local dict = {}
|
||||
local a, b = 0, 1
|
||||
|
||||
local result = { SIGC }
|
||||
local resultlen = 1
|
||||
local n = 2
|
||||
local word = ""
|
||||
for i = 1, len do
|
||||
local c = sub(input, i, i)
|
||||
local wc = word..c
|
||||
if not (basedictcompress[wc] or dict[wc]) then
|
||||
local write = basedictcompress[word] or dict[word]
|
||||
if not write then
|
||||
error "algorithm error, could not fetch word"
|
||||
end
|
||||
result[n] = write
|
||||
resultlen = resultlen + #write
|
||||
n = n+1
|
||||
if len <= resultlen then
|
||||
return input
|
||||
end
|
||||
dict, a, b = dictAddA(wc, dict, a, b)
|
||||
word = c
|
||||
else
|
||||
word = wc
|
||||
end
|
||||
end
|
||||
result[n] = basedictcompress[word] or dict[word]
|
||||
resultlen = resultlen+#result[n]
|
||||
if len <= resultlen then
|
||||
return input
|
||||
end
|
||||
return tconcat(result)
|
||||
local result = { SIGC }
|
||||
local resultlen = 1
|
||||
local n = 2
|
||||
local word = ""
|
||||
for i = 1, len do
|
||||
local c = sub(input, i, i)
|
||||
local wc = word..c
|
||||
if not (basedictcompress[wc] or dict[wc]) then
|
||||
local write = basedictcompress[word] or dict[word]
|
||||
if not write then
|
||||
error "algorithm error, could not fetch word"
|
||||
end
|
||||
result[n] = write
|
||||
resultlen = resultlen + #write
|
||||
n = n+1
|
||||
if len <= resultlen then
|
||||
return input
|
||||
end
|
||||
dict, a, b = dictAddA(wc, dict, a, b)
|
||||
word = c
|
||||
else
|
||||
word = wc
|
||||
end
|
||||
end
|
||||
result[n] = basedictcompress[word] or dict[word]
|
||||
resultlen = resultlen+#result[n]
|
||||
if len <= resultlen then
|
||||
return input
|
||||
end
|
||||
return tconcat(result)
|
||||
end
|
||||
|
||||
local function dictAddB(str, dict, a, b)
|
||||
if a >= 256 then
|
||||
a, b = 0, b+1
|
||||
if b >= 256 then
|
||||
dict = {}
|
||||
b = 1
|
||||
end
|
||||
end
|
||||
dict[char(a,b)] = str
|
||||
a = a+1
|
||||
return dict, a, b
|
||||
if a >= 256 then
|
||||
a, b = 0, b+1
|
||||
if b >= 256 then
|
||||
dict = {}
|
||||
b = 1
|
||||
end
|
||||
end
|
||||
dict[char(a,b)] = str
|
||||
a = a+1
|
||||
return dict, a, b
|
||||
end
|
||||
|
||||
local function decompress(input)
|
||||
if type(input) ~= "string" then
|
||||
error( "string expected, got "..type(input))
|
||||
end
|
||||
if type(input) ~= "string" then
|
||||
error( "string expected, got "..type(input))
|
||||
end
|
||||
|
||||
if #input <= 1 then
|
||||
return input
|
||||
end
|
||||
if #input <= 1 then
|
||||
return input
|
||||
end
|
||||
|
||||
local control = sub(input, 1, 4)
|
||||
if control ~= SIGC then
|
||||
return input
|
||||
end
|
||||
input = sub(input, 5)
|
||||
local len = #input
|
||||
local control = sub(input, 1, 4)
|
||||
if control ~= SIGC then
|
||||
return input
|
||||
end
|
||||
input = sub(input, 5)
|
||||
local len = #input
|
||||
|
||||
if len < 2 then
|
||||
error("invalid input - not a compressed string")
|
||||
end
|
||||
if len < 2 then
|
||||
error("invalid input - not a compressed string")
|
||||
end
|
||||
|
||||
local dict = {}
|
||||
local a, b = 0, 1
|
||||
local dict = {}
|
||||
local a, b = 0, 1
|
||||
|
||||
local result = {}
|
||||
local n = 1
|
||||
local last = sub(input, 1, 2)
|
||||
result[n] = basedictdecompress[last] or dict[last]
|
||||
n = n+1
|
||||
for i = 3, len, 2 do
|
||||
local code = sub(input, i, i+1)
|
||||
local lastStr = basedictdecompress[last] or dict[last]
|
||||
if not lastStr then
|
||||
error( "could not find last from dict. Invalid input?")
|
||||
end
|
||||
local toAdd = basedictdecompress[code] or dict[code]
|
||||
if toAdd then
|
||||
result[n] = toAdd
|
||||
n = n+1
|
||||
dict, a, b = dictAddB(lastStr..sub(toAdd, 1, 1), dict, a, b)
|
||||
else
|
||||
local tmp = lastStr..sub(lastStr, 1, 1)
|
||||
result[n] = tmp
|
||||
n = n+1
|
||||
dict, a, b = dictAddB(tmp, dict, a, b)
|
||||
end
|
||||
last = code
|
||||
end
|
||||
return tconcat(result)
|
||||
local result = {}
|
||||
local n = 1
|
||||
local last = sub(input, 1, 2)
|
||||
result[n] = basedictdecompress[last] or dict[last]
|
||||
n = n+1
|
||||
for i = 3, len, 2 do
|
||||
local code = sub(input, i, i+1)
|
||||
local lastStr = basedictdecompress[last] or dict[last]
|
||||
if not lastStr then
|
||||
error( "could not find last from dict. Invalid input?")
|
||||
end
|
||||
local toAdd = basedictdecompress[code] or dict[code]
|
||||
if toAdd then
|
||||
result[n] = toAdd
|
||||
n = n+1
|
||||
dict, a, b = dictAddB(lastStr..sub(toAdd, 1, 1), dict, a, b)
|
||||
else
|
||||
local tmp = lastStr..sub(lastStr, 1, 1)
|
||||
result[n] = tmp
|
||||
n = n+1
|
||||
dict, a, b = dictAddB(tmp, dict, a, b)
|
||||
end
|
||||
last = code
|
||||
end
|
||||
return tconcat(result)
|
||||
end
|
||||
|
||||
local function split(str, pattern)
|
||||
@@ -157,39 +157,39 @@ local function split(str, pattern)
|
||||
end
|
||||
|
||||
local function matchesFilter(fname)
|
||||
if not fname:find('lzwfs') then -- don't compress anything with lzwfs in name (sigh)
|
||||
for _, filter in pairs(filters) do
|
||||
if fname:match(filter) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
if not fname:find('lzwfs') then -- don't compress anything with lzwfs in name (sigh)
|
||||
for _, filter in pairs(filters) do
|
||||
if fname:match(filter) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function fs.open(fname, flags)
|
||||
if not enabled then
|
||||
return native.open(fname, flags)
|
||||
end
|
||||
if not enabled then
|
||||
return native.open(fname, flags)
|
||||
end
|
||||
|
||||
if flags == 'r' then
|
||||
local f, err = native.open(fname, 'rb')
|
||||
if not f then
|
||||
return f, err
|
||||
end
|
||||
if flags == 'r' then
|
||||
local f, err = native.open(fname, 'rb')
|
||||
if not f then
|
||||
return f, err
|
||||
end
|
||||
|
||||
local ctr = 0
|
||||
local lines
|
||||
return {
|
||||
read = function()
|
||||
if not lines then
|
||||
lines = decompress(f.readAll())
|
||||
read = function()
|
||||
if not lines then
|
||||
lines = decompress(f.readAll())
|
||||
end
|
||||
ctr = ctr + 1
|
||||
return lines:sub(ctr, ctr)
|
||||
end,
|
||||
readLine = function()
|
||||
ctr = ctr + 1
|
||||
return lines:sub(ctr, ctr)
|
||||
end,
|
||||
readLine = function()
|
||||
if not lines then
|
||||
lines = split(decompress(f.readAll()))
|
||||
lines = split(decompress(f.readAll()))
|
||||
end
|
||||
ctr = ctr + 1
|
||||
return lines[ctr]
|
||||
@@ -197,61 +197,61 @@ function fs.open(fname, flags)
|
||||
readAll = function()
|
||||
return decompress(f.readAll())
|
||||
end,
|
||||
close = function()
|
||||
f.close()
|
||||
close = function()
|
||||
f.close()
|
||||
end,
|
||||
}
|
||||
elseif flags == 'w' or flags == 'a' then
|
||||
if not matchesFilter(fs.combine(fname, '')) then
|
||||
return native.open(fname, flags)
|
||||
end
|
||||
}
|
||||
elseif flags == 'w' or flags == 'a' then
|
||||
if not matchesFilter(fs.combine(fname, '')) then
|
||||
return native.open(fname, flags)
|
||||
end
|
||||
|
||||
local c = { }
|
||||
local c = { }
|
||||
|
||||
if flags == 'a' then
|
||||
local f = fs.open(fname, 'r')
|
||||
if f then
|
||||
tinsert(c, f.readAll())
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
if flags == 'a' then
|
||||
local f = fs.open(fname, 'r')
|
||||
if f then
|
||||
tinsert(c, f.readAll())
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
|
||||
local f, err = native.open(fname, 'wb')
|
||||
if not f then
|
||||
return f, err
|
||||
end
|
||||
local f, err = native.open(fname, 'wb')
|
||||
if not f then
|
||||
return f, err
|
||||
end
|
||||
|
||||
return {
|
||||
write = function(str)
|
||||
tinsert(c, str)
|
||||
return {
|
||||
write = function(str)
|
||||
tinsert(c, str)
|
||||
end,
|
||||
writeLine = function(str)
|
||||
tinsert(c, str)
|
||||
tinsert(c, '\n')
|
||||
tinsert(c, str)
|
||||
tinsert(c, '\n')
|
||||
end,
|
||||
flush = function()
|
||||
-- this isn't gonna work...
|
||||
-- f.write(compress(tconcat(c)))
|
||||
f.flush();
|
||||
flush = function()
|
||||
-- this isn't gonna work...
|
||||
-- f.write(compress(tconcat(c)))
|
||||
f.flush();
|
||||
end,
|
||||
close = function()
|
||||
f.write(compress(tconcat(c)))
|
||||
f.close()
|
||||
close = function()
|
||||
f.write(compress(tconcat(c)))
|
||||
f.close()
|
||||
end,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
return native.open(fname, flags)
|
||||
return native.open(fname, flags)
|
||||
end
|
||||
|
||||
function fs.option(category, action, option)
|
||||
if category == 'compression' then
|
||||
if action == 'enabled' then
|
||||
enabled = option
|
||||
elseif action == 'filters' then
|
||||
filters = option
|
||||
end
|
||||
end
|
||||
if category == 'compression' then
|
||||
if action == 'enabled' then
|
||||
enabled = option
|
||||
elseif action == 'filters' then
|
||||
filters = option
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print('lzwfs started')
|
||||
|
||||
@@ -6,11 +6,11 @@ local CONFIG = 'usr/config/lzwfs'
|
||||
local config = { }
|
||||
|
||||
if fs.exists(CONFIG) then
|
||||
local f = fs.open(CONFIG, 'r')
|
||||
local f = fs.open(CONFIG, 'r')
|
||||
if f then
|
||||
config = textutils.unserialize(f.readAll())
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
os.run(_ENV, '/packages/lzwfs/lzwfs.lua')
|
||||
|
||||
@@ -14,7 +14,7 @@ local config = Config.load('lzwfs', {
|
||||
})
|
||||
|
||||
local tab = UI.Tab {
|
||||
title = 'Compression',
|
||||
tabTitle = 'Compression',
|
||||
description = 'Disk compression',
|
||||
[1] = UI.Window {
|
||||
x = 2, y = 2, ex = -2, ey = 6,
|
||||
@@ -29,6 +29,7 @@ local tab = UI.Tab {
|
||||
},
|
||||
entry = UI.TextEntry {
|
||||
x = 3, y = 5 , ex = -3,
|
||||
limit = 256,
|
||||
shadowText = 'enter new path',
|
||||
accelerators = {
|
||||
enter = 'add_path',
|
||||
|
||||
11
mbs/.package
11
mbs/.package
@@ -8,4 +8,15 @@ https://github.com/SquidDev-CC/mbs
|
||||
MBS is a series of utilities for improving the default CraftOS experience.
|
||||
]],
|
||||
license = 'MIT',
|
||||
install = [[
|
||||
local Alt = require('opus.alternate')
|
||||
Alt.set('shell', '.mbs/bin/shell.lua')
|
||||
Alt.add('lua', '.mbs/bin/lua.lua')
|
||||
]],
|
||||
uninstall = [[
|
||||
local Alt = require('opus.alternate')
|
||||
Alt.remove('shell', '.mbs/bin/shell.lua')
|
||||
Alt.remove('lua', '.mbs/bin/lua.lua')
|
||||
fs.delete('.mbs')
|
||||
]],
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ local shell = _ENV.shell
|
||||
|
||||
if not fs.exists('.mbs') then
|
||||
print('Installing MBS')
|
||||
--shell.run('mbs download')
|
||||
shell.run('mbs download')
|
||||
end
|
||||
print('Initializing MBS')
|
||||
--shell.run('mbs startup')
|
||||
shell.run('mbs startup')
|
||||
|
||||
@@ -2,7 +2,6 @@ local Event = require('opus.event')
|
||||
local Milo = require('milo')
|
||||
local Sound = require('opus.sound')
|
||||
local Storage = require('milo.storage')
|
||||
local TurtleInv = require('milo.turtleInv')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
@@ -19,6 +18,7 @@ multishell.setTitle(multishell.getCurrent(), 'Milo')
|
||||
local function Syntax(msg)
|
||||
print([[
|
||||
Turtle must be provided with:
|
||||
* Introspection module (never bound)
|
||||
* Workbench
|
||||
|
||||
Turtle must be connected to:
|
||||
@@ -46,6 +46,10 @@ if not modem.getNameLocal() then
|
||||
Syntax('Wired modem is not active')
|
||||
end
|
||||
|
||||
local introspection = device['plethora:introspection'] or
|
||||
turtle.equip('left', 'plethora:module:0') and device['plethora:introspection'] or
|
||||
Syntax('Introspection module missing')
|
||||
|
||||
if not device.workbench then
|
||||
turtle.equip('right', 'minecraft:crafting_table:0')
|
||||
if not device.workbench then
|
||||
@@ -54,7 +58,6 @@ if not device.workbench then
|
||||
end
|
||||
|
||||
local localName = modem.getNameLocal()
|
||||
TurtleInv.setLocalName(localName)
|
||||
|
||||
local context = {
|
||||
resources = Util.readTable(Milo.RESOURCE_FILE) or { },
|
||||
@@ -73,7 +76,7 @@ local context = {
|
||||
turtleInventory = {
|
||||
name = localName,
|
||||
mtype = 'hidden',
|
||||
adapter = TurtleInv,
|
||||
adapter = introspection.getInventory(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,9 +219,7 @@ local s, m = pcall(function()
|
||||
UI:start()
|
||||
end)
|
||||
|
||||
if turtle.setStatus then
|
||||
turtle.setStatus('idle')
|
||||
end
|
||||
turtle.setStatus('idle')
|
||||
|
||||
_G._syslog = oldDebug
|
||||
if not s then error(m) end
|
||||
|
||||
@@ -12,12 +12,8 @@ local fs = _G.fs
|
||||
local peripheral = _G.peripheral
|
||||
local shell = _ENV.shell
|
||||
|
||||
local configName = ({...})[1]
|
||||
local configPath = 'miloRemote' .. (configName and "_"..configName or "")
|
||||
|
||||
local context = {
|
||||
state = Config.load(configPath, { displayMode = 0, deposit = true }),
|
||||
configPath = configPath,
|
||||
state = Config.load('miloRemote', { displayMode = 0, deposit = true }),
|
||||
responseHandlers = { },
|
||||
}
|
||||
|
||||
@@ -162,7 +158,7 @@ function page.grid:eventHandler(event)
|
||||
if event.type == 'grid_sort' then
|
||||
context.state.sortColumn = event.sortColumn
|
||||
context.state.inverseSort = event.inverseSort
|
||||
Config.update(configPath, context.state)
|
||||
Config.update('miloRemote', context.state)
|
||||
end
|
||||
return UI.Grid.eventHandler(self, event)
|
||||
end
|
||||
@@ -185,7 +181,7 @@ function page:eventHandler(event)
|
||||
self.statusBar:draw()
|
||||
context:setStatus(depositMode[context.state.deposit].help)
|
||||
context:notifyInfo(depositMode[context.state.deposit].help)
|
||||
Config.update(configPath, context.state)
|
||||
Config.update('miloRemote', context.state)
|
||||
|
||||
elseif event.type == 'focus_change' then
|
||||
context:setStatus(event.focused.help)
|
||||
@@ -247,7 +243,7 @@ function page:eventHandler(event)
|
||||
context:setStatus(event.button.help)
|
||||
context:notifyInfo(event.button.help)
|
||||
self.grid:draw()
|
||||
Config.update(configPath, context.state)
|
||||
Config.update('miloRemote', context.state)
|
||||
|
||||
elseif event.type == 'text_change' and event.element == self.statusBar.filter then
|
||||
self.filter = event.text or ''
|
||||
@@ -281,12 +277,11 @@ end
|
||||
|
||||
local function splitKey(key)
|
||||
local t = Util.split(key, '(.-):')
|
||||
|
||||
local item = { }
|
||||
if t[3] then
|
||||
item.nbt = t[3]
|
||||
if #t[#t] > 8 then
|
||||
item.nbtHash = table.remove(t)
|
||||
end
|
||||
t[3] = nil
|
||||
item.damage = tonumber(table.remove(t))
|
||||
item.name = table.concat(t, ':')
|
||||
return item
|
||||
end
|
||||
@@ -323,7 +318,7 @@ function page:applyFilter()
|
||||
v.score = fuzzy(v.lname, filter)
|
||||
if v.score then
|
||||
if v.count > 0 then
|
||||
v.score = v.score + .2
|
||||
v.score = v.score + 1
|
||||
end
|
||||
table.insert(r, v)
|
||||
end
|
||||
@@ -450,7 +445,7 @@ end
|
||||
|
||||
function context:setState(key, value)
|
||||
self.state[key] = value
|
||||
Config.update(configPath, self.state)
|
||||
Config.update('miloRemote', self.state)
|
||||
end
|
||||
|
||||
context.responseHandlers['received'] = function(response)
|
||||
|
||||
@@ -20,12 +20,10 @@ local Craft = {
|
||||
local function splitKey(key)
|
||||
local t = Util.split(key, '(.-):')
|
||||
local item = { }
|
||||
|
||||
if t[3] then
|
||||
item.nbt = t[3]
|
||||
t[3] = nil
|
||||
if #t[#t] > 8 then
|
||||
item.nbtHash = table.remove(t)
|
||||
end
|
||||
|
||||
item.damage = tonumber(table.remove(t))
|
||||
item.name = table.concat(t, ':')
|
||||
return item
|
||||
end
|
||||
@@ -34,7 +32,7 @@ local function makeRecipeKey(item)
|
||||
if type(item) == 'string' then
|
||||
item = splitKey(item)
|
||||
end
|
||||
return table.concat({ item.name, item.nbt }, ':')
|
||||
return table.concat({ item.name, item.damage or 0, item.nbtHash }, ':')
|
||||
end
|
||||
|
||||
local function convert(ingredient)
|
||||
@@ -49,7 +47,8 @@ local function getCraftingTool(storage, item)
|
||||
|
||||
for _,v in pairs(items) do
|
||||
if item.name == v.name and
|
||||
(not item.nbt or item.nbt == v.nbt) then
|
||||
(not item.damage or item.damage == v.damage) and
|
||||
(not item.nbtHash or item.nbtHash == v.nbtHash) then
|
||||
return v
|
||||
end
|
||||
end
|
||||
@@ -94,7 +93,11 @@ function Craft.getItemCount(items, item)
|
||||
local count = 0
|
||||
for _,v in pairs(items) do
|
||||
if v.name == item.name and
|
||||
v.nbt == item.nbt then
|
||||
(not item.damage or v.damage == item.damage) and
|
||||
v.nbtHash == item.nbtHash then
|
||||
if item.damage then
|
||||
return v.count
|
||||
end
|
||||
count = count + v.count
|
||||
end
|
||||
end
|
||||
@@ -384,7 +387,18 @@ function Craft.findRecipe(key)
|
||||
end
|
||||
|
||||
local item = itemDB:splitKey(key)
|
||||
return Craft.recipes[makeRecipeKey(item)]
|
||||
if item.damage then
|
||||
return Craft.recipes[makeRecipeKey(item)]
|
||||
end
|
||||
|
||||
-- handle cases where the request is like : IC2:reactorVent:*
|
||||
for rkey,recipe in pairs(Craft.recipes) do
|
||||
local r = itemDB:splitKey(rkey)
|
||||
if item.name == r.name and
|
||||
(not item.nbtHash or r.nbtHash == item.nbtHash) then
|
||||
return recipe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- determine the full list of ingredients needed to craft
|
||||
|
||||
@@ -93,7 +93,7 @@ function Milo:getMatches(item, flags)
|
||||
local count = 0
|
||||
local items = self:listItems()
|
||||
|
||||
if not flags.ignoreNbt then
|
||||
if not flags.ignoreDamage and not flags.ignoreNbtHash then
|
||||
local key = item.key or itemDB:makeKey(item)
|
||||
local v = items[key]
|
||||
if v then
|
||||
@@ -104,7 +104,8 @@ function Milo:getMatches(item, flags)
|
||||
else
|
||||
for key,v in pairs(items) do
|
||||
if item.name == v.name and
|
||||
(flags.ignoreNbt or item.nbt == v.nbt) then
|
||||
(flags.ignoreDamage or item.damage == v.damage) and
|
||||
(flags.ignoreNbtHash or item.nbtHash == v.nbtHash) then
|
||||
|
||||
t[key] = Util.shallowCopy(v)
|
||||
count = count + v.count
|
||||
@@ -124,7 +125,7 @@ function Milo:getTurtleInventory()
|
||||
|
||||
for i, v in pairs(self.context.turtleInventory.adapter.list()) do
|
||||
list[i] = itemDB:get(v, function()
|
||||
return self.context.turtleInventory.adapter.getItemDetail(i)
|
||||
return self.context.turtleInventory.adapter.getItemMeta(i)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -276,15 +277,22 @@ function Milo:learnRecipe()
|
||||
for _,v1 in pairs(results) do
|
||||
for _,v2 in pairs(ingredients) do
|
||||
if v1.name == v2.name and
|
||||
v1.nbt == v2.nbt then
|
||||
v1.nbtHash == v2.nbtHash and
|
||||
(v1.damage == v2.damage or
|
||||
(v1.maxDamage > 0 and v2.maxDamage > 0 and
|
||||
v1.damage ~= v2.damage)) then
|
||||
if not newRecipe.crafingTools then
|
||||
newRecipe.craftingTools = { }
|
||||
end
|
||||
local tool = Util.shallowCopy(v2)
|
||||
if tool.maxDamage > 0 then
|
||||
tool.damage = '*'
|
||||
v2.damage = '*'
|
||||
end
|
||||
|
||||
--[[
|
||||
Turtles can only craft one item at a time using a tool :(
|
||||
]] -- Todo: check if this still applies
|
||||
]]--
|
||||
maxCount = 1
|
||||
|
||||
newRecipe.craftingTools[itemDB:makeKey(tool)] = true
|
||||
|
||||
@@ -19,17 +19,15 @@ function Adapter:listItems(throttle)
|
||||
local cache = { }
|
||||
throttle = throttle or Util.throttle()
|
||||
|
||||
local list = self.list()
|
||||
|
||||
for k,v in pairs(list) do
|
||||
for k,v in pairs(self.list()) do
|
||||
if v.count > 0 then
|
||||
local key = table.concat({ v.name, v.nbt }, ':')
|
||||
local key = table.concat({ v.name, v.damage, v.nbtHash }, ':')
|
||||
|
||||
local entry = cache[key]
|
||||
if entry then
|
||||
entry.count = entry.count + v.count
|
||||
else
|
||||
cache[key] = itemDB:get(v, function() return self.getItemDetail(k) end)
|
||||
cache[key] = itemDB:get(v, function() return self.getItemMeta(k) end)
|
||||
end
|
||||
throttle()
|
||||
end
|
||||
@@ -39,10 +37,6 @@ function Adapter:listItems(throttle)
|
||||
-- useful for when inserting into chests
|
||||
-- ie. insert only if chest does not have item and has free slots
|
||||
|
||||
-- bodge to make statsView not delay
|
||||
-- todo: handle this better properly
|
||||
self.__used = Util.size(list)
|
||||
|
||||
self.cache = cache
|
||||
end
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ local device = _G.device
|
||||
local os = _G.os
|
||||
local parallel = _G.parallel
|
||||
|
||||
local SCAN_CHUNK_SIZE = 16
|
||||
|
||||
local Storage = class()
|
||||
|
||||
local function loadOld(storage)
|
||||
@@ -265,22 +263,7 @@ function Storage:listItems(throttle)
|
||||
end
|
||||
|
||||
if #t > 0 then
|
||||
local chunk = {}
|
||||
|
||||
-- Split the work into chunks to avoid spamming too many coroutines.
|
||||
for i = 1, #t do
|
||||
table.insert(chunk, t[i])
|
||||
|
||||
-- When we reach the chunk limit, execute them and start a new chunk
|
||||
if #chunk >= SCAN_CHUNK_SIZE then
|
||||
parallel.waitForAll(table.unpack(chunk))
|
||||
chunk = {}
|
||||
end
|
||||
end
|
||||
|
||||
if #chunk > 0 then
|
||||
parallel.waitForAll(table.unpack(chunk))
|
||||
end
|
||||
parallel.waitForAll(table.unpack(t))
|
||||
end
|
||||
|
||||
for _, adapter in self:onlineAdapters() do
|
||||
@@ -308,134 +291,6 @@ function Storage:listItems(throttle)
|
||||
return self.cache
|
||||
end
|
||||
|
||||
-- provide a raw list of all the items in all storage chests
|
||||
-- it might be beneficial to move this to the adapter class at some point and cache the raw item list in this class at some point
|
||||
function Storage:listItemsRaw(throttle)
|
||||
local res = {}
|
||||
|
||||
throttle = throttle or Util.throttle()
|
||||
|
||||
for _, v in pairs(self.nodes) do
|
||||
if v.category == "storage" then
|
||||
local chest = device[v.name]
|
||||
local items = chest.list()
|
||||
|
||||
for slot, item in pairs(items) do
|
||||
items[slot] = itemDB:get(item, function() return chest.getItemDetail(slot) end)
|
||||
end
|
||||
|
||||
res[v.name] = items
|
||||
throttle()
|
||||
end
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
-- provide a list of items and which chests provide them
|
||||
function Storage:listProviders(throttle)
|
||||
local res = {}
|
||||
|
||||
local rawItems = self:listItemsRaw(throttle)
|
||||
|
||||
for chest, items in pairs(rawItems) do
|
||||
for slot, item in pairs(items) do
|
||||
local key = table.concat({item.name, item.nbt}, ":")
|
||||
if not res[key] then
|
||||
res[key] = {}
|
||||
end
|
||||
table.insert(res[key], {item = item, device = device[chest], lockedToThis = (self.nodes[chest].lock or {})[key] or false, slot = slot})
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
-- defrags the storage system
|
||||
function Storage:defrag(throttle)
|
||||
local items = self:listProviders(throttle)
|
||||
local slotsSaved = 0
|
||||
|
||||
-- This will make sure the table is sorted in the following order:
|
||||
-- Unlocked stacks with less than maxCount items | Locked stacks with less than maxCount items | stacks with more than maxCount items
|
||||
-- This way the locked stacks will be filled first
|
||||
local function sortFunction(a, b)
|
||||
local preferenceA, preferenceB
|
||||
preferenceA = (a.item.count == a.item.maxCount and 3)
|
||||
or (a.lockedToThis and 2)
|
||||
or 1
|
||||
preferenceB = (b.item.count == b.item.maxCount and 3)
|
||||
or (b.lockedToThis and 2)
|
||||
or 1
|
||||
|
||||
if preferenceA < preferenceB then
|
||||
return true
|
||||
elseif preferenceB > preferenceA then
|
||||
return false
|
||||
else
|
||||
return a.item.count < b.item.count
|
||||
end
|
||||
end
|
||||
|
||||
for _, providers in pairs(items) do
|
||||
table.sort(providers, sortFunction)
|
||||
|
||||
-- We're done when we either compressed the stacks so far, that there's only one left (#providers == 1)
|
||||
-- Or when we've compressed so far, that the there's only one stack which has a lower count than the maxCount
|
||||
-- Because of the sorting, we know that this will be the stack in providers[1], so we check if providers[2] is at the maxCount
|
||||
while #providers > 1 and providers[2].item.count ~= providers[2].item.maxCount do
|
||||
local from = providers[1]
|
||||
local to
|
||||
|
||||
-- We're pushing to the highest stack which is still below the maxCount, this way as many slots as possible will be filled
|
||||
-- This loop is guarenteed to assign a value to "to", as the only cases where it wouldn't (#providers == 1 or no provider with less than maxCount)
|
||||
-- are ruled out by the condition of the outer while loop
|
||||
for i = 2, #providers do
|
||||
-- Give preference to locked chests
|
||||
if not (to and to.lockedToThis or false) and providers[i].lockedToThis then
|
||||
to = providers[i]
|
||||
elseif ((to and to.lockedToThis or false) == providers[i].lockedToThis) and providers[i].item.count < providers[i].item.maxCount then
|
||||
to = providers[i]
|
||||
elseif providers[i].item.count == providers[i].item.maxCount then
|
||||
-- As this slot is already at maxCount, all the remaining ones will also be due to sorting
|
||||
-- If any of the remaining providers is locked that doesn't matter. We wouldn't have been able to push there anyways
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local toMove = math.min(to.item.maxCount - to.item.count, from.item.count)
|
||||
local s, m = pcall(function()
|
||||
from.device.pushItems(to.device.name, from.slot, toMove, to.slot)
|
||||
end)
|
||||
|
||||
if not s and m then
|
||||
_G._syslog(m)
|
||||
end
|
||||
|
||||
if s then
|
||||
to.item.count = to.item.count + toMove
|
||||
from.item.count = from.item.count - toMove
|
||||
else
|
||||
-- Do not try to send to the target again after it failed
|
||||
for i = 2, #providers do
|
||||
if to == providers[i] then
|
||||
table.remove(providers, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if from.item.count <= 0 then
|
||||
table.remove(providers, 1)
|
||||
slotsSaved = slotsSaved + 1
|
||||
end
|
||||
|
||||
table.sort(providers, sortFunction)
|
||||
end
|
||||
end
|
||||
|
||||
return slotsSaved
|
||||
end
|
||||
|
||||
function Storage:updateCache(adapter, item, count)
|
||||
if not adapter.cache then
|
||||
adapter.dirty = true
|
||||
@@ -443,7 +298,7 @@ function Storage:updateCache(adapter, item, count)
|
||||
return
|
||||
end
|
||||
|
||||
local key = item.key or table.concat({ item.name, item.nbt }, ':')
|
||||
local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
local entry = adapter.cache[key]
|
||||
|
||||
if not entry then
|
||||
@@ -489,18 +344,15 @@ function Storage:_sn(name)
|
||||
end
|
||||
|
||||
local function isValidTransfer(adapter, target)
|
||||
if string.find(target,":inventory") or string.find(target,":equipment") then
|
||||
return false
|
||||
end
|
||||
-- lazily cache transfer locations
|
||||
--[[if not adapter.transferLocations then
|
||||
if not adapter.transferLocations then
|
||||
adapter.transferLocations = adapter.getTransferLocations()
|
||||
end
|
||||
for _,v in pairs(adapter.transferLocations) do]]
|
||||
-- if v == target then
|
||||
for _,v in pairs(adapter.transferLocations) do
|
||||
if v == target then
|
||||
return true
|
||||
-- end
|
||||
--end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function rawExport(source, target, item, qty, slot)
|
||||
@@ -532,15 +384,14 @@ local function rawExport(source, target, item, qty, slot)
|
||||
local stacks = source.list()
|
||||
for key,stack in Util.rpairs(stacks) do
|
||||
if stack.name == item.name and
|
||||
stack.nbt == item.nbt then
|
||||
stack.damage == item.damage and
|
||||
stack.nbtHash == item.nbtHash then
|
||||
local amount = math.min(qty, stack.count)
|
||||
if amount > 0 then
|
||||
amount = transfer(key, amount, slot)
|
||||
if amount > 0 then
|
||||
source.lastUpdate = os.clock()
|
||||
target.lastUpdate = os.clock()
|
||||
else
|
||||
-- break -- this should work ?? is cache out of sync ?
|
||||
end
|
||||
end
|
||||
qty = qty - amount
|
||||
@@ -562,7 +413,7 @@ end
|
||||
function Storage:export(target, slot, count, item)
|
||||
local timer = Util.timer()
|
||||
local total = 0
|
||||
local key = item.key or table.concat({ item.name, item.nbt }, ':')
|
||||
local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
|
||||
local function provide(adapter, pcount)
|
||||
-- update cache before export to allow for simultaneous calls
|
||||
@@ -572,7 +423,6 @@ function Storage:export(target, slot, count, item)
|
||||
|
||||
if amount ~= pcount then
|
||||
-- this *should* only happen if cache is out of sync
|
||||
-- or... the target is full
|
||||
self:updateCache(adapter, item, pcount - amount)
|
||||
end
|
||||
|
||||
@@ -583,43 +433,28 @@ function Storage:export(target, slot, count, item)
|
||||
end
|
||||
count = count - amount
|
||||
total = total + amount
|
||||
|
||||
return amount
|
||||
end
|
||||
|
||||
-- request from adapters with this item
|
||||
for _, adapter in self:onlineAdapters() do
|
||||
local cache = adapter.cache and adapter.cache[key]
|
||||
if cache then
|
||||
local request = math.min(count, cache.count)
|
||||
|
||||
local amount = provide(adapter, request)
|
||||
|
||||
-- couldn't provide the amount that was requested
|
||||
-- either the target must be full - or the cache is invalid
|
||||
if amount ~= request then
|
||||
break
|
||||
end
|
||||
provide(adapter, math.min(count, cache.count))
|
||||
if count <= 0 then
|
||||
return total
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if slot then -- ignore warning when exporting to all slots
|
||||
_G._syslog('STORAGE warning: %s(%d): %s%s %s failed to export',
|
||||
item.displayName or item.name, count, self:_sn(target.name),
|
||||
slot and string.format('[%d]', slot) or '[*]', key)
|
||||
end
|
||||
_G._syslog('STORAGE warning: %s(%d): %s%s %s failed to export',
|
||||
item.displayName or item.name, count, self:_sn(target.name),
|
||||
slot and string.format('[%d]', slot) or '[*]', key)
|
||||
|
||||
-- TODO: If there are misses when a slot is specified than something is wrong...
|
||||
-- The caller should confirm the quantity beforehand
|
||||
-- If no slot and full amount is not exported, then no need to check rest of adapters
|
||||
-- ... so should not reach here
|
||||
|
||||
-- but... there is the case where exporting to all slots of the target
|
||||
-- this is valid
|
||||
|
||||
return total
|
||||
end
|
||||
|
||||
@@ -653,7 +488,7 @@ function Storage:import(source, slot, count, item)
|
||||
|
||||
local timer = Util.timer()
|
||||
local total = 0
|
||||
local key = item.key or table.concat({ item.name, item.nbt }, ':')
|
||||
local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
|
||||
if not self.cache then
|
||||
self:listItems()
|
||||
@@ -666,15 +501,13 @@ function Storage:import(source, slot, count, item)
|
||||
entry = itemDB:add(item)
|
||||
else
|
||||
-- get the metadata from the device and add to db
|
||||
entry = itemDB:add(source.adapter.getItemDetail(slot))
|
||||
entry = itemDB:add(source.adapter.getItemMeta(slot))
|
||||
end
|
||||
itemDB:flush()
|
||||
end
|
||||
item = entry
|
||||
|
||||
local function insert(adapter)
|
||||
if adapter.__used and adapter.__size and adapter.__used == adapter.__size then return 0 end
|
||||
|
||||
local amount = rawInsert(adapter, source.adapter, slot, count)
|
||||
|
||||
if amount > 0 then
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
--[[ Emulate a CC:T inventory on the turtle
|
||||
]]
|
||||
|
||||
local TurtleInv = {}
|
||||
|
||||
local turtle = _G.turtle
|
||||
|
||||
local inventorySize = 16
|
||||
|
||||
local localName = "milo_local_name_unset"
|
||||
|
||||
function TurtleInv.setLocalName(name)
|
||||
localName = name
|
||||
end
|
||||
|
||||
function TurtleInv.size()
|
||||
return inventorySize
|
||||
end
|
||||
|
||||
function TurtleInv.list()
|
||||
local list = {}
|
||||
for slot = 1, inventorySize do
|
||||
list[slot] = turtle.getItemDetail(slot)
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function TurtleInv.getItemDetail(slot)
|
||||
return turtle.getItemDetail(slot, true)
|
||||
end
|
||||
|
||||
function TurtleInv.pullItems(fromName, fromSlot, limit, toSlot)
|
||||
return peripheral.call(fromName, "pushItems", localName, fromSlot, limit, toSlot)
|
||||
end
|
||||
|
||||
function TurtleInv.pushItems(toName, fromSlot, limit, toSlot)
|
||||
return peripheral.call(toName, "pullItems", localName, fromSlot, limit, toSlot)
|
||||
end
|
||||
|
||||
|
||||
return TurtleInv
|
||||
@@ -6,7 +6,6 @@ fs.delete('packages/milo/Milo.lua')
|
||||
fs.delete('packages/milo/plugins/listing.lua')
|
||||
fs.delete('packages/milo/apis/milo.lua')
|
||||
fs.delete('packages/milo/plugins/manipulator.lua')
|
||||
fs.delete('packages/milo/apps')
|
||||
|
||||
if peripheral.find('workbench') and shell.openForegroundTab then
|
||||
shell.openForegroundTab('MiloLocal')
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
local Milo = require('milo')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local turtle = _G.turtle
|
||||
|
||||
local learnPage = UI.Page {
|
||||
titleBar = UI.TitleBar { title = 'Learn Recipe' },
|
||||
wizard = UI.Wizard {
|
||||
y = 2, ey = -2,
|
||||
general = UI.WizardPage {
|
||||
index = 1,
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
disableHeader = true,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'name'},
|
||||
pages = {
|
||||
general = UI.WizardPage {
|
||||
index = 1,
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
disableHeader = true,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'name'},
|
||||
},
|
||||
sortColumn = 'name',
|
||||
},
|
||||
accelerators = {
|
||||
grid_select = 'nextView',
|
||||
},
|
||||
sortColumn = 'name',
|
||||
},
|
||||
accelerators = {
|
||||
grid_select = 'nextView',
|
||||
},
|
||||
},
|
||||
},
|
||||
notification = UI.Notification { },
|
||||
}
|
||||
|
||||
local general = learnPage.wizard.general
|
||||
local general = learnPage.wizard.pages.general
|
||||
|
||||
function general:validate()
|
||||
Milo:setState('learnType', self.grid:getSelected().value)
|
||||
@@ -33,7 +37,7 @@ end
|
||||
function learnPage:enable()
|
||||
local t = { }
|
||||
|
||||
for _, page in pairs(self.wizard:getPages()) do
|
||||
for _, page in pairs(self.wizard.pages) do
|
||||
if page.validFor then
|
||||
t[page.validFor] = {
|
||||
name = page.validFor,
|
||||
@@ -59,7 +63,7 @@ function learnPage.wizard:getPage(index)
|
||||
local pages = { }
|
||||
table.insert(pages, general)
|
||||
local selected = general.grid:getSelected()
|
||||
for _, page in pairs(self:getPages()) do
|
||||
for _, page in pairs(self.pages) do
|
||||
if page.validFor and (not selected or selected.value == page.validFor) then
|
||||
table.insert(pages, page)
|
||||
end
|
||||
|
||||
@@ -33,11 +33,6 @@ local page = UI.Page {
|
||||
event = 'rescan',
|
||||
help = 'Rescan all inventories'
|
||||
},
|
||||
{
|
||||
text = 'Defragment storage',
|
||||
event = 'defrag',
|
||||
help = 'Defragments the storage'
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -255,10 +250,6 @@ function page:eventHandler(event)
|
||||
self.grid:draw()
|
||||
self:setFocus(self.statusBar.filter)
|
||||
|
||||
elseif event.type == 'defrag' then
|
||||
self:defrag()
|
||||
self:refresh(true)
|
||||
|
||||
elseif event.type == 'toggle_display' then
|
||||
displayMode = (displayMode + 1) % 2
|
||||
Util.merge(event.button, displayModes[displayMode])
|
||||
@@ -366,15 +357,6 @@ function page:refresh(force)
|
||||
self.throttle:disable()
|
||||
end
|
||||
|
||||
function page:defrag()
|
||||
local throttle = function() self.throttle:update() end
|
||||
|
||||
self.throttle:enable()
|
||||
local saved = context.storage:defrag(throttle)
|
||||
self.throttle:disable()
|
||||
self:notifyInfo(("Saved %d slots"):format(saved))
|
||||
end
|
||||
|
||||
function page:applyFilter()
|
||||
local function filterItems(t, filter)
|
||||
self.grid.sortColumn = Milo:getState('sortColumn') or 'count'
|
||||
@@ -390,7 +372,7 @@ function page:applyFilter()
|
||||
v.score = fuzzy(v.lname, filter)
|
||||
if v.score then
|
||||
if v.count > 0 then
|
||||
v.score = v.score + .2
|
||||
v.score = v.score + 1
|
||||
end
|
||||
table.insert(r, v)
|
||||
end
|
||||
|
||||
@@ -28,43 +28,13 @@ local networkPage = UI.Page {
|
||||
y = 2, ey = -3,
|
||||
values = context.storage.nodes,
|
||||
columns = {
|
||||
{ key = 'suffix', width = 5, align = 'right' },
|
||||
{ key = 'suffix', width = 4, align = 'right' },
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
{ heading = 'Type', key = 'mtype', width = 4 },
|
||||
{ heading = 'Pri', key = 'priority', width = 3 },
|
||||
},
|
||||
sortColumn = 'displayName',
|
||||
help = 'Select Node',
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
local t = { row.name:match(':(.+)_(%d+)$') }
|
||||
if #t ~= 2 then
|
||||
t = { row.name:match('(.+)_(%d+)$') }
|
||||
end
|
||||
if t and #t == 2 then
|
||||
row.name, row.suffix = table.unpack(t)
|
||||
row.name = row.name .. '_' .. row.suffix
|
||||
end
|
||||
row.displayName = row.displayName or row.name
|
||||
return row
|
||||
end,
|
||||
getRowTextColor = function(self, row, selected)
|
||||
if not device[row.name] then
|
||||
return colors.red
|
||||
end
|
||||
if row.mtype == 'ignore' then
|
||||
return colors.lightGray
|
||||
end
|
||||
return UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
sortCompare = function(self, a, b)
|
||||
if self.sortColumn == 'displayName' then
|
||||
local an = a.displayName or a.name
|
||||
local bn = b.displayName or b.name
|
||||
return an:lower() < bn:lower()
|
||||
end
|
||||
return UI.Grid.sortCompare(self, a, b)
|
||||
end,
|
||||
},
|
||||
remove = UI.Button {
|
||||
y = -2, x = -4,
|
||||
@@ -85,6 +55,39 @@ local networkPage = UI.Page {
|
||||
}
|
||||
}
|
||||
|
||||
function networkPage.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
local t = { row.name:match(':(.+)_(%d+)$') }
|
||||
if #t ~= 2 then
|
||||
t = { row.name:match('(.+)_(%d+)$') }
|
||||
end
|
||||
if t and #t == 2 then
|
||||
row.name, row.suffix = table.unpack(t)
|
||||
row.name = row.name .. '_' .. row.suffix
|
||||
end
|
||||
row.displayName = row.displayName or row.name
|
||||
return row
|
||||
end
|
||||
|
||||
function networkPage.grid:getRowTextColor(row, selected)
|
||||
if not device[row.name] then
|
||||
return colors.red
|
||||
end
|
||||
if row.mtype == 'ignore' then
|
||||
return colors.lightGray
|
||||
end
|
||||
return UI.Grid:getRowTextColor(row, selected)
|
||||
end
|
||||
|
||||
function networkPage.grid:sortCompare(a, b)
|
||||
if self.sortColumn == 'displayName' then
|
||||
local an = a.displayName or a.name
|
||||
local bn = b.displayName or b.name
|
||||
return an:lower() < bn:lower()
|
||||
end
|
||||
return UI.Grid.sortCompare(self, a, b)
|
||||
end
|
||||
|
||||
function networkPage:getList()
|
||||
for _, v in pairs(device) do
|
||||
if not context.storage.nodes[v.name] then
|
||||
@@ -93,7 +96,7 @@ function networkPage:getList()
|
||||
mtype = 'ignore',
|
||||
category = 'ignore',
|
||||
}
|
||||
for _, page in pairs(nodeWizard.wizard:getPages()) do
|
||||
for _, page in pairs(nodeWizard.wizard.pages) do
|
||||
if page.isValidType and page:isValidType(node) then
|
||||
context.storage.nodes[v.name] = node
|
||||
break
|
||||
@@ -188,91 +191,46 @@ nodeWizard = UI.Page {
|
||||
titleBar = UI.TitleBar { title = 'Configure' },
|
||||
wizard = UI.Wizard {
|
||||
y = 2, ey = -2,
|
||||
general = UI.WizardPage {
|
||||
index = 1,
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 1, ey = 3,
|
||||
manualControls = true,
|
||||
[1] = UI.TextEntry {
|
||||
formLabel = 'Name', formKey = 'displayName',
|
||||
help = 'Set a friendly name',
|
||||
limit = 64,
|
||||
pages = {
|
||||
general = UI.WizardPage {
|
||||
index = 1,
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 1, ey = 3,
|
||||
manualControls = true,
|
||||
[1] = UI.TextEntry {
|
||||
formLabel = 'Name', formKey = 'displayName',
|
||||
help = 'Set a friendly name',
|
||||
limit = 64,
|
||||
},
|
||||
[2] = UI.Chooser {
|
||||
width = 25,
|
||||
formLabel = 'Type', formKey = 'mtype',
|
||||
--nochoice = 'Storage',
|
||||
help = 'Select type',
|
||||
},
|
||||
},
|
||||
[2] = UI.Chooser {
|
||||
width = 25,
|
||||
formLabel = 'Type', formKey = 'mtype',
|
||||
--nochoice = 'Storage',
|
||||
help = 'Select type',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 5, ey = -2, x = 2, ex = -2,
|
||||
columns = {
|
||||
{ heading = 'Slot', key = 'slot', width = 4 },
|
||||
{ heading = 'Name', key = 'displayName', },
|
||||
{ heading = 'Qty', key = 'count' , width = 3 },
|
||||
},
|
||||
sortColumn = 'slot',
|
||||
help = 'Contents of inventory',
|
||||
},
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 5, ey = -2, x = 2, ex = -2,
|
||||
columns = {
|
||||
{ heading = 'Slot', key = 'slot', width = 4 },
|
||||
{ heading = 'Name', key = 'displayName', },
|
||||
{ heading = 'Qty', key = 'count' , width = 3 },
|
||||
},
|
||||
sortColumn = 'slot',
|
||||
help = 'Contents of inventory',
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = itemDB:getName(row)
|
||||
return row
|
||||
end,
|
||||
},
|
||||
enable = function(self)
|
||||
UI.WizardPage.enable(self)
|
||||
self:focusFirst()
|
||||
end,
|
||||
isValidFor = function()
|
||||
return false
|
||||
end,
|
||||
showInventory = function(self, node)
|
||||
local inventory
|
||||
|
||||
if device[node.name] and device[node.name].list then
|
||||
pcall(function()
|
||||
inventory = device[node.name].list()
|
||||
for k,v in pairs(inventory) do
|
||||
v.slot = k
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
self.grid:setValues(inventory or { })
|
||||
end,
|
||||
validate = function(self)
|
||||
if self.form:save() then
|
||||
nodeWizard.node.category = Util.find(nodeWizard.choices, 'value', nodeWizard.node.mtype).category
|
||||
|
||||
nodeWizard.nodePages = { }
|
||||
table.insert(nodeWizard.nodePages, nodeWizard.wizard.general)
|
||||
for _, page in pairs(nodeWizard.wizard:getPages()) do
|
||||
if not page.isValidFor or page:isValidFor(nodeWizard.node) then
|
||||
table.insert(nodeWizard.nodePages, page)
|
||||
if page.setNode then
|
||||
page:setNode(nodeWizard.node)
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(nodeWizard.nodePages, nodeWizard.wizard.confirmation)
|
||||
return true
|
||||
end
|
||||
end,
|
||||
},
|
||||
confirmation = UI.WizardPage {
|
||||
title = 'Confirm changes',
|
||||
index = 2,
|
||||
notice = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
value =
|
||||
confirmation = UI.WizardPage {
|
||||
title = 'Confirm changes',
|
||||
index = 2,
|
||||
notice = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
value =
|
||||
[[Press accept to save the changes.
|
||||
|
||||
The settings will take effect immediately!]],
|
||||
},
|
||||
},
|
||||
isValidFor = function()
|
||||
return false
|
||||
end,
|
||||
},
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
@@ -297,11 +255,6 @@ The settings will take effect immediately!]],
|
||||
accelerators = {
|
||||
delete = 'remove_entry',
|
||||
},
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = itemDB:getName(row)
|
||||
return row
|
||||
end,
|
||||
},
|
||||
remove = UI.Button {
|
||||
x = -4, y = 4,
|
||||
@@ -312,10 +265,14 @@ The settings will take effect immediately!]],
|
||||
margin = 1,
|
||||
manualControls = true,
|
||||
[1] = UI.Checkbox {
|
||||
formLabel = 'Ignore NBT', formKey = 'ignoreNbt',
|
||||
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
||||
help = 'Ignore damage of item',
|
||||
},
|
||||
[2] = UI.Checkbox {
|
||||
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
||||
help = 'Ignore NBT of item',
|
||||
},
|
||||
[2] = UI.Chooser {
|
||||
[3] = UI.Chooser {
|
||||
width = 13,
|
||||
formLabel = 'Mode', formKey = 'blacklist',
|
||||
nochoice = 'whitelist',
|
||||
@@ -323,7 +280,7 @@ The settings will take effect immediately!]],
|
||||
{ name = 'whitelist', value = false },
|
||||
{ name = 'blacklist', value = true },
|
||||
},
|
||||
help = 'Accept item by default or deny by default'
|
||||
help = 'Ignore damage of item'
|
||||
},
|
||||
scan = UI.Button {
|
||||
x = -11, y = 1,
|
||||
@@ -334,76 +291,143 @@ The settings will take effect immediately!]],
|
||||
statusBar = UI.StatusBar {
|
||||
backgroundColor = 'primary',
|
||||
},
|
||||
show = function(self, entry, callback, whitelistOnly)
|
||||
self.entry = entry
|
||||
self.callback = callback
|
||||
|
||||
if not self.entry.filter then
|
||||
self.entry.filter = { }
|
||||
end
|
||||
|
||||
self.form:setValues(entry)
|
||||
self:resetGrid()
|
||||
|
||||
self.form[2].inactive = whitelistOnly
|
||||
|
||||
UI.SlideOut.show(self)
|
||||
self:setFocus(self.form.scan)
|
||||
|
||||
Milo:pauseCrafting({ key = 'gridInUse', msg = 'Crafting paused' })
|
||||
end,
|
||||
hide = function(self)
|
||||
UI.SlideOut.hide(self)
|
||||
Milo:resumeCrafting({ key = 'gridInUse' })
|
||||
end,
|
||||
resetGrid = function(self)
|
||||
local t = { }
|
||||
for k in pairs(self.entry.filter) do
|
||||
table.insert(t, itemDB:splitKey(k))
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'focus_change' then
|
||||
self.statusBar:setStatus(event.focused.help)
|
||||
|
||||
elseif event.type == 'scan_turtle' then
|
||||
local inventory = Milo:getTurtleInventory()
|
||||
for _,item in pairs(inventory) do
|
||||
self.entry.filter[itemDB:makeKey(item)] = true
|
||||
end
|
||||
self:resetGrid()
|
||||
self.grid:update()
|
||||
self.grid:draw()
|
||||
Milo:emptyInventory()
|
||||
|
||||
elseif event.type == 'remove_entry' then
|
||||
local row = self.grid:getSelected()
|
||||
if row then
|
||||
Util.removeByValue(self.grid.values, row)
|
||||
self.grid:update()
|
||||
self.grid:draw()
|
||||
end
|
||||
|
||||
elseif event.type == 'save' then
|
||||
self.form:save()
|
||||
self.entry.filter = { }
|
||||
for _,v in pairs(self.grid.values) do
|
||||
self.entry.filter[itemDB:makeKey(v)] = true
|
||||
end
|
||||
self:hide()
|
||||
self.callback()
|
||||
|
||||
elseif event.type == 'cancel' then
|
||||
self:hide()
|
||||
else
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
--[[ Filter slide out ]] --
|
||||
function nodeWizard.filter:show(entry, callback, whitelistOnly)
|
||||
self.entry = entry
|
||||
self.callback = callback
|
||||
|
||||
if not self.entry.filter then
|
||||
self.entry.filter = { }
|
||||
end
|
||||
|
||||
self.form:setValues(entry)
|
||||
self:resetGrid()
|
||||
|
||||
self.form[3].inactive = whitelistOnly
|
||||
|
||||
UI.SlideOut.show(self)
|
||||
self:setFocus(self.form.scan)
|
||||
|
||||
Milo:pauseCrafting({ key = 'gridInUse', msg = 'Crafting paused' })
|
||||
end
|
||||
|
||||
function nodeWizard.filter:hide()
|
||||
UI.SlideOut.hide(self)
|
||||
Milo:resumeCrafting({ key = 'gridInUse' })
|
||||
end
|
||||
|
||||
function nodeWizard.filter:resetGrid()
|
||||
local t = { }
|
||||
for k in pairs(self.entry.filter) do
|
||||
table.insert(t, itemDB:splitKey(k))
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
end
|
||||
|
||||
function nodeWizard.filter.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = itemDB:getName(row)
|
||||
return row
|
||||
end
|
||||
|
||||
function nodeWizard.filter:eventHandler(event)
|
||||
if event.type == 'focus_change' then
|
||||
self.statusBar:setStatus(event.focused.help)
|
||||
|
||||
elseif event.type == 'scan_turtle' then
|
||||
local inventory = Milo:getTurtleInventory()
|
||||
for _,item in pairs(inventory) do
|
||||
self.entry.filter[itemDB:makeKey(item)] = true
|
||||
end
|
||||
self:resetGrid()
|
||||
self.grid:update()
|
||||
self.grid:draw()
|
||||
Milo:emptyInventory()
|
||||
|
||||
elseif event.type == 'remove_entry' then
|
||||
local row = self.grid:getSelected()
|
||||
if row then
|
||||
Util.removeByValue(self.grid.values, row)
|
||||
self.grid:update()
|
||||
self.grid:draw()
|
||||
end
|
||||
|
||||
elseif event.type == 'save' then
|
||||
self.form:save()
|
||||
self.entry.filter = { }
|
||||
for _,v in pairs(self.grid.values) do
|
||||
self.entry.filter[itemDB:makeKey(v)] = true
|
||||
end
|
||||
self:hide()
|
||||
self.callback()
|
||||
|
||||
elseif event.type == 'cancel' then
|
||||
self:hide()
|
||||
|
||||
else
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--[[ General Page ]] --
|
||||
function nodeWizard.wizard.pages.general:enable()
|
||||
UI.WizardPage.enable(self)
|
||||
self:focusFirst()
|
||||
end
|
||||
|
||||
function nodeWizard.wizard.pages.general:isValidFor()
|
||||
return false
|
||||
end
|
||||
|
||||
function nodeWizard.wizard.pages.general:showInventory(node)
|
||||
local inventory
|
||||
|
||||
if device[node.name] and device[node.name].list then
|
||||
pcall(function()
|
||||
inventory = device[node.name].list()
|
||||
for k,v in pairs(inventory) do
|
||||
v.slot = k
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
self.grid:setValues(inventory or { })
|
||||
end
|
||||
|
||||
function nodeWizard.wizard.pages.general.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = itemDB:getName(row)
|
||||
return row
|
||||
end
|
||||
|
||||
function nodeWizard.wizard.pages.general:validate()
|
||||
if self.form:save() then
|
||||
nodeWizard.node.category = Util.find(nodeWizard.choices, 'value', nodeWizard.node.mtype).category
|
||||
|
||||
nodeWizard.nodePages = { }
|
||||
table.insert(nodeWizard.nodePages, nodeWizard.wizard.pages.general)
|
||||
for _, page in pairs(nodeWizard.wizard.pages) do
|
||||
if not page.isValidFor or page:isValidFor(nodeWizard.node) then
|
||||
table.insert(nodeWizard.nodePages, page)
|
||||
if page.setNode then
|
||||
page:setNode(nodeWizard.node)
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(nodeWizard.nodePages, nodeWizard.wizard.pages.confirmation)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Confirmation ]]--
|
||||
function nodeWizard.wizard.pages.confirmation:isValidFor()
|
||||
return false
|
||||
end
|
||||
|
||||
--[[ Wizard ]] --
|
||||
function nodeWizard:enable(node)
|
||||
local adapter = node.adapter
|
||||
@@ -416,7 +440,7 @@ function nodeWizard:enable(node)
|
||||
{ name = 'Ignore', value = 'ignore', category = 'ignore' },
|
||||
{ name = 'Hidden', value = 'hidden', category = 'ignore', help = 'Do not show in list' },
|
||||
}
|
||||
for _, page in pairs(self.wizard:getPages()) do
|
||||
for _, page in pairs(self.wizard.pages) do
|
||||
if page.isValidType then
|
||||
local choice = page:isValidType(self.node)
|
||||
if choice and not Util.find(self.choices, 'value', choice.value) then
|
||||
@@ -424,15 +448,15 @@ function nodeWizard:enable(node)
|
||||
end
|
||||
end
|
||||
end
|
||||
self.wizard.general.form[1].shadowText = self.node.name
|
||||
self.wizard.general.form[2].choices = self.choices
|
||||
self.wizard.general.form:setValues(self.node)
|
||||
self.wizard.pages.general.form[1].shadowText = self.node.name
|
||||
self.wizard.pages.general.form[2].choices = self.choices
|
||||
self.wizard.pages.general.form:setValues(self.node)
|
||||
|
||||
self.wizard.general:showInventory(self.node)
|
||||
self.wizard.pages.general:showInventory(self.node)
|
||||
|
||||
self.nodePages = { }
|
||||
table.insert(self.nodePages, self.wizard.general)
|
||||
table.insert(self.nodePages, self.wizard.confirmation)
|
||||
table.insert(self.nodePages, self.wizard.pages.general)
|
||||
table.insert(self.nodePages, self.wizard.pages.confirmation)
|
||||
|
||||
UI.Page.enable(self)
|
||||
end
|
||||
|
||||
@@ -18,9 +18,6 @@ function ExportTask:cycle(context)
|
||||
|
||||
for node in context.storage:filterActive('machine', filter) do
|
||||
tasks:add(function()
|
||||
|
||||
local slots
|
||||
|
||||
for _, entry in pairs(node.exports) do
|
||||
|
||||
if not entry.filter then
|
||||
@@ -30,7 +27,7 @@ function ExportTask:cycle(context)
|
||||
end
|
||||
|
||||
local function exportSingleSlot()
|
||||
local slot = node.adapter.getItemDetail(entry.slot)
|
||||
local slot = node.adapter.getItemMeta(entry.slot)
|
||||
|
||||
if slot and slot.count == slot.maxCount then
|
||||
return
|
||||
@@ -41,7 +38,8 @@ function ExportTask:cycle(context)
|
||||
for key in pairs(entry.filter) do
|
||||
local filterItem = itemDB:splitKey(key)
|
||||
if (slot.name == filterItem.name and
|
||||
(entry.ignoreNbt or slot.nbt == filterItem.nbt)) then
|
||||
(entry.ignoreDamage or slot.damage == filterItem.damage) and
|
||||
(entry.ignoreNbtHash or slot.nbtHash == filterItem.nbtHash)) then
|
||||
|
||||
local items = Milo:getMatches(filterItem, entry)
|
||||
local _, item = next(items)
|
||||
@@ -68,35 +66,13 @@ function ExportTask:cycle(context)
|
||||
end
|
||||
|
||||
local function exportItems()
|
||||
local function canExport(item)
|
||||
if not node.adapter.__size then
|
||||
node.adapter.__size = node.adapter.size()
|
||||
end
|
||||
|
||||
if not slots then
|
||||
slots = node.adapter.list()
|
||||
end
|
||||
|
||||
for i = 1, node.adapter.__size do
|
||||
local slot = slots[i]
|
||||
if (not slot or slot.name == item.name and
|
||||
(entry.ignoreNbt or slot.nbt == item.nbt) and
|
||||
slot.count < item.maxCount) then
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for key in pairs(entry.filter) do
|
||||
local items = Milo:getMatches(itemDB:splitKey(key), entry)
|
||||
for _,item in pairs(items) do
|
||||
if canExport(item) then
|
||||
if context.storage:export(node, nil, item.count, item) == 0 then
|
||||
break
|
||||
end
|
||||
-- refresh the slots
|
||||
slots = nil
|
||||
if context.storage:export(node, nil, item.count, item) == 0 then
|
||||
-- TODO: really shouldn't break here as there may be room in other slots
|
||||
-- leaving for now for performance reasons
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ function ImportTask:cycle(context)
|
||||
for _, entry in pairs(node.imports) do
|
||||
|
||||
local function itemMatchesFilter(item)
|
||||
if not entry.ignoreNbt then
|
||||
if not entry.ignoreDamage and not entry.ignoreNbtHash then
|
||||
local key = itemDB:makeKey(item)
|
||||
return entry.filter[key]
|
||||
end
|
||||
@@ -29,7 +29,8 @@ function ImportTask:cycle(context)
|
||||
for key in pairs(entry.filter) do
|
||||
local v = itemDB:splitKey(key)
|
||||
if item.name == v.name and
|
||||
(entry.ignoreNbt or item.nbt == v.nbt) then
|
||||
(entry.ignoreDamage or item.damage == v.damage) and
|
||||
(entry.ignoreNbtHash or item.nbtHash == v.nbtHash) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -51,7 +52,7 @@ function ImportTask:cycle(context)
|
||||
|
||||
local function importSlot(slotNo)
|
||||
local item = itemDB:get(list[slotNo], function()
|
||||
return node.adapter.getItemDetail(slotNo)
|
||||
return node.adapter.getItemMeta(slotNo)
|
||||
end)
|
||||
if item and matchesFilter(item) then
|
||||
if context.storage:import(node, slotNo, item.count, item) ~= item.count then
|
||||
|
||||
@@ -2,7 +2,7 @@ local Ansi = require('opus.ansi')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local infoTab = UI.Tab {
|
||||
title = 'Info',
|
||||
tabTitle = 'Info',
|
||||
index = 4,
|
||||
textArea = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
@@ -20,18 +20,16 @@ function infoTab:draw()
|
||||
Ansi.orange, item.displayName, Ansi.reset,
|
||||
item.name)
|
||||
|
||||
if item.nbt then
|
||||
value = value .. item.nbt .. '\n'
|
||||
if item.nbtHash then
|
||||
value = value .. item.nbtHash .. '\n'
|
||||
end
|
||||
|
||||
value = value .. string.format('\n%sCount:%s %s',
|
||||
Ansi.yellow, Ansi.reset, item.count)
|
||||
|
||||
if item.durability then
|
||||
value = value .. string.format('\n%Durability:%s %s',
|
||||
Ansi.yellow, Ansi.reset, item.durability)
|
||||
end
|
||||
|
||||
value = value .. string.format('\n%sDamage:%s %s',
|
||||
Ansi.yellow, Ansi.reset, item.damage)
|
||||
|
||||
if item.maxDamage and item.maxDamage > 0 then
|
||||
value = value .. string.format(' (max: %s)', item.maxDamage)
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ local colors = _G.colors
|
||||
local context = Milo:getContext()
|
||||
|
||||
local machinesTab = UI.Tab {
|
||||
title = 'Machine',
|
||||
tabTitle = 'Machine',
|
||||
index = 3,
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
|
||||
@@ -7,7 +7,7 @@ local Util = require('opus.util')
|
||||
local context = Milo:getContext()
|
||||
|
||||
local manageTab = UI.Tab {
|
||||
title = 'Manage',
|
||||
tabTitle = 'Manage',
|
||||
index = 1,
|
||||
form = UI.Form {
|
||||
x = 1, ex = -1, ey = -1,
|
||||
@@ -29,7 +29,11 @@ local manageTab = UI.Tab {
|
||||
transform = 'number',
|
||||
},
|
||||
[4] = UI.Checkbox {
|
||||
formLabel = 'Ignore NBT', formKey = 'ignoreNbt',
|
||||
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
||||
help = 'Ignore damage of item',
|
||||
},
|
||||
[5] = UI.Checkbox {
|
||||
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
||||
help = 'Ignore NBT of item',
|
||||
},
|
||||
},
|
||||
@@ -40,6 +44,8 @@ function manageTab:setItem(item)
|
||||
self.res = Util.shallowCopy(context.resources[item.key] or { })
|
||||
self.res.displayName = self.item.displayName
|
||||
self.form:setValues(self.res)
|
||||
|
||||
-- TODO: ignore damage should not be active if there is not a maxDamage value
|
||||
end
|
||||
|
||||
function manageTab:eventHandler(event)
|
||||
@@ -70,7 +76,8 @@ function manageTab:eventHandler(event)
|
||||
|
||||
local newKey = {
|
||||
name = self.item.name,
|
||||
nbt = not self.res.ignoreNbt and self.item.nbt or nil,
|
||||
damage = self.res.ignoreDamage and 0 or self.item.damage,
|
||||
nbtHash = not self.res.ignoreNbtHash and self.item.nbtHash or nil,
|
||||
}
|
||||
|
||||
context.resources[self.item.key] = nil
|
||||
|
||||
@@ -4,7 +4,7 @@ local Milo = require('milo')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local recipeTab = UI.Tab {
|
||||
title = 'Recipe',
|
||||
tabTitle = 'Recipe',
|
||||
index = 2,
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 2, ey = -4,
|
||||
@@ -42,7 +42,7 @@ function recipeTab:setItem(item)
|
||||
})
|
||||
end
|
||||
local key = itemDB:splitKey(self.recipe.result)
|
||||
self.ignoreResultNBT.inactive = not key.nbt
|
||||
self.ignoreResultNBT.inactive = not key.nbtHash
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
end
|
||||
@@ -53,7 +53,7 @@ function recipeTab:eventHandler(event)
|
||||
Milo:updateRecipe(self.recipe.result)
|
||||
|
||||
local item = itemDB:splitKey(self.recipe.result)
|
||||
item.nbt = nil
|
||||
item.nbtHash = nil
|
||||
self.recipe.result = itemDB:makeKey(item)
|
||||
|
||||
-- add updated entry
|
||||
@@ -64,13 +64,13 @@ function recipeTab:eventHandler(event)
|
||||
|
||||
elseif event.type == 'grid_focus_row' then
|
||||
local key = itemDB:splitKey(event.selected.key)
|
||||
self.ignoreNBT.inactive = not key.nbt
|
||||
self.ignoreNBT.inactive = not key.nbtHash
|
||||
self.ignoreNBT:draw()
|
||||
|
||||
elseif event.type == 'ignore_nbt' then
|
||||
local selected = self.grid:getSelected()
|
||||
local item = itemDB:splitKey(selected.key)
|
||||
item.nbt = nil
|
||||
item.nbtHash = nil
|
||||
selected.key = itemDB:makeKey(item)
|
||||
self.grid:draw()
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ local colors = _G.colors
|
||||
local context = Milo:getContext()
|
||||
|
||||
local resetTab = UI.Tab {
|
||||
title = 'Reset',
|
||||
tabTitle = 'Reset',
|
||||
index = 5,
|
||||
noFill = true,
|
||||
textArea = UI.TextArea {
|
||||
|
||||
@@ -156,7 +156,6 @@ local function createPage(node)
|
||||
if row.requested then
|
||||
row.remaining = math.max(0, row.requested - row.crafted)
|
||||
--_syslog('%d %d %d %d', row.remaining, row.requested, row.total, row.crafted)
|
||||
row.total = row.total or 0
|
||||
row.status = (row.status or '') ..
|
||||
string.format(' %d of %d', row.crafted + row.total, row.total + row.requested)
|
||||
else
|
||||
|
||||
@@ -2,7 +2,7 @@ local Craft = require('milo.craft2')
|
||||
local itemDB = require('core.itemDB')
|
||||
local Milo = require('milo')
|
||||
|
||||
local BLAZE_POWDER = "minecraft:blaze_powder"
|
||||
local BLAZE_POWDER = "minecraft:blaze_powder:0"
|
||||
|
||||
local PotionImportTask = {
|
||||
name = 'potions',
|
||||
|
||||
@@ -94,7 +94,7 @@ local function client(socket)
|
||||
local function deposit()
|
||||
local node = makeNode(data.source or 'inventory')
|
||||
if node then
|
||||
local slot = node.adapter.getItemDetail(data.slot)
|
||||
local slot = node.adapter.getItemMeta(data.slot)
|
||||
if slot then
|
||||
if context.storage:import(node, data.slot, slot.count, slot) > 0 then
|
||||
local item = Milo:getItem(slot)
|
||||
|
||||
@@ -23,7 +23,7 @@ local page = UI.Page {
|
||||
tabs = UI.Tabs {
|
||||
y = 2, ey = -2,
|
||||
inventory = UI.Tab {
|
||||
title = 'Inventory',
|
||||
tabTitle = 'Inventory',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
@@ -33,7 +33,7 @@ local page = UI.Page {
|
||||
},
|
||||
},
|
||||
autostore = UI.Tab {
|
||||
title = 'Deposit',
|
||||
tabTitle = 'Deposit',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
@@ -58,7 +58,7 @@ function page.tabs.inventory:enable()
|
||||
local list = { }
|
||||
|
||||
for k, item in pairs(inv) do
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemDetail(k) end)
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(k) end)
|
||||
local key = makeKey(item)
|
||||
if not list[key] then
|
||||
item.key = key
|
||||
@@ -129,7 +129,7 @@ Event.onInterval(5, function()
|
||||
|
||||
pcall(function() -- prevent errors from some mod items
|
||||
for slot,v in pairs(ni.getInventory().list()) do
|
||||
local item = itemDB:get(v, function() ni.getInventory().getItemDetail(slot) end)
|
||||
local item = itemDB:get(v, function() ni.getInventory().getItemMeta(slot) end)
|
||||
if item then
|
||||
if context.state.autostore[makeKey(item)] then
|
||||
context:sendRequest({
|
||||
|
||||
@@ -53,7 +53,7 @@ function page:updateInventoryList()
|
||||
|
||||
for slot, item in pairs(inv) do
|
||||
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemDetail(slot) end)
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end)
|
||||
local key = makeKey(item)
|
||||
if not list[key] then
|
||||
item.displayName = item.displayName:match('(.+) %(damage:.+%)') or item.displayName
|
||||
@@ -89,7 +89,7 @@ function page:depositAll()
|
||||
local inv = ni.getInventory().list()
|
||||
|
||||
for slot, item in pairs(inv) do
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemDetail(slot) end)
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end)
|
||||
local key = makeKey(item)
|
||||
if not context.state.depositAll.retain[key] then
|
||||
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
||||
|
||||
@@ -33,7 +33,7 @@ function page:enable()
|
||||
local list = { }
|
||||
|
||||
for k, item in pairs(inv) do
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemDetail(k) end)
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(k) end)
|
||||
local key = itemDB:makeKey(item)
|
||||
if not list[key] then
|
||||
item.key = key
|
||||
@@ -58,9 +58,9 @@ local function getFood(food)
|
||||
for slot,v in pairs(ni.getInventory().list()) do
|
||||
local key = itemDB:makeKey(v)
|
||||
if key == food then
|
||||
local item = ni.getInventory().getItemDetail(slot)
|
||||
if item and item.saturation then
|
||||
return slot
|
||||
local item = ni.getInventory().getItem(slot)
|
||||
if item and item.consume then
|
||||
return item
|
||||
end
|
||||
break
|
||||
end
|
||||
@@ -87,7 +87,7 @@ Event.onInterval(5, function()
|
||||
if context.state.food and ni.getMetaOwner().food.hungry then
|
||||
local item = getFood(context.state.food)
|
||||
if item then
|
||||
ni.getInventory().consume(item)
|
||||
item.consume()
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -101,4 +101,4 @@ return {
|
||||
callback = function()
|
||||
UI:setPage(page)
|
||||
end,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ local Util = require('opus.util')
|
||||
local colors = _G.colors
|
||||
local fs = _G.fs
|
||||
|
||||
local context = ({ ... })[1]
|
||||
local STARTUP_FILE = 'usr/autorun/miloRemote.lua'
|
||||
|
||||
local STARTUP_FILE = 'usr/autorun/'..context.configPath..'.lua'
|
||||
local context = ({ ... })[1]
|
||||
|
||||
local setup = UI.SlideOut {
|
||||
titleBar = UI.TitleBar {
|
||||
@@ -59,7 +59,7 @@ function setup:eventHandler(event)
|
||||
self.statusBar:setStatus(event.focused.help)
|
||||
|
||||
elseif event.type == 'form_complete' then
|
||||
Config.update(context.configPath, context.state)
|
||||
Config.update('miloRemote', context.state)
|
||||
self:hide()
|
||||
context.page:refresh('list')
|
||||
context.page.grid:draw()
|
||||
|
||||
@@ -15,13 +15,14 @@ function ReplenishTask:cycle(context)
|
||||
local _, count = Milo:getMatches(item, res)
|
||||
|
||||
if count < res.low then
|
||||
local nbt
|
||||
if not res.ignoreNbt then
|
||||
nbt = item.nbt
|
||||
local nbtHash
|
||||
if not res.ignoreNbtHash then
|
||||
nbtHash = item.nbtHash
|
||||
end
|
||||
Milo:requestCrafting({
|
||||
name = item.name,
|
||||
nbt = nbt,
|
||||
damage = res.ignoreDamage and 0 or item.damage,
|
||||
nbtHash = nbtHash,
|
||||
requested = res.low - count,
|
||||
count = count,
|
||||
replenish = true,
|
||||
|
||||
@@ -83,7 +83,7 @@ local function createPage(node)
|
||||
parent = monitor,
|
||||
tabs = UI.Tabs {
|
||||
[1] = UI.Tab {
|
||||
title = 'Overview',
|
||||
tabTitle = 'Overview',
|
||||
backgroundColor = colors.black,
|
||||
noFill = true,
|
||||
onlineLabel = UI.Text {
|
||||
@@ -135,14 +135,14 @@ local function createPage(node)
|
||||
},
|
||||
},
|
||||
[2] = UI.Tab {
|
||||
title = 'Stats',
|
||||
tabTitle = 'Stats',
|
||||
noFill = true,
|
||||
textArea = UI.TextArea {
|
||||
y = 3,
|
||||
},
|
||||
},
|
||||
[3] = UI.Tab {
|
||||
title = 'Storage',
|
||||
tabTitle = 'Storage',
|
||||
noFill = true,
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
@@ -151,13 +151,13 @@ local function createPage(node)
|
||||
{ heading = 'Size', key = 'size', width = 5 },
|
||||
{ heading = 'Used', key = 'used', width = 5 },
|
||||
{ heading = 'Perc', key = 'perc', width = 5 },
|
||||
|
||||
-- TODO: add % to each number
|
||||
},
|
||||
sortColumn = 'name',
|
||||
},
|
||||
},
|
||||
[4] = UI.Tab {
|
||||
title = 'Offline',
|
||||
tabTitle = 'Offline',
|
||||
noFill = true,
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
@@ -168,14 +168,14 @@ local function createPage(node)
|
||||
},
|
||||
},
|
||||
[5] = UI.Tab {
|
||||
title = 'Activity',
|
||||
tabTitle = 'Activity',
|
||||
noFill = true,
|
||||
term = UI.Embedded {
|
||||
--visible = true,
|
||||
},
|
||||
},
|
||||
[6] = UI.Tab {
|
||||
title = 'Tasks',
|
||||
tabTitle = 'Tasks',
|
||||
noFill = true,
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
@@ -224,7 +224,7 @@ local function createPage(node)
|
||||
name = n.displayName or n.name,
|
||||
size = n.adapter.__size,
|
||||
used = n.adapter.__used,
|
||||
perc = tostring(math.floor(n.adapter.__used / n.adapter.__size * 100)) .. "%",
|
||||
perc = math.floor(n.adapter.__used / n.adapter.__size * 100),
|
||||
updated = updated,
|
||||
})
|
||||
totals.usedSlots = totals.usedSlots + n.adapter.__used
|
||||
@@ -449,7 +449,7 @@ Unlocked Slots : %d of %d (%d%%)
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'tab_activate' then
|
||||
local state = Milo:getState('statusState') or { }
|
||||
state[node.name] = event.activated.title
|
||||
state[node.name] = event.activated.tabTitle
|
||||
Milo:setState('statusState', state)
|
||||
end
|
||||
return UI.Page.eventHandler(self, event)
|
||||
@@ -472,7 +472,7 @@ Unlocked Slots : %d of %d (%d%%)
|
||||
-- restore active tab
|
||||
local tabState = Milo:getState('statusState') or { }
|
||||
if tabState[node.name] then
|
||||
page.tabs:selectTab(Util.find(page.tabs, 'title', tabState[node.name]))
|
||||
page.tabs:selectTab(Util.find(page.tabs, 'tabTitle', tabState[node.name]))
|
||||
end
|
||||
|
||||
return page
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
local Peripheral = require('opus.peripheral')
|
||||
|
||||
local defaultStoragePath = "/usr/config/storage"
|
||||
|
||||
local page = UI.Page {
|
||||
notification = UI.Notification {},
|
||||
|
||||
infoText = UI.TextArea {
|
||||
x = 2, y = 2,
|
||||
height = 2,
|
||||
textColor = colors.yellow,
|
||||
value = "Select storage types to merge into your Milo storage config.",
|
||||
},
|
||||
|
||||
typeGrid = UI.CheckboxGrid {
|
||||
x = 2, y = 4,
|
||||
ex = -2, ey = -4,
|
||||
sortColumn = "amount",
|
||||
inverseSort = true,
|
||||
columns = {
|
||||
{heading = 'Type', key = 'type'},
|
||||
{heading = 'Amount', key = 'amount', align = 'right', width = 6},
|
||||
},
|
||||
},
|
||||
|
||||
rescanButton = UI.Button {
|
||||
x = 2, y = -2,
|
||||
text = 'Rescan',
|
||||
event = 'rescan',
|
||||
},
|
||||
|
||||
doneButton = UI.Button {
|
||||
x = -7, y = -2,
|
||||
text = 'Save',
|
||||
event = 'save',
|
||||
},
|
||||
|
||||
confirm = UI.Question {
|
||||
x = -38, y = -2,
|
||||
label = 'Overwrite Milo settings?',
|
||||
},
|
||||
|
||||
fileSelect = UI.FileSelect {
|
||||
modal = true,
|
||||
enable = function() end,
|
||||
transitionHint = 'expandUp',
|
||||
show = function(self)
|
||||
UI.FileSelect.enable(self)
|
||||
self:focusFirst()
|
||||
self:draw()
|
||||
end,
|
||||
disable = function(self)
|
||||
UI.FileSelect.disable(self)
|
||||
self.parent:focusFirst()
|
||||
self.parent:capture(self.parent)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'select_cancel' then
|
||||
self:disable()
|
||||
elseif event.type == 'select_file' then
|
||||
self:disable()
|
||||
end
|
||||
return UI.FileSelect.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
function page:scan()
|
||||
self.storages = Util.filter(Peripheral.getList(), function(dev)
|
||||
return dev.pushItems
|
||||
end)
|
||||
|
||||
local types = {}
|
||||
Util.each(self.storages, function(dev, name)
|
||||
if not types[dev.type] then types[dev.type] = {amount = 0, type = dev.type} end
|
||||
types[dev.type].amount = types[dev.type].amount + 1
|
||||
end)
|
||||
|
||||
self.typeGrid:setValues(types)
|
||||
self:draw()
|
||||
self:sync()
|
||||
end
|
||||
|
||||
function page:saveConfig(path)
|
||||
local config = Util.readTable(path) or {}
|
||||
Util.each(self.storages, function(dev, name)
|
||||
if self.typeGrid.values[dev.type] and self.typeGrid.values[dev.type].checked and (not config[name] or config[name].mtype == 'ignore') then
|
||||
config[name] = {
|
||||
name = name,
|
||||
category = 'storage',
|
||||
mtype = 'storage',
|
||||
}
|
||||
end
|
||||
end)
|
||||
Util.writeTable(path, config)
|
||||
|
||||
self.notification:success("Config saved to "..path)
|
||||
end
|
||||
|
||||
function page:enable()
|
||||
UI.Page.enable(self)
|
||||
self:scan()
|
||||
end
|
||||
|
||||
function page.typeGrid:getRowTextColor(row, selected)
|
||||
return row.checked and colors.yellow or UI.Grid.getRowTextColor(self, row, selected)
|
||||
end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == "rescan" then
|
||||
self:scan()
|
||||
|
||||
elseif event.type == "save" then
|
||||
self.confirm:show()
|
||||
|
||||
elseif event.type == "question_yes" then
|
||||
self:saveConfig(defaultStoragePath)
|
||||
self.confirm:hide()
|
||||
|
||||
elseif event.type == "question_no" then
|
||||
self.confirm:hide()
|
||||
self.fileSelect:show()
|
||||
|
||||
elseif event.type == "select_file" then
|
||||
self:saveConfig(event.file)
|
||||
|
||||
else return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
UI:setPage(page)
|
||||
UI:start()
|
||||
@@ -1,172 +0,0 @@
|
||||
-- (Super)MultiFurnace Controller (did I mention, it's SUPER!?)
|
||||
-- This app is designed to wrap up to 4 of kepler155c's furni.lua (multiFurni) arrays and divide up workload,
|
||||
-- it functions as a straight drop-in for furni.lua and no other adjustments are required to make it work.
|
||||
-- Additionally, you get the ability to target any one multiFurni array for smelting when creating the machine recipe in Milo
|
||||
-- Further uses for this direct targeting can be limited-scope auto-smelting, using anywhere from 1/2 to 1/4 of your total
|
||||
-- capacity to auto-smelt, leaving the rest of the cluster available for you when you want it, great for multi-user bases!
|
||||
|
||||
-- Plug this turtle into a modem on your Milo network, and another modem leading to 2-4 turtles running furni.lua (or even furniController.lua for chained setups)
|
||||
|
||||
-- Slots are as follows:
|
||||
-- 1: Master Furnace Input
|
||||
-- 2: Master Furnace Fuel Input
|
||||
-- 3: Master Furnace Output
|
||||
-- 4: Optional (Options: "fuel"/"input"/"output"/nil (Default: nil [ignore]))
|
||||
-- 5-8: Furnace Inputs for 2 to 4 furni.lua arrays (slots mapped in order ascending, T1_Input=4, T2_Input=5, etc)
|
||||
-- 9-12: Furnace Fuels for 2 to 4 furni.lua arrays
|
||||
-- 13-16: Furnace Outputs for 2 to 4 furni.lua arrays
|
||||
|
||||
-- Only user option, slot 4, what to use it for?
|
||||
|
||||
local useSlot4 = nil
|
||||
|
||||
-- Begin main program code
|
||||
-- Find modem with -only- turtles attached (these should be our furni/furniController arrays)
|
||||
local devModem = ""
|
||||
for _, modem in ipairs({peripheral.find("modem")}) do
|
||||
if #modem.getNamesRemote() > 1 then -- We're only looking for 2 or more devices on a network segment, ignore anything less
|
||||
local nTurtles = 0
|
||||
for _, dev in ipairs(modem.getNamesRemote()) do
|
||||
if modem.getTypeRemote(dev) == "turtle" then nTurtles = nTurtles + 1 end
|
||||
end
|
||||
if nTurtles == #modem.getNamesRemote() then
|
||||
devModem = modem
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if devModem ~= "" then
|
||||
print("Found turtle-only modem, detected", #devModem.getNamesRemote(), "turtles", (#devModem.getNamesRemote() > 4 and "(Max 4 will be mapped)" or "(All will be mapped)"))
|
||||
else
|
||||
print("Did not find a modem with only turtles connected. Please check your networking cables/modems and devices, then try again.")
|
||||
return -- We don't have a modem, halt
|
||||
end
|
||||
|
||||
local devTurtles = {}
|
||||
for _, dev in ipairs(devModem.getNamesRemote()) do
|
||||
if #devTurtles >= 4 then break end
|
||||
devTurtles[#devTurtles+1] = peripheral.wrap(dev)
|
||||
print("Mapping", devTurtles[#devTurtles].getLabel(), "("..dev..")", "as device", #devTurtles)
|
||||
devTurtles[#devTurtles].inputSlot = #devTurtles + 4 -- Set the input for this device on second row
|
||||
devTurtles[#devTurtles].fuelSlot = #devTurtles + 8 -- Set the fuel for this device on third row
|
||||
devTurtles[#devTurtles].outputSlot = #devTurtles + 12 -- Set the output for this device on fourth row
|
||||
if devTurtles[#devTurtles].isOn() then
|
||||
print("Resynchronizing", devTurtles[#devTurtles].getLabel())
|
||||
devTurtles[#devTurtles].reboot()
|
||||
else
|
||||
print("Powering", devTurtles[#devTurtles].getLabel(), "on")
|
||||
devTurtles[#devTurtles].turnOn()
|
||||
end
|
||||
end
|
||||
|
||||
local function listInventory() -- Supplement a local .list()-like function
|
||||
local tList = {}
|
||||
for i = 1, 16 do
|
||||
local slotData = turtle.getItemDetail(i) -- DWGFJTLR
|
||||
if slotData ~= nil then
|
||||
slotData.maxStack=turtle.getItemCount(i) + turtle.getItemSpace(i)
|
||||
tList[i] = slotData
|
||||
end
|
||||
end
|
||||
return tList
|
||||
end
|
||||
|
||||
local function manageLocalResources()
|
||||
--print("Input found")
|
||||
local itemCount = turtle.getItemCount(1) / #devTurtles
|
||||
if itemCount < 1 then itemCount = 1 end -- Patch for single items fed into master slot
|
||||
if turtle.getItemCount(1) > 0 then -- Input
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.select(1) and ((turtle.compareTo(dev.inputSlot) and turtle.getItemSpace(dev.inputSlot) > 0) or turtle.getItemCount(dev.inputSlot) == 0) then -- Move Input
|
||||
turtle.transferTo(dev.inputSlot, itemCount)
|
||||
end
|
||||
if useSlot4 == "input" and turtle.select(4) and ((turtle.compareTo(dev.inputSlot) and turtle.getItemSpace(dev.inputSlot) > 0) or turtle.getItemCount(dev.inputSlot) == 0) then -- Move Input
|
||||
turtle.transferTo(dev.inputSlot, itemCount)
|
||||
end --Slot 4 input
|
||||
end
|
||||
end
|
||||
if turtle.select(2) and turtle.getSelectedSlot() == 2 then -- Fuel
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.compareTo(dev.fuelSlot) or turtle.getItemCount(dev.fuelSlot) == 0 then turtle.transferTo(dev.fuelSlot,64) end -- Move fuel into slot
|
||||
end
|
||||
end
|
||||
if useSlot4 == "fuel" and turtle.select(4) and turtle.getSelectedSlot() == 4 then -- Fuel
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.compareTo(dev.fuelSlot) or turtle.getItemCount(dev.fuelSlot) == 0 then turtle.transferTo(dev.fuelSlot,64) end -- Move fuel into slot
|
||||
end
|
||||
end -- Slot 4 fuel
|
||||
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.getItemCount(3) == 0 and turtle.getItemCount(dev.outputSlot) > 0 then
|
||||
turtle.select(dev.outputSlot)
|
||||
turtle.transferTo(3, 64)
|
||||
elseif turtle.getItemCount(dev.outputSlot) > 0 and turtle.select(3) and turtle.compareTo(dev.outputSlot) then -- Move output
|
||||
--turtle.setStatus("moving")
|
||||
turtle.select(dev.outputSlot)
|
||||
turtle.transferTo(3, 64)
|
||||
end
|
||||
if useSlot4 == "output" then -- Slot 4 output
|
||||
if turtle.getItemCount(4) == 0 and turtle.getItemCount(dev.outputSlot) > 0 then
|
||||
turtle.select(dev.outputSlot)
|
||||
turtle.transferTo(4, 64)
|
||||
elseif turtle.getItemCount(dev.outputSlot) > 0 and turtle.select(4) and turtle.compareTo(dev.outputSlot) then
|
||||
turtle.select(dev.outputSlot)
|
||||
turtle.transferTo(4, 64)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function manageRemoteResources()
|
||||
local localList = listInventory()
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
local devList = dev.list()
|
||||
--print(textutils.serialize(devList))
|
||||
if devList[2] == nil then
|
||||
if localList[dev.fuelSlot] ~= nil then
|
||||
turtle.setStatus("fueling")
|
||||
dev.pullItems(devModem.getNameLocal(), dev.fuelSlot, 64, 2)
|
||||
end
|
||||
else
|
||||
if localList[dev.fuelSlot] ~= nil and localList[dev.fuelSlot].name == devList[2].name then
|
||||
turtle.setStatus("fueling")
|
||||
dev.pullItems(devModem.getNameLocal(), dev.fuelSlot, 64, 2)
|
||||
end
|
||||
end
|
||||
if devList[1] == nil then
|
||||
if localList[dev.inputSlot] ~= nil then
|
||||
turtle.setStatus("pushing")
|
||||
dev.pullItems(devModem.getNameLocal(), dev.inputSlot, 64, 1)
|
||||
end
|
||||
else
|
||||
if localList[dev.inputSlot] ~= nil and localList[dev.inputSlot].name == devList[1].name then
|
||||
turtle.setStatus("pushing")
|
||||
dev.pullItems(devModem.getNameLocal(), dev.inputSlot, 64, 1)
|
||||
end
|
||||
end -- Move input
|
||||
if devList[3] ~= nil then
|
||||
if localList[dev.outputSlot] == nil then
|
||||
turtle.setStatus("pulling")
|
||||
dev.pushItems(devModem.getNameLocal(), 3, 64, dev.outputSlot)
|
||||
end
|
||||
else
|
||||
if localList[dev.outputSlot] ~= nil then
|
||||
if devList[3] ~= nil and localList[dev.outputSlot].name == devList[3].name then
|
||||
turtle.setStatus("pulling")
|
||||
dev.pushItems(devModem.getNameLocal(), 3, 64, dev.outputSlot)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
while true do -- Main Loop
|
||||
local turtleList = listInventory()
|
||||
if turtleList[1] ~= nil or turtleList[13] ~= nil or turtleList[14] ~= nil or turtleList[15] ~= nil or turtleList[16] ~= nil or ((useSlot4 == "input" or useSlot4 == "fuel") and turtleList[4] ~= nil) then
|
||||
manageLocalResources()
|
||||
end
|
||||
manageRemoteResources()
|
||||
turtle.setStatus("sleeping")
|
||||
sleep(1)
|
||||
end
|
||||
29
miloApps/apps/storageGen.lua
Normal file
29
miloApps/apps/storageGen.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
--[[
|
||||
For initially setting up large amounts of storage chests.
|
||||
]]
|
||||
|
||||
local Util = require('opus.util')
|
||||
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local args = { ... }
|
||||
local st = args[1] or error('Specify a storage type (ie. minecraft:chest)')
|
||||
|
||||
local config = { }
|
||||
peripheral.find(st, function(n)
|
||||
config[n] = {
|
||||
name = n,
|
||||
category = 'storage',
|
||||
mtype = 'storage',
|
||||
}
|
||||
end)
|
||||
|
||||
print('Found ' .. Util.size(config))
|
||||
|
||||
if Util.size(config) == 0 then
|
||||
error('Invalid peripheral type')
|
||||
end
|
||||
|
||||
Util.writeTable('usr/config/storageGen', config)
|
||||
print('storageGen file created in usr/config')
|
||||
print('update /usr/config/storage with contents (or rename to storage)')
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
[ "4486006f811b88cacd5f211fd579717e29b600cd" ] = {
|
||||
title = "Simple",
|
||||
category = "Turtle",
|
||||
category = "Mining",
|
||||
icon = "\030 \0315\\\030 \031 \010\030 \0304\031f _ \030 \031c/\0315\\\010\030 \0304 ",
|
||||
run = "simpleMiner.lua",
|
||||
requires = 'turtle',
|
||||
},
|
||||
[ "da39a3ee5e6b4b0d3255bfef95601890afd80709" ] = {
|
||||
title = "Scanning",
|
||||
category = "Turtle",
|
||||
category = "Mining",
|
||||
icon = "\030 \0315\\\030 \031 \010\030 \0304\031f _ \030 \031c/\0315\\\010\030 \0304 ",
|
||||
run = "scanningMiner.lua",
|
||||
requires = 'turtle',
|
||||
|
||||
@@ -2,24 +2,24 @@ local fs = _G.fs
|
||||
local shell = _ENV.shell
|
||||
|
||||
local function recurse(path)
|
||||
if fs.isDir(path) then
|
||||
for _, v in pairs(fs.listEx(path)) do
|
||||
if not v.isReadOnly then
|
||||
recurse(fs.combine(path, v.name))
|
||||
end
|
||||
end
|
||||
elseif path:match('%.lua$') and not fs.isReadOnly(path) then
|
||||
local sz = fs.getSize(path)
|
||||
shell.run('minify.lua minify ' .. path)
|
||||
print(string.format('%s : %.2f%%', path, (sz - fs.getSize(path)) / sz * 100))
|
||||
end
|
||||
if fs.isDir(path) then
|
||||
for _, v in pairs(fs.listEx(path)) do
|
||||
if not v.isReadOnly then
|
||||
recurse(fs.combine(path, v.name))
|
||||
end
|
||||
end
|
||||
elseif path:match('%.lua$') and not fs.isReadOnly(path) then
|
||||
local sz = fs.getSize(path)
|
||||
shell.run('minify.lua minify ' .. path)
|
||||
print(string.format('%s : %.2f%%', path, (sz - fs.getSize(path)) / sz * 100))
|
||||
end
|
||||
end
|
||||
|
||||
local path = ({ ... })[1] or error('Syntax: minifyDir PATH')
|
||||
|
||||
path = fs.combine(path, '')
|
||||
if not fs.isDir(path) then
|
||||
error('Invalid path')
|
||||
error('Invalid path')
|
||||
end
|
||||
|
||||
recurse(path)
|
||||
|
||||
@@ -2,6 +2,7 @@ local Event = require('opus.event')
|
||||
local Socket = require('opus.socket')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
|
||||
local remoteId
|
||||
@@ -22,7 +23,7 @@ local function wrapTerm(socket)
|
||||
'setTextColor', 'setTextColour', 'setBackgroundColor',
|
||||
'setBackgroundColour', 'scroll', 'setCursorBlink', }
|
||||
|
||||
socket.term = _G.device.terminal
|
||||
socket.term = multishell.term
|
||||
socket.oldTerm = Util.shallowCopy(socket.term)
|
||||
|
||||
for _,k in pairs(methods) do
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user