cleanup + app changes

This commit is contained in:
kepler155c@gmail.com 2019-01-17 23:33:19 -05:00
parent 644fd0352f
commit 2fd2b552fc
4 changed files with 44 additions and 46 deletions

View File

@ -8,25 +8,20 @@ local PACKAGE_DIR = 'packages'
local Packages = { } local Packages = { }
function Packages:installed() function Packages:installed()
self.cache = { } local list = { }
if fs.exists(PACKAGE_DIR) then if fs.exists(PACKAGE_DIR) then
for _, dir in pairs(fs.list(PACKAGE_DIR)) do for _, dir in pairs(fs.list(PACKAGE_DIR)) do
local path = fs.combine(fs.combine(PACKAGE_DIR, dir), '.package') local path = fs.combine(fs.combine(PACKAGE_DIR, dir), '.package')
self.cache[dir] = Util.readTable(path) list[dir] = Util.readTable(path)
end end
end end
return self.cache return list
end end
function Packages:list() function Packages:list()
if self.packageList then return Util.readTable('usr/config/packages') or { }
return self.packageList
end
self.packageList = Util.readTable('usr/config/packages') or { }
return self.packageList
end end
function Packages:isInstalled(package) function Packages:isInstalled(package)

View File

@ -195,7 +195,7 @@ UI.Icon.defaults = {
function UI.Icon:eventHandler(event) function UI.Icon:eventHandler(event)
if event.type == 'mouse_click' then if event.type == 'mouse_click' then
self:setFocus(self.button) self:setFocus(self.button)
self:emit({ type = self.button.event, button = self.button }) --self:emit({ type = self.button.event, button = self.button })
return true return true
elseif event.type == 'mouse_doubleclick' then elseif event.type == 'mouse_doubleclick' then
self:emit({ type = self.button.event, button = self.button }) self:emit({ type = self.button.event, button = self.button })
@ -403,9 +403,13 @@ function page:eventHandler(event)
elseif event.type == 'delete' then elseif event.type == 'delete' then
local focused = page:getFocused() local focused = page:getFocused()
if focused.app then if focused.app then
focused.app.disabled = true if focused.app.filename then
local filename = focused.app.filename or fs.combine(REGISTRY_DIR, focused.app.key) fs.delete(focused.app.filename)
Util.writeTable(filename, focused.app) else
focused.app.disabled = true
local filename = focused.app.filename or fs.combine(REGISTRY_DIR, focused.app.key)
Util.writeTable(filename, focused.app)
end
loadApplications() loadApplications()
page:refresh() page:refresh()
page:draw() page:draw()

View File

@ -103,11 +103,6 @@
\030 \031f\030f\0310\136\140\140\030 ", \030 \031f\030f\0310\136\140\140\030 ",
run = "https://gist.github.com/LDDestroier/c7528d95bc0103545c2a/raw", run = "https://gist.github.com/LDDestroier/c7528d95bc0103545c2a/raw",
}, },
[ "785af2a4ad3c4ee912623c6e0b6d4299ea305bf6" ] = {
title = "Pipes",
category = "Games",
run = "https://pastebin.com/raw/skcs9x1s",
},
[ "53a5d150062b1e03206b9e15854b81060e3c7552" ] = { [ "53a5d150062b1e03206b9e15854b81060e3c7552" ] = {
title = "Minesweeper", title = "Minesweeper",
category = "Games", category = "Games",

View File

@ -19,7 +19,6 @@ local state = { }
turtle.pathfind = Pathing.pathfind turtle.pathfind = Pathing.pathfind
turtle.point = { x = 0, y = 0, z = 0, heading = 0 } turtle.point = { x = 0, y = 0, z = 0, heading = 0 }
function turtle.getPoint() return turtle.point end
function turtle.getState() return state end function turtle.getState() return state end
function turtle.isAborted() return state.abort end function turtle.isAborted() return state.abort end
function turtle.getStatus() return state.status end function turtle.getStatus() return state.status end
@ -34,6 +33,7 @@ local function _defaultMove(action)
return true return true
end end
function turtle.getPoint() return turtle.point end
function turtle.setPoint(pt, isGPS) function turtle.setPoint(pt, isGPS)
turtle.point.x = pt.x turtle.point.x = pt.x
turtle.point.y = pt.y turtle.point.y = pt.y
@ -77,6 +77,8 @@ local function _dig(name, inspect, dig)
return dig() return dig()
end end
-- override dig
-- optionally check that the block is a certain type
function turtle.dig(s) function turtle.dig(s)
return _dig(s, turtle.inspect, turtle.native.dig) return _dig(s, turtle.inspect, turtle.native.dig)
end end
@ -147,11 +149,9 @@ function turtle.getHeadingInfo(heading)
return headings[heading] return headings[heading]
end end
-- hackish way to support unlimited fuel function turtle.isTurtleAtSide(side)
if type(turtle.getFuelLevel()) ~= 'number' then local sideType = peripheral.getType(side)
function turtle.getFuelLevel() return sideType and sideType == 'turtle'
return 10000000
end
end end
-- [[ Policies ]] -- -- [[ Policies ]] --
@ -228,7 +228,7 @@ local function _place(action, indexOrId)
end end
end end
if slot and slot.qty == 0 then if slot and slot.count == 0 then
return false, 'No items to place' return false, 'No items to place'
end end
@ -321,18 +321,7 @@ function turtle.setMoveCallback(cb) state.moveCallback = cb end
function turtle.clearMoveCallback() state.moveCallback = noop end function turtle.clearMoveCallback() state.moveCallback = noop end
function turtle.getMoveCallback() return state.moveCallback end function turtle.getMoveCallback() return state.moveCallback end
function turtle.refuel(qtyOrName, qty) -- convenience method for setting multiple values
if not qtyOrName or type(qtyOrName) == 'number' then
return turtle.native.refuel(qtyOrName or 64)
end
return inventoryAction(turtle.native.refuel, qtyOrName, qty or 64)
end
function turtle.isTurtleAtSide(side)
local sideType = peripheral.getType(side)
return sideType and sideType == 'turtle'
end
function turtle.set(args) function turtle.set(args)
for k,v in pairs(args) do for k,v in pairs(args) do
@ -363,6 +352,22 @@ function turtle.set(args)
end end
end end
-- [[ Fuel ]] --
if type(turtle.getFuelLevel()) ~= 'number' then
-- Support unlimited fuel
function turtle.getFuelLevel()
return 10000000
end
end
-- override to optionally specify a fuel
function turtle.refuel(qtyOrName, qty)
if not qtyOrName or type(qtyOrName) == 'number' then
return turtle.native.refuel(qtyOrName or 64)
end
return inventoryAction(turtle.native.refuel, qtyOrName, qty or 64)
end
-- [[ Heading ]] -- -- [[ Heading ]] --
function turtle.getHeading() function turtle.getHeading()
return turtle.point.heading return turtle.point.heading
@ -740,9 +745,9 @@ function turtle.getSlot(indexOrId, slots)
slots = slots or turtle.getInventory() slots = slots or turtle.getInventory()
local _,c = string.gsub(indexOrId, ':', '') local _,c = string.gsub(indexOrId, ':', '')
if c == 2 then -- combined id and dmg .. ie. minecraft:coal:0 if c == 2 then -- combined id and dmg .. ie. minecraft:coal:0
return Util.find(slots, 'iddmg', indexOrId) return Util.find(slots, 'key', indexOrId)
end end
return Util.find(slots, 'id', indexOrId) return Util.find(slots, 'name', indexOrId)
end end
local detail = turtle.getItemDetail(indexOrId) local detail = turtle.getItemDetail(indexOrId)
@ -759,7 +764,6 @@ function turtle.getSlot(indexOrId, slots)
qty = detail.count, qty = detail.count,
dmg = detail.damage, dmg = detail.damage,
id = detail.name, id = detail.name,
iddmg = detail.name .. ':' .. detail.damage,
} }
end end
@ -798,7 +802,7 @@ function turtle.getSummedInventory()
local slots = turtle.getFilledSlots() local slots = turtle.getFilledSlots()
local t = { } local t = { }
for _,slot in pairs(slots) do for _,slot in pairs(slots) do
local entry = t[slot.iddmg] local entry = t[slot.key]
if not entry then if not entry then
entry = { entry = {
count = 0, count = 0,
@ -810,9 +814,8 @@ function turtle.getSummedInventory()
qty = 0, qty = 0,
dmg = slot.dmg, dmg = slot.dmg,
id = slot.id, id = slot.id,
iddmg = slot.iddmg,
} }
t[slot.iddmg] = entry t[slot.key] = entry
end end
entry.qty = entry.qty + slot.qty entry.qty = entry.qty + slot.qty
entry.count = entry.qty entry.count = entry.qty
@ -931,8 +934,8 @@ function turtle.getItemCount(idOrName)
local slots = turtle.getFilledSlots() local slots = turtle.getFilledSlots()
local count = 0 local count = 0
for _,slot in pairs(slots) do for _,slot in pairs(slots) do
if slot.iddmg == idOrName or slot.name == idOrName then if slot.key == idOrName or slot.name == idOrName then
count = count + slot.qty count = count + slot.count
end end
end end
return count return count
@ -967,7 +970,7 @@ function turtle.unequip(side)
return turtle.equip(side) return turtle.equip(side)
end end
-- [[ ]] -- -- deprecate
function turtle.run(fn, ...) function turtle.run(fn, ...)
local args = { ... } local args = { ... }
local s, m local s, m
@ -1233,6 +1236,7 @@ function turtle.enableGPS(timeout)
end end
end end
-- deprecate
function turtle.addFeatures(...) function turtle.addFeatures(...)
for _,feature in pairs({ ... }) do for _,feature in pairs({ ... }) do
require('turtle.' .. feature) require('turtle.' .. feature)