From 922c391bf29cef0a05ded955c38cca9f1963a725 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sun, 17 Nov 2019 18:21:48 -0700 Subject: [PATCH] cleanup + example start --- common/Devices.lua | 8 +-- common/SoundPlayer.lua | 2 +- common/etc/apps.db | 6 +++ {games => common}/etc/sounds.txt | 0 examples/.package | 6 +++ examples/grid.lua | 44 ++++++++++++++++ games/etc/apps.db | 6 --- {common/etc => ignore}/scripts/abort | 0 {common/etc => ignore}/scripts/goHome | 0 {common/etc => ignore}/scripts/moveTo | 0 {common/etc => ignore}/scripts/reboot | 0 {common/etc => ignore}/scripts/setHome | 0 {common/etc => ignore}/scripts/shutdown | 0 {common/etc => ignore}/scripts/summon | 0 recipeBook/.package | 2 +- recipeBook/recipeBook.lua | 70 ++++++++++++------------- 16 files changed, 95 insertions(+), 49 deletions(-) rename {games => common}/etc/sounds.txt (100%) create mode 100644 examples/.package create mode 100644 examples/grid.lua rename {common/etc => ignore}/scripts/abort (100%) rename {common/etc => ignore}/scripts/goHome (100%) rename {common/etc => ignore}/scripts/moveTo (100%) rename {common/etc => ignore}/scripts/reboot (100%) rename {common/etc => ignore}/scripts/setHome (100%) rename {common/etc => ignore}/scripts/shutdown (100%) rename {common/etc => ignore}/scripts/summon (100%) diff --git a/common/Devices.lua b/common/Devices.lua index 57ac8fe..6ad2f08 100644 --- a/common/Devices.lua +++ b/common/Devices.lua @@ -1,5 +1,3 @@ -_G.requireInjector(_ENV) - local Ansi = require('opus.ansi') local Event = require('opus.event') local UI = require('opus.ui') @@ -27,7 +25,7 @@ local peripheralsPage = UI.Page { }, } -function peripheralsPage.grid:draw() +function peripheralsPage.grid:enable() local sides = peripheral.getNames() Util.clear(self.values) @@ -39,7 +37,7 @@ function peripheralsPage.grid:draw() end self:update() self:adjustWidth() - UI.Grid.draw(self) + UI.Grid.enable(self) end function peripheralsPage:updatePeripherals() @@ -84,7 +82,6 @@ local methodsPage = UI.Page { } function methodsPage:enable(p) - self.peripheral = p or self.peripheral p = peripheral.wrap(self.peripheral.side) @@ -136,7 +133,6 @@ function methodsPage:eventHandler(event) end function methodsPage:getDocumentation() - local method = self.grid:getSelected() if method.noext then -- computercraft docs diff --git a/common/SoundPlayer.lua b/common/SoundPlayer.lua index db69f40..bcce449 100644 --- a/common/SoundPlayer.lua +++ b/common/SoundPlayer.lua @@ -8,7 +8,7 @@ if not peripheral.find('speaker') then error('No speaker attached') end -local rawSounds = Util.readLines('packages/games/etc/sounds.txt') or error('Unable to read sounds file') +local rawSounds = Util.readLines('packages/common/etc/sounds.txt') or error('Unable to read sounds file') local sounds = { } for _, s in pairs(rawSounds) do table.insert(sounds, { name = s }) diff --git a/common/etc/apps.db b/common/etc/apps.db index 7e6a4ad..d12829c 100644 --- a/common/etc/apps.db +++ b/common/etc/apps.db @@ -59,4 +59,10 @@ iconExt = "\030 \031 \128\030d\159\030 \031d\140\030d\031 \155\030 \0315\140\0305\031 \155\030 \128\010\030 \031d\136\145\0315\136\145\031d\153\031 \128\0315\153\010\030 \031 \128\031d\130\140\134\0315\140\134\031 \128", run = "packages/common/hexedit.lua", }, + [ "fb1c39e9f4f3c2628ad173ab401a6e4e4baf783d" ] = { + title = "Sounds", + category = "System", + run = "SoundPlayer", + iconExt = "\030 \031 \128\0307\159\129\030 \0317\149\0310\144\0300\031 \155\030 \0310\137\144\010\0307\0317\128\128\128\030 \149\0300\031 \149\030 \128\0310\149\0300\031 \149\010\030 \031 \128\0317\130\0307\031 \144\030 \0317\149\0310\129\134\152\129", + }, } diff --git a/games/etc/sounds.txt b/common/etc/sounds.txt similarity index 100% rename from games/etc/sounds.txt rename to common/etc/sounds.txt diff --git a/examples/.package b/examples/.package new file mode 100644 index 0000000..da8c112 --- /dev/null +++ b/examples/.package @@ -0,0 +1,6 @@ +{ + title = 'Example programs for coding in Opus', + repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/examples', + description = [[Starter/example programs for creating Opus programs.]], + license = 'MIT', +} diff --git a/examples/grid.lua b/examples/grid.lua new file mode 100644 index 0000000..b979a87 --- /dev/null +++ b/examples/grid.lua @@ -0,0 +1,44 @@ +local UI = require('opus.ui') + +local page = UI.Page { + menuBar = UI.MenuBar { + buttons = { + { text = 'Shuffle', event = 'shuffle' }, + { text = 'Clear', event = 'clear', }, + } + }, + grid = UI.ScrollingGrid { + y = 2, ey = -2, + values = { + { col = 'column1', value = 'value1' }, + { col = 'column2', value = 'value2' }, + { col = 'column3', value = 'value3' }, + }, + columns = { + { heading = 'HDR1', key = 'col' }, + { heading = 'HDR2', key = 'value' }, + } + }, + statusBar = UI.StatusBar { }, +} + +function page:eventHandler(event) + if event.type == 'grid_select' then + self.statusBar:setStatus('Selected: ' .. event.selected.value) + + elseif event.type == 'shuffle' then + for _,v in pairs(self.grid.values) do + v.col = 'column' .. math.random(1,3) + end + self.grid:update() + self.grid:draw() + + elseif event.type == 'clear' then + self.grid:setValues({ }) + self.grid:draw() + end + return UI.Page.eventHandler(self, event) +end + +UI:setPage(page) +UI:pullEvents() diff --git a/games/etc/apps.db b/games/etc/apps.db index 11aaac5..f149739 100644 --- a/games/etc/apps.db +++ b/games/etc/apps.db @@ -17,12 +17,6 @@ run = "Pipes", iconExt = "\030 \031 \128\0300\0310\128\030 \031 \128\0310\143\0300\031 \130\030 \128\0300\0310\128\010\0300\031 \131\0310\128\031 \131\131\030 \0310\159\031 \128\0310\143\010\030 \031 \128\0315\143\031 \128\128\128\128\0300\131", }, - [ "fb1c39e9f4f3c2628ad173ab401a6e4e4baf783d" ] = { - title = "Sounds", - category = "System", - run = "SoundPlayer", - iconExt = "\030 \031 \128\0307\159\129\030 \0317\149\0310\144\0300\031 \155\030 \0310\137\144\010\0307\0317\128\128\128\030 \149\0300\031 \149\030 \128\0310\149\0300\031 \149\010\030 \031 \128\0317\130\0307\031 \144\030 \0317\149\0310\129\134\152\129", - }, [ "a2accffe95b2c8be30e8a05e0c6ab7e8f5966f43" ] = { title = "Strafe", category = "Games", diff --git a/common/etc/scripts/abort b/ignore/scripts/abort similarity index 100% rename from common/etc/scripts/abort rename to ignore/scripts/abort diff --git a/common/etc/scripts/goHome b/ignore/scripts/goHome similarity index 100% rename from common/etc/scripts/goHome rename to ignore/scripts/goHome diff --git a/common/etc/scripts/moveTo b/ignore/scripts/moveTo similarity index 100% rename from common/etc/scripts/moveTo rename to ignore/scripts/moveTo diff --git a/common/etc/scripts/reboot b/ignore/scripts/reboot similarity index 100% rename from common/etc/scripts/reboot rename to ignore/scripts/reboot diff --git a/common/etc/scripts/setHome b/ignore/scripts/setHome similarity index 100% rename from common/etc/scripts/setHome rename to ignore/scripts/setHome diff --git a/common/etc/scripts/shutdown b/ignore/scripts/shutdown similarity index 100% rename from common/etc/scripts/shutdown rename to ignore/scripts/shutdown diff --git a/common/etc/scripts/summon b/ignore/scripts/summon similarity index 100% rename from common/etc/scripts/summon rename to ignore/scripts/summon diff --git a/recipeBook/.package b/recipeBook/.package index 8b0f49b..12e145e 100644 --- a/recipeBook/.package +++ b/recipeBook/.package @@ -1,6 +1,6 @@ { title = 'Recipe books for crafting programs', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/recipeBook', - description = [[ WIP ]], + description = [[Recipe book manager for Milo and programs that utilize crafting]], license = 'MIT', } diff --git a/recipeBook/recipeBook.lua b/recipeBook/recipeBook.lua index fc0b719..3aa67c3 100644 --- a/recipeBook/recipeBook.lua +++ b/recipeBook/recipeBook.lua @@ -60,37 +60,37 @@ local page = UI.Page { sortColumn = 'name', autospace = true, }, - add = UI.SlideOut { - backgroundColor = colors.cyan, - titleBar = UI.TitleBar { - title = 'Add a new book', - }, - form = UI.Form { - x = 2, ex = -2, y = 2, ey = -1, - [1] = UI.TextEntry { - formLabel = 'Name', formKey = 'name', - shadowText = 'Friendly name', - limit = 64, - required = true, - }, - [2] = UI.TextEntry { - formLabel = 'Version', formKey = 'version', - shadowText = 'Mod version', - limit = 10, - }, - [3] = UI.TextEntry { - formLabel = 'URL', formKey = 'url', - shadowText = 'URL for recipes', - limit = 128, - required = true, - }, - [4] = UI.TextEntry { - formLabel = 'File name', formKey = 'localName', - shadowText = 'Short name for saving file', - limit = 20, - required = true, - }, - }, + add = UI.SlideOut { + backgroundColor = colors.cyan, + titleBar = UI.TitleBar { + title = 'Add a new book', + }, + form = UI.Form { + x = 2, ex = -2, y = 2, ey = -1, + [1] = UI.TextEntry { + formLabel = 'Name', formKey = 'name', + shadowText = 'Friendly name', + limit = 64, + required = true, + }, + [2] = UI.TextEntry { + formLabel = 'Version', formKey = 'version', + shadowText = 'Mod version', + limit = 10, + }, + [3] = UI.TextEntry { + formLabel = 'URL', formKey = 'url', + shadowText = 'URL for recipes', + limit = 128, + required = true, + }, + [4] = UI.TextEntry { + formLabel = 'File name', formKey = 'localName', + shadowText = 'Short name for saving file', + limit = 20, + required = true, + }, + }, }, notification = UI.Notification { }, } @@ -156,8 +156,8 @@ function page:eventHandler(event) self.grid:draw() elseif event.type == 'add_book' then - self.add.form:setValues({ }) - self.add:show() + self.add.form:setValues({ }) + self.add:show() elseif event.type == 'form_complete' then self.add:hide() @@ -166,8 +166,8 @@ function page:eventHandler(event) self.grid:setValues(getRecipeBooks()) self.grid:draw() - elseif event.type == 'form_cancel' then - self.add:hide() + elseif event.type == 'form_cancel' then + self.add:hide() elseif event.type == 'grid_focus_row' then self.info:draw()