From 2fd2b552fcb36d0bf56b9086eb1894a9e290882c Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 17 Jan 2019 23:33:19 -0500 Subject: [PATCH] cleanup + app changes --- sys/apis/packages.lua | 13 +++------ sys/apps/Overview.lua | 12 +++++--- sys/etc/app.db | 5 ---- sys/extensions/6.tl3.lua | 60 +++++++++++++++++++++------------------- 4 files changed, 44 insertions(+), 46 deletions(-) diff --git a/sys/apis/packages.lua b/sys/apis/packages.lua index 7f39255..ffbc803 100644 --- a/sys/apis/packages.lua +++ b/sys/apis/packages.lua @@ -8,25 +8,20 @@ local PACKAGE_DIR = 'packages' local Packages = { } function Packages:installed() - self.cache = { } + local list = { } if fs.exists(PACKAGE_DIR) then for _, dir in pairs(fs.list(PACKAGE_DIR)) do local path = fs.combine(fs.combine(PACKAGE_DIR, dir), '.package') - self.cache[dir] = Util.readTable(path) + list[dir] = Util.readTable(path) end end - return self.cache + return list end function Packages:list() - if self.packageList then - return self.packageList - end - self.packageList = Util.readTable('usr/config/packages') or { } - - return self.packageList + return Util.readTable('usr/config/packages') or { } end function Packages:isInstalled(package) diff --git a/sys/apps/Overview.lua b/sys/apps/Overview.lua index be73986..309c2c1 100644 --- a/sys/apps/Overview.lua +++ b/sys/apps/Overview.lua @@ -195,7 +195,7 @@ UI.Icon.defaults = { function UI.Icon:eventHandler(event) if event.type == 'mouse_click' then self:setFocus(self.button) - self:emit({ type = self.button.event, button = self.button }) + --self:emit({ type = self.button.event, button = self.button }) return true elseif event.type == 'mouse_doubleclick' then self:emit({ type = self.button.event, button = self.button }) @@ -403,9 +403,13 @@ function page:eventHandler(event) elseif event.type == 'delete' then local focused = page:getFocused() if focused.app then - focused.app.disabled = true - local filename = focused.app.filename or fs.combine(REGISTRY_DIR, focused.app.key) - Util.writeTable(filename, focused.app) + if focused.app.filename then + fs.delete(focused.app.filename) + 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() page:refresh() page:draw() diff --git a/sys/etc/app.db b/sys/etc/app.db index f36d4f9..643db6a 100644 --- a/sys/etc/app.db +++ b/sys/etc/app.db @@ -103,11 +103,6 @@ \030 \031f\030f\0310\136\140\140\030 ", run = "https://gist.github.com/LDDestroier/c7528d95bc0103545c2a/raw", }, - [ "785af2a4ad3c4ee912623c6e0b6d4299ea305bf6" ] = { - title = "Pipes", - category = "Games", - run = "https://pastebin.com/raw/skcs9x1s", - }, [ "53a5d150062b1e03206b9e15854b81060e3c7552" ] = { title = "Minesweeper", category = "Games", diff --git a/sys/extensions/6.tl3.lua b/sys/extensions/6.tl3.lua index 58ca25d..7660732 100644 --- a/sys/extensions/6.tl3.lua +++ b/sys/extensions/6.tl3.lua @@ -19,7 +19,6 @@ local state = { } turtle.pathfind = Pathing.pathfind 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.isAborted() return state.abort end function turtle.getStatus() return state.status end @@ -34,6 +33,7 @@ local function _defaultMove(action) return true end +function turtle.getPoint() return turtle.point end function turtle.setPoint(pt, isGPS) turtle.point.x = pt.x turtle.point.y = pt.y @@ -77,6 +77,8 @@ local function _dig(name, inspect, dig) return dig() end +-- override dig +-- optionally check that the block is a certain type function turtle.dig(s) return _dig(s, turtle.inspect, turtle.native.dig) end @@ -147,11 +149,9 @@ function turtle.getHeadingInfo(heading) return headings[heading] end --- hackish way to support unlimited fuel -if type(turtle.getFuelLevel()) ~= 'number' then - function turtle.getFuelLevel() - return 10000000 - end +function turtle.isTurtleAtSide(side) + local sideType = peripheral.getType(side) + return sideType and sideType == 'turtle' end -- [[ Policies ]] -- @@ -228,7 +228,7 @@ local function _place(action, indexOrId) end end - if slot and slot.qty == 0 then + if slot and slot.count == 0 then return false, 'No items to place' end @@ -321,18 +321,7 @@ function turtle.setMoveCallback(cb) state.moveCallback = cb end function turtle.clearMoveCallback() state.moveCallback = noop end function turtle.getMoveCallback() return state.moveCallback end -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 - -function turtle.isTurtleAtSide(side) - local sideType = peripheral.getType(side) - return sideType and sideType == 'turtle' -end - +-- convenience method for setting multiple values function turtle.set(args) for k,v in pairs(args) do @@ -363,6 +352,22 @@ function turtle.set(args) 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 ]] -- function turtle.getHeading() return turtle.point.heading @@ -740,9 +745,9 @@ function turtle.getSlot(indexOrId, slots) slots = slots or turtle.getInventory() local _,c = string.gsub(indexOrId, ':', '') 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 - return Util.find(slots, 'id', indexOrId) + return Util.find(slots, 'name', indexOrId) end local detail = turtle.getItemDetail(indexOrId) @@ -759,7 +764,6 @@ function turtle.getSlot(indexOrId, slots) qty = detail.count, dmg = detail.damage, id = detail.name, - iddmg = detail.name .. ':' .. detail.damage, } end @@ -798,7 +802,7 @@ function turtle.getSummedInventory() local slots = turtle.getFilledSlots() local t = { } for _,slot in pairs(slots) do - local entry = t[slot.iddmg] + local entry = t[slot.key] if not entry then entry = { count = 0, @@ -810,9 +814,8 @@ function turtle.getSummedInventory() qty = 0, dmg = slot.dmg, id = slot.id, - iddmg = slot.iddmg, } - t[slot.iddmg] = entry + t[slot.key] = entry end entry.qty = entry.qty + slot.qty entry.count = entry.qty @@ -931,8 +934,8 @@ function turtle.getItemCount(idOrName) local slots = turtle.getFilledSlots() local count = 0 for _,slot in pairs(slots) do - if slot.iddmg == idOrName or slot.name == idOrName then - count = count + slot.qty + if slot.key == idOrName or slot.name == idOrName then + count = count + slot.count end end return count @@ -967,7 +970,7 @@ function turtle.unequip(side) return turtle.equip(side) end --- [[ ]] -- +-- deprecate function turtle.run(fn, ...) local args = { ... } local s, m @@ -1233,6 +1236,7 @@ function turtle.enableGPS(timeout) end end +-- deprecate function turtle.addFeatures(...) for _,feature in pairs({ ... }) do require('turtle.' .. feature)