From c8f200ebb6cc140d46b31721c6e872bf7c4a0fa9 Mon Sep 17 00:00:00 2001 From: xAnavrins Date: Tue, 16 Jul 2019 22:29:47 -0400 Subject: [PATCH 1/2] Fix apps.db and legacy icon transparency --- sys/apps/Network.lua | 4 +-- sys/etc/apps.db | 77 +++++++++++++------------------------------- sys/etc/fstab | 2 +- 3 files changed, 24 insertions(+), 59 deletions(-) diff --git a/sys/apps/Network.lua b/sys/apps/Network.lua index bc551a4..6ae002a 100644 --- a/sys/apps/Network.lua +++ b/sys/apps/Network.lua @@ -188,9 +188,7 @@ function page:eventHandler(event) os.queueEvent('overview_shortcut', { title = t.label, category = "VNC", - icon = "\ - \031e\\\031 \031e/\031dn\ - \031e\\/\031 \0319c", + icon = "\010\030 \009\009\031e\\\031 \031e/\031dn\010\030 \009\009 \031e\\/\031 \031bc", run = "vnc.lua " .. t.id, }) diff --git a/sys/etc/apps.db b/sys/etc/apps.db index 7bf79ab..e753fd1 100644 --- a/sys/etc/apps.db +++ b/sys/etc/apps.db @@ -14,63 +14,49 @@ [ "53ebc572b4a44802ba114729f07bdaaf5409a9d7" ] = { title = "Network", category = "Apps", - icon = "\0304 \030 \ -\030f \0304 \0307 \030 \031 \031f)\ -\030f \0304 \0307 \030 \031f)", + icon = "\0304 \030 \010\030f \0304 \0307 \030 \031 \031f)\010\030f \0304 \0307 \030 \031f)", iconExt = "\030 \031 \128\128\128\128\0305\140\030 \0315\137\144\010\0314\131\131\0304\031f\148\030 \031 \128\0305\155\150\149\010\147\0300\031f\141\0304\149\0307\0318\149\030 \031 \128\128\128", run = "Network.lua", }, - c7116629a6a855cb774d9c7c8ad822fd83c71fb5 = { + [ "c7116629a6a855cb774d9c7c8ad822fd83c71fb5" ] = { title = "Reboot", category = "System", - icon = "\0304\031f \030f\0310o..\0304\031f \ -\0304\031f \030f\0310.o.\0304\031f \ -\0304\031f - ", + icon = "\0304\031f \030f\0310o..\0304\031f \010\0304\031f \030f\0310.o.\0304\031f \010\0304\031f - ", iconExt = "\0307\031 \135\0300\0317\159\0307\0310\144\031 \139\010\0300\0317\131\0307\0310\147\0300\0317\156\131\010\030 \130\143\143\129", run = "rom/programs/reboot", }, - fb91e24fa52d8d2b32937bf04d843f730319a902 = { + [ "fb91e24fa52d8d2b32937bf04d843f730319a902" ] = { title = "Update", category = "System", - icon = "\0301\03171\03180\030 \031 \ -\0301\03181\030 \031 \ -\0301\03170\03180\03171\0307\031f>", + icon = "\0301\03171\03180\030 \031 \010\0301\03181\030 \031 \010\0301\03170\03180\03171\0307\031f>", iconExt = "\030 \031 \128\0313\152\131\131\132\031 \128\010\030 \0313\139\159\129\0303\031 \159\129\139\010\030 \031 \128\0313\136\0303\031 \143\143\030 \0313\134\031 \128", run = "update update", }, - c47ae15370cfe1ed2781eedc1dc2547d12d9e972 = { + [ "c47ae15370cfe1ed2781eedc1dc2547d12d9e972" ] = { title = "Help", category = "Apps", - icon = " \031f?\031 \ -\031f?\031 \ - \031f?", + icon = "\030 \0310 ? \010\030 \0310? \010\030 \0310\009 ?", iconExt = "\0300\031 \129\030 \0310\131\0300\031 \148\030 \0310\148\010\030 \031 \128\0300\131\030 \0310\142\129\010\030 \031 \128\0300\131\030 \128\128", run = "Help.lua", }, - b0832074630eb731d7fbe8074de48a90cd9bb220 = { + [ "b0832074630eb731d7fbe8074de48a90cd9bb220" ] = { title = "Lua", category = "Apps", - icon = "\030f \ -\030f\0310lua>\031 \ -\030f ", + icon = "\030 \010\030 \0310lua>\031 \010\030 ", iconExt = "\0300\031 \151\030 \128\0300\159\159\159\030 \0310\144\0304\031 \159\030 \128\010\0300\031 \149\030 \128\0300\149\149\151\145\030 \128\0314\153\010\030 \130\131\130\131\130\131\0314\130\031 \128", run = "Lua.lua", }, - bc0792d8dc81e8aa30b987246a5ce97c40cd6833 = { + [ "bc0792d8dc81e8aa30b987246a5ce97c40cd6833" ] = { title = "System", category = "System", - icon = " \0307\031f| \ -\0307\031f---o\030 \031 \ - \0307\031f| ", + icon = "\030 \0307\031f| \010\0307\031f---o\030 \031 \010\030 \009 \0307\031f| ", iconExt = "\030 \0318\138\0308\031 \130\0318\128\031 \129\030 \0318\133\010\030 \0318\143\0308\128\0317\143\0318\128\030 \143\010\030 \0318\138\135\143\139\133", run = "System.lua", }, [ "2a4d562b1d9a9c90bdede6fac8ce4f7402462b86" ] = { title = "Tasks", category = "System", - icon = "\030f\031f \0315/\ -\030f\031f \0315/\\/ \ -\030f\0315/\031f ", + icon = "\030 \031f \0315/\010\030 \031f \0315/\\/ \010\030 \0315/\031f ", iconExt = "\030 \031 \128\128\0305\159\030 \128\0305\159\030 \0315\134\031 \128\010\030 \031 \128\0315\152\129\137\0305\031 \158\139\030 \128\010\030 \0315\134\031 \128\128\128\128\0305\154\030 \128", run = "Tasks.lua", }, @@ -83,86 +69,67 @@ [ "6a381ca189cbddd63737cbaf6e8b593844ce467ba52b1c5e5e05d8f29864385d" ] = { title = "Sniffer", category = "Apps", - icon = "\31\102\128\128\128\128\31\53\149\30\53\31\102\154\30\102\31\53\137\10\30\52\31\102\159\31\52\128\128\30\102\144\31\53\130\30\53\31\102\155\140\10\31\52\151\30\52\31\102\148\30\102\31\52\151\30\52\31\102\148\30\102\128\128\128", - iconExt = "\030 \031 \128\128\128\128\0315\149\0305\031 \154\030 \0315\137\010\0304\031 \159\0314\128\128\030 \144\0315\130\0305\031 \155\140\010\0314\151\0304\031f\148\030f\0314\151\0304\031f\148\030 \031 \128\128\128", + iconExt = "\030 \031 \128\128\128\128\0315\149\0305\031 \154\030 \0315\137\010\0304\031 \159\0314\128\128\030 \144\0315\130\0305\031 \155\140\010\0314\151\0304\031f\148\030f\0314\151\0304\031f\148\030 \031 \128\128\128", run = "Sniff.lua", }, [ "01c933b2a36ad8ed2d54089cb2903039046c1216" ] = { title = "Enchat", - icon = "\030e\031f\151\030f\031e\156\0311\140\0314\140\0315\140\031d\140\031b\140\031a\132\ -\030f\0314\128\030e\031f\132\030f\031e\132\0318nchat\ -\030f\031e\138\141\0311\140\0314\140\0315\132\0317v\03183\031a\132", + iconExt = "\030e\031f\151\030f\031e\156\0311\140\0314\140\0315\140\031d\140\031b\140\031a\132\010\030f\0314\128\030e\031f\132\030f\031e\132\0318nchat\010\030f\031e\138\141\0311\140\0314\140\0315\132\0317v\03183\031a\132", category = "Apps", run = "Enchat", }, [ "6ce6c512ea433a7fc5c8841628e7696cd0ff7f2b" ] = { title = "Files", category = "Apps", - icon = "\0300\0317==\031 \0307 \ -\0300\0317====\ -\0300\0317====", + icon = "\0300\0317==\031 \0307 \010\0300\0317====\010\0300\0317====", iconExt = "\0300\031f\136\140\132\0308\031 \130\030 \0318\144\010\157\0300\031f\147\030f\0310\142\143\030 \149\010\0300\031f\136\140\132\140\030 \0310\149", run = "Files.lua", }, [ "7fddb7d8d1d60b1eeefa9af01082e0811d4b484d" ] = { title = "Shutdown", category = "System", - icon = "\0304\031f \ -\0304\031f \030f\0310zz\031 \ -\0304\031f \030f ", + icon = "\0304\031f \010\0304\031f \030f\0310zz\031 \010\0304\031f \030f ", iconExt = "\030e\031 \135\030 \031e\148\030e\128\031 \151\139\010\030e\031e\128\030 \031 \128\031e\143\031 \128\030e\031e\128\010\030 \031e\139\030e\031 \130\131\129\030 \031e\135", run = "/rom/programs/shutdown", }, [ "bdc1fd5d3c0f3dcfd55d010426e61bf9451e680d" ] = { title = "Shell", category = "Apps", - icon = "\0304 \030 \ -\0304 \030f\0314> \0310_\031 \ -\0304 \030f \030 ", + icon = "\0304 \030 \010\0304 \030f\0314> \0310_\031 \010\0304 \030f \030 ", iconExt = "\030f\0314\151\131\131\131\131\010\030f\0314\149\030f\0314> \0310_ \010\030f\0314\149\030f ", run = "shell", }, [ "b77aad5fb24921ef76ac8f3e500ed93fddae8f2a" ] = { title = "Redirection", category = "Games", - icon = "\0307 \0308 \0307 \ -\0308\031b> \030b\0310>\0308\0318 \ -\0307 ", + icon = "\0307 \0308 \0307 \010\0308\031b> \030b\0310>\0308\0318 \010\0307 ", run = "rom/programs/fun/advanced/redirection", requires = 'advanced', }, [ "f39d173d91c22348565c20283b89d4d1cabd3b7e" ] = { title = "Falling", category = "Games", - icon = "\030f \0302 \ -\0309 \0302 \0301 \ -\030e \0309 \0301 ", + icon = "\030f \0302 \010\0309 \0302 \0301 \010\030e \0309 \0301 ", run = "rom/programs/pocket/falling", requires = 'advancedPocket', }, [ "db56e2e1db9f7accfc37f2b132d27505c66ba521" ] = { title = "Adventure", category = "Games", - icon = "\030f\0310You \031 \ -\030f\0310Ther\030 \031 \ -\030f\0314?\031f \031 \030 ", + icon = "\030f\0310You \031 \010\030f\0310Ther\030 \031 \010\030f\0314?\031f \031 \030 ", run = "rom/programs/fun/adventure", }, [ "76b849f460640bc789c433894382fb5acbac42a2" ] = { title = "Worm", category = "Games", - icon = "\030d \030 \030e \030 \ -\030d \030 \ -\030d ", + icon = "\030d \030 \030e \030 \010\030d \030 \010\030d ", iconExt = "\0305\031 \151\030 \0315\135\131\0305\031 \146\010\030 \0315\130\141\0305\031 \139\030 \0315\130\010\0305\031 \146\143\030 \0315\158\031e\130", run = "/rom/programs/fun/worm", }, [ "9f46ca3ef617166776ef6014a58d4e66859caa62" ] = { title = "DJ", category = "Games", - icon = " \030f \ -\030f \0307 \ -\030f \0307 \0300 ", + icon = " \030f \010\030f \0307 \010\030f \0307 \0300 ", iconExt = "\030 \031 \128\0307\143\131\131\131\131\143\030 \128\010\0307\031 \129\0317\128\0319\136\0309\031b\136\132\0307\0319\132\0317\128\031 \130\010\030 \0317\130\143\0307\128\128\128\128\030 \143\129", run = "/rom/programs/fun/dj", }, diff --git a/sys/etc/fstab b/sys/etc/fstab index 235ecf0..6514f50 100644 --- a/sys/etc/fstab +++ b/sys/etc/fstab @@ -2,4 +2,4 @@ sys/apps/pain.lua urlfs https://github.com/LDDestroier/CC/raw/master/pain.lua sys/apps/update.lua urlfs http://pastebin.com/raw/UzGHLbNC sys/apps/Enchat.lua urlfs https://raw.githubusercontent.com/LDDestroier/enchat/master/enchat3.lua sys/apps/cloud.lua urlfs https://cloud-catcher.squiddev.cc/cloud.lua -sys/apps/ntftrans.lua urlfs https://pastebin.com/raw/e8XrzeDY \ No newline at end of file +sys/apps/nfttrans.lua urlfs https://pastebin.com/raw/e8XrzeDY From 672cca30841d6fdd40f75d9025aa9810ff900e14 Mon Sep 17 00:00:00 2001 From: xAnavrins Date: Tue, 16 Jul 2019 23:21:33 -0400 Subject: [PATCH 2/2] ui theme generator + better module handling --- sys/apps/system/requires.lua | 3 +- sys/init/1.device.lua | 78 +-------------------- sys/init/3.modules.lua | 93 ++++++++++++++++++++----- sys/init/3.relay.lua | 2 +- sys/modules/opus/ui.lua | 29 ++++++++ sys/modules/opus/ui/components/Menu.lua | 1 + 6 files changed, 110 insertions(+), 96 deletions(-) diff --git a/sys/apps/system/requires.lua b/sys/apps/system/requires.lua index 38acef9..1e41216 100644 --- a/sys/apps/system/requires.lua +++ b/sys/apps/system/requires.lua @@ -100,4 +100,5 @@ function tab:eventHandler(event) end end -return tab +--this needs rework - see 4.user.lua +--return tab diff --git a/sys/init/1.device.lua b/sys/init/1.device.lua index c4946d3..b61a767 100644 --- a/sys/init/1.device.lua +++ b/sys/init/1.device.lua @@ -34,25 +34,12 @@ local keys = _G.keys local mouse = _G.device.mouse local os = _G.os -local drivers = { } - kernel.hook('peripheral', function(_, eventData) local side = eventData[1] if side then local dev = Peripheral.addDevice(device, side) if dev then - if drivers[dev.type] then - local e = drivers[dev.type](dev) - if type(e) == 'table' then - for _, v in pairs(e) do - os.queueEvent('device_attach', v.name) - end - elseif e then - os.queueEvent('device_attach', e.name) - end - end - - os.queueEvent('device_attach', dev.name, dev) + os.queueEvent('device_attach', dev.name) end end end) @@ -61,12 +48,7 @@ kernel.hook('peripheral_detach', function(_, eventData) local side = eventData[1] if side then for _, dev in pairs(Util.findAll(device, 'side', side)) do - os.queueEvent('device_detach', dev.name, dev) - if dev._children then - for _,v in pairs(dev._children) do - os.queueEvent('peripheral_detach', v.name) - end - end + os.queueEvent('device_detach', dev.name) device[dev.name] = nil end end @@ -124,59 +106,3 @@ end function keyboard.removeHotkey(code) keyboard.hotkeys[code] = nil end - -local function createDevice(name, devType, method, manipulator) - local dev = { - name = name, - side = name, - type = devType, - } - local methods = { - 'drop', 'getDocs', 'getItem', 'getItemMeta', 'getTransferLocations', - 'list', 'pullItems', 'pushItems', 'size', 'suck', - } - if manipulator[method] then - for _,k in pairs(methods) do - dev[k] = function(...) - return manipulator[method]()[k](...) - end - end - if not manipulator._children then - manipulator._children = { dev } - else - table.insert(manipulator._children, dev) - end - device[name] = dev - end -end - -drivers['manipulator'] = function(dev) - if dev.getName then - pcall(function() - local name = dev.getName() - if name then - if dev.getInventory then - createDevice(name .. ':inventory', 'inventory', 'getInventory', dev) - end - if dev.getEquipment then - createDevice(name .. ':equipment', 'equipment', 'getEquipment', dev) - end - if dev.getEnder then - createDevice(name .. ':enderChest', 'enderChest', 'getEnder', dev) - end - - return dev._children - end - end) - end -end - --- initialize drivers -for _,v in pairs(device) do - if drivers[v.type] then - local s, m = pcall(drivers[v.type], v) - if not s and m then - _G.printError(m) - end - end -end diff --git a/sys/init/3.modules.lua b/sys/init/3.modules.lua index 8dd5fcb..174f2be 100644 --- a/sys/init/3.modules.lua +++ b/sys/init/3.modules.lua @@ -3,17 +3,17 @@ local Util = require('opus.util') local device = _G.device local kernel = _G.kernel local os = _G.os -local peripheral = _G.peripheral local containers = { manipulator = true, neuralInterface = true, } +local cache = { } + local function getModules(dev, side) local list = { } - - if dev then + if dev and dev.listModules then for _, module in pairs(dev.listModules()) do list[module] = Util.shallowCopy(dev) list[module].name = module @@ -24,29 +24,86 @@ local function getModules(dev, side) return list end -for _,v in pairs(device) do - if containers[v.type] then - local list = getModules(v, v.side) - for k, dev in pairs(list) do - -- neural and attached modules have precedence over manipulator modules - if not device[k] or v.type ~= 'manipulator' then - device[k] = dev - end +-- if a device has been reattached, reuse the existing +-- table so any references to the table are retained +local function addDevice(dev, args, doQueue) + local name = args.name + + if not cache[name] then + cache[name] = { } + end + device[name] = cache[name] + Util.merge(device[name], dev) + Util.merge(device[name], args) + + if doQueue then + os.queueEvent('device_attach', name) + end +end + +local function addContainer(v, doQueue) + -- add devices like plethora:scanner + for name, dev in pairs(getModules(v, v.side)) do + -- neural and attached modules have precedence over manipulator modules + if not device[name] or v.type ~= 'manipulator' then + addDevice(dev, { name = dev.name, type = dev.name, side = dev.side }, doQueue) end end + + if v.getName then + pcall(function() + local name = v.getName() + if name then + if v.getInventory then + addDevice(v.getInventory(), { + name = name .. ':inventory', + type = 'inventory', + side = v.side + }, doQueue) + end + if v.getEquipment then + addDevice(v.getEquipment(), { + name = name .. ':equipment', + type = 'equipment', + side = v.side + }, doQueue) + end + if v.getEnder then + addDevice(v.getEnder(), { + name = name .. ':enderChest', + type = 'enderChest', + side = v.side + }, doQueue) + end + end + end) + end +end + +for k,v in pairs(device) do + if containers[v.type] then + cache[k] = v + addContainer(v) + end end -- register modules as peripherals kernel.hook('device_attach', function(_, eventData) - local dev = eventData[2] + local name = eventData[1] + local dev = device[name] if dev and containers[dev.type] then - local list = getModules(peripheral.wrap(dev.side), dev.side) - for k,v in pairs(list) do - if not device[k] or dev.type ~= 'manipulator' then - device[k] = v - os.queueEvent('device_attach', k, v) - end + -- so... basically, if you get a handle to device.neuralInterface + -- (or manipulator) - that handle will still be valid after + -- a module is removed + if cache[name] then + device[name] = cache[name] + -- TODO: cannot simply merge - need to remove + -- all functions then merge + Util.merge(device[name], dev) + else + cache[name] = dev end + addContainer(dev, true) end end) diff --git a/sys/init/3.relay.lua b/sys/init/3.relay.lua index 5ddc4bc..a2132e7 100644 --- a/sys/init/3.relay.lua +++ b/sys/init/3.relay.lua @@ -23,5 +23,5 @@ end -- register oc devices as peripherals kernel.hook('device_attach', function(_, eventData) - register(device[eventData[2]]) + register(device[eventData[1]]) end) diff --git a/sys/modules/opus/ui.lua b/sys/modules/opus/ui.lua index 0acfb16..b291e82 100644 --- a/sys/modules/opus/ui.lua +++ b/sys/modules/opus/ui.lua @@ -12,6 +12,7 @@ local fs = _G.fs local os = _G.os local peripheral = _G.peripheral local term = _G.term +local textutils = _G.textutils --[[ Using the shorthand window definition, elements are created from @@ -217,6 +218,34 @@ function Manager:loadTheme(filename) end end +function Manager:generateTheme(filename) + local t = { } + for k,v in pairs(self) do + if type(v) == 'table' then + if v._preload then + v._preload() + v = self[k] + end + if v.defaults and v.defaults.UIElement ~= 'Device' then + for p,d in pairs(v.defaults) do + if p:find('olor') then + if not t[k] then + t[k] = { } + end + for c, n in pairs(colors) do + if n == d then + t[k][p] = 'colors.' .. c + break + end + end + end + end + end + end + end + Util.writeFile(filename, textutils.serialize(t):gsub('(")', '')) +end + function Manager:emitEvent(event) local currentPage = self:getActivePage() if currentPage and currentPage.focused then diff --git a/sys/modules/opus/ui/components/Menu.lua b/sys/modules/opus/ui/components/Menu.lua index f581874..e31e8df 100644 --- a/sys/modules/opus/ui/components/Menu.lua +++ b/sys/modules/opus/ui/components/Menu.lua @@ -7,6 +7,7 @@ UI.Menu.defaults = { UIElement = 'Menu', disableHeader = true, columns = { { heading = 'Prompt', key = 'prompt', width = 20 } }, + menuItems = { }, } function UI.Menu:postInit() self.values = self.menuItems