From b8544644b74d1318aa512cf3e73f9c306ed96f80 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Fri, 28 Jun 2019 13:50:34 -0400 Subject: [PATCH] move apis into rom/modules/main for shell compatibility --- builder/apis/blocks.lua | 6 +- builder/apis/builder.lua | 4 +- builder/apis/commands.lua | 4 +- builder/apis/schematic.lua | 6 +- builder/apis/turtle.lua | 10 +- builder/builder.lua | 8 +- builder/supplier.lua | 6 +- builder/viewer.lua | 4 +- ccemux/autorun/startup.lua | 2 +- ccemux/system/ccemux.lua | 4 +- common/Appstore.lua | 6 +- common/Devices.lua | 8 +- common/DiskCopy.lua | 10 +- common/Events.lua | 6 +- common/Follow.lua | 12 +- common/SoundPlayer.lua | 7 +- common/Turtles.lua | 12 +- common/canvasClient.lua | 4 +- common/debugMonitor.lua | 2 +- common/edit.lua | 2 +- common/multiMiner.lua | 14 +- common/recorder.lua | 2 +- core/apis/chestAdapter.lua | 6 +- core/apis/chestAdapter18.lua | 6 +- core/apis/itemDB.lua | 4 +- core/apis/meAdapter.lua | 6 +- core/apis/meAdapter18.lua | 6 +- core/apis/message.lua | 4 +- core/apis/nameDB.lua | 4 +- core/apis/proxy.lua | 2 +- core/apis/refinedAdapter.lua | 6 +- core/apis/swarm.lua | 6 +- core/apis/tableDB.lua | 4 +- farms/apis/craft.lua | 2 +- farms/apis/level.lua | 4 +- farms/attack.lua | 4 +- farms/farmer.lua | 4 +- farms/rancher.lua | 4 +- farms/spawner.lua | 4 +- farms/superTreefarm.lua | 6 +- farms/treefarm.lua | 4 +- forestry/alveary.lua | 4 +- forestry/filing.lua | 4 +- games/ccTunes.lua | 2 +- gps/gpsServer.lua | 6 +- ignore/glasses.lua | 8 +- ignore/neuralFly.lua | 4 +- mbs/.package | 11 + mbs/autorun/startup.lua | 7 + mbs/etc/apps.db | 7 + mbs/mbs.lua | 260 +++++ milo/MiloLocal.lua | 8 +- milo/MiloRemote.lua | 14 +- milo/apis/craft2.lua | 2 +- milo/apis/init.lua | 6 +- milo/apis/massAdapter.lua | 2 +- milo/apis/miniAdapter.lua | 4 +- milo/apis/storage.lua | 8 +- milo/apis/taskRunner.lua | 2 +- milo/apps/brewArray.lua | 4 +- milo/apps/cobblegen.lua | 2 +- milo/apps/enderchest.lua | 4 +- milo/apps/furni.lua | 4 +- milo/apps/storageGen.lua | 2 +- milo/apps/water.lua | 4 +- milo/core/learnWizard.lua | 2 +- milo/core/listing.lua | 8 +- milo/core/machines.lua | 8 +- milo/plugins/activityView.lua | 8 +- milo/plugins/backupView.lua | 6 +- milo/plugins/brewingStandView.lua | 4 +- milo/plugins/craftTask.lua | 6 +- milo/plugins/demandCraft.lua | 4 +- milo/plugins/exportView.lua | 4 +- milo/plugins/importView.lua | 4 +- milo/plugins/inputChestView.lua | 4 +- milo/plugins/item.lua | 4 +- milo/plugins/item/infoTab.lua | 4 +- milo/plugins/item/machinesTab.lua | 4 +- milo/plugins/item/manageTab.lua | 6 +- milo/plugins/item/recipeTab.lua | 2 +- milo/plugins/item/resetTab.lua | 4 +- milo/plugins/jobMonitor.lua | 12 +- milo/plugins/machineLearn.lua | 4 +- milo/plugins/machineMover.lua | 4 +- milo/plugins/massStorageView.lua | 4 +- milo/plugins/remote.lua | 4 +- milo/plugins/remote/autostore.lua | 6 +- milo/plugins/remote/craft.lua | 2 +- milo/plugins/remote/deposit.lua | 2 +- milo/plugins/remote/depositAll.lua | 4 +- milo/plugins/remote/feeder.lua | 6 +- milo/plugins/remote/setup.lua | 6 +- milo/plugins/speakerView.lua | 4 +- milo/plugins/statsView.lua | 8 +- milo/plugins/storageView.lua | 2 +- milo/plugins/transferView.lua | 6 +- milo/plugins/trashcanView.lua | 2 +- milo/plugins/turtleLearn.lua | 2 +- miners/findSwarm.lua | 10 +- miners/scanningMiner.lua | 10 +- miners/simpleMiner.lua | 6 +- monitor/mirror.lua | 4 +- monitor/mirrorClient.lua | 6 +- monitor/mirrorHost.lua | 4 +- monitor/mwm.lua | 12 +- neural/Scanner.lua | 8 +- neural/Sensor.lua | 8 +- neural/autorun/interface.lua | 2 +- neural/autorun/splash.lua | 2 +- neural/elytraFly.lua | 4 +- neural/mobFollow.lua | 6 +- neural/mobPickup.lua | 6 +- neural/mobRancher.lua | 4 +- neural/neuralLook.lua | 4 +- neural/neuralRecorder.lua | 6 +- neural/neuralReplay.lua | 4 +- neural/shootingGallery.lua | 2 +- pickup/pickup.lua | 8 +- pickup/pickupRemote.lua | 10 +- recipeBook/recipeBook.lua | 6 +- shellex/apis/shell.lua | 2 +- shellex/ls.lua | 4 +- storage/.package | 9 - storage/Crafter.lua | 1127 --------------------- storage/apis/controllerAdapter.lua | 18 - storage/apis/craft.lua | 320 ------ storage/chestManager.lua | 1504 ---------------------------- storage/etc/apps.db | 19 - storage/levelEmitter.lua | 374 ------- storage/storageActivity.lua | 163 --- swshop/installPlugin.lua | 2 +- swshop/shopConfig.lua | 2 +- swshop/shopTab.lua | 6 +- swshop/shopView-example.lua | 4 +- swshop/shopView.lua | 10 +- swshop/swshop.lua | 2 +- turtle/apis/equipper.lua | 2 +- turtle/autorun/startup.lua | 8 +- turtle/lavaRefuel.lua | 2 +- turtle/obsidian.lua | 4 +- turtle/system/turtle.lua | 4 +- 142 files changed, 613 insertions(+), 3869 deletions(-) create mode 100644 mbs/.package create mode 100644 mbs/autorun/startup.lua create mode 100644 mbs/etc/apps.db create mode 100644 mbs/mbs.lua delete mode 100644 storage/.package delete mode 100644 storage/Crafter.lua delete mode 100644 storage/apis/controllerAdapter.lua delete mode 100644 storage/apis/craft.lua delete mode 100644 storage/chestManager.lua delete mode 100644 storage/etc/apps.db delete mode 100644 storage/levelEmitter.lua delete mode 100644 storage/storageActivity.lua diff --git a/builder/apis/blocks.lua b/builder/apis/blocks.lua index 1b509dc..d1156b0 100644 --- a/builder/apis/blocks.lua +++ b/builder/apis/blocks.lua @@ -1,7 +1,7 @@ -local class = require('class') -local Util = require('util') +local class = require('opus.class') +local Util = require('opus.util') local TableDB = require('core.tableDB') -local JSON = require('json') +local JSON = require('opus.json') -- see https://github.com/Khroki/MCEdit-Unified/blob/master/pymclevel/minecraft.yaml -- see https://github.com/Khroki/MCEdit-Unified/blob/master/Items/minecraft/blocks.json diff --git a/builder/apis/builder.lua b/builder/apis/builder.lua index 2f51ccd..5434b72 100644 --- a/builder/apis/builder.lua +++ b/builder/apis/builder.lua @@ -1,7 +1,7 @@ local Blocks = require('builder.blocks') -local class = require('class') +local class = require('opus.class') local Message = require('core.message') -local Util = require('util') +local Util = require('opus.util') local device = _G.device local fs = _G.fs diff --git a/builder/apis/commands.lua b/builder/apis/commands.lua index 32bfbf7..96b4220 100644 --- a/builder/apis/commands.lua +++ b/builder/apis/commands.lua @@ -1,6 +1,6 @@ local Builder = require('builder.builder') -local Event = require('event') -local Util = require('util') +local Event = require('opus.event') +local Util = require('opus.util') local commands = _G.commands local fs = _G.fs diff --git a/builder/apis/schematic.lua b/builder/apis/schematic.lua index 68a888f..15215bc 100644 --- a/builder/apis/schematic.lua +++ b/builder/apis/schematic.lua @@ -1,7 +1,7 @@ -local class = require('class') -local Util = require('util') +local class = require('opus.class') +local Util = require('opus.util') local DEFLATE = require('builder.deflatelua') -local Point = require('point') +local Point = require('opus.point') local bit = _G.bit local fs = _G.fs diff --git a/builder/apis/turtle.lua b/builder/apis/turtle.lua index af2c85a..94c0d78 100644 --- a/builder/apis/turtle.lua +++ b/builder/apis/turtle.lua @@ -1,12 +1,12 @@ local Adapter = require('core.inventoryAdapter') local Builder = require('builder.builder') -local class = require('class') -local Event = require('event') +local class = require('opus.class') +local Event = require('opus.event') local itemDB = require('core.itemDB') local Message = require('core.message') -local Point = require('point') -local UI = require('ui') -local Util = require('util') +local Point = require('opus.point') +local UI = require('opus.ui') +local Util = require('opus.util') local device = _G.device local fs = _G.fs diff --git a/builder/builder.lua b/builder/builder.lua index 3bc4338..48a38a8 100644 --- a/builder/builder.lua +++ b/builder/builder.lua @@ -3,13 +3,13 @@ if not _G.turtle and not _G.commands then end local Adapter = require('core.inventoryAdapter') -local Event = require('event') -local GPS = require('gps') +local Event = require('opus.event') +local GPS = require('opus.gps') local itemDB = require('core.itemDB') local Schematic = require('builder.schematic') local TableDB = require('core.tableDB') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local fs = _G.fs diff --git a/builder/supplier.lua b/builder/supplier.lua index 0f93b97..c6f8ecc 100644 --- a/builder/supplier.lua +++ b/builder/supplier.lua @@ -1,9 +1,9 @@ -local Event = require('event') +local Event = require('opus.event') local MEProvider = require('core.meProvider') local Message = require('core.message') -local Point = require('point') +local Point = require('opus.point') local TableDB = require('core.tableDB') -local Util = require('util') +local Util = require('opus.util') local device = _G.device local os = _G.os diff --git a/builder/viewer.lua b/builder/viewer.lua index b59cf59..29fa3ce 100644 --- a/builder/viewer.lua +++ b/builder/viewer.lua @@ -1,7 +1,7 @@ local Builder = require('builder.builder') local Schematic = require('builder.schematic') local TableDB = require('core.tableDB') -local Util = require('util') +local Util = require('opus.util') local device = _G.device local fs = _G.fs @@ -157,4 +157,4 @@ for i = 1, #Builder.schematic.blocks do end pcall(_G.read) -cn.clear() \ No newline at end of file +cn.clear() diff --git a/ccemux/autorun/startup.lua b/ccemux/autorun/startup.lua index 239b695..a0fe3a9 100644 --- a/ccemux/autorun/startup.lua +++ b/ccemux/autorun/startup.lua @@ -6,7 +6,7 @@ if ccemux then -- add a System setup tab fs.mount('sys/apps/system/ccemux.lua', 'linkfs', 'packages/ccemux/system/ccemux.lua') - local Config = require('config') + local Config = require('opus.config') for k,v in pairs(Config.load('ccemux')) do if not peripheral.getType(k) then diff --git a/ccemux/system/ccemux.lua b/ccemux/system/ccemux.lua index d77fd7a..c62dd0f 100644 --- a/ccemux/system/ccemux.lua +++ b/ccemux/system/ccemux.lua @@ -1,5 +1,5 @@ -local Config = require('config') -local UI = require('ui') +local Config = require('opus.config') +local UI = require('opus.ui') local ccemux = _G.ccemux diff --git a/common/Appstore.lua b/common/Appstore.lua index 4b5ce3d..71e5c4f 100644 --- a/common/Appstore.lua +++ b/common/Appstore.lua @@ -1,7 +1,7 @@ -local Ansi = require('ansi') +local Ansi = require('opus.ansi') local SHA = require('crypto.sha2') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local fs = _G.fs local http = _G.http diff --git a/common/Devices.lua b/common/Devices.lua index ccc8159..ec50550 100644 --- a/common/Devices.lua +++ b/common/Devices.lua @@ -1,9 +1,9 @@ _G.requireInjector(_ENV) -local Ansi = require('ansi') -local Event = require('event') -local UI = require('ui') -local Util = require('util') +local Ansi = require('opus.ansi') +local Event = require('opus.event') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local peripheral = _G.peripheral diff --git a/common/DiskCopy.lua b/common/DiskCopy.lua index ce17f2b..7e0afa5 100644 --- a/common/DiskCopy.lua +++ b/common/DiskCopy.lua @@ -1,8 +1,8 @@ -local Ansi = require('ansi') -local Config = require('config') -local Event = require('event') -local UI = require('ui') -local Util = require('util') +local Ansi = require('opus.ansi') +local Config = require('opus.config') +local Event = require('opus.event') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local fs = _G.fs diff --git a/common/Events.lua b/common/Events.lua index ac9d8ba..6e00514 100644 --- a/common/Events.lua +++ b/common/Events.lua @@ -1,6 +1,6 @@ -local Event = require('event') -local UI = require('ui') -local Util = require('util') +local Event = require('opus.event') +local UI = require('opus.ui') +local Util = require('opus.util') local multishell = _ENV.multishell local os = _G.os diff --git a/common/Follow.lua b/common/Follow.lua index 41554d3..3ad0007 100644 --- a/common/Follow.lua +++ b/common/Follow.lua @@ -1,10 +1,10 @@ -local Event = require('event') -local GPS = require('gps') -local Point = require('point') -local Socket = require('socket') +local Event = require('opus.event') +local GPS = require('opus.gps') +local Point = require('opus.point') +local Socket = require('opus.socket') local Swarm = require('core.swarm') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local network = _G.network diff --git a/common/SoundPlayer.lua b/common/SoundPlayer.lua index 4e9f092..459259e 100644 --- a/common/SoundPlayer.lua +++ b/common/SoundPlayer.lua @@ -1,7 +1,6 @@ -local Sound = require('sound') - -local UI = require('ui') -local Util = require('util') +local Sound = require('opus.sound') +local UI = require('opus.ui') +local Util = require('opus.util') local peripheral = _G.peripheral diff --git a/common/Turtles.lua b/common/Turtles.lua index 42b9a3f..b5e78ce 100644 --- a/common/Turtles.lua +++ b/common/Turtles.lua @@ -1,10 +1,10 @@ -local Config = require('config') -local Event = require('event') +local Config = require('opus.config') +local Event = require('opus.event') local itemDB = require('core.itemDB') -local Socket = require('socket') -local Terminal = require('terminal') -local UI = require('ui') -local Util = require('util') +local Socket = require('opus.socket') +local Terminal = require('opus.terminal') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local fs = _G.fs diff --git a/common/canvasClient.lua b/common/canvasClient.lua index 3f94393..0983c16 100644 --- a/common/canvasClient.lua +++ b/common/canvasClient.lua @@ -1,5 +1,5 @@ -local Point = require('point') -local Util = require('util') +local Point = require('opus.point') +local Util = require('opus.util') local device = _G.device local os = _G.os diff --git a/common/debugMonitor.lua b/common/debugMonitor.lua index cb6a96e..2d963b5 100644 --- a/common/debugMonitor.lua +++ b/common/debugMonitor.lua @@ -1,4 +1,4 @@ -local Util = require('util') +local Util = require('opus.util') local os = _G.os local peripheral = _G.peripheral diff --git a/common/edit.lua b/common/edit.lua index 9a4e398..ecb911d 100644 --- a/common/edit.lua +++ b/common/edit.lua @@ -1,4 +1,4 @@ -local input = require('input') +local input = require('opus.input') local colors = _G.colors local fs = _G.fs diff --git a/common/multiMiner.lua b/common/multiMiner.lua index b816954..f62a110 100644 --- a/common/multiMiner.lua +++ b/common/multiMiner.lua @@ -1,11 +1,11 @@ -local Event = require('event') -local GPS = require('gps') +local Event = require('opus.event') +local GPS = require('opus.gps') local itemDB = require('core.itemDB') -local Point = require('point') -local Socket = require('socket') -local Sound = require('sound') -local Util = require('util') -local UI = require('ui') +local Point = require('opus.point') +local Socket = require('opus.socket') +local Sound = require('opus.sound') +local Util = require('opus.util') +local UI = require('opus.ui') local colors = _G.colors local device = _G.device diff --git a/common/recorder.lua b/common/recorder.lua index 382c28c..e6c7a94 100644 --- a/common/recorder.lua +++ b/common/recorder.lua @@ -14,7 +14,7 @@ local version = "Version 1.1.6" -- Original code by Bomb Bloke -- Modified to integrate with opus os -local Util = require('util') +local Util = require('opus.util') local multishell = _ENV.multishell local os = _G.os diff --git a/core/apis/chestAdapter.lua b/core/apis/chestAdapter.lua index c503cad..202e440 100644 --- a/core/apis/chestAdapter.lua +++ b/core/apis/chestAdapter.lua @@ -1,7 +1,7 @@ -local class = require('class') +local class = require('opus.class') local itemDB = require('core.itemDB') -local Peripheral = require('peripheral') -local Util = require('util') +local Peripheral = require('opus.peripheral') +local Util = require('opus.util') local os = _G.os diff --git a/core/apis/chestAdapter18.lua b/core/apis/chestAdapter18.lua index e1c02ef..b171aaf 100644 --- a/core/apis/chestAdapter18.lua +++ b/core/apis/chestAdapter18.lua @@ -1,7 +1,7 @@ -local class = require('class') -local Util = require('util') +local class = require('opus.class') +local Util = require('opus.util') local itemDB = require('core.itemDB') -local Peripheral = require('peripheral') +local Peripheral = require('opus.peripheral') local ChestAdapter = class() diff --git a/core/apis/itemDB.lua b/core/apis/itemDB.lua index 7091854..c8b66f2 100644 --- a/core/apis/itemDB.lua +++ b/core/apis/itemDB.lua @@ -1,7 +1,7 @@ -local Map = require('map') +local Map = require('opus.map') local nameDB = require('core.nameDB') local TableDB = require('core.tableDB') -local Util = require('util') +local Util = require('opus.util') local itemDB = TableDB({ fileName = 'usr/config/items.db' }) diff --git a/core/apis/meAdapter.lua b/core/apis/meAdapter.lua index e2914d1..2e8db49 100644 --- a/core/apis/meAdapter.lua +++ b/core/apis/meAdapter.lua @@ -1,7 +1,7 @@ -local class = require('class') +local class = require('opus.class') local itemDB = require('core.itemDB') -local Peripheral = require('peripheral') -local Util = require('util') +local Peripheral = require('opus.peripheral') +local Util = require('opus.util') local os = _G.os diff --git a/core/apis/meAdapter18.lua b/core/apis/meAdapter18.lua index 0f45776..9f2119a 100644 --- a/core/apis/meAdapter18.lua +++ b/core/apis/meAdapter18.lua @@ -1,7 +1,7 @@ -local class = require('class') +local class = require('opus.class') local RSAdapter = require('core.refinedAdapter') -local Peripheral = require('peripheral') -local Util = require('util') +local Peripheral = require('opus.peripheral') +local Util = require('opus.util') local MEAdapter = class(RSAdapter) diff --git a/core/apis/message.lua b/core/apis/message.lua index afeb26d..272e7e9 100644 --- a/core/apis/message.lua +++ b/core/apis/message.lua @@ -1,4 +1,4 @@ -local Event = require('event') +local Event = require('opus.event') local Message = { } @@ -92,4 +92,4 @@ function Message.waitForMessage(msgType, timeout, fromId) until e == 'timer' and side == timerId end -return Message \ No newline at end of file +return Message diff --git a/core/apis/nameDB.lua b/core/apis/nameDB.lua index 76d0852..784557e 100644 --- a/core/apis/nameDB.lua +++ b/core/apis/nameDB.lua @@ -1,6 +1,6 @@ -local JSON = require('json') +local JSON = require('opus.json') local TableDB = require('core.tableDB') -local Util = require('util') +local Util = require('opus.util') local fs = _G.fs diff --git a/core/apis/proxy.lua b/core/apis/proxy.lua index eb3d819..1e0d894 100644 --- a/core/apis/proxy.lua +++ b/core/apis/proxy.lua @@ -1,4 +1,4 @@ -local Socket = require('socket') +local Socket = require('opus.socket') local Proxy = { } diff --git a/core/apis/refinedAdapter.lua b/core/apis/refinedAdapter.lua index 3f5cead..2f116ca 100644 --- a/core/apis/refinedAdapter.lua +++ b/core/apis/refinedAdapter.lua @@ -1,7 +1,7 @@ -local class = require('class') +local class = require('opus.class') local itemDB = require('core.itemDB') -local Peripheral = require('peripheral') -local Util = require('util') +local Peripheral = require('opus.peripheral') +local Util = require('opus.util') local RefinedAdapter = class() diff --git a/core/apis/swarm.lua b/core/apis/swarm.lua index 1eb7d44..527a07b 100644 --- a/core/apis/swarm.lua +++ b/core/apis/swarm.lua @@ -1,6 +1,6 @@ -local class = require('class') -local Event = require('event') -local Map = require('map') +local class = require('opus.class') +local Event = require('opus.event') +local Map = require('opus.map') local Proxy = require('core.proxy') local Swarm = class() diff --git a/core/apis/tableDB.lua b/core/apis/tableDB.lua index fd059bf..86f665e 100644 --- a/core/apis/tableDB.lua +++ b/core/apis/tableDB.lua @@ -1,5 +1,5 @@ -local class = require('class') -local Util = require('util') +local class = require('opus.class') +local Util = require('opus.util') local TableDB = class() function TableDB:init(args) diff --git a/farms/apis/craft.lua b/farms/apis/craft.lua index 71108e7..48683ce 100644 --- a/farms/apis/craft.lua +++ b/farms/apis/craft.lua @@ -1,5 +1,5 @@ local itemDB = require('core.itemDB') -local Util = require('util') +local Util = require('opus.util') local fs = _G.fs local turtle = _G.turtle diff --git a/farms/apis/level.lua b/farms/apis/level.lua index 05eb8b8..d12e9a6 100644 --- a/farms/apis/level.lua +++ b/farms/apis/level.lua @@ -1,5 +1,5 @@ -local Point = require('point') -local Util = require('util') +local Point = require('opus.point') +local Util = require('opus.util') local turtle = _G.turtle diff --git a/farms/attack.lua b/farms/attack.lua index 0119100..20d4aeb 100644 --- a/farms/attack.lua +++ b/farms/attack.lua @@ -1,6 +1,6 @@ local Equipper = require('turtle.equipper') -local Point = require('point') -local Util = require('util') +local Point = require('opus.point') +local Util = require('opus.util') local os = _G.os local turtle = _G.turtle diff --git a/farms/farmer.lua b/farms/farmer.lua index 86a0716..e0b726d 100644 --- a/farms/farmer.lua +++ b/farms/farmer.lua @@ -1,6 +1,6 @@ local Equipper = require('turtle.equipper') -local Point = require('point') -local Util = require('util') +local Point = require('opus.point') +local Util = require('opus.util') local fs = _G.fs local os = _G.os diff --git a/farms/rancher.lua b/farms/rancher.lua index c29b95b..0104220 100644 --- a/farms/rancher.lua +++ b/farms/rancher.lua @@ -1,7 +1,7 @@ local Adapter = require('core.chestAdapter18') -local Config = require('config') +local Config = require('opus.config') local Equipper = require('turtle.equipper') -local Util = require('util') +local Util = require('opus.util') local fs = _G.fs local os = _G.os diff --git a/farms/spawner.lua b/farms/spawner.lua index 1180553..003e152 100644 --- a/farms/spawner.lua +++ b/farms/spawner.lua @@ -1,6 +1,6 @@ local Equipper = require('turtle.equipper') -local Point = require('point') -local Util = require('util') +local Point = require('opus.point') +local Util = require('opus.util') local fs = _G.fs local os = _G.os diff --git a/farms/superTreefarm.lua b/farms/superTreefarm.lua index 9076a94..ca45395 100644 --- a/farms/superTreefarm.lua +++ b/farms/superTreefarm.lua @@ -1,7 +1,7 @@ local Equipper = require('turtle.equipper') -local GPS = require('gps') -local Point = require('point') -local Util = require('util') +local GPS = require('opus.gps') +local Point = require('opus.point') +local Util = require('opus.util') local fs = _G.fs local os = _G.os diff --git a/farms/treefarm.lua b/farms/treefarm.lua index ecd1b44..543ca64 100644 --- a/farms/treefarm.lua +++ b/farms/treefarm.lua @@ -18,8 +18,8 @@ place the turtle in the original position before restarting the program. ]]-- -local Point = require('point') -local Util = require('util') +local Point = require('opus.point') +local Util = require('opus.util') local fs = _G.fs local os = _G.os diff --git a/forestry/alveary.lua b/forestry/alveary.lua index b25a701..e688f3e 100644 --- a/forestry/alveary.lua +++ b/forestry/alveary.lua @@ -1,7 +1,7 @@ _G.requireInjector(_ENV) -local Event = require('event') -local UI = require('ui') +local Event = require('opus.event') +local UI = require('opus.ui') redstone.setBundledOutput('bottom', 0) diff --git a/forestry/filing.lua b/forestry/filing.lua index 17423fd..e2a0a73 100644 --- a/forestry/filing.lua +++ b/forestry/filing.lua @@ -1,7 +1,7 @@ _G.requireInjector(_ENV) -local Event = require('event') -local Util = require('util') +local Event = require('opus.event') +local Util = require('opus.util') local chest = peripheral.wrap('top') diff --git a/games/ccTunes.lua b/games/ccTunes.lua index 9561fe8..1291c59 100644 --- a/games/ccTunes.lua +++ b/games/ccTunes.lua @@ -1,4 +1,4 @@ -local Sound = require('sound') +local Sound = require('opus.sound') local os = _G.os diff --git a/gps/gpsServer.lua b/gps/gpsServer.lua index 1ee4390..354d0c2 100644 --- a/gps/gpsServer.lua +++ b/gps/gpsServer.lua @@ -1,6 +1,6 @@ -local Config = require('config') -local GPS = require('gps') -local Util = require('util') +local Config = require('opus.config') +local GPS = require('opus.gps') +local Util = require('opus.util') local args = { ... } local colors = _G.colors diff --git a/ignore/glasses.lua b/ignore/glasses.lua index cd8a26f..831d542 100644 --- a/ignore/glasses.lua +++ b/ignore/glasses.lua @@ -1,7 +1,7 @@ -local class = require('class') -local UI = require('ui') -local Event = require('event') -local Peripheral = require('peripheral') +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() diff --git a/ignore/neuralFly.lua b/ignore/neuralFly.lua index af2595c..46b37c6 100644 --- a/ignore/neuralFly.lua +++ b/ignore/neuralFly.lua @@ -1,7 +1,7 @@ _G.requireInjector(_ENV) -local Config = require('config') -local GPS = require('gps') +local Config = require('opus.config') +local GPS = require('opus.gps') local ni = _G.device.neuralInterface local os = _G.os diff --git a/mbs/.package b/mbs/.package new file mode 100644 index 0000000..ed4248d --- /dev/null +++ b/mbs/.package @@ -0,0 +1,11 @@ +{ + title = 'MBS - Mildly Better Shell', + repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/mbs', + description = [[ + A shell alternative and more by SquidDev-CC. See: + https://github.com/SquidDev-CC/mbs + + MBS is a series of utilities for improving the default CraftOS experience. + ]], + licence = 'MIT', +} diff --git a/mbs/autorun/startup.lua b/mbs/autorun/startup.lua new file mode 100644 index 0000000..196668d --- /dev/null +++ b/mbs/autorun/startup.lua @@ -0,0 +1,7 @@ +if not fs.exists('.mbs') then + print('Installing MBS') + shell.run('mbs download') +end +print('Initializing MBS') +shell.run('mbs startup') + diff --git a/mbs/etc/apps.db b/mbs/etc/apps.db new file mode 100644 index 0000000..f3e73b5 --- /dev/null +++ b/mbs/etc/apps.db @@ -0,0 +1,7 @@ +{ + [ "mbs" ] = { + title = "MBS", + category = "Apps", + run = ".mbs/bin/shell.lua", + }, +} diff --git a/mbs/mbs.lua b/mbs/mbs.lua new file mode 100644 index 0000000..8e54a1a --- /dev/null +++ b/mbs/mbs.lua @@ -0,0 +1,260 @@ +local arg = table.pack(...) +local root_dir = ".mbs" +local rom_dir = "rom/.mbs" +local install_dir = fs.exists(root_dir) and root_dir or rom_dir +local repo_url = "https://raw.githubusercontent.com/SquidDev-CC/mbs/master/" + +--- Write a string with the given colour to the terminal +local function write_coloured(colour, text) + local old = term.getTextColour() + term.setTextColour(colour) + io.write(text) + term.setTextColour(old) +end + +--- Print usage for this program +local commands = { "install", "modules", "module", "download" } +local function print_usage() + local name = fs.getName(shell.getRunningProgram()):gsub("%.lua$", "") + write_coloured(colours.cyan, name .. " modules ") io.write("Print the status of all modules\n") + write_coloured(colours.cyan, name .. " module ") io.write("Print information about a given module\n") + write_coloured(colours.cyan, name .. " install ") io.write("Download all modules and create a startup file\n") + write_coloured(colours.cyan, name .. " download ") io.write("Download all modules WITHOUT creating a startup file\n") +end + +--- Attempt to load a module from the given path, returning the module or false +-- and an error message. +local function load_module(path) + if fs.isDir(path) then return false, "Invalid module (is directory)" end + + local fn, err = loadfile(path, _ENV) + if not fn then return false, "Invalid module (" .. err .. ")" end + + local ok, res = pcall(fn) + if not ok then return false, "Invalid module (" .. res .. ")" end + + if type(res) ~= "table" or type(res.description) ~= "string" or type(res.enabled) ~= "function" then + return false, "Malformed module" + end + + return res +end + +--- Setup all modules +local function setup_module(module) + for _, setting in ipairs(module.settings) do + if settings.get(setting.name) == nil then + settings.set(setting.name, setting.default) + end + end +end + +--- Download a set of files +local function download_files(files) + if #files == 0 then return end + + local urls = {} + for _, file in ipairs(files) do + local url = repo_url .. file + http.request(url) + urls[url] = file + end + + while true do + local event, url, arg1 = os.pullEvent() + if event == "http_success" and urls[url] then + local handle = fs.open(fs.combine(root_dir, urls[url]), "w") + handle.write(arg1.readAll()) + handle.close() + arg1.close() + + urls[url] = nil + if next(urls) == nil then return end + elseif event == "http_failure" and urls[url] then + error("Could not download " .. urls[url], 0) + end + end +end + +--- read completion helper, completes text using the given options +local function complete_multi(text, options, add_spaces) + local results = {} + for n = 1, #options do + local option = options[n] + if #option + (add_spaces and 1 or 0) > #text and option:sub(1, #text) == text then + local result = option:sub(#text + 1) + if add_spaces then + results[#results + 1] = result .. " " + else + results[#results + 1] = result + end + end + end + return results +end + +--- Append an object to a list if it is not already contained within +local function add_unique(list, x) + for i = 1, #list do if list[i] == x then return end end + list[#list + 1] = x +end + +local function load_all_modules() + -- Load all modules and update them. + local module_dir = fs.combine(root_dir, "modules") + local modules = fs.isDir(module_dir) and fs.list(module_dir) or {} + + -- Add the default modules if not already there. + for _, module in ipairs { "lua.lua", "pager.lua", "readline.lua", "shell.lua" } do + add_unique(modules, module) + end + + local files = {} + for i = 1, #modules do files[i] = "modules/" .. modules[i] end + download_files(files) + + -- Scan for dependencies in enabled modules, downloading them as well + local deps = {} + for i = 1, #files do + local module = load_module(fs.combine(root_dir, files[i])) + if module then + setup_module(module) + if module.enabled() then + for _, dep in ipairs(module.dependencies) do deps[#deps + 1] = dep end + end + end + end + download_files(deps) +end + +if arg.n == 0 then + printError("Expected some command") + print_usage() + error() +elseif arg[1] == "download" then + load_all_modules() +elseif arg[1] == "install" then + load_all_modules() + + -- Move the existing startup file. We have to read the whole thing, + -- as otherwise we'd end up copying inside ourselves. + if fs.exists("startup") and not fs.isDir("startup") then + write_coloured(colours.cyan, "Moving your existing startup file to startup/30_startup.lua.\n") + + local handle = fs.open("startup", "r") + local contents = handle.readAll() + handle.close() + fs.delete("startup") + + handle = fs.open("startup/30_startup.lua", "w") + handle.write(contents) + handle.close() + end + + -- Also move the startup.lua file afterwards + if fs.exists("startup.lua") and not fs.isDir("startup.lua") then + write_coloured(colours.cyan, "Moving your existing startup.lua file to startup/31_startup.lua.\n") + fs.move("startup.lua", "startup/31_startup.lua") + end + + if fs.exists("startup/99_mbs.lua") then + write_coloured(colours.cyan, "Deleting the old startup/99_mbs.lua file. We now run before other startup files.\n") + fs.delete("startup/99_mbs.lua") + end + + -- We'll run at the first possible position to ensure + local handle = fs.open("startup/00_mbs.lua", "w") + handle.writeLine(("assert(loadfile(%q, _ENV))('startup')"):format(shell.getRunningProgram())) + handle.close() + + write_coloured(colours.green, "Installed! ") + io.write("Please reboot to apply changes.\n") +elseif arg[1] == "startup" then + -- Gather a list of all modules + local module_dir = fs.combine(install_dir, "modules") + local files = fs.isDir(module_dir) and fs.list(module_dir) or {} + + -- Load those modules and determine which are enabled. + local enabled = {} + local module_names = {} + for _, file in ipairs(files) do + local module = load_module(fs.combine(module_dir, file)) + if module then + setup_module(module) + module_names[#module_names + 1] = file:gsub("%.lua$", "") + if module.enabled() then enabled[#enabled + 1] = module end + end + end + + shell.setCompletionFunction(shell.getRunningProgram(), function(_, index, text, previous) + if index == 1 then + return complete_multi(text, commands, true) + elseif index == 2 and previous[#previous] == "module" then + return complete_multi(text, module_names, false) + end + end) + + -- Setup those modules + for _, module in ipairs(enabled) do + if type(module.setup) == "function" then module.setup(install_dir) end + end + + -- And run the startup hook if needed + for _, module in ipairs(enabled) do + --if type(module.startup) == "function" then module.startup(install_dir) end + end + +elseif arg[1] == "modules" then + local module_dir = fs.combine(install_dir, "modules") + local files = fs.isDir(module_dir) and fs.list(module_dir) or {} + local found_any = false + + for _, file in ipairs(files) do + local res, err = load_module(fs.combine(module_dir, file)) + write_coloured(colours.cyan, file:gsub("%.lua$", "") .. " ") + if res then + write(res.description) + if res.enabled() then + write_coloured(colours.green, " (enabled)") + else + write_coloured(colours.red, " (disabled)") + end + found_any = true + else + write_coloured(colours.red, err) + end + + io.write("\n") + end + + if not found_any then error("No modules found. Maybe try running the `install` command?", 0) end +elseif arg[1] == "module" then + if not arg[2] then error("Expected module name", 0) end + local module, err = load_module(fs.combine(install_dir, fs.combine("modules", arg[2] .. ".lua"))) + if not module then error(err, 0) end + + io.write(module.description) + if module.enabled() then + write_coloured(colours.green, " (enabled)") + else + write_coloured(colours.red, " (disabled)") + end + io.write("\n\n") + + for _, setting in ipairs(module.settings) do + local value = settings.get(setting.name) + write_coloured(colours.cyan, setting.name) + io.write(" " .. setting.description .. " (") + write_coloured(colours.yellow, textutils.serialise(value)) + if value ~= setting.default then + io.write(", default is \n") + write_coloured(colours.yellow, textutils.serialise(setting.default)) + end + + io.write(")\n") + end +else + printError("Unknown command") + print_usage() + error() +end diff --git a/milo/MiloLocal.lua b/milo/MiloLocal.lua index 90cc784..2954212 100644 --- a/milo/MiloLocal.lua +++ b/milo/MiloLocal.lua @@ -1,9 +1,9 @@ -local Event = require('event') +local Event = require('opus.event') local Milo = require('milo') -local Sound = require('sound') +local Sound = require('opus.sound') local Storage = require('milo.storage') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local device = _G.device diff --git a/milo/MiloRemote.lua b/milo/MiloRemote.lua index 6cb3bb6..09bb855 100644 --- a/milo/MiloRemote.lua +++ b/milo/MiloRemote.lua @@ -1,11 +1,11 @@ -local Config = require('config') -local Event = require('event') +local Config = require('opus.config') +local Event = require('opus.event') local fuzzy = require('milo.fuzzyMatch') -local Sound = require('sound') -local Socket = require('socket') -local sync = require('sync').sync -local UI = require('ui') -local Util = require('util') +local Sound = require('opus.sound') +local Socket = require('opus.socket') +local sync = require('opus.sync').sync +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local fs = _G.fs diff --git a/milo/apis/craft2.lua b/milo/apis/craft2.lua index 0634f90..2918300 100644 --- a/milo/apis/craft2.lua +++ b/milo/apis/craft2.lua @@ -1,6 +1,6 @@ local itemDB = require('core.itemDB') local Tasks = require('milo.taskRunner') -local Util = require('util') +local Util = require('opus.util') local fs = _G.fs local turtle = _G.turtle diff --git a/milo/apis/init.lua b/milo/apis/init.lua index 46a2696..8bfdb55 100644 --- a/milo/apis/init.lua +++ b/milo/apis/init.lua @@ -1,8 +1,8 @@ -local Config = require('config') +local Config = require('opus.config') local Craft = require('milo.craft2') local itemDB = require('core.itemDB') -local Sound = require('sound') -local Util = require('util') +local Sound = require('opus.sound') +local Util = require('opus.util') local os = _G.os local turtle = _G.turtle diff --git a/milo/apis/massAdapter.lua b/milo/apis/massAdapter.lua index 0534662..f272e4b 100644 --- a/milo/apis/massAdapter.lua +++ b/milo/apis/massAdapter.lua @@ -1,4 +1,4 @@ -local class = require('class') +local class = require('opus.class') local itemDB = require('core.itemDB') local Mini = require('milo.miniAdapter') diff --git a/milo/apis/miniAdapter.lua b/milo/apis/miniAdapter.lua index 34fab70..aaf14f3 100644 --- a/milo/apis/miniAdapter.lua +++ b/milo/apis/miniAdapter.lua @@ -1,6 +1,6 @@ -local class = require('class') +local class = require('opus.class') local itemDB = require('core.itemDB') -local Util = require('util') +local Util = require('opus.util') local device = _G.device diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index 51cf986..e107685 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -1,9 +1,9 @@ local Adapter = require('milo.miniAdapter') -local class = require('class') -local Config = require('config') -local Event = require('event') +local class = require('opus.class') +local Config = require('opus.config') +local Event = require('opus.event') local itemDB = require('core.itemDB') -local Util = require('util') +local Util = require('opus.util') local device = _G.device local os = _G.os diff --git a/milo/apis/taskRunner.lua b/milo/apis/taskRunner.lua index 470493e..ce67751 100644 --- a/milo/apis/taskRunner.lua +++ b/milo/apis/taskRunner.lua @@ -1,4 +1,4 @@ -local class = require('class') +local class = require('opus.class') local os = _G.os diff --git a/milo/apps/brewArray.lua b/milo/apps/brewArray.lua index 06b3fcc..d56187a 100644 --- a/milo/apps/brewArray.lua +++ b/milo/apps/brewArray.lua @@ -19,8 +19,8 @@ CONFIGURATION: Use this turtle for machine crafting. --]] -local Event = require('event') -local Util = require('util') +local Event = require('opus.event') +local Util = require('opus.util') local device = _G.device local fs = _G.fs diff --git a/milo/apps/cobblegen.lua b/milo/apps/cobblegen.lua index 6fe4356..01bc612 100644 --- a/milo/apps/cobblegen.lua +++ b/milo/apps/cobblegen.lua @@ -1,4 +1,4 @@ -local Util = require('util') +local Util = require('opus.util') local fs = _G.fs local os = _G.os diff --git a/milo/apps/enderchest.lua b/milo/apps/enderchest.lua index 308b695..0efd3d5 100644 --- a/milo/apps/enderchest.lua +++ b/milo/apps/enderchest.lua @@ -2,8 +2,8 @@ Send items to a players enderchest. --]] -local Event = require('event') -local Util = require('util') +local Event = require('opus.event') +local Util = require('opus.util') local device = _G.device local fs = _G.fs diff --git a/milo/apps/furni.lua b/milo/apps/furni.lua index 700d02e..e96c608 100644 --- a/milo/apps/furni.lua +++ b/milo/apps/furni.lua @@ -15,8 +15,8 @@ CONFIGURATION: Use this turtle for machine crafting. --]] -local Event = require('event') -local Util = require('util') +local Event = require('opus.event') +local Util = require('opus.util') local device = _G.device local fs = _G.fs diff --git a/milo/apps/storageGen.lua b/milo/apps/storageGen.lua index 2e0cdc2..e2676a5 100644 --- a/milo/apps/storageGen.lua +++ b/milo/apps/storageGen.lua @@ -2,7 +2,7 @@ For initially setting up large amounts of storage chests. ]] -local Util = require('util') +local Util = require('opus.util') local peripheral = _G.peripheral diff --git a/milo/apps/water.lua b/milo/apps/water.lua index fb3ec5f..33a3ee5 100644 --- a/milo/apps/water.lua +++ b/milo/apps/water.lua @@ -1,5 +1,5 @@ -local Sound = require('sound') -local Util = require('util') +local Sound = require('opus.sound') +local Util = require('opus.util') local fs = _G.fs local os = _G.os diff --git a/milo/core/learnWizard.lua b/milo/core/learnWizard.lua index eb0ae16..ee5ff2f 100644 --- a/milo/core/learnWizard.lua +++ b/milo/core/learnWizard.lua @@ -1,5 +1,5 @@ local Milo = require('milo') -local UI = require('ui') +local UI = require('opus.ui') local turtle = _G.turtle diff --git a/milo/core/listing.lua b/milo/core/listing.lua index 898c1f2..c44526e 100644 --- a/milo/core/listing.lua +++ b/milo/core/listing.lua @@ -1,10 +1,10 @@ local Craft = require('milo.craft2') -local Event = require('event') +local Event = require('opus.event') local fuzzy = require('milo.fuzzyMatch') local Milo = require('milo') -local Sound = require('sound') -local UI = require('ui') -local Util = require('util') +local Sound = require('opus.sound') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local context = Milo:getContext() diff --git a/milo/core/machines.lua b/milo/core/machines.lua index 84cab82..a6185e7 100644 --- a/milo/core/machines.lua +++ b/milo/core/machines.lua @@ -1,9 +1,9 @@ -local Event = require('event') +local Event = require('opus.event') local itemDB = require('core.itemDB') -local Map = require('map') +local Map = require('opus.map') local Milo = require('milo') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/activityView.lua b/milo/plugins/activityView.lua index 85b3b97..723d313 100644 --- a/milo/plugins/activityView.lua +++ b/milo/plugins/activityView.lua @@ -1,8 +1,8 @@ -local Ansi = require('ansi') -local Event = require('event') +local Ansi = require('opus.ansi') +local Event = require('opus.event') local Milo = require('milo') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local context = Milo:getContext() diff --git a/milo/plugins/backupView.lua b/milo/plugins/backupView.lua index aff4b1b..f52a00e 100644 --- a/milo/plugins/backupView.lua +++ b/milo/plugins/backupView.lua @@ -1,7 +1,7 @@ -local Ansi = require('ansi') -local Event = require('event') +local Ansi = require('opus.ansi') +local Event = require('opus.event') local Milo = require('milo') -local UI = require('ui') +local UI = require('opus.ui') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/brewingStandView.lua b/milo/plugins/brewingStandView.lua index 8f2d971..88b550a 100644 --- a/milo/plugins/brewingStandView.lua +++ b/milo/plugins/brewingStandView.lua @@ -1,5 +1,5 @@ -local Ansi = require('ansi') -local UI = require('ui') +local Ansi = require('opus.ansi') +local UI = require('opus.ui') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/craftTask.lua b/milo/plugins/craftTask.lua index 8765ab5..1de1a1a 100644 --- a/milo/plugins/craftTask.lua +++ b/milo/plugins/craftTask.lua @@ -1,7 +1,7 @@ local Craft = require('milo.craft2') local Milo = require('milo') -local Sound = require('sound') -local Util = require('util') +local Sound = require('opus.sound') +local Util = require('opus.util') local context = Milo:getContext() @@ -79,4 +79,4 @@ function craftTask:cycle() end end -Milo:registerTask(craftTask) \ No newline at end of file +Milo:registerTask(craftTask) diff --git a/milo/plugins/demandCraft.lua b/milo/plugins/demandCraft.lua index b6942ac..ab0abae 100644 --- a/milo/plugins/demandCraft.lua +++ b/milo/plugins/demandCraft.lua @@ -1,8 +1,8 @@ local Craft = require('milo.craft2') local itemDB = require('core.itemDB') local Milo = require('milo') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors diff --git a/milo/plugins/exportView.lua b/milo/plugins/exportView.lua index caf9a2d..1df574c 100644 --- a/milo/plugins/exportView.lua +++ b/milo/plugins/exportView.lua @@ -1,6 +1,6 @@ local itemDB = require('core.itemDB') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/importView.lua b/milo/plugins/importView.lua index d0572de..396d26c 100644 --- a/milo/plugins/importView.lua +++ b/milo/plugins/importView.lua @@ -1,6 +1,6 @@ local itemDB = require('core.itemDB') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/inputChestView.lua b/milo/plugins/inputChestView.lua index 9defacd..fe0fd9a 100644 --- a/milo/plugins/inputChestView.lua +++ b/milo/plugins/inputChestView.lua @@ -1,5 +1,5 @@ -local Ansi = require('ansi') -local UI = require('ui') +local Ansi = require('opus.ansi') +local UI = require('opus.ui') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/item.lua b/milo/plugins/item.lua index 640bfe8..c6dcd85 100644 --- a/milo/plugins/item.lua +++ b/milo/plugins/item.lua @@ -1,6 +1,6 @@ local Milo = require('milo') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local context = Milo:getContext() diff --git a/milo/plugins/item/infoTab.lua b/milo/plugins/item/infoTab.lua index 5fd3900..7ae99c7 100644 --- a/milo/plugins/item/infoTab.lua +++ b/milo/plugins/item/infoTab.lua @@ -1,5 +1,5 @@ -local Ansi = require('ansi') -local UI = require('ui') +local Ansi = require('opus.ansi') +local UI = require('opus.ui') local colors = _G.colors diff --git a/milo/plugins/item/machinesTab.lua b/milo/plugins/item/machinesTab.lua index b7ef7e3..4ff7e04 100644 --- a/milo/plugins/item/machinesTab.lua +++ b/milo/plugins/item/machinesTab.lua @@ -1,7 +1,7 @@ local Craft = require('milo.craft2') local Milo = require('milo') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local context = Milo:getContext() diff --git a/milo/plugins/item/manageTab.lua b/milo/plugins/item/manageTab.lua index 94bed1e..f7db7b5 100644 --- a/milo/plugins/item/manageTab.lua +++ b/milo/plugins/item/manageTab.lua @@ -1,8 +1,8 @@ local itemDB = require('core.itemDB') -local Map = require('map') +local Map = require('opus.map') local Milo = require('milo') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local context = Milo:getContext() diff --git a/milo/plugins/item/recipeTab.lua b/milo/plugins/item/recipeTab.lua index 458050f..0a08fca 100644 --- a/milo/plugins/item/recipeTab.lua +++ b/milo/plugins/item/recipeTab.lua @@ -1,7 +1,7 @@ local Craft = require('milo.craft2') local itemDB = require('core.itemDB') local Milo = require('milo') -local UI = require('ui') +local UI = require('opus.ui') local colors = _G.colors diff --git a/milo/plugins/item/resetTab.lua b/milo/plugins/item/resetTab.lua index d524747..a0a12ae 100644 --- a/milo/plugins/item/resetTab.lua +++ b/milo/plugins/item/resetTab.lua @@ -1,7 +1,7 @@ local Craft = require('milo.craft2') local Milo = require('milo') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local context = Milo:getContext() diff --git a/milo/plugins/jobMonitor.lua b/milo/plugins/jobMonitor.lua index 98f5cbb..846e279 100644 --- a/milo/plugins/jobMonitor.lua +++ b/milo/plugins/jobMonitor.lua @@ -1,10 +1,10 @@ local Craft = require('milo.craft2') -local Event = require('event') +local Event = require('opus.event') local itemDB = require('core.itemDB') local Milo = require('milo') -local Sound = require('sound') -local UI = require('ui') -local Util = require('util') +local Sound = require('opus.sound') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local context = Milo:getContext() @@ -87,11 +87,11 @@ local function createPage(node) { heading = 'Qty', key = 'remaining', width = 4 }, { heading = 'Crafting', key = 'displayName', }, { heading = 'Status', key = 'status', }, - { heading = 'need', key = 'need', width = 4 }, + -- { heading = 'need', key = 'need', width = 4 }, -- { heading = 'total', key = 'total', width = 4 }, -- { heading = 'used', key = 'used', width = 4 }, -- { heading = 'count', key = 'count', width = 4 }, - { heading = 'crafted', key = 'crafted', width = 5 }, + -- { heading = 'crafted', key = 'crafted', width = 5 }, -- { heading = 'Progress', key = 'progress', width = 8 }, }, headerBackgroundColor = colors.black, diff --git a/milo/plugins/machineLearn.lua b/milo/plugins/machineLearn.lua index c2fd19c..76e5069 100644 --- a/milo/plugins/machineLearn.lua +++ b/milo/plugins/machineLearn.lua @@ -1,7 +1,7 @@ local itemDB = require('core.itemDB') local Milo = require('milo') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/machineMover.lua b/milo/plugins/machineMover.lua index 57f5527..fd3cec9 100644 --- a/milo/plugins/machineMover.lua +++ b/milo/plugins/machineMover.lua @@ -1,7 +1,7 @@ local Craft = require('milo.craft2') local Milo = require('milo') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local context = Milo:getContext() diff --git a/milo/plugins/massStorageView.lua b/milo/plugins/massStorageView.lua index ca701af..e198b3e 100644 --- a/milo/plugins/massStorageView.lua +++ b/milo/plugins/massStorageView.lua @@ -1,5 +1,5 @@ -local Ansi = require('ansi') -local UI = require('ui') +local Ansi = require('opus.ansi') +local UI = require('opus.ui') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/remote.lua b/milo/plugins/remote.lua index 4fe0e13..ff1b929 100644 --- a/milo/plugins/remote.lua +++ b/milo/plugins/remote.lua @@ -1,7 +1,7 @@ -local Event = require('event') +local Event = require('opus.event') local itemDB = require('core.itemDB') local Milo = require('milo') -local Socket = require('socket') +local Socket = require('opus.socket') local device = _G.device diff --git a/milo/plugins/remote/autostore.lua b/milo/plugins/remote/autostore.lua index bbc45b7..0c7272b 100644 --- a/milo/plugins/remote/autostore.lua +++ b/milo/plugins/remote/autostore.lua @@ -1,7 +1,7 @@ local itemDB = require('core.itemDB') -local Event = require('event') -local UI = require('ui') -local Util = require('util') +local Event = require('opus.event') +local UI = require('opus.ui') +local Util = require('opus.util') local args = { ... } local colors = _G.colors diff --git a/milo/plugins/remote/craft.lua b/milo/plugins/remote/craft.lua index 68e14e5..5731495 100644 --- a/milo/plugins/remote/craft.lua +++ b/milo/plugins/remote/craft.lua @@ -1,4 +1,4 @@ -local Sound = require('sound') +local Sound = require('opus.sound') local args = { ... } local context = args[1] diff --git a/milo/plugins/remote/deposit.lua b/milo/plugins/remote/deposit.lua index 1be3e09..21fba74 100644 --- a/milo/plugins/remote/deposit.lua +++ b/milo/plugins/remote/deposit.lua @@ -1,4 +1,4 @@ -local Event = require('event') +local Event = require('opus.event') local device = _G.device local os = _G.os diff --git a/milo/plugins/remote/depositAll.lua b/milo/plugins/remote/depositAll.lua index fe76df6..e3fcba4 100644 --- a/milo/plugins/remote/depositAll.lua +++ b/milo/plugins/remote/depositAll.lua @@ -1,5 +1,5 @@ -local Config = require('config') -local UI = require('ui') +local Config = require('opus.config') +local UI = require('opus.ui') local itemDB = require('core.itemDB') local args = { ... } diff --git a/milo/plugins/remote/feeder.lua b/milo/plugins/remote/feeder.lua index 3d5353d..36ed597 100644 --- a/milo/plugins/remote/feeder.lua +++ b/milo/plugins/remote/feeder.lua @@ -1,7 +1,7 @@ local itemDB = require('core.itemDB') -local Event = require('event') -local Sound = require('sound') -local UI = require('ui') +local Event = require('opus.event') +local Sound = require('opus.sound') +local UI = require('opus.ui') local args = { ... } local colors = _G.colors diff --git a/milo/plugins/remote/setup.lua b/milo/plugins/remote/setup.lua index c8ff101..10dfd7c 100644 --- a/milo/plugins/remote/setup.lua +++ b/milo/plugins/remote/setup.lua @@ -1,6 +1,6 @@ -local Config = require('config') -local UI = require('ui') -local Util = require('util') +local Config = require('opus.config') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local fs = _G.fs diff --git a/milo/plugins/speakerView.lua b/milo/plugins/speakerView.lua index c790358..e637d74 100644 --- a/milo/plugins/speakerView.lua +++ b/milo/plugins/speakerView.lua @@ -1,6 +1,6 @@ local Milo = require('milo') -local Sound = require('sound') -local UI = require('ui') +local Sound = require('opus.sound') +local UI = require('opus.ui') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/statsView.lua b/milo/plugins/statsView.lua index f2db0b7..9d34d5a 100644 --- a/milo/plugins/statsView.lua +++ b/milo/plugins/statsView.lua @@ -1,8 +1,8 @@ -local Ansi = require('ansi') -local Event = require('event') +local Ansi = require('opus.ansi') +local Event = require('opus.event') local Milo = require('milo') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local context = Milo:getContext() diff --git a/milo/plugins/storageView.lua b/milo/plugins/storageView.lua index 6b5c9c5..50a6788 100644 --- a/milo/plugins/storageView.lua +++ b/milo/plugins/storageView.lua @@ -1,5 +1,5 @@ local itemDB = require('core.itemDB') -local UI = require('ui') +local UI = require('opus.ui') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/transferView.lua b/milo/plugins/transferView.lua index 343e528..36101da 100644 --- a/milo/plugins/transferView.lua +++ b/milo/plugins/transferView.lua @@ -1,8 +1,8 @@ -local Ansi = require('ansi') +local Ansi = require('opus.ansi') local Milo = require('milo') local Tasks = require('milo.taskRunner') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/trashcanView.lua b/milo/plugins/trashcanView.lua index 34a85df..2de4a4e 100644 --- a/milo/plugins/trashcanView.lua +++ b/milo/plugins/trashcanView.lua @@ -1,6 +1,6 @@ local Milo = require('milo') local Tasks = require('milo.taskRunner') -local UI = require('ui') +local UI = require('opus.ui') local colors = _G.colors local device = _G.device diff --git a/milo/plugins/turtleLearn.lua b/milo/plugins/turtleLearn.lua index 4212e83..43c6125 100644 --- a/milo/plugins/turtleLearn.lua +++ b/milo/plugins/turtleLearn.lua @@ -1,6 +1,6 @@ local itemDB = require('core.itemDB') local Milo = require('milo') -local UI = require('ui') +local UI = require('opus.ui') local colors = _G.colors local turtle = _G.turtle diff --git a/miners/findSwarm.lua b/miners/findSwarm.lua index bb6b756..89e8790 100644 --- a/miners/findSwarm.lua +++ b/miners/findSwarm.lua @@ -1,9 +1,9 @@ -local Event = require('event') -local GPS = require('gps') -local Point = require('point') -local Sound = require('sound') +local Event = require('opus.event') +local GPS = require('opus.gps') +local Point = require('opus.point') +local Sound = require('opus.sound') local Swarm = require('core.swarm') -local Util = require('util') +local Util = require('opus.util') local os = _G.os local peripheral = _G.peripheral diff --git a/miners/scanningMiner.lua b/miners/scanningMiner.lua index b588c23..fa73f16 100644 --- a/miners/scanningMiner.lua +++ b/miners/scanningMiner.lua @@ -9,12 +9,12 @@ Plethora scanner Bucket --]] -local Event = require('event') +local Event = require('opus.event') local Equipper = require('turtle.equipper') -local GPS = require('gps') -local Point = require('point') -local UI = require('ui') -local Util = require('util') +local GPS = require('opus.gps') +local Point = require('opus.point') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local fs = _G.fs diff --git a/miners/simpleMiner.lua b/miners/simpleMiner.lua index 2985b1c..afd7c14 100644 --- a/miners/simpleMiner.lua +++ b/miners/simpleMiner.lua @@ -1,6 +1,6 @@ -local Pathing = require('pathfind') -local Point = require('point') -local Util = require('util') +local Pathing = require('opus.pathfind') +local Point = require('opus.point') +local Util = require('opus.util') local fs = _G.fs local read = _G.read diff --git a/monitor/mirror.lua b/monitor/mirror.lua index edf26f3..eafa8c7 100644 --- a/monitor/mirror.lua +++ b/monitor/mirror.lua @@ -1,5 +1,5 @@ -local Terminal = require('terminal') -local Util = require('util') +local Terminal = require('opus.terminal') +local Util = require('opus.util') local device = _G.device local os = _G.os diff --git a/monitor/mirrorClient.lua b/monitor/mirrorClient.lua index 5f5acb0..e1a76ae 100644 --- a/monitor/mirrorClient.lua +++ b/monitor/mirrorClient.lua @@ -1,6 +1,6 @@ -local Event = require('event') -local Socket = require('socket') -local Util = require('util') +local Event = require('opus.event') +local Socket = require('opus.socket') +local Util = require('opus.util') local multishell = _ENV.multishell local os = _G.os diff --git a/monitor/mirrorHost.lua b/monitor/mirrorHost.lua index f06dad6..e1caf47 100644 --- a/monitor/mirrorHost.lua +++ b/monitor/mirrorHost.lua @@ -1,5 +1,5 @@ -local Event = require('event') -local Socket = require('socket') +local Event = require('opus.event') +local Socket = require('opus.socket') local colors = _G.colors local term = _G.term diff --git a/monitor/mwm.lua b/monitor/mwm.lua index 49c36f0..8ad3ef1 100644 --- a/monitor/mwm.lua +++ b/monitor/mwm.lua @@ -1,12 +1,6 @@ -if not _G.requireInjector then - local BASE ='https://raw.githubusercontent.com/kepler155c/opus/develop-1.8/sys/apis' - _ENV.LUA_PATH=BASE .. '/?.lua' - load(_G.http.get(BASE .. '/injector.lua').readAll())()(_ENV) -end - -local Terminal = require('terminal') -local trace = require('trace') -local Util = require('util') +local Terminal = require('opus.terminal') +local trace = require('opus.trace') +local Util = require('opus.util') local colors = _G.colors local os = _G.os diff --git a/neural/Scanner.lua b/neural/Scanner.lua index c9fba35..041783c 100644 --- a/neural/Scanner.lua +++ b/neural/Scanner.lua @@ -1,7 +1,7 @@ -local Event = require('event') +local Event = require('opus.event') local itemDB = require('core.itemDB') -local UI = require('ui') -local Util = require('util') +local UI = require('opus.ui') +local Util = require('opus.util') local device = _G.device local gps = _G.gps @@ -215,4 +215,4 @@ UI:pullEvents() if canvas then canvas:clear() -end \ No newline at end of file +end diff --git a/neural/Sensor.lua b/neural/Sensor.lua index 4e67671..ec50092 100644 --- a/neural/Sensor.lua +++ b/neural/Sensor.lua @@ -1,7 +1,7 @@ -local Config = require('config') -local Event = require('event') -local UI = require('ui') -local Util = require('util') +local Config = require('opus.config') +local Event = require('opus.event') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local device = _G.device diff --git a/neural/autorun/interface.lua b/neural/autorun/interface.lua index 0a94eb0..26239cb 100644 --- a/neural/autorun/interface.lua +++ b/neural/autorun/interface.lua @@ -1,4 +1,4 @@ -local GPS = require('gps') +local GPS = require('opus.gps') local device = _G.device diff --git a/neural/autorun/splash.lua b/neural/autorun/splash.lua index 2ce8cc2..b74f722 100644 --- a/neural/autorun/splash.lua +++ b/neural/autorun/splash.lua @@ -34,7 +34,7 @@ local hex = { local function update() local canvas = device['plethora:glasses'] and device['plethora:glasses'].canvas() if canvas then - local Tween = require('ui.tween') + local Tween = require('opus.ui.tween') canvas.clear() local w, h = canvas.getSize() diff --git a/neural/elytraFly.lua b/neural/elytraFly.lua index 253375f..eb171ff 100644 --- a/neural/elytraFly.lua +++ b/neural/elytraFly.lua @@ -1,7 +1,7 @@ -- original concept: osmarks https://pastebin.com/xEDKdM85 -local Sound = require('sound') -local Util = require('util') +local Sound = require('opus.sound') +local Util = require('opus.util') local fs = _G.fs local modules = _G.peripheral.wrap('back') diff --git a/neural/mobFollow.lua b/neural/mobFollow.lua index 6163c56..5f2da19 100644 --- a/neural/mobFollow.lua +++ b/neural/mobFollow.lua @@ -1,6 +1,6 @@ -local GPS = require('gps') -local Util = require('util') -local Point = require('point') +local GPS = require('opus.gps') +local Util = require('opus.util') +local Point = require('opus.point') local Proxy = require('core.proxy') local os = _G.os diff --git a/neural/mobPickup.lua b/neural/mobPickup.lua index ca9248c..66e9023 100644 --- a/neural/mobPickup.lua +++ b/neural/mobPickup.lua @@ -4,9 +4,9 @@ ]] local neural = require('neural.interface') -local Point = require('point') -local Sound = require('sound') -local Util = require('util') +local Point = require('opus.point') +local Sound = require('opus.sound') +local Util = require('opus.util') local os = _G.os diff --git a/neural/mobRancher.lua b/neural/mobRancher.lua index 5ba8deb..83c58d2 100644 --- a/neural/mobRancher.lua +++ b/neural/mobRancher.lua @@ -4,8 +4,8 @@ ]] local neural = require('neural.interface') -local Sound = require('sound') -local Map = require('map') +local Sound = require('opus.sound') +local Map = require('opus.map') local os = _G.os diff --git a/neural/neuralLook.lua b/neural/neuralLook.lua index fb27c50..9a35c78 100644 --- a/neural/neuralLook.lua +++ b/neural/neuralLook.lua @@ -1,6 +1,6 @@ -local Array = require('array') +local Array = require('opus.array') local neural = require('neural.interface') -local Point = require('point') +local Point = require('opus.point') local os = _G.os diff --git a/neural/neuralRecorder.lua b/neural/neuralRecorder.lua index 10f8ea3..b1484f6 100644 --- a/neural/neuralRecorder.lua +++ b/neural/neuralRecorder.lua @@ -1,6 +1,6 @@ -local GPS = require('gps') -local Point = require('point') -local Util = require('util') +local GPS = require('opus.gps') +local Point = require('opus.point') +local Util = require('opus.util') local os = _G.os local parallel = _G.parallel diff --git a/neural/neuralReplay.lua b/neural/neuralReplay.lua index a796df4..543ff39 100644 --- a/neural/neuralReplay.lua +++ b/neural/neuralReplay.lua @@ -1,5 +1,5 @@ -local GPS = require('gps') -local Util = require('util') +local GPS = require('opus.gps') +local Util = require('opus.util') local os = _G.os local peripheral = _G.peripheral diff --git a/neural/shootingGallery.lua b/neural/shootingGallery.lua index 1cd1115..9f21b91 100644 --- a/neural/shootingGallery.lua +++ b/neural/shootingGallery.lua @@ -1,6 +1,6 @@ local Angle = require('neural.angle') local Mobs = require('neural.mobs') -local Point = require('point') +local Point = require('opus.point') local device = _G.device local os = _G.os diff --git a/pickup/pickup.lua b/pickup/pickup.lua index 63df6be..afdf90c 100644 --- a/pickup/pickup.lua +++ b/pickup/pickup.lua @@ -1,8 +1,8 @@ -local Event = require('event') +local Event = require('opus.event') local ChestAdapter = require('core.chestAdapter18') -local Point = require('point') -local Socket = require('socket') -local Util = require('util') +local Point = require('opus.point') +local Socket = require('opus.socket') +local Util = require('opus.util') local device = _G.device local os = _G.os diff --git a/pickup/pickupRemote.lua b/pickup/pickupRemote.lua index e6b3320..c00dbdd 100644 --- a/pickup/pickupRemote.lua +++ b/pickup/pickupRemote.lua @@ -7,11 +7,11 @@ if not device.wireless_modem then error('Wireless modem is required') end -local Event = require('event') -local GPS = require('gps') -local Socket = require('socket') -local UI = require('ui') -local Util = require('util') +local Event = require('opus.event') +local GPS = require('opus.gps') +local Socket = require('opus.socket') +local UI = require('opus.ui') +local Util = require('opus.util') multishell.setTitle(multishell.getCurrent(), 'Pickup Remote') diff --git a/recipeBook/recipeBook.lua b/recipeBook/recipeBook.lua index d929a9b..fc0b719 100644 --- a/recipeBook/recipeBook.lua +++ b/recipeBook/recipeBook.lua @@ -1,6 +1,6 @@ -local Ansi = require('ansi') -local UI = require('ui') -local Util = require('util') +local Ansi = require('opus.ansi') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local fs = _G.fs diff --git a/shellex/apis/shell.lua b/shellex/apis/shell.lua index 23a4bb2..bc36096 100644 --- a/shellex/apis/shell.lua +++ b/shellex/apis/shell.lua @@ -1,4 +1,4 @@ -local Util = require('util') +local Util = require('opus.util') local shell = _ENV.shell diff --git a/shellex/ls.lua b/shellex/ls.lua index 8c86d61..3e3c990 100644 --- a/shellex/ls.lua +++ b/shellex/ls.lua @@ -380,7 +380,7 @@ for _,dir in ipairs(dirsArg) do end end -io.output():setvbuf("line") +--io.output():setvbuf("line") local ok, msg = pcall(function() if #file_set > 0 then display(sort(file_set)) end @@ -389,7 +389,7 @@ local ok, msg = pcall(function() end) io.output():flush() -io.output():setvbuf("no") +--io.output():setvbuf("no") set_color() if not ok then diff --git a/storage/.package b/storage/.package deleted file mode 100644 index 1327c20..0000000 --- a/storage/.package +++ /dev/null @@ -1,9 +0,0 @@ -{ - required = { - 'core', - }, - title = 'Manage inventory', - repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/storage', - description = [[Storage manager for Minecraft 1.7 (Use Milo for new versions)]], - licence = 'MIT', -} diff --git a/storage/Crafter.lua b/storage/Crafter.lua deleted file mode 100644 index ea44de5..0000000 --- a/storage/Crafter.lua +++ /dev/null @@ -1,1127 +0,0 @@ ---[[ - Turtle/machine crafting. - - Requirements: - Turtle must be restricted forward and back by some obstacle. - The turtle must have access to the main inventory at the most forward location. - Machines must be placed above or below the line along the turtle's backwards travel. - - Optional: - Monitors can be placed touching the turtle at the most forward position to - display crafting status. - - Sample setups: - M = machine, I = inventory, O = obstacle, T = turtle - - Turtle facing <--- - - MMMM - IT O - MMM - - IMMMM - O O - MMMMMM -]]-- - -local InventoryAdapter = require('core.inventoryAdapter') -local Config = require('config') -local Event = require('event') -local itemDB = require('core.itemDB') -local Peripheral = require('peripheral') -local UI = require('ui') -local Terminal = require('terminal') -local Util = require('util') - -local colors = _G.colors -local os = _G.os -local term = _G.term -local turtle = _G.turtle - -local config = { - computerFacing = 'north', - inventorySide = 'front', - monitor = 'type/monitor', -} -Config.load('crafter', config) - -repeat until not turtle.forward() - -local inventoryAdapter = InventoryAdapter.wrap({ - side = config.inventorySide, - facing = config.computerFacing -}) -if not inventoryAdapter then - error('Invalid inventory configuration') -end - -local RESOURCE_FILE = 'usr/config/resources.db' -local RECIPES_FILE = 'usr/config/recipes2.db' -local MACHINES_FILE = 'usr/config/machines.db' - -local STATUS_ERROR = 'error' -local STATUS_INFO = 'info' -local STATUS_SUCCESS = 'success' -local STATUS_WARNING = 'warning' - -local recipes = Util.readTable(RECIPES_FILE) or { } -local resources -local machines = { } -local jobListGrid -local listing, docked = false, false - -local function getItem(items, inItem, ignoreDamage, ignoreNbtHash) - for _,item in pairs(items) do - if item.name == inItem.name and - (ignoreDamage or item.damage == inItem.damage) and - (ignoreNbtHash or item.nbtHash == inItem.nbtHash) then - return item - end - end -end - -local function uniqueKey(item) - return table.concat({ item.name, item.damage, item.nbtHash }, ':') -end - -local function getItemQuantity(items, res) - local count = 0 - for _,v in pairs(items) do - if res.name == v.name and - ((not res.damage and v.maxDamage > 0) or res.damage == v.damage) and - ((not res.nbtHash and v.nbtHash) or res.nbtHash == v.nbtHash) then - count = count + v.count - end - end - return count -end - -local function mergeResources(t) - for _,v in pairs(resources) do - local item = getItem(t, v) - if item then - Util.merge(item, v) - else - item = Util.shallowCopy(v) - item.count = 0 - table.insert(t, item) - end - end - - for k in pairs(recipes) do - local v = itemDB:splitKey(k) - local item = getItem(t, v) - if not item then - item = Util.shallowCopy(v) - item.count = 0 - table.insert(t, item) - end - item.has_recipe = true - end - - for _,v in pairs(t) do - if not v.displayName then - v.displayName = itemDB:getName(v) - end - v.lname = v.displayName:lower() - end -end - -local function filterItems(t, filter) - if filter then - local r = {} - filter = filter:lower() - for _,v in pairs(t) do - if string.find(v.lname, filter) then - table.insert(r, v) - end - end - return r - end - return t -end - -local function clearGrid() - for i = 1, 16 do - local count = turtle.getItemCount(i) - if count > 0 then - inventoryAdapter:insert(i, count) - if turtle.getItemCount(i) ~= 0 then - return false - end - end - end - return true -end - -local function undock() - while listing do - os.sleep(.5) - end - docked = false -end - -local function gotoMachine(machine) - undock() - for _ = 1, machine.index do - if not turtle.back() then - return - end - end - - return true -end - -local function dock() - if not docked then - repeat until not turtle.forward() - end - docked = true -end - -local function getItems() - while not docked do - os.sleep(.5) - end - - listing = true - - local items - for _ = 1, 5 do - items = inventoryAdapter:listItems() - if items then - break - end - end - if not items then - error('could not check inventory') - end - - listing = false - - return items -end - -local function isMachineEmpty(machine, item) - local list = { true } - - pcall(function() -- fails randomly in 1.7x - local side = turtle.getAction(machine.dir).side - local methods = Util.transpose(Peripheral.getMethods(side)) - - if methods.getAllStacks then -- 1.7x - list = Peripheral.call(side, 'getAllStacks', false) - elseif methods.list then - list = Peripheral.call(side, 'list') - elseif methods.getProgress then - if Peripheral.call(side, 'getProgress') == 0 then - return true - end - else - item.statusCode = STATUS_ERROR - item.status = 'Unable to check empty status' - return - end - - if tonumber(machine.ignoreSlot) then - list[tonumber(machine.ignoreSlot)] = nil - end - end) - - if Util.empty(list) then - return true - end - item.statusCode = STATUS_INFO - item.status = 'machine busy' -end - -local function craftItem(ikey, item, items, machineStatus) - dock() - - local resource = resources[ikey] - if not resource or not resource.machine then - item.statusCode = STATUS_ERROR - item.status = 'machine not defined' - return - end - - local machine = Util.find(machines, 'order', resource.machine) - if not machine then - item.statusCode = STATUS_ERROR - item.status = 'invalid machine' - return - end - - local ms = machineStatus[machine.order] - if not ms then - ms = { count = 0 } - machineStatus[machine.order] = ms - end - - local slot = 1 - local maxCount = math.ceil(item.need / item.recipe.count) - maxCount = math.min(machine.maxCount or 64, maxCount) - - if maxCount > 0 and maxCount - ms.count <= 0 then - item.statusCode = STATUS_INFO - item.status = 'machine busy' - return - end - - maxCount = maxCount - ms.count - - for key,qty in pairs(item.recipe.ingredients) do - local ingredient = itemDB:get(key) - local c = math.min(maxCount * qty, getItemQuantity(items, ingredient)) - c = math.min(c, ingredient.maxCount) - c = math.floor(c / qty) - if c < maxCount then - maxCount = c - end - if maxCount <= 0 then - item.status = 'Missing ' .. ingredient.displayName - item.statusCode = STATUS_WARNING - return - end - end - - if machine.maxCount then - ms.count = ms.count + maxCount - end - - turtle.setStatus('Craft: ' .. itemDB:getName(ikey)) - for key,qty in pairs(item.recipe.ingredients) do - local ingredient = itemDB:get(key) --- local c = item.craftable * qty --- while c > 0 do - inventoryAdapter:provide(ingredient, maxCount * qty, slot) - if turtle.getItemCount(slot) ~= maxCount * qty then - item.status = 'Extract failed: ' .. (ingredient.displayName or itemDB:getName(ingredient)) - item.statusCode = STATUS_ERROR - return - end --- c = c - maxCount - slot = slot + 1 - --end - end - - if not gotoMachine(machine) then - item.status = 'failed to find machine' - item.statusCode = STATUS_ERROR - else - if machine.empty and not isMachineEmpty(machine, item) then - return - end - - if machine.dir == 'up' then - turtle.emptyInventory(turtle.dropUp) - else - turtle.emptyInventory(turtle.dropDown) - end - if #turtle.getFilledSlots() ~= 0 then - item.statusCode = STATUS_INFO - item.status = 'machine busy' - else - item.statusCode = STATUS_SUCCESS - item.status = 'crafting' - end - end -end - -local function expandList(list, items) - local summed = { } - - local function sumItems(key, count) - local item = itemDB:splitKey(key) - local summedItem = summed[key] - if not summedItem then - summedItem = Util.shallowCopy(item) - summedItem.recipe = recipes[key] - summedItem.count = getItemQuantity(items, item) - summedItem.displayName = itemDB:getName(item) - summedItem.total = 0 - summedItem.need = 0 - summedItem.used = 0 - summedItem.craftable = 0 - summed[key] = summedItem - end - local total = count - local used = math.min(summedItem.count, total) - local need = total - used - - summedItem.total = summedItem.total + total - summedItem.count = summedItem.count - used - summedItem.used = summedItem.used + used - summedItem.need = summedItem.need + need - - if need > 0 and summedItem.recipe then - need = math.ceil(need / summedItem.recipe.count) - for ikey,iqty in pairs(summedItem.recipe.ingredients) do - sumItems(ikey, math.ceil(need * iqty)) - end - end - end - - for key, item in pairs(list) do - sumItems(key, item.count) - end - - return Util.filter(summed, function(a) return a.need > 0 end) -end - -local function watchResources(items) - local craftList = { } - - for _,res in pairs(resources) do - if res.low then - local item = Util.shallowCopy(res) - item.nbtHash = res.nbtHash - item.damage = res.damage - if res.ignoreDamage then - item.damage = nil - end - item.count = getItemQuantity(items, item) - if item.count < res.low then - item.displayName = itemDB:getName(res) - item.count = res.low -- - item.count - craftList[uniqueKey(res)] = item - end - end - end - - return craftList -end - -local function craftItems() - local machineStatus = { } - local items = getItems() - local craftList = watchResources(items) - local list = expandList(craftList, items) - jobListGrid:setValues(list) - jobListGrid:update() - jobListGrid:draw() - jobListGrid:sync() - for key, item in pairs(list) do - if item.need > 0 and item.recipe then - craftItem(key, item, items, machineStatus) - dock() - items = getItems() - clearGrid() - elseif item.need > 0 then - item.status = 'no recipe' - item.statusCode = STATUS_ERROR - end - jobListGrid:update() - jobListGrid:draw() - jobListGrid:sync() - end - turtle.setStatus('idle') -end - -local function loadResources() - resources = Util.readTable(RESOURCE_FILE) or { } - for k,v in pairs(resources) do - Util.merge(v, itemDB:splitKey(k)) - end -end - -local function saveResources() - local t = { } - - for k,v in pairs(resources) do - v = Util.shallowCopy(v) - - v.name = nil - v.damage = nil - v.nbtHash = nil - t[k] = v - end - - Util.writeTable(RESOURCE_FILE, t) -end - -local function findMachines() - turtle.setStatus('Inspecting machines') - - dock() - - local function getName(dir) - local side = turtle.getAction(dir).side - if Peripheral.isPresent(side) then - local methods = Util.transpose(Peripheral.getMethods(side)) - if methods.getMetadata then - local name = Peripheral.call(side, 'getMetadata').displayName - if name and not string.find(name, '.', 1, true) then - return name - end - elseif methods.getInventoryName then -- 1.7x - return Peripheral.call(side, 'getInventoryName') - end - return Peripheral.getType(side) - end - local _, machine = turtle.getAction(dir).inspect() - if not machine or type(machine) ~= 'table' then - return 'Unknown' - end - return machine.name or 'Unknown' - end - - local index = 0 - - local function getMachine(dir) - local name = getName(dir) - table.insert(machines, { - name = name, - rawName = name, - index = index, - dir = dir, - order = #machines + 1 - }) - end - - repeat - getMachine('down') - getMachine('up') - index = index + 1 - undock() - until not turtle.back() - - local mf = Util.readTable(MACHINES_FILE) or { } - for _,m in pairs(machines) do - local m2 = Util.find(mf, 'order', m.order) - if m2 then - if not m2.rawName then - m2.rawName = m.rawName - end - if m.rawName == m2.rawName then - m.name = m2.name or m.name - end - m.empty = m2.empty - m.ignore = m2.ignore - m.ignoreSlot = m2.ignoreSlot - m.maxCount = m2.maxCount - end - end -end - -local function jobMonitor() - local mon = Peripheral.lookup(config.monitor) - - if mon then - mon = UI.Device({ - device = mon, - textScale = .5, - }) - else - mon = UI.Device({ - device = Terminal.getNullTerm(term.current()) - }) - end - - jobListGrid = UI.Grid({ - parent = mon, - sortColumn = 'displayName', - columns = { - { heading = 'Qty', key = 'need', width = 6 }, - { heading = 'Crafting', key = 'displayName', width = (mon.width - 18) / 2 }, - { heading = 'Status', key = 'status', }, - }, - }) - - function jobListGrid:getRowTextColor(row, selected) - if row.statusCode == STATUS_ERROR then - return colors.red - elseif row.statusCode == STATUS_WARNING then - return colors.yellow - elseif row.statusCode == STATUS_SUCCESS then - return colors.lime - end - - return UI.Grid:getRowTextColor(row, selected) - end - - jobListGrid:draw() - jobListGrid:sync() -end - -local itemPage = UI.Page { - titleBar = UI.TitleBar { - title = 'Limit Resource', - previousPage = true, - event = 'form_cancel', - }, - form = UI.Form { - x = 1, y = 2, height = 10, ex = -1, - [1] = UI.TextEntry { - width = 7, - formLabel = 'Min', formKey = 'low', help = 'Craft if below min' - }, - [2] = UI.Chooser { - width = 7, - formLabel = 'Ignore Dmg', formKey = 'ignoreDamage', - nochoice = 'No', - choices = { - { name = 'Yes', value = true }, - { name = 'No', value = false }, - }, - help = 'Ignore damage of item' - }, - [3] = UI.Button { - text = 'Select', event= 'selectMachine', - formLabel = 'Machine' - }, - info = UI.TextArea { - x = 2, ex = -2, y = 6, height = 3, - textColor = colors.gray, - }, - button = UI.Button { - x = 2, y = 9, - text = 'Recipe', event = 'learn', - }, - }, - machines = UI.SlideOut { - backgroundColor = colors.cyan, - titleBar = UI.TitleBar { - title = 'Select Machine', - previousPage = true, - }, - grid = UI.ScrollingGrid { - y = 2, ey = -4, - values = machines, - disableHeader = true, - columns = { - { heading = '', key = 'index', width = 2 }, - { heading = 'Name', key = 'name'}, - }, - sortColumn = 'order', - }, - button1 = UI.Button { - x = -14, y = -2, - text = 'Ok', event = 'setMachine', - }, - button2 = UI.Button { - x = -9, y = -2, - text = 'Cancel', event = 'cancelMachine', - }, - }, - statusBar = UI.StatusBar { } -} - -function itemPage:enable(item) - if item then - self.item = Util.shallowCopy(item) - self.form:setValues(item) - self.titleBar.title = item.displayName or item.name - end - UI.Page.enable(self) - self:focusFirst() -end - -function itemPage.form.info:draw() - local recipe = recipes[uniqueKey(itemPage.item)] - self.value = '' - if recipe and itemPage.item.machine then - self.value = string.format('Crafts %d using the %s machine', - recipe.count, - machines[itemPage.item.machine].name) - end - UI.TextArea.draw(self) -end - -function itemPage.machines.grid:getRowTextColor(row, selected) - if itemPage.item.machine == row.order then - return colors.yellow - end - return UI.Grid:getRowTextColor(row, selected) -end - ---[[ -function itemPage.machines:eventHandler(event) - if event.type == 'grid_focus_row' then - self.statusBar:setStatus(string.format('%d %s', event.selected.index, event.selected.dir)) - else - return UI.SlideOut.eventHandler(self, event) - end - return true -end -]] - -function itemPage:eventHandler(event) - if event.type == 'form_cancel' then - UI:setPreviousPage() - - elseif event.type == 'learn' then - UI:setPage('learn', self.item) - - elseif event.type == 'setMachine' then - self.item.machine = self.machines.grid:getSelected().order - self.machines:hide() - - elseif event.type == 'cancelMachine' then - self.machines:hide() - - elseif event.type == 'selectMachine' then - local machineCopy = Util.shallowCopy(machines) - Util.filterInplace(machineCopy, function(m) return not m.ignore end) - self.machines.grid:setValues(machineCopy) - if self.item.machine then - local _, index = Util.find(machineCopy, 'order', self.item.machine) - if index then - self.machines.grid:setIndex(index) - end - else - self.machines.grid:setIndex(1) - end - self.machines:show() - - elseif event.type == 'focus_change' then - self.statusBar:setStatus(event.focused.help) - self.statusBar:draw() - - elseif event.type == 'form_complete' then - local values = self.form.values - local keys = { 'name', 'low', 'damage', 'nbtHash', 'machine' } - - local filtered = { } - for _,key in pairs(keys) do - filtered[key] = values[key] - end - filtered.low = tonumber(filtered.low) - filtered.machine = self.item.machine - - if values.ignoreDamage == true then - filtered.damage = 0 - filtered.ignoreDamage = true - end - - local key = uniqueKey(filtered) - - resources[key] = filtered - saveResources() - - UI:setPreviousPage() - - else - return UI.Page.eventHandler(self, event) - end - return true -end - -local learnPage = UI.Page { - ingredients = UI.ScrollingGrid { - y = 2, height = 3, - disableHeader = true, - columns = { - { heading = 'Name', key = 'displayName', width = 31 }, - { heading = 'Qty', key = 'count' , width = 5 }, - }, - sortColumn = 'displayName', - }, - grid = UI.ScrollingGrid { - y = 6, height = 5, - disableHeader = true, - columns = { - { heading = 'Name', key = 'displayName', width = 31 }, - { heading = 'Qty', key = 'count' , width = 5 }, - }, - sortColumn = 'displayName', - }, - filter = UI.TextEntry { - x = 20, ex = -2, y = 5, - limit = 50, - shadowText = 'filter', - backgroundColor = colors.lightGray, - backgroundFocusColor = colors.lightGray, - }, - count = UI.TextEntry { - x = 11, y = -1, width = 5, - limit = 50, - }, - button1 = UI.Button { - x = -14, y = -1, - text = 'Ok', event = 'accept', - }, - button2 = UI.Button { - x = -9, y = -1, - text = 'Cancel', event = 'cancel', - }, -} - -function learnPage:enable(target) - self.target = target - self.allItems = getItems() - mergeResources(self.allItems) - - self.filter.value = '' - self.grid.values = self.allItems - self.grid:update() - self.ingredients.values = { } - self.count.value = 1 - - if target.has_recipe then - local recipe = recipes[uniqueKey(target)] - self.count.value = recipe.count - for k,v in pairs(recipe.ingredients) do - self.ingredients.values[k] = - { name = k, count = v, displayName = itemDB:getName(k) } - end - end - self.ingredients:update() - - self:setFocus(self.filter) - UI.Page.enable(self) -end - -function learnPage:draw() - UI.Window.draw(self) - self:write(2, 1, 'Ingredients', nil, colors.yellow) - self:write(2, 5, 'Inventory', nil, colors.yellow) - self:write(2, 12, 'Produces') -end - -function learnPage:eventHandler(event) - - if event.type == 'text_change' and event.element == self.filter then - local t = filterItems(learnPage.allItems, event.text) - self.grid:setValues(t) - self.grid:draw() - - elseif event.type == 'cancel' then - UI:setPreviousPage() - - elseif event.type == 'accept' then - - local recipe = { - count = tonumber(self.count.value) or 1, - ingredients = { }, - } - for key, item in pairs(self.ingredients.values) do - recipe.ingredients[key] = item.count - end - recipes[uniqueKey(self.target)] = recipe - Util.writeTable(RECIPES_FILE, recipes) - - UI:setPreviousPage() - - elseif event.type == 'grid_select' then - if event.element == self.grid then - local key = uniqueKey(event.selected) - if not self.ingredients.values[key] then - self.ingredients.values[key] = Util.shallowCopy(event.selected) - self.ingredients.values[key].count = 0 - end - self.ingredients.values[key].count = self.ingredients.values[key].count + 1 - self.ingredients:update() - self.ingredients:draw() - elseif event.element == self.ingredients then - event.selected.count = event.selected.count - 1 - if event.selected.count == 0 then - self.ingredients.values[uniqueKey(event.selected)] = nil - self.ingredients:update() - end - self.ingredients:draw() - end - - else - return UI.Page.eventHandler(self, event) - end - return true -end - -local machinesPage = UI.Page { - titleBar = UI.TitleBar { - previousPage = true, - title = 'Machines', - }, - grid = UI.ScrollingGrid { - y = 2, ey = -2, - values = machines, - columns = { - { heading = 'Name', key = 'name' }, - { heading = 'Side', key = 'dir', width = 5 }, - { heading = 'Index', key = 'index', width = 5 }, - }, - sortColumn = 'order', - }, - detail = UI.SlideOut { - backgroundColor = colors.cyan, - form = UI.Form { - x = 1, y = 2, ex = -1, ey = -2, - [1] = UI.TextEntry { - formLabel = 'Name', formKey = 'name', help = '...', - limit = 64, - }, - [2] = UI.Chooser { - width = 7, - formLabel = 'Hidden', formKey = 'ignore', - nochoice = 'No', - choices = { - { name = 'Yes', value = true }, - { name = 'No', value = false }, - }, - help = 'Do not show this machine' - }, - [3] = UI.Chooser { - width = 7, - formLabel = 'Empty', formKey = 'empty', - nochoice = 'No', - choices = { - { name = 'Yes', value = true }, - { name = 'No', value = false }, - }, - help = 'Check if machine is empty before crafting' - }, - [4] = UI.TextEntry { - formLabel = 'Ignore Slot', formKey = 'ignoreSlot', help = '...', - limit = 4, - }, - [5] = UI.TextEntry { - formLabel = 'Max Craft', formKey = 'maxCount', help = '...', - limit = 4, - }, - }, - statusBar = UI.StatusBar(), - }, - statusBar = UI.StatusBar { - values = 'Select Machine', - }, - accelerators = { - h = 'toggle_hidden', - } -} - -function machinesPage:enable() - self.grid:update() - UI.Page.enable(self) -end - -function machinesPage.detail:eventHandler(event) - if event.type == 'focus_change' then - self.statusBar:setStatus(event.focused.help) - end - return UI.SlideOut.eventHandler(self, event) -end - -function machinesPage.grid:getRowTextColor(row, selected) - if row.ignore then - return colors.yellow - end - return UI.Grid:getRowTextColor(row, selected) -end - -function machinesPage:eventHandler(event) - if event.type == 'grid_select' then - self.detail.form:setValues(event.selected) - self.detail:show() - - elseif event.type == 'toggle_hidden' then - local selected = self.grid:getSelected() - if selected then - selected.ignore = not selected.ignore - Util.writeTable(MACHINES_FILE, machines) - self:draw() - end - - elseif event.type == 'form_complete' then - self.detail.form.values.empty = self.detail.form.values.empty == true - self.detail.form.values.ignore = self.detail.form.values.ignore == true - self.detail.form.values.ignoreSlot = tonumber(self.detail.form.values.ignoreSlot) - self.detail.form.values.maxCount = tonumber(self.detail.form.values.maxCount) - Util.writeTable(MACHINES_FILE, machines) - self.detail:hide() - - elseif event.type == 'form_cancel' then - self.detail:hide() - - else - UI.Page.eventHandler(self, event) - end - return true -end - -local listingPage = UI.Page { - menuBar = UI.MenuBar { - buttons = { - { text = 'Forget', event = 'forget' }, - { text = 'Machines', event = 'machines' }, - { text = 'Refresh', event = 'refresh', x = -9 }, - }, - }, - grid = UI.Grid { - y = 2, height = UI.term.height - 2, - columns = { - { heading = 'Name', key = 'displayName' }, - { heading = 'Qty', key = 'count' , width = 5 }, - { heading = 'Min', key = 'low' , width = 4 }, - }, - sortColumn = 'displayName', - }, - statusBar = UI.Window { - y = -1, - filter = UI.TextEntry { - limit = 50, - shadowText = 'filter', - shadowTextColor = colors.lightGray, - backgroundColor = colors.gray, - backgroundFocusColor = colors.gray, - }, - }, - accelerators = { - r = 'refresh', - q = 'quit', - } -} - -function listingPage.grid:getRowTextColor(row, selected) - if row.is_craftable then - return colors.yellow - end - if row.has_recipe then - return colors.cyan - end - return UI.Grid:getRowTextColor(row, selected) -end - -function listingPage.grid:getDisplayValues(row) - row = Util.shallowCopy(row) - row.count = Util.toBytes(row.count) - if row.low then - row.low = Util.toBytes(row.low) - end - return row -end - -function listingPage.statusBar.filter:eventHandler(event) - if event.type == 'mouse_rightclick' then - self.value = '' - self:draw() - local page = UI:getCurrentPage() - page.filter = nil - page:applyFilter() - page.grid:draw() - page:setFocus(self) - end - return UI.TextEntry.eventHandler(self, event) -end - -function listingPage:eventHandler(event) - if event.type == 'quit' then - UI:exitPullEvents() - - elseif event.type == 'grid_select' then - local selected = event.selected - UI:setPage('item', selected) - - elseif event.type == 'refresh' then - self:refresh() - self.grid:draw() - self.statusBar.filter:focus() - - elseif event.type == 'machines' then - UI:setPage('machines') - - elseif event.type == 'craft' then - UI:setPage('craft', self.grid:getSelected()) - - elseif event.type == 'forget' then - local item = self.grid:getSelected() - if item then - local key = uniqueKey(item) - - if recipes[key] then - recipes[key] = nil - Util.writeTable(RECIPES_FILE, recipes) - end - - if resources[key] then - resources[key] = nil - Util.writeTable(RESOURCE_FILE, resources) - end - - self.statusBar:timedStatus('Forgot: ' .. item.name, 3) - self:refresh() - self.grid:draw() - end - - elseif event.type == 'text_change' then - self.filter = event.text - if #self.filter == 0 then - self.filter = nil - end - self:applyFilter() - self.grid:draw() - self.statusBar.filter:focus() - - else - UI.Page.eventHandler(self, event) - end - return true -end - -function listingPage:enable() - self:refresh() - self:setFocus(self.statusBar.filter) - UI.Page.enable(self) -end - -function listingPage:refresh() - self.allItems = getItems() - mergeResources(self.allItems) - self:applyFilter() -end - -function listingPage:applyFilter() - local t = filterItems(self.allItems, self.filter) - self.grid:setValues(t) -end - --- randomly errors in 1.7x with "you are not attached to this computer" -print('Inspecting machines') -local retryCount = 0 -while true do - Util.clear(machines) - local s, m = pcall(findMachines) - if not s and m then - _G.printError(m) - else - break - end - retryCount = retryCount + 1 - if retryCount > 3 then - error(m) - end - print('retrying...') -end - -loadResources() -dock() -clearGrid() -jobMonitor() - -UI:setPages({ - listing = listingPage, - machines = machinesPage, - item = itemPage, - learn = learnPage, -}) - -UI:setPage(listingPage) -listingPage:setFocus(listingPage.statusBar.filter) - -Event.on('turtle_abort', function() - UI:exitPullEvents() -end) - -Event.onInterval(30, function() - dock() - if turtle.getFuelLevel() < 100 then - turtle.select(1) - inventoryAdapter:provide({ name = 'minecraft:coal', damage = 1 }, 16, 1) - turtle.refuel() - end - craftItems() -end) - -turtle.setStatus('idle') -UI:pullEvents() -jobListGrid.parent:reset() diff --git a/storage/apis/controllerAdapter.lua b/storage/apis/controllerAdapter.lua deleted file mode 100644 index 73bcb97..0000000 --- a/storage/apis/controllerAdapter.lua +++ /dev/null @@ -1,18 +0,0 @@ -local Adapter = { } - -function Adapter.wrap(args) - local adapters = { - 'core.refinedAdapter', - 'core.meAdapter', - } - - for _,adapterType in ipairs(adapters) do - local adapter = require(adapterType)(args) - - if adapter:isValid() then - return adapter - end - end -end - -return Adapter diff --git a/storage/apis/craft.lua b/storage/apis/craft.lua deleted file mode 100644 index 388b0bc..0000000 --- a/storage/apis/craft.lua +++ /dev/null @@ -1,320 +0,0 @@ -local itemDB = require('core.itemDB') -local Util = require('util') - -local fs = _G.fs -local turtle = _G.turtle - -local RECIPES_DIR = 'packages/core/etc/recipes' -local USER_RECIPES = 'usr/config/recipes.db' - -local Craft = { } - -local function clearGrid(inventoryAdapter) - for i = 1, 16 do - local count = turtle.getItemCount(i) - if count > 0 then - inventoryAdapter:insert(i, count) - if turtle.getItemCount(i) ~= 0 then - -- inventory is possibly full - return false - end - end - end - return true -end - -local function splitKey(key) - local t = Util.split(key, '(.-):') - local item = { } - 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 - -function Craft.getItemCount(items, item) - if type(item) == 'string' then - item = splitKey(item) - end - - local count = 0 - for _,v in pairs(items) do - if v.name == item.name and - (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 - return count -end - -local function turtleCraft(recipe, qty, inventoryAdapter) - if not clearGrid(inventoryAdapter) then - return false - end - - for k,v in pairs(recipe.ingredients) do - local item = splitKey(v) - local provideQty = qty - --[[ - Turtles can only craft 1 item at a time when using a tool. - - if recipe.craftingTools and recipe.craftingTools[k] then - provideQty = 1 - end - ]]-- - inventoryAdapter:provide(item, provideQty, k) - if turtle.getItemCount(k) == 0 then -- ~= qty then - -- FIX: ingredients cannot be stacked ---_G._syslog('failed ' .. v .. ' - ' .. provideQty) - return false - end - end - - return turtle.craft() -end - -function Craft.loadRecipes() - Craft.recipes = { } - - Util.merge(Craft.recipes, (Util.readTable(fs.combine(RECIPES_DIR, 'minecraft.db')) or { }).recipes) - - local config = Util.readTable('usr/config/recipeBooks.db') or { } - for _, book in pairs(config) do - local recipeFile = Util.readTable(book) - Util.merge(Craft.recipes, recipeFile.recipes) - end - - local recipes = Util.readTable(USER_RECIPES) or { } - Util.merge(Craft.recipes, recipes) -end - -function Craft.sumIngredients(recipe) - -- produces { ['minecraft:planks:0'] = 8 } - local t = { } - for _,item in pairs(recipe.ingredients) do - t[item] = (t[item] or 0) + 1 - end --- need a check for crafting tool - return t -end - -function Craft.craftRecipe(recipe, count, inventoryAdapter) - if type(recipe) == 'string' then - recipe = Craft.recipes[recipe] - if not recipe then - return 0, 'No recipe' - end - end - - local items = inventoryAdapter:listItems() - if not items then - return 0, 'Inventory changed' - end - - count = math.ceil(count / recipe.count) - local maxCount = recipe.maxCount or math.floor(64 / recipe.count) - - for key,icount in pairs(Craft.sumIngredients(recipe)) do - local itemCount = Craft.getItemCount(items, key) - local need = icount * count - if recipe.craftingTools and recipe.craftingTools[key] then - need = 1 - end - maxCount = math.min(maxCount, itemDB:getMaxCount(key)) - if itemCount < need then - local irecipe = Craft.findRecipe(key) - if irecipe then - local iqty = need - itemCount - local crafted = Craft.craftRecipe(irecipe, iqty, inventoryAdapter) - if crafted ~= iqty then - turtle.select(1) - return 0 - end - end - end - end - - local crafted = 0 - repeat - if not turtleCraft(recipe, math.min(count, maxCount), inventoryAdapter) then - turtle.select(1) - break - end - crafted = crafted + math.min(count, maxCount) - count = count - maxCount - until count <= 0 - - clearGrid(inventoryAdapter) - turtle.select(1) - return crafted * recipe.count -end - -local function makeRecipeKey(item) - if type(item) == 'string' then - item = splitKey(item) - end - return table.concat({ item.name, item.damage or 0, item.nbtHash }, ':') -end - -function Craft.findRecipe(key) - if type(key) ~= 'string' then - key = itemDB:makeKey(key) - end - - local item = itemDB:splitKey(key) - 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 --- a quantity of a recipe. -function Craft.getResourceList(inRecipe, items, inCount) - local summed = { } - - local function sumItems(recipe, key, count) - local item = itemDB:splitKey(key) - local summedItem = summed[key] - if not summedItem then - summedItem = Util.shallowCopy(item) - summedItem.recipe = Craft.findRecipe(key) - summedItem.count = Craft.getItemCount(items, item) - summedItem.displayName = itemDB:getName(item) - summedItem.total = 0 - summedItem.need = 0 - summedItem.used = 0 - summed[key] = summedItem - end - local total = count - local used = math.min(summedItem.count, total) - local need = total - used - - if recipe.craftingTools and recipe.craftingTools[key] then - summedItem.total = 1 - if summedItem.count > 0 then - summedItem.used = 1 - summedItem.need = 0 - need = 0 - elseif not summedItem.recipe then - summedItem.need = 1 - need = 1 - else - need = 1 - end - else - summedItem.total = summedItem.total + total - summedItem.count = summedItem.count - used - summedItem.used = summedItem.used + used - if not summedItem.recipe then - summedItem.need = summedItem.need + need - end - end - - if need > 0 and summedItem.recipe then - need = math.ceil(need / summedItem.recipe.count) - for ikey,iqty in pairs(Craft.sumIngredients(summedItem.recipe)) do - sumItems(summedItem.recipe, ikey, math.ceil(need * iqty)) - end - end - end - - inCount = math.ceil(inCount / inRecipe.count) - for ikey,iqty in pairs(Craft.sumIngredients(inRecipe)) do - sumItems(inRecipe, ikey, math.ceil(inCount * iqty)) - end - - return summed -end - -function Craft.getResourceList4(inRecipe, items, count) - local summed = Craft.getResourceList(inRecipe, items, count) --- filter down to just raw materials - return Util.filter(summed, function(a) return a.used > 0 or a.need > 0 end) -end - --- given a certain quantity, return how many of those can be crafted -function Craft.getCraftableAmount(inRecipe, count, items, missing) - local function sumItems(recipe, summedItems, count) - local canCraft = 0 - - for _ = 1, count do - for _,item in pairs(recipe.ingredients) do - local summedItem = summedItems[item] or Craft.getItemCount(items, item) - - local irecipe = Craft.findRecipe(item) - if irecipe and summedItem <= 0 then - summedItem = summedItem + sumItems(irecipe, summedItems, 1) - end - if summedItem <= 0 then - if missing and not irecipe then - missing.name = item - end - return canCraft - end - if not recipe.craftingTools or not recipe.craftingTools[item] then - summedItems[item] = summedItem - 1 - end - end - canCraft = canCraft + recipe.count - end - - return canCraft - end - - return sumItems(inRecipe, { }, math.ceil(count / inRecipe.count)) -end - -function Craft.canCraft(item, count, items) - return Craft.getCraftableAmount(Craft.recipes[item], count, items) == count -end - -function Craft.setRecipes(recipes) - Craft.recipes = recipes -end - -function Craft.getCraftableAmountTest() - local results = { } - Craft.setRecipes(Util.readTable('usr/etc/recipes.db')) - - local items = { - { name = 'minecraft:planks', damage = 0, count = 5 }, - { name = 'minecraft:log', damage = 0, count = 2 }, - } - results[1] = { item = 'chest', expected = 1, - got = Craft.getCraftableAmount(Craft.recipes['minecraft:chest:0'], 2, items) } - - items = { - { name = 'minecraft:log', damage = 0, count = 1 }, - { name = 'minecraft:coal', damage = 1, count = 1 }, - } - results[2] = { item = 'torch', expected = 4, - got = Craft.getCraftableAmount(Craft.recipes['minecraft:torch:0'], 4, items) } - - return results -end - -function Craft.craftRecipeTest(name, count) - local ChestAdapter = require('core.chestAdapter18') - local chestAdapter = ChestAdapter({ wrapSide = 'top', direction = 'down' }) - Craft.setRecipes(Util.readTable('usr/etc/recipes.db')) - return { Craft.craftRecipe(Craft.recipes[name], count, chestAdapter) } -end - -Craft.loadRecipes() - -return Craft diff --git a/storage/chestManager.lua b/storage/chestManager.lua deleted file mode 100644 index 8b082d2..0000000 --- a/storage/chestManager.lua +++ /dev/null @@ -1,1504 +0,0 @@ ---[[ - Provides: autocrafting, resource limits, on-demand crafting, storage stocker. - - Using a turtle allows for crafting of items eliminating the need for AE/RS - molecular assemblers / crafters. - - Inventory setup: - Turtle/computer must be touching at least one type of inventory - - Generic inventory block such as: - Vanilla chest - RFTools modular storage - Storage drawers controller - and many others... - - Applied energistics - AE cable or interface (depending upon AE/MC version) - - Refined storage - TODO: add required block - - Turtle crafting (optional): - 1. The turtle must have a crafting table equipped. - 2. Requires a vanilla chest beside the turtle with the "craftingChest" - configuration variable defined. - -- or -- - If using MC 1.7x, you can equip the turtle with a duck antenna and - set the duckAntenna configuration value to true. - -- or -- - If plethora mod is available, equip the turtle with an introspection - module. - - Controller (optional): - Provides the ability to request crafting from AE / RS - - Applied Energistics - In versions 1.7x, AE can be used for both inventory access and crafting - requests. - - In versions 1.8+, AE can only be used to request crafting. - - Refined Storage - In versions 1.8x, inventory access works depending upon version. - - Turtle/computer must be touching an interface for inventory access. If only - requesting crafting, the controller must be either be touching or connected - via CC cables. - - Restocking (optional): - If using a limited inventory block, such as RFTools modular storage, you - can have the main inventory automatically replenish items from the restocking - inventory. Each cycle, the restocking inventory will be checked and if the - main inventory has less than a stack of an item, it will pull that item - from the restocking inventory into the main inventory. - - Configuration: - Configuration file is usr/config/inventoryManager - - valid sides: - top, bottom, left, right, front, back - - valid directions: - up, down, north, south, east, west - - Required: - computerFacing : direction turtle is facing - inventory : side for the main inventory (can be the same as the controller) - - Optional: - craftingChest : side for the chest used for crafting - controller : side for AE cable/interface or RS controller - stock : side for restocking inventory - duckAntenna : true/false if the 1.7 openperipherals duck antenna is equipped - trashDirection : direction of trash block (trashcan/inventory/etc) in - relationship to the main inventory. This block does not - need to touch the turtle, only the main inventory block. - monitor : valid options include: - type/monitor - will use the first monitor found - side/north - specify a direction (top/bottom/east/etc) - name/monitor_1 - specify the exact name of the peripheral -]]-- - -local Ansi = require('ansi') -local Config = require('config') -local Craft = require('storage.craft') -local Event = require('event') -local itemDB = require('core.itemDB') -local Peripheral = require('peripheral') -local Terminal = require('terminal') -local UI = require('ui') -local Util = require('util') - -local ControllerAdapter = require('controllerAdapter') -local InventoryAdapter = require('core.inventoryAdapter') - -local colors = _G.colors -local device = _G.device -local multishell = _ENV.multishell -local os = _G.os -local term = _G.term -local turtle = _G.turtle - -if multishell then - multishell.setTitle(multishell.getCurrent(), 'Resource Manager') -end - -local config = { - computerFacing = 'north', -- direction turtle is facing - - inventory = 'top', -- main inventory - craftingChest = 'bottom', -- required in 1.8+ for crafting - duckAntenna = false, - controller = 'none', -- AE / RS controller - stock = 'none', -- another inventory for restocking main inventory - - trashDirection = 'up', -- trash/chest in relation to inventory - monitor = 'type/monitor', -} - -Config.loadWithCheck('inventoryManager', config) - ---local controllerAdapter = ControllerAdapter.wrap({ side = config.controller, facing = config.computerFacing }) -local inventoryAdapter = InventoryAdapter.wrap({ side = config.inventory, facing = config.computerFacing }) -local stockAdapter = InventoryAdapter.wrap({ side = config.stock, facing = config.computerFacing }) -local turtleChestAdapter = InventoryAdapter.wrap({ side = config.craftingChest, facing = config.computerFacing }) -local modem = device.modem -local introspectionModule = device['plethora:introspection'] -local duckAntenna - -if not inventoryAdapter then - error('Invalid inventory configuration') -end - -local controllerAdapter -if inventoryAdapter.craft then - controllerAdapter = inventoryAdapter -end - -if device.workbench and config.duckAntenna then - local oppositeSide = { - [ 'left' ] = 'right', - [ 'right' ] = 'left', - } - local duckAntennaSide = oppositeSide[device.workbench.side] - duckAntenna = Peripheral.wrap(duckAntennaSide) - if duckAntenna and not duckAntenna.getAllStacks then - duckAntenna = nil - end -end - -local STATUS_INFO = 'info' -local STATUS_WARNING = 'warning' -local STATUS_ERROR = 'error' - -local RESOURCE_FILE = 'usr/config/resources.db' -local RECIPES_FILE = 'usr/config/recipes.db' - -local craftingPaused = false -local canCraft = not not (turtle and turtle.craft) -local canLearn = not not (canCraft and (duckAntenna or turtleChestAdapter or introspectionModule)) -local userRecipes = Util.readTable(RECIPES_FILE) or { } -local jobList -local resources -local demandCrafting = { } - -local function getItem(items, inItem, ignoreDamage, ignoreNbtHash) - for _,item in pairs(items) do - if item.name == inItem.name and - (ignoreDamage or item.damage == inItem.damage) and - (ignoreNbtHash or item.nbtHash == inItem.nbtHash) then - return item - end - end -end - -local function uniqueKey(item) - return table.concat({ item.name, item.damage, item.nbtHash }, ':') -end - -local function mergeResources(t) - for _,v in pairs(resources) do - local item = getItem(t, v) - if item then - Util.merge(item, v) - else - item = Util.shallowCopy(v) - item.count = 0 - table.insert(t, item) - end - end - - for k in pairs(Craft.recipes) do - local v = itemDB:splitKey(k) - local item = getItem(t, v) - if not item then - item = Util.shallowCopy(v) - item.count = 0 - table.insert(t, item) - end - item.has_recipe = true - end - - for _,v in pairs(t) do - if not v.displayName then - v.displayName = itemDB:getName(v) - end - v.lname = v.displayName:lower() - end -end - -local function listItems() - local items - for _ = 1, 5 do - items = inventoryAdapter:listItems() - if items then - break - end - jobList:showError('Error - retrying in 3 seconds') - os.sleep(3) - end - if not items then --- error('could not check inventory') -term.clear() -jobList:showError('Error - rebooting in 5 seconds') -print('Communication failure') -print('rebooting in 5 secs') -os.sleep(5) -os.reboot() - end - - return items -end - -local function filterItems(t, filter, displayMode) - if filter or displayMode > 0 then - local r = { } - if filter then - filter = filter:lower() - end - for _,v in pairs(t) do - if not filter or string.find(v.lname, filter, 1, true) then - if not displayMode or - displayMode == 0 or - displayMode == 1 and v.count > 0 or - displayMode == 2 and v.has_recipe then - table.insert(r, v) - end - end - end - return r - end - return t -end - -local function clearGrid() - local function clear() - for i = 1, 16 do - local count = turtle.getItemCount(i) - if count > 0 then - inventoryAdapter:insert(i, count) - if turtle.getItemCount(i) ~= 0 then - return false - end - end - end - return true - end - return clear() or clear() -end - -local function addCraftingRequest(item, craftList, count) - local key = uniqueKey(item) - local request = craftList[key] - if not craftList[key] then - request = { name = item.name, damage = item.damage, nbtHash = item.nbtHash, count = 0 } - request.displayName = itemDB:getName(request) - craftList[key] = request - end - request.count = request.count + count - return request -end - --- Craft -local function craftItem(recipe, items, originalItem, craftList, count) - local missing = { } - local toCraft = Craft.getCraftableAmount(recipe, count, items, missing) - if missing.name then - originalItem.status = string.format('%s missing', itemDB:getName(missing.name)) - originalItem.statusCode = STATUS_WARNING - end - - local crafted = 0 - - if toCraft > 0 then - crafted = Craft.craftRecipe(recipe, toCraft, inventoryAdapter) - clearGrid() - items = listItems() - count = count - crafted - end - - if count > 0 and items then - local ingredients = Craft.getResourceList4(recipe, items, count) - for _,ingredient in pairs(ingredients) do - if ingredient.need > 0 then - local item = addCraftingRequest(ingredient, craftList, ingredient.need) - if Craft.findRecipe(item) then - item.status = string.format('%s missing', itemDB:getName(ingredient)) - item.statusCode = STATUS_WARNING - else - item.status = 'no recipe' - item.statusCode = STATUS_ERROR - end - end - end - end - return crafted -end - --- Craft as much as possible regardless if all ingredients are available -local function forceCraftItem(inRecipe, items, originalItem, craftList, inCount) - local summed = { } - local throttle = Util.throttle() - - local function sumItems(recipe, count) - count = math.ceil(count / recipe.count) - local craftable = count - - for key,iqty in pairs(Craft.sumIngredients(recipe)) do - throttle() - local item = itemDB:splitKey(key) - local summedItem = summed[key] - if not summedItem then - summedItem = Util.shallowCopy(item) - summedItem.recipe = Craft.findRecipe(item) - summedItem.count = Craft.getItemCount(items, key) - summedItem.need = 0 - summedItem.used = 0 - summedItem.craftable = 0 - summed[key] = summedItem - end - - local total = count * iqty -- 4 * 2 - local used = math.min(summedItem.count, total) -- 5 - local need = total - used -- 3 - - if recipe.craftingTools and recipe.craftingTools[key] then - if summedItem.count > 0 then - summedItem.used = 1 - summedItem.need = 0 - need = 0 - elseif not summedItem.recipe then - summedItem.need = 1 - need = 1 - else - need = 1 - end - else - summedItem.count = summedItem.count - used - summedItem.used = summedItem.used + used - end - - if need > 0 then - if not summedItem.recipe then - craftable = math.min(craftable, math.floor(used / iqty)) - summedItem.need = summedItem.need + need - else - local c = sumItems(summedItem.recipe, need) -- 4 - craftable = math.min(craftable, math.floor((used + c) / iqty)) - summedItem.craftable = summedItem.craftable + c - end - end - end - if craftable > 0 then - craftable = Craft.craftRecipe(recipe, craftable * recipe.count, inventoryAdapter) / recipe.count - clearGrid() - end - - return craftable * recipe.count - end - - local count = sumItems(inRecipe, inCount) - - if count < inCount then - for _,ingredient in pairs(summed) do - if ingredient.need > 0 then - local item = addCraftingRequest(ingredient, craftList, ingredient.need) - if Craft.findRecipe(item) then - item.status = string.format('%s missing', itemDB:getName(ingredient)) - item.statusCode = STATUS_WARNING - else - item.status = '(no recipe)' - item.statusCode = STATUS_ERROR - end - end - end - end - return count -end - -local function craft(recipe, items, item, craftList) - item.status = nil - item.statusCode = nil - item.crafted = 0 - - if craftingPaused or not canCraft then - return - end - - if not clearGrid() then - item.status = 'Grid obstructed' - item.statusCode = STATUS_ERROR - return - end - - if item.forceCrafting then - item.crafted = forceCraftItem(recipe, items, item, craftList, item.count) - else - item.crafted = craftItem(recipe, items, item, craftList, item.count) - end -end - -local function craftItems(craftList, allItems) - -- turtle crafting - if canCraft then - for _,key in pairs(Util.keys(craftList)) do - local item = craftList[key] - local recipe = Craft.recipes[key] - if recipe then - craft(recipe, allItems, item, craftList) - allItems = listItems() -- refresh counts - if not allItems then - break - end - elseif not controllerAdapter then - item.status = '(no recipe)' - item.statusCode = STATUS_ERROR - end - end - end - - -- redstone control - for _,item in pairs(craftList) do - if item.rsControl then - item.status = '(activated)' - item.statusCode = STATUS_INFO - end - end - - -- controller - if controllerAdapter then - for key,item in pairs(craftList) do - if (not canCraft or not Craft.recipes[key]) and not item.rsControl then - if controllerAdapter:isCrafting(item) then - item.status = '(crafting)' - item.statusCode = STATUS_INFO - elseif not controllerAdapter:isCPUAvailable() then - item.status = '(waiting)' - item.statusCode = STATUS_WARNING - else - local count = item.count - item.crafted = 0 - while count >= 1 do -- try to request smaller quantities until successful - local s = pcall(function() - item.status = '(no recipe)' - item.statusCode = STATUS_ERROR - if not controllerAdapter:craft(item, count) then - item.status = '(missing ingredients)' - item.statusCode = STATUS_WARNING - error('failed') - end - item.status = '(crafting)' - item.statusCode = STATUS_INFO - item.crafted = count - end) - if s then - break -- successfully requested crafting - end - count = math.floor(count / 2) - end - end - end - end - end - - -- remote processing ---[[ - if modem then - for key,item in pairs(craftList) do - if not Craft.recipes[key] and item.crafted < item.count then - modem.transmit(205, 0, item) - end - end - end ---]] - - if not controllerAdapter and not canCraft then - for _,item in pairs(craftList) do - if not item.rsControl then - item.status = 'Invalid setup' - item.statusCode = STATUS_INFO - end - end - end -end - -local function restock() - if turtle and stockAdapter then - local items = inventoryAdapter:listItems() - local stock = stockAdapter:listItems() - - if items and stock then - for _,v in pairs(stock) do - local count = Craft.getItemCount(items, v) - if count < v.maxCount then - stockAdapter:provide(v, v.maxCount - count) - clearGrid() - end - end - end - end -end - -local function eject(item, qty) - if _G.turtle then - local s, m = pcall(function() - inventoryAdapter:provide(item, qty) - _G.turtle.emptyInventory() - end) - end -end - -local function jobMonitor() - local mon = Peripheral.lookup(config.monitor) - - if mon then - mon = UI.Device({ - device = mon, - textScale = .5, - }) - else - mon = UI.Device({ - device = Terminal.getNullTerm(term.current()) - }) - end - - jobList = UI.Page { - parent = mon, - grid = UI.Grid { - sortColumn = 'displayName', - backgroundFocusColor = colors.black, - columns = { - { heading = 'Qty', key = 'count', width = 6 }, - { heading = 'Crafting', key = 'displayName', width = mon.width / 2 - 10 }, - { heading = 'Status', key = 'status', width = mon.width - 10 }, - }, - }, - } - - function jobList:showError(msg) - self.grid:clear() - self.grid:centeredWrite(math.ceil(self.grid.height / 2), msg) - self:sync() - end - - function jobList:updateList(craftList) - self.grid:setValues(craftList) - self.grid:update() - self:draw() - self:sync() - end - - function jobList.grid:getRowTextColor(row, selected) - if row.statusCode == STATUS_ERROR then - return colors.red - elseif row.statusCode == STATUS_WARNING then - return colors.yellow - elseif row.statusCode == STATUS_INFO then - return colors.lime - end - return UI.Grid:getRowTextColor(row, selected) - end - - jobList:enable() - jobList:draw() - jobList:sync() -end - -local function getAutocraftItems() - local craftList = { } - - for _,res in pairs(resources) do - if res.auto then - res = Util.shallowCopy(res) - res.count = 256 -- this could be higher to increase autocrafting speed - local key = uniqueKey(res) - craftList[key] = res - end - end - return craftList -end - -local function getItemWithQty(items, res, ignoreDamage, ignoreNbtHash) - local item = getItem(items, res, ignoreDamage, ignoreNbtHash) - - if item and (ignoreDamage or ignoreNbtHash) then - local count = 0 - - for _,v in pairs(items) do - if item.name == v.name and - (ignoreDamage or item.damage == v.damage) and - (ignoreNbtHash or item.nbtHash == v.nbtHash) then - count = count + v.count - end - end - item.count = count - end - - return item -end - -local function watchResources(items) - local craftList = { } - local outputs = { } - - for _,res in pairs(resources) do - local item = getItemWithQty(items, res, res.ignoreDamage, res.ignoreNbtHash) - if not item then - item = { - damage = res.damage, - nbtHash = res.nbtHash, - name = res.name, - displayName = itemDB:getName(res), - count = 0 - } - end - - if res.limit and item.count > res.limit then - inventoryAdapter:provide( - { name = item.name, damage = item.damage, nbtHash = item.nbtHash }, - item.count - res.limit, - nil, - config.trashDirection) - - elseif res.low and item.count < res.low then - if res.ignoreDamage then - item.damage = 0 - end - local key = uniqueKey(res) - - craftList[key] = { - damage = item.damage, - nbtHash = item.nbtHash, - count = res.low - item.count, - name = item.name, - displayName = item.displayName, - status = '', - rsControl = res.rsControl, - } - end - - if res.rsControl and res.rsDevice and res.rsSide then - local enable = item.count < res.low - if not outputs[res.rsDevice] then - outputs[res.rsDevice] = { } - end - outputs[res.rsDevice][res.rsSide] = outputs[res.rsDevice][res.rsSide] or enable - end - end - - for rsDevice, sides in pairs(outputs) do - for side, enable in pairs(sides) do - pcall(function() - device[rsDevice].setOutput(side, enable) - end) - end - end - - return craftList -end - -local function loadResources() - resources = Util.readTable(RESOURCE_FILE) or { } - for k,v in pairs(resources) do - Util.merge(v, itemDB:splitKey(k)) - end -end - -local function saveResources() - local t = { } - - for k,v in pairs(resources) do - v = Util.shallowCopy(v) - local keys = Util.transpose({ 'auto', 'low', 'limit', - 'ignoreDamage', 'ignoreNbtHash', - 'rsControl', 'rsDevice', 'rsSide' }) - - for _,key in pairs(Util.keys(v)) do - if not keys[key] then - v[key] = nil - end - end - if not Util.empty(v) then - t[k] = v - end - end - - Util.writeTable(RESOURCE_FILE, t) -end - -local itemPage = UI.Page { - titleBar = UI.TitleBar { - title = 'Limit Resource', - previousPage = true, - event = 'form_cancel', - }, - form = UI.Form { - x = 1, y = 2, height = 10, ex = -1, - [1] = UI.TextEntry { - width = 7, - formLabel = 'Min', formKey = 'low', help = 'Craft if below min' - }, - [2] = UI.TextEntry { - width = 7, - formLabel = 'Max', formKey = 'limit', help = 'Eject if above max' - }, - [3] = UI.Chooser { - width = 7, - formLabel = 'Autocraft', formKey = 'auto', - nochoice = 'No', - choices = { - { name = 'Yes', value = true }, - { name = 'No', value = false }, - }, - help = 'Craft until out of ingredients' - }, - [4] = UI.Chooser { - width = 7, - formLabel = 'Ignore Dmg', formKey = 'ignoreDamage', - nochoice = 'No', - choices = { - { name = 'Yes', value = true }, - { name = 'No', value = false }, - }, - help = 'Ignore damage of item' - }, - [5] = UI.Chooser { - width = 7, - formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash', - nochoice = 'No', - choices = { - { name = 'Yes', value = true }, - { name = 'No', value = false }, - }, - help = 'Ignore NBT of item' - }, ---[[ - [6] = UI.Button { - x = 2, y = -2, width = 10, - formLabel = 'Redstone', - event = 'show_rs', - text = 'Configure', - }, -]] - infoButton = UI.Button { - x = 2, y = -2, - event = 'show_info', - text = 'Info', - }, - }, - rsControl = UI.SlideOut { - backgroundColor = colors.cyan, - titleBar = UI.TitleBar { - title = "Redstone Control", - }, - form = UI.Form { - y = 2, - [1] = UI.Chooser { - width = 7, - formLabel = 'RS Control', formKey = 'rsControl', - nochoice = 'No', - choices = { - { name = 'Yes', value = true }, - { name = 'No', value = false }, - }, - help = 'Control via redstone' - }, - [2] = UI.Chooser { - width = 25, - formLabel = 'RS Device', formKey = 'rsDevice', - --choices = devices, - help = 'Redstone Device' - }, - [3] = UI.Chooser { - width = 10, - formLabel = 'RS Side', formKey = 'rsSide', - --nochoice = 'No', - choices = { - { name = 'up', value = 'up' }, - { name = 'down', value = 'down' }, - { name = 'east', value = 'east' }, - { name = 'north', value = 'north' }, - { name = 'west', value = 'west' }, - { name = 'south', value = 'south' }, - }, - help = 'Output side' - }, - }, - }, - info = UI.SlideOut { - titleBar = UI.TitleBar { - title = "Information", - }, - textArea = UI.TextArea { - x = 2, ex = -2, y = 3, ey = -4, - backgroundColor = colors.black, - }, - cancel = UI.Button { - ex = -2, y = -2, width = 6, - text = 'Okay', - event = 'hide_info', - }, - }, - statusBar = UI.StatusBar { } -} - -function itemPage:enable(item) - self.item = item - - self.form:setValues(item) - self.titleBar.title = item.displayName or item.name - - UI.Page.enable(self) - self:focusFirst() -end - -function itemPage.rsControl:enable() - local devices = self.form[1].choices - Util.clear(devices) - for _,dev in pairs(device) do - if dev.setOutput then - table.insert(devices, { name = dev.name, value = dev.name }) - end - end - - if Util.size(devices) == 0 then - table.insert(devices, { name = 'None found', values = '' }) - end - - UI.SlideOut.enable(self) -end - -function itemPage.rsControl:eventHandler(event) - if event.type == 'form_cancel' then - self:hide() - elseif event.type == 'form_complete' then - self:hide() - else - return UI.SlideOut.eventHandler(self, event) - end - return true -end - -function itemPage:eventHandler(event) - if event.type == 'form_cancel' then - UI:setPreviousPage() - - elseif event.type == 'show_rs' then - self.rsControl:show() - - elseif event.type == 'show_info' then - local value = - string.format('%s%s%s\n%s\n', - Ansi.orange, self.item.displayName, Ansi.reset, - self.item.name) - - if self.item.nbtHash then - value = value .. self.item.nbtHash .. '\n' - end - - value = value .. string.format('\n%sDamage:%s %s', - Ansi.yellow, Ansi.reset, self.item.damage) - - if self.item.maxDamage and self.item.maxDamage > 0 then - value = value .. string.format(' (max: %s)', self.item.maxDamage) - end - - if self.item.maxCount then - value = value .. string.format('\n%sStack Size: %s%s', - Ansi.yellow, Ansi.reset, self.item.maxCount) - end - - self.info.textArea.value = value - self.info:show() - - elseif event.type == 'hide_info' then - self.info:hide() - - elseif event.type == 'focus_change' then - self.statusBar:setStatus(event.focused.help) - self.statusBar:draw() - - elseif event.type == 'form_complete' then - local values = self.form.values - local originalKey = uniqueKey(self.item) - - local filtered = Util.shallowCopy(values) - filtered.low = tonumber(filtered.low) - filtered.limit = tonumber(filtered.limit) - - if filtered.auto ~= true then - filtered.auto = nil - end - - if filtered.rsControl ~= true then - filtered.rsControl = nil - filtered.rsSide = nil - filtered.rsDevice = nil - end - - if filtered.ignoreDamage == true then - filtered.damage = 0 - else - filtered.ignoreDamage = nil - end - - if filtered.ignoreNbtHash == true then - filtered.nbtHash = nil - else - filtered.ignoreNbtHash = nil - end - resources[originalKey] = nil - resources[uniqueKey(filtered)] = filtered - - filtered.count = nil - saveResources() - - UI:setPreviousPage() - - else - return UI.Page.eventHandler(self, event) - end - return true -end - -local listingPage = UI.Page { - menuBar = UI.MenuBar { - buttons = { - { text = 'Learn', event = 'learn' }, - { text = 'Forget', event = 'forget' }, - { text = 'Craft', event = 'craft' }, - { text = 'Refresh', event = 'refresh', x = -9 }, - }, - }, - grid = UI.Grid { - y = 2, ey = -2, - columns = { - { heading = 'Name', key = 'displayName' }, - { heading = 'Qty', key = 'count' , width = 4 }, - { heading = 'Min', key = 'low' , width = 4 }, - { heading = 'Max', key = 'limit' , width = 4 }, - }, - sortColumn = 'displayName', - }, - statusBar = UI.StatusBar { - filter = UI.TextEntry { - x = 1, ex = -4, - limit = 50, - shadowText = 'filter', - shadowTextColor = colors.gray, - backgroundColor = colors.cyan, - backgroundFocusColor = colors.cyan, - }, - display = UI.Button { - x = -3, - event = 'toggle_display', - value = 0, - text = 'A', - }, - }, - notification = UI.Notification(), - accelerators = { - r = 'refresh', - q = 'quit', - grid_select_right = 'craft', - }, - displayMode = 0, -} - -function listingPage.statusBar:draw() - return UI.Window.draw(self) -end - -function listingPage.grid:getRowTextColor(row, selected) - if row.is_craftable then - return colors.yellow - end - if canCraft and row.has_recipe then - return colors.cyan - end - return UI.Grid:getRowTextColor(row, selected) -end - -function listingPage.grid:getDisplayValues(row) - row = Util.shallowCopy(row) - row.count = Util.toBytes(row.count) - if row.low then - row.low = Util.toBytes(row.low) - end - if row.limit then - row.limit = Util.toBytes(row.limit) - end - return row -end - -function listingPage:eventHandler(event) - if event.type == 'quit' then - UI:exitPullEvents() - - elseif event.type == 'grid_select' then - local selected = event.selected - UI:setPage('item', selected) - - elseif event.type == 'refresh' then - self:refresh() - self.grid:draw() - self.statusBar.filter:focus() - - elseif event.type == 'toggle_display' then - local values = { - [0] = 'A', - [1] = 'I', - [2] = 'C', - } - - event.button.value = (event.button.value + 1) % 3 - self.displayMode = event.button.value - event.button.text = values[event.button.value] - event.button:draw() - self:applyFilter() - self.grid:draw() - - elseif event.type == 'learn' then - if canLearn then - UI:setPage('learn') - else - self.notification:error('Missing a crafting chest or workbench\nCheck configuration') - end - - elseif event.type == 'craft' or event.type == 'grid_select_right' then - local item = self.grid:getSelected() - if Craft.findRecipe(item) or true then -- or item.is_craftable then - UI:setPage('craft', self.grid:getSelected()) - else - self.notification:error('No recipe defined') - end - - elseif event.type == 'forget' then - local item = self.grid:getSelected() - if item then - local key = uniqueKey(item) - - if userRecipes[key] then - userRecipes[key] = nil - Util.writeTable(RECIPES_FILE, userRecipes) - Craft.loadRecipes() - end - - if resources[key] then - resources[key] = nil - saveResources() - end - - self.notification:info('Forgot: ' .. item.name) - self:refresh() - self.grid:draw() - end - - elseif event.type == 'text_change' then - self.filter = event.text - if #self.filter == 0 then - self.filter = nil - end - self:applyFilter() - self.grid:draw() - self.statusBar.filter:focus() - - else - UI.Page.eventHandler(self, event) - end - return true -end - -function listingPage:enable() - self:refresh() - self:setFocus(self.statusBar.filter) - UI.Page.enable(self) -end - -function listingPage:refresh() - self.allItems = listItems() - mergeResources(self.allItems) - self:applyFilter() -end - -function listingPage:applyFilter() - local t = filterItems(self.allItems, self.filter, self.displayMode) - self.grid:setValues(t) -end - -local function getTurtleInventory() - if duckAntenna then - local list = duckAntenna.getAllStacks(false) - for _,v in pairs(list) do - v.name = v.id - v.damage = v.dmg - v.displayName = v.display_name - v.count = v.qty - v.maxDamage = v.max_dmg - v.maxCount = v.max_size - v.nbtHash = v.nbt_hash - if not itemDB:get(v) then - itemDB:add(v) - end - end - itemDB:flush() - return list - end - - if introspectionModule then - local list = { } - for i = 1,16 do - list[i] = introspectionModule.getInventory().getItemMeta(i) - end - return list - end - - local inventory = { } - for i = 1,16 do - local qty = turtle.getItemCount(i) - if qty > 0 then - turtleChestAdapter:insert(i, qty) - local items = turtleChestAdapter:listItems() - _, inventory[i] = next(items) - turtleChestAdapter:extract(1, qty, i) - end - end - return inventory -end - -local function learnRecipe(page) - local ingredients = getTurtleInventory() - if ingredients then - turtle.select(1) - if canLearn and turtle.craft() then - local results = getTurtleInventory() - if results and results[1] then - clearGrid() - - local maxCount - local newRecipe = { - ingredients = ingredients, - } - - local numResults = 0 - for _,v in pairs(results) do - if v.count > 0 then - numResults = numResults + 1 - end - end - if numResults > 1 then - for _,v1 in pairs(results) do - for _,v2 in pairs(ingredients) do - if v1.name == v2.name and - 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 = '*' - end - - --[[ - Turtles can only craft one item at a time using a tool :( - ]]-- - maxCount = 1 - - newRecipe.craftingTools[uniqueKey(tool)] = true - v1.craftingTool = true - break - end - end - end - end - - local recipe - for _,v in pairs(results) do - if not v.craftingTool then - recipe = v - if maxCount then - recipe.maxCount = maxCount - end - break - end - end - - if not recipe then - _G._syslog(results) - _G._syslog(newRecipe) - error('Failed - view system log') - end - - newRecipe.count = recipe.count - - local key = uniqueKey(recipe) - if recipe.maxCount ~= 64 then - newRecipe.maxCount = recipe.maxCount - end - for k,ingredient in pairs(Util.shallowCopy(ingredients)) do - if ingredient.maxDamage > 0 then - -- ingredient.damage = '*' -- I don't think this is right - end - ingredients[k] = uniqueKey(ingredient) - end - - userRecipes[key] = newRecipe - - Util.writeTable(RECIPES_FILE, userRecipes) - Craft.loadRecipes() - - local displayName = itemDB:getName(recipe) - - listingPage.statusBar.filter:setValue(displayName) - listingPage.notification:success('Learned: ' .. displayName) - listingPage.filter = displayName - listingPage:refresh() - listingPage.grid:draw() - - eject(recipe, recipe.count) - return true - end - else - listingPage.notification:error('Failed to craft', 3) - end - else - listingPage.notification:error('No recipe defined', 3) - end -end - -local learnPage = UI.Dialog { - height = 7, width = UI.term.width - 6, - title = 'Learn Recipe', - idField = UI.Text { - x = 5, - y = 3, - width = UI.term.width - 10, - value = 'Place recipe in turtle' - }, - accept = UI.Button { - x = -14, y = -3, - text = 'Ok', event = 'accept', - }, - cancel = UI.Button { - x = -9, y = -3, - text = 'Cancel', event = 'cancel' - }, - statusBar = UI.StatusBar { - status = 'Crafting paused' - } -} - -function learnPage:enable() - craftingPaused = true - self:focusFirst() - UI.Dialog.enable(self) -end - -function learnPage:disable() - craftingPaused = false - UI.Dialog.disable(self) -end - -function learnPage:eventHandler(event) - if event.type == 'cancel' then - UI:setPreviousPage() - elseif event.type == 'accept' then - if learnRecipe(self) then - UI:setPreviousPage() - end - else - return UI.Dialog.eventHandler(self, event) - end - return true -end - -local craftPage = UI.Page { - titleBar = UI.TitleBar { }, - wizard = UI.Wizard { - y = 2, ey = -2, - pages = { - quantity = UI.Window { - index = 1, - text = UI.Text { - x = 6, y = 3, - value = 'Quantity', - }, - count = UI.TextEntry { - x = 15, y = 3, width = 10, - limit = 6, - value = 1, - }, - ejectText = UI.Text { - x = 6, y = 4, - value = 'Eject', - }, - eject = UI.Chooser { - x = 15, y = 4, width = 7, - value = true, - nochoice = 'No', - choices = { - { name = 'Yes', value = true }, - { name = 'No', value = false }, - }, - }, - }, - resources = UI.Window { - index = 2, - grid = UI.ScrollingGrid { - y = 2, ey = -2, - columns = { - { heading = 'Name', key = 'displayName' }, - { heading = 'Total', key = 'total' , width = 5 }, - { heading = 'Used', key = 'used' , width = 5 }, - { heading = 'Need', key = 'need' , width = 5 }, - }, - sortColumn = 'displayName', - }, - }, - }, - }, -} - -function craftPage:enable(item) - self.item = item - self:focusFirst() - self.titleBar.title = itemDB:getName(item) --- self.wizard.pages.quantity.eject.value = true - UI.Page.enable(self) -end - -function craftPage.wizard.pages.resources.grid:getDisplayValues(row) - local function dv(v) - if v == 0 then - return '' - end - return Util.toBytes(v) - end - row = Util.shallowCopy(row) - row.total = Util.toBytes(row.total) - row.used = dv(row.used) - row.need = dv(row.need) - return row -end - -function craftPage.wizard.pages.resources.grid:getRowTextColor(row, selected) - if row.need > 0 then - return colors.orange - end - return UI.Grid:getRowTextColor(row, selected) -end - -function craftPage.wizard:eventHandler(event) - if event.type == 'nextView' then - local count = tonumber(self.pages.quantity.count.value) - if not count or count <= 0 then - self.pages.quantity.count.backgroundColor = colors.red - self.pages.quantity.count:draw() - return false - end - self.pages.quantity.count.backgroundColor = colors.black - end - return UI.Wizard.eventHandler(self, event) -end - -function craftPage.wizard.pages.resources:enable() - local items = listItems() - local count = tonumber(self.parent.quantity.count.value) - local recipe = Craft.findRecipe(craftPage.item) - if recipe then - local ingredients = Craft.getResourceList4(recipe, items, count) - for _,v in pairs(ingredients) do - v.displayName = itemDB:getName(v) - end - self.grid:setValues(ingredients) - else - self.grid:setValues({ }) - end - return UI.Window.enable(self) -end - -function craftPage:eventHandler(event) - if event.type == 'cancel' then - UI:setPreviousPage() - - elseif event.type == 'accept' then - local key = uniqueKey(self.item) - demandCrafting[key] = Util.shallowCopy(self.item) - demandCrafting[key].count = tonumber(self.wizard.pages.quantity.count.value) - demandCrafting[key].ocount = demandCrafting[key].count - demandCrafting[key].forceCrafting = true - demandCrafting[key].eject = self.wizard.pages.quantity.eject.value == true - UI:setPreviousPage() - else - return UI.Page.eventHandler(self, event) - end - return true -end - -loadResources() -if canCraft then - clearGrid() -end - -UI:setPages({ - listing = listingPage, - item = itemPage, - learn = learnPage, - craft = craftPage, -}) - -jobMonitor() -UI:setPage(listingPage) -listingPage:setFocus(listingPage.statusBar.filter) - ---[[ -Event.on('modem_message', function(e, side, sport, dport, item) - _syslog({ e, side, sport, dport, item }) - if dport == 205 and type(item) == 'table' then - inventoryAdapter:provide( - item, - item.count - item.crafted, - nil, - config.trashDirection) - end -end) ---]] - -Event.onInterval(5, function() - - if not craftingPaused then - restock() - local items = listItems() - if not items or Util.size(items) == 0 then - jobList:showError('No items in system') - else - local demandCrafted - if Util.size(demandCrafting) > 0 then - items = listItems() - if items then - demandCrafted = Util.shallowCopy(demandCrafting) - craftItems(demandCrafted, items) - end - end - - items = listItems() - local craftList - if items then - craftList = watchResources(items) - craftItems(craftList, items) - end - - if demandCrafted and craftList then - for k,v in pairs(demandCrafted) do - craftList[k] = v - end - end - - for _,key in pairs(Util.keys(demandCrafting)) do - local item = demandCrafting[key] - if item.crafted then - item.count = math.max(0, item.count - item.crafted) - if item.count <= 0 then - demandCrafting[key] = nil - item.statusCode = 'success' - if item.eject then - eject(item, item.ocount) - end - end - end - end - - jobList:updateList(craftList) - - craftList = getAutocraftItems(items) -- autocrafted items don't show on job monitor - craftItems(craftList, items) - end - end -end) - -UI:pullEvents() -jobList.parent:reset() diff --git a/storage/etc/apps.db b/storage/etc/apps.db deleted file mode 100644 index 603a26b..0000000 --- a/storage/etc/apps.db +++ /dev/null @@ -1,19 +0,0 @@ -{ - [ "81c0d915fa6d82fd30661c5e66e204cea52bb2b5" ] = { - title = "Activity", - category = "Apps", - icon = "\0318/\030f\031 \030 \0318\\\ -\030f \0308\0319o\030f\031 \ -\0318\\\030f\031 \030 \0318/", - run = "storageActivity.lua", - }, - [ "9e092dda4f0e27d0c7686ddd00272079e678b6e6" ] = { - title = "Storage", - category = "Apps", - icon = "\0307 \ -\0307 \0308\0311 \0305 \0308\031 \0307 \0308 \0301 \ -\0307 ", - run = "chestManager.lua", - requires = 'turtle', - }, -} diff --git a/storage/levelEmitter.lua b/storage/levelEmitter.lua deleted file mode 100644 index b086b8a..0000000 --- a/storage/levelEmitter.lua +++ /dev/null @@ -1,374 +0,0 @@ -local InventoryAdapter = require('core.inventoryAdapter') -local Config = require('config') -local Event = require('event') -local itemDB = require('core.itemDB') -local UI = require('ui') -local Util = require('util') - -local colors = _G.colors -local multishell = _ENV.multishell -local rs = _G.rs - -local RESOURCE_FILE = 'usr/config/levelEmitter.db' - -multishell.setTitle(multishell.getCurrent(), 'Level Emitter') - -local config = { - inventorySide = 'bottom', -} -Config.loadWithCheck('levelEmitter', config) - -local inventoryAdapter = InventoryAdapter.wrap({ wrapSide = config.inventorySide }) -if not inventoryAdapter then - error('No inventory found') -end - -local resources - -local function getItem(items, inItem, ignoreDamage, ignoreNbtHash) - for _,item in pairs(items) do - if item.name == inItem.name and - (ignoreDamage or item.damage == inItem.damage) and - (ignoreNbtHash or item.nbtHash == inItem.nbtHash) then - return item - end - end -end - -local function uniqueKey(item) - return table.concat({ item.name, item.damage, item.nbtHash }, ':') -end - -local function mergeResources(t) - for _,v in pairs(resources) do - local item = getItem(t, v) - if item then - Util.merge(item, v) - else - item = Util.shallowCopy(v) - item.count = 0 - table.insert(t, item) - end - end - - for _,v in pairs(t) do - if not v.displayName then - v.displayName = itemDB:getName(v) - end - v.lname = v.displayName:lower() - end -end - -local function getItemWithQty(items, res, ignoreDamage, ignoreNbtHash) - local item = getItem(items, res, ignoreDamage, ignoreNbtHash) - - if item and (ignoreDamage or ignoreNbtHash) then - local count = 0 - - for _,v in pairs(items) do - if item.name == v.name and - (ignoreDamage or item.damage == v.damage) and - (ignoreNbtHash or item.nbtHash == v.nbtHash) then - count = count + v.count - end - end - item.count = count - end - - return item -end - -local function loadResources() - resources = Util.readTable(RESOURCE_FILE) or { } - for k,v in pairs(resources) do - Util.merge(v, itemDB:splitKey(k)) - end -end - -local function saveResources() - local t = { } - - for k,v in pairs(resources) do - v = Util.shallowCopy(v) - local keys = Util.transpose({ 'limit', 'low', 'ignoreDamage', 'ignoreNbtHash' }) - - for _,key in pairs(Util.keys(v)) do - if not keys[key] then - v[key] = nil - end - end - if not Util.empty(v) then - t[k] = v - end - end - - Util.writeTable(RESOURCE_FILE, t) -end - -local itemPage = UI.Page { - titleBar = UI.TitleBar { - title = 'Limit Resource', - previousPage = true, - event = 'form_cancel', - }, - form = UI.Form { - x = 1, y = 2, height = 10, ex = -1, - [1] = UI.TextEntry { - width = 7, - formLabel = 'Min', formKey = 'low', help = 'Output a signal if below' - }, - [2] = UI.TextEntry { - width = 7, - formLabel = 'Max', formKey = 'limit', help = 'Output a signal if above' - }, - [4] = UI.Chooser { - width = 7, - formLabel = 'Ignore Dmg', formKey = 'ignoreDamage', - nochoice = 'No', - choices = { - { name = 'Yes', value = true }, - { name = 'No', value = false }, - }, - help = 'Ignore damage of item' - }, - [5] = UI.Chooser { - width = 7, - formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash', - nochoice = 'No', - choices = { - { name = 'Yes', value = true }, - { name = 'No', value = false }, - }, - help = 'Ignore NBT of item' - }, - }, - statusBar = UI.StatusBar { } -} - -function itemPage:enable(item) - self.item = Util.shallowCopy(item) - - self.form:setValues(item) - self.titleBar.title = item.displayName or item.name - - UI.Page.enable(self) - self:focusFirst() -end - -function itemPage:eventHandler(event) - if event.type == 'form_cancel' then - UI:setPreviousPage() - - elseif event.type == 'focus_change' then - self.statusBar:setStatus(event.focused.help) - self.statusBar:draw() - - elseif event.type == 'form_complete' then - local filtered = Util.shallowCopy(self.form.values) - - if filtered.ignoreDamage == true then - filtered.damage = 0 - else - filtered.ignoreDamage = nil - end - - if filtered.ignoreNbtHash == true then - filtered.nbtHash = nil - else - filtered.ignoreNbtHash = nil - end - - local originalKey = uniqueKey(self.item) - resources[originalKey] = nil - - filtered.low = tonumber(filtered.low) - filtered.limit = tonumber(filtered.limit) - if filtered.limit or filtered.low then - resources[uniqueKey(filtered)] = filtered - else - resources[uniqueKey(filtered)] = nil - end - - saveResources() - - UI:setPreviousPage() - - else - return UI.Page.eventHandler(self, event) - end - return true -end - -local listingPage = UI.Page { - menuBar = UI.MenuBar { - buttons = { - { text = 'Forget', event = 'forget' }, - { text = 'Refresh', event = 'refresh', x = -9 }, - }, - }, - grid = UI.Grid { - y = 2, height = UI.term.height - 2, - columns = { - { heading = 'Name', key = 'displayName' , width = 22 }, - { heading = 'Qty', key = 'count' , width = 5 }, - { heading = 'Min', key = 'limit' , width = 4 }, - { heading = 'Max', key = 'low' , width = 4 }, - }, - sortColumn = 'displayName', - }, - statusBar = UI.StatusBar { - filterText = UI.Text { - x = 2, - value = 'Filter', - }, - filter = UI.TextEntry { - x = 9, ex = -5, - limit = 50, - backgroundColor = colors.gray, - backgroundFocusColor = colors.gray, - }, - display = UI.Button { - x = -3, - event = 'toggle_display', - value = 0, - text = 'A', - }, - }, - accelerators = { - r = 'refresh', - q = 'quit', - }, - displayMode = 0, -} - -function listingPage.grid:getDisplayValues(row) - row = Util.shallowCopy(row) - row.count = Util.toBytes(row.count) - if row.low then - row.low = Util.toBytes(row.low) - end - if row.limit then - row.limit = Util.toBytes(row.limit) - end - return row -end - -function listingPage:eventHandler(event) - if event.type == 'quit' then - UI:exitPullEvents() - - elseif event.type == 'grid_select' then - local selected = event.selected - UI:setPage('item', selected) - - elseif event.type == 'refresh' then - self:refresh() - self.grid:draw() - self.statusBar.filter:focus() - - elseif event.type == 'toggle_display' then - local values = { - [0] = 'A', - [1] = 'I', - [2] = 'C', - } - - event.button.value = (event.button.value + 1) % 3 - self.displayMode = event.button.value - event.button.text = values[event.button.value] - event.button:draw() - self:applyFilter() - self.grid:draw() - - elseif event.type == 'forget' then - local item = self.grid:getSelected() - if item then - local key = uniqueKey(item) - - if resources[key] then - resources[key] = nil - saveResources() - end - - self.statusBar:timedStatus('Forgot: ' .. item.name, 3) - self:refresh() - self.grid:draw() - end - - elseif event.type == 'text_change' then - self.filter = event.text - if #self.filter == 0 then - self.filter = nil - end - self:applyFilter() - self.grid:draw() - self.statusBar.filter:focus() - - else - UI.Page.eventHandler(self, event) - end - return true -end - -function listingPage:enable() - self:refresh() - self:setFocus(self.statusBar.filter) - UI.Page.enable(self) -end - -function listingPage:refresh() - self.allItems = inventoryAdapter:listItems() - mergeResources(self.allItems) - self:applyFilter() -end - -function listingPage:applyFilter() - local filter = self.filter - local displayMode = self.displayMode - local t = self.allItems - - if filter or displayMode > 0 then - t = { } - if filter then - filter = filter:lower() - end - for _,v in pairs(self.allItems) do - if not filter or string.find(v.lname, filter, 1, true) then - if not displayMode or - displayMode == 0 or - displayMode == 1 and v.count > 0 or - displayMode == 2 and v.has_recipe then - table.insert(t, v) - end - end - end - end - - self.grid:setValues(t) -end - -loadResources() - -UI:setPages({ - listing = listingPage, - item = itemPage, -}) - -UI:setPage(listingPage) -listingPage:setFocus(listingPage.statusBar.filter) - -Event.onInterval(5, function() - local items = inventoryAdapter:listItems() - - if items and Util.size(items) > 0 then - for _,res in pairs(resources) do - local item = getItemWithQty(items, res, res.ignoreDamage, res.ignoreNbtHash) - rs.setOutput('bottom', (res.limit and - item and item.count > res.limit) or - (res.low and - (not item or item.count < res.low)) or false) - end - end -end) - -UI:pullEvents() diff --git a/storage/storageActivity.lua b/storage/storageActivity.lua deleted file mode 100644 index 7e7e0d0..0000000 --- a/storage/storageActivity.lua +++ /dev/null @@ -1,163 +0,0 @@ -local InventoryAdapter = require('core.inventoryAdapter') -local Event = require('event') -local UI = require('ui') -local Util = require('util') - -local colors = _G.colors -local multishell = _ENV.multishell - -local storage = InventoryAdapter.wrap() -if not storage then - error('Not connected to a valid inventory') -end - -multishell.setTitle(multishell.getCurrent(), 'Storage Activity') -UI:configure('StorageActivity', ...) - -local changedPage = UI.Page { - grid = UI.Grid { - ey = -6, - columns = { - { heading = 'Qty', key = 'count', width = 6 }, - { heading = 'Change', key = 'change', width = 6 }, - { heading = 'Rate', key = 'rate', width = 6 }, - { heading = 'Name', key = 'displayName' }, - }, - sortColumn = 'displayName', - }, - buttons = UI.Window { - y = -5, height = 5, - backgroundColor = colors.gray, - prevButton = UI.Button { - x = 2, y = 2, height = 3, width = 5, - event = 'previous', - backgroundColor = colors.lightGray, - text = ' < ' - }, - resetButton = UI.Button { - x = 8, y = 2, height = 3, ex = -8, - event = 'reset', - backgroundColor = colors.lightGray, - text = 'Reset' - }, - nextButton = UI.Button { - x = -6, y = 2, height = 3, width = 5, - event = 'next', - backgroundColor = colors.lightGray, - text = ' > ' - }, - }, - accelerators = { - q = 'quit', - } -} - -function changedPage.grid:getDisplayValues(row) - row = Util.shallowCopy(row) - - local ind = '+' - if row.change < 0 then - ind = '' - end - - row.change = ind .. Util.toBytes(row.change) - row.count = Util.toBytes(row.count) - row.rate = Util.toBytes(row.rate) - - return row -end - -function changedPage:eventHandler(event) - if event.type == 'reset' then - self.lastItems = nil - self.grid:setValues({ }) - self.grid:clear() - self.grid:draw() - - elseif event.type == 'next' then - self.grid:nextPage() - - elseif event.type == 'previous' then - self.grid:previousPage() - - elseif event.type == 'quit' then - Event.exitPullEvents() - - else - return UI.Page.eventHandler(self, event) - end - - return true -end - -local function uniqueKey(item) - return table.concat({ item.name, item.damage, item.nbtHash }, ':') -end - -function changedPage:refresh() - local t = storage:listItems() - - if not t or Util.empty(t) then - self.grid:clear() - self.grid:centeredWrite(math.ceil(self.height/2), 'Communication failure') - return - end - - for k,v in pairs(t) do - t[k] = Util.shallowCopy(v) - end - - if not self.lastItems then - self.lastItems = t - self.timestamp = os.clock() - self.grid:setValues({ }) - else - self.elapsed = os.clock() - self.timestamp - local changedItems = { } - local found - for _,v in pairs(self.lastItems) do - found = false - for k2,v2 in pairs(t) do - if uniqueKey(v) == uniqueKey(v2) then - if v.count ~= v2.count then - local c = Util.shallowCopy(v2) - c.lastCount = v.count - table.insert(changedItems, c) - end - table.remove(t, k2) - found = true - break - end - end - -- New item - if not found then - local c = Util.shallowCopy(v) - c.lastCount = v.count - c.count = 0 - table.insert(changedItems, c) - end - end - -- No items left - for _,v in pairs(t) do - v.lastCount = 0 - table.insert(changedItems, v) - end - - for _,v in pairs(changedItems) do - v.change = v.count - v.lastCount - v.rate = Util.round(60 / self.elapsed * v.change, 1) - end - - self.grid:setValues(changedItems) - end - self.grid:draw() -end - -Event.onInterval(5, function() - changedPage:refresh() - changedPage:sync() -end) - -UI:setPage(changedPage) -changedPage:draw() -UI:pullEvents() diff --git a/swshop/installPlugin.lua b/swshop/installPlugin.lua index 4725205..4a04fd4 100644 --- a/swshop/installPlugin.lua +++ b/swshop/installPlugin.lua @@ -1,4 +1,4 @@ -local Util = require('util') +local Util = require('opus.util') local fs = _G.fs local read = _G.read diff --git a/swshop/shopConfig.lua b/swshop/shopConfig.lua index b71c566..573f7a4 100644 --- a/swshop/shopConfig.lua +++ b/swshop/shopConfig.lua @@ -1,4 +1,4 @@ -local UI = require('ui') +local UI = require('opus.ui') local colors = _G.colors local device = _G.device diff --git a/swshop/shopTab.lua b/swshop/shopTab.lua index 9bec226..f79b28d 100644 --- a/swshop/shopTab.lua +++ b/swshop/shopTab.lua @@ -1,6 +1,6 @@ -local Config = require('config') -local Map = require('map') -local UI = require('ui') +local Config = require('opus.config') +local Map = require('opus.map') +local UI = require('opus.ui') local os = _G.os diff --git a/swshop/shopView-example.lua b/swshop/shopView-example.lua index c97205c..f4ac2a1 100644 --- a/swshop/shopView-example.lua +++ b/swshop/shopView-example.lua @@ -1,5 +1,5 @@ -local Config = require('config') -local Event = require('event') +local Config = require('opus.config') +local Event = require('opus.event') local itemDB = require('core.itemDB') local Milo = require('milo') diff --git a/swshop/shopView.lua b/swshop/shopView.lua index 41b23db..9880a01 100644 --- a/swshop/shopView.lua +++ b/swshop/shopView.lua @@ -1,10 +1,10 @@ -local Config = require('config') -local Event = require('event') +local Config = require('opus.config') +local Event = require('opus.event') local itemDB = require('core.itemDB') local Milo = require('milo') -local Sound = require('sound') -local UI = require('ui') -local Util = require('util') +local Sound = require('opus.sound') +local UI = require('opus.ui') +local Util = require('opus.util') local colors = _G.colors local multishell = _ENV.multishell diff --git a/swshop/swshop.lua b/swshop/swshop.lua index 5b17427..62b68db 100644 --- a/swshop/swshop.lua +++ b/swshop/swshop.lua @@ -1,4 +1,4 @@ -local Util = require('util') +local Util = require('opus.util') local fs = _G.fs local os = _G.os diff --git a/turtle/apis/equipper.lua b/turtle/apis/equipper.lua index 7a43965..4b0d76d 100644 --- a/turtle/apis/equipper.lua +++ b/turtle/apis/equipper.lua @@ -1,4 +1,4 @@ -local Config = require('config') +local Config = require('opus.config') local peripheral = _G.peripheral local turtle = _G.turtle diff --git a/turtle/autorun/startup.lua b/turtle/autorun/startup.lua index cc64e0c..0910d5f 100644 --- a/turtle/autorun/startup.lua +++ b/turtle/autorun/startup.lua @@ -5,10 +5,10 @@ end -- update if fs.exists('packages/turtle/autorun/gps.lua') then fs.delete('packages/turtle/autorun/gps.lua') end -local Config = require('config') -local GPS = require('gps') -local Point = require('point') -local Util = require('util') +local Config = require('opus.config') +local GPS = require('opus.gps') +local Point = require('opus.point') +local Util = require('opus.util') local device = _G.device local fs = _G.fs diff --git a/turtle/lavaRefuel.lua b/turtle/lavaRefuel.lua index 0b2c249..c1944ef 100644 --- a/turtle/lavaRefuel.lua +++ b/turtle/lavaRefuel.lua @@ -1,5 +1,5 @@ local Equipper = require('turtle.equipper') -local Point = require('point') +local Point = require('opus.point') local peripheral = _G.peripheral local turtle = _G.turtle diff --git a/turtle/obsidian.lua b/turtle/obsidian.lua index 4296c22..04570f4 100644 --- a/turtle/obsidian.lua +++ b/turtle/obsidian.lua @@ -1,5 +1,5 @@ -local Point = require('point') -local Util = require('util') +local Point = require('opus.point') +local Util = require('opus.util') local os = _G.os local turtle = _G.turtle diff --git a/turtle/system/turtle.lua b/turtle/system/turtle.lua index c7fd057..a144205 100644 --- a/turtle/system/turtle.lua +++ b/turtle/system/turtle.lua @@ -1,5 +1,5 @@ -local Config = require('config') -local UI = require('ui') +local Config = require('opus.config') +local UI = require('opus.ui') local colors = _G.colors local fs = _G.fs