From 7d7b03474da98efb303852da01b83e56633c0452 Mon Sep 17 00:00:00 2001 From: hkc Date: Fri, 20 Oct 2023 02:41:39 +0300 Subject: [PATCH] Resume playback whenever needed --- mess/tmpc.lua | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/mess/tmpc.lua b/mess/tmpc.lua index dbcef7e..8aa5ec6 100644 --- a/mess/tmpc.lua +++ b/mess/tmpc.lua @@ -282,17 +282,13 @@ local mplayer = { currentScreen = 2, } -local function setupTerminal() - for k, v in pairs(mplayer.colors) do - term.setPaletteColor(v, settings.get("mplayer.colors." .. k)) - end - term.setCursorPos(1, 1) - term.setBackgroundColor(mplayer.colors.bg) - term.setTextColor(mplayer.colors.fg) - term.clear() +for k, v in pairs(mplayer.colors) do + term.setPaletteColor(v, settings.get("mplayer.colors." .. k)) end - -setupTerminal() +term.setCursorPos(1, 1) +term.setBackgroundColor(mplayer.colors.bg) +term.setTextColor(mplayer.colors.fg) +term.clear() local tw, th = term.getSize() parallel.waitForAny( @@ -416,6 +412,11 @@ function() elseif ev == "tape_removed" then mplayer.songs = {} elseif ev == "tape_inserted" then + local seekToAndPlay = nil + if drive.getState() == "PLAYING" then + seekToAndPlay = drive.getPosition() + end + drive.stop() drive.seek(-drive.getSize()) for i = 1, 48 do @@ -431,6 +432,12 @@ function() } end end + + if seekToAndPlay ~= nil then + drive.seek(-drive.getSize()) + drive.seek(seekToAndPlay) + drive.play() + end elseif ev ~= "timer" then if drive.isDummy then local m = term.redirect(peripheral.wrap("right"))