From a49d2d820dcfe384d743c8fdbee1ad53902458c7 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Mon, 3 Dec 2018 15:40:51 -0500 Subject: [PATCH] app tweaks --- core/Music.lua | 70 ++++++++++++++---------------------- core/Turtles.lua | 22 ++++++------ milo/apis/storage.lua | 2 -- milo/plugins/refreshTask.lua | 6 ---- 4 files changed, 38 insertions(+), 62 deletions(-) diff --git a/core/Music.lua b/core/Music.lua index c33f3ef..118ca4f 100644 --- a/core/Music.lua +++ b/core/Music.lua @@ -3,23 +3,32 @@ _G.requireInjector() local Event = require('event') local UI = require('ui') -local colors = _G.colors -local device = _G.device -local turtle = _G.turtle +local colors = _G.colors +local peripheral = _G.peripheral -if not turtle then - error('This program can only be run on a turtle') -end - -local radio = device.drive or error('No drive attached') -if radio.side ~= 'top' and radio.side ~= 'bottom' then - error('Disk drive must be above or below turtle') -end +local speaker = peripheral.find('speaker') or + error('Speaker must be attached') UI:configure('Music', ...) UI.Button.defaults.backgroundFocusColor = colors.gray +local songs = { + { record = 'record.11', title = '11' }, + { record = 'record.13', title = '13' }, + { record = 'record.block', title = 'Block' }, + { record = 'record.cat', title = 'Cat' }, + { record = 'record.chirp', title = 'Chirp' }, + { record = 'record.far', title = 'Faf' }, + { record = 'record.mall', title = 'Mall' }, + { record = 'record.mellohi', title = 'Mellohi' }, + { record = 'record.stal', title = 'Stal' }, + { record = 'record.strad', title = 'Strad' }, + { record = 'record.wait', title = 'Wait' }, + { record = 'record.ward', title = 'Ward' }, +} +local songNo = 1 + local page = UI.Page({ volume = 15, stationName = UI.Text({ @@ -168,41 +177,18 @@ function page:setVolume(volume) end function page:seek() - - local actions = { - top = { - suck = turtle.suckUp, - drop = turtle.dropUp, - }, - bottom = { - suck = turtle.suckDown, - drop = turtle.dropDown, - }, - } - - local slot = turtle.selectOpenSlot() - actions[radio.side].suck() - repeat - slot = slot + 1 - if (slot > 16) then - slot = 1 - end - until turtle.getItemCount(slot) >= 1 - turtle.select(slot) - actions[radio.side].drop() + songNo = songNo + 1 + if songNo > #songs then + songNo = 1 + end self:updateStationName() end function page:play(onOff) self.playing = onOff if self.playing then - - if not radio.hasAudio() then - self:seek() - end - self:updateStationName() - radio.playAudio() + speaker.playSound(songs[songNo]) Event.addNamedTimer('songTimer', 180, false, function() if self.playing then @@ -213,7 +199,7 @@ function page:play(onOff) end) else - radio.stopAudio() + --radio.stopAudio() end end @@ -223,7 +209,7 @@ function page.stationName:draw() end function page:updateStationName() - local title = radio.getAudioTitle() + local title = songs[songNo].title if title then self.stationName.value = title @@ -248,9 +234,7 @@ page:setVolume(page.volume, true) UI:setPage(page) -turtle.setStatus('Jamming') UI:pullEvents() -turtle.setStatus('idle') page:play(false) UI.term:reset() diff --git a/core/Turtles.lua b/core/Turtles.lua index 6ce66f6..2af92e3 100644 --- a/core/Turtles.lua +++ b/core/Turtles.lua @@ -43,7 +43,7 @@ local page = UI.Page { }, tabs = UI.Tabs { x = 1, y = 5, ey = -2, - scripts = UI.Grid { + scripts = UI.ScrollingGrid { tabTitle = 'Run', backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, columns = { @@ -53,7 +53,7 @@ local page = UI.Page { sortColumn = 'label', autospace = true, }, - turtles = UI.Grid { + turtles = UI.ScrollingGrid { tabTitle = 'Select', backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, columns = { @@ -66,7 +66,7 @@ local page = UI.Page { sortColumn = 'label', autospace = true, }, - inventory = UI.Grid { + inventory = UI.ScrollingGrid { backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, tabTitle = 'Inv', columns = { @@ -78,7 +78,7 @@ local page = UI.Page { sortColumn = 'index', }, --[[ - policy = UI.Grid { + policy = UI.ScrollingGrid { tabTitle = 'Mod', backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, columns = { @@ -196,7 +196,7 @@ function page.tabs.inventory:getRowTextColor(row, selected) if page.turtle and row.selected then return colors.yellow end - return UI.Grid.getRowTextColor(self, row, selected) + return UI.ScrollingGrid.getRowTextColor(self, row, selected) end function page.tabs.inventory:draw() @@ -217,7 +217,7 @@ function page.tabs.inventory:draw() end self:adjustWidth() self:update() - UI.Grid.draw(self) + UI.ScrollingGrid.draw(self) end function page.tabs.inventory:eventHandler(event) @@ -225,7 +225,7 @@ function page.tabs.inventory:eventHandler(event) local fn = string.format('turtle.select(%d)', event.selected.index) page:runFunction(fn) else - return UI.Grid.eventHandler(self, event) + return UI.ScrollingGrid.eventHandler(self, event) end return true end @@ -238,14 +238,14 @@ function page.tabs.scripts:draw() table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) }) end self:update() - UI.Grid.draw(self) + UI.ScrollingGrid.draw(self) end function page.tabs.scripts:eventHandler(event) if event.type == 'grid_select' then page:runScript(event.selected.label) else - return UI.Grid.eventHandler(self, event) + return UI.ScrollingGrid.eventHandler(self, event) end return true end @@ -269,7 +269,7 @@ function page.tabs.turtles:draw() end end self:update() - UI.Grid.draw(self) + UI.ScrollingGrid.draw(self) end function page.tabs.turtles:eventHandler(event) @@ -283,7 +283,7 @@ function page.tabs.turtles:eventHandler(event) socket = nil end else - return UI.Grid.eventHandler(self, event) + return UI.ScrollingGrid.eventHandler(self, event) end return true end diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index 603079f..a5acbd6 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -15,7 +15,6 @@ function Storage:init(nodes) dirty = true, activity = { }, storageOnline = true, - lastRefresh = os.clock(), } Util.merge(self, defaults) @@ -148,7 +147,6 @@ end function Storage:refresh(throttle) self.dirty = true - self.lastRefresh = os.clock() _G._debug('STORAGE: Forcing full refresh') for _, adapter in self:onlineAdapters() do adapter.dirty = true diff --git a/milo/plugins/refreshTask.lua b/milo/plugins/refreshTask.lua index 9b89f81..3d87078 100644 --- a/milo/plugins/refreshTask.lua +++ b/milo/plugins/refreshTask.lua @@ -1,7 +1,5 @@ local Milo = require('milo') --- Do a full scan of inventories every minute - local RefreshTask = { name = 'refresher', priority = 0, @@ -20,10 +18,6 @@ function RefreshTask:cycle(context) end end end - --- if os.clock() - context.storage.lastRefresh > 60 then --- context.storage:refresh() --- end end Milo:registerTask(RefreshTask)