Barnet

playnbs.lua

Jun 9th, 2021 (edited)
6,250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. --[[
  2.   playMonitor
  3.   By SoniEx2
  4. --]] --
  5. -- fastq is no better than CCland other than for table/function support,
  6. -- so we don't use it by default.
  7. -- REQUIRES FASTQ
  8. local use_fastq = false
  9.  
  10. local x = function(...)
  11.     local args = {...} -- args table
  12.  
  13.     local monitorBaseSettings = {
  14.         hasColor = (args[1] == "true" or args[1] == "on" or args[1] == "1"),
  15.         title = args[2]:gsub("%_", "% "),
  16.         -- avoid errors
  17.         footerLeft = "",
  18.         footerRight = ""
  19.     }
  20.  
  21.     local playerslave = dofile("EasyPlay/Core/player_slave.lua")
  22.     local playermonitor = dofile("EasyPlay/Core/player_monitor.lua")
  23.     local playernbs = dofile("EasyPlay/Core/player_nbs.lua")
  24.     local controller = dofile("EasyPlay/Core/controller.lua")
  25.  
  26.     local function play(filename, monside, ...)
  27.         local id = os.clock() -- heh
  28.         local subid = 1
  29.         local maxsubid = 1
  30.         local speakers = {...};
  31.  
  32.         local threads = {}
  33.  
  34.         table.insert(threads, controller.new())
  35.  
  36.         local monitor = peripheral.wrap(monside)
  37.         table.insert(threads,
  38.                      playermonitor.new(monitor, id, subid, monitorBaseSettings))
  39.  
  40.         for i, side in ipairs(speakers) do
  41.             table.insert(threads, playerslave.new(side, id, subid))
  42.         end
  43.  
  44.         table.insert(threads,
  45.                      playernbs.new(id, maxsubid, filename, monitorBaseSettings))
  46.  
  47.         table.insert(threads, function()
  48.             local count = 0
  49.             while true do
  50.                 local evt, p1_id, p2_subid, p3_side = os.pullEvent(
  51.                                                           "player:slaveinfo")
  52.  
  53.                 monitorBaseSettings.footerLeft = #speakers ..
  54.                                                      " speakers connected"
  55.             end
  56.         end)
  57.  
  58.         parallel.waitForAny(unpack(threads))
  59.     end
  60.  
  61.     play(select(3, ...))
  62. end
  63.  
  64. if use_fastq then
  65.     dofile("EasyPlay/Core/fastq.lua").init(x, ...)
  66. else
  67.     x(...)
  68. end
  69.  
Add Comment
Please, Sign In to add comment