View difference between Paste ID: TAyLgzEq and G1yQWjHk
SHOW: | | - or go back to the newest paste.
1
-- (C) 2023 Freekeh99, All Rights Reserved.
2
3
-- Memory
4
local nowplaying = nil
5
local nostalgiamode = false
6
7
-- Text functions
8
local function centerText(text, y)
9
  local x = (term.getSize() - string.len(text)) / 2
10
  term.setCursorPos(x, y)
11
  term.write(text)
12
  -- Reset cursor position
13
  term.setCursorPos(1, 1)
14
end
15
16
local function optionsText(key, text, y)
17
  local x = 3
18
  term.setCursorPos(x, y)
19
  term.write("[" .. key .. "] " .. text)
20
end
21-
  centerText("Welcome to TunePlay", 1)
21+
22
-- Number key convertion to number
23-
  centerText("Version 1.0", 6)
23+
local function numberKey(key)
24
  if key == keys.one then
25
    return 1
26
  elseif key == keys.two then
27
    return 2
28
  elseif key == keys.three then
29
    return 3
30
  elseif key == keys.four then
31-
  optionsText("1", "Choose a song", 3)
31+
    return 4
32-
  optionsText("2", "Start playback", 4)
32+
  elseif key == keys.five then
33-
  optionsText("3", "Stop playback", 5)
33+
    return 5
34-
  optionsText("4", "Back to main menu", 6)
34+
  elseif key == keys.six then
35-
  optionsText("5", "Exit", 7)
35+
    return 6
36
  elseif key == keys.seven then
37
    return 7
38
  elseif key == keys.eight then
39
    return 8
40-
	"music.creative",
40+
  elseif key == keys.nine then
41-
	"music.credits",
41+
    return 9
42-
	"music.dragon",
42+
  elseif key == keys.zero then
43-
	"music.end",
43+
    return 0
44-
	"music.game",
44+
45-
	"music.menu",
45+
  return nil
46-
	"music.nether.basalt_deltas",
46+
47-
	"music.nether.crimson_forest",
47+
48-
	"music.nether.nether_wastes",
48+
49-
	"music.nether.soul_sand_valley",
49+
50-
	"music.nether.warped_forest",
50+
51-
	"music.overworld.deep_dark",
51+
52-
	"music.overworld.dripstone_caves",
52+
53-
	"music.overworld.frozen_peaks",
53+
  centerText("Welcome to TunePlay v1.0", 1)
54-
	"music.overworld.grove",
54+
55-
	"music.overworld.jagged_peaks",
55+
  if nowplaying ~= nil then
56-
	"music.overworld.lush_caves",
56+
    centerText("Now playing:", 5)
57-
	"music.overworld.meadow",
57+
    centerText(song_titles[nowplaying], 6)
58-
	"music.overworld.old_growth_taiga",
58+
59-
	"music.overworld.snowy_slopes",
59+
60-
	"music.overworld.stony_peaks",
60+
61-
	"music.overworld.swamp",
61+
62-
	"music.under_water",
62+
63-
	"music_disc.11",
63+
64-
	"music_disc.13",
64+
65-
	"music_disc.5",
65+
66-
	"music_disc.blocks",
66+
  if nowplaying ~= nil then
67-
	"music_disc.cat",
67+
    optionsText("P", "Choose another song", 3)
68-
	"music_disc.chirp",
68+
  else
69-
	"music_disc.far",
69+
    optionsText("P", "Choose a song", 3)
70-
	"music_disc.mall",
70+
71-
	"music_disc.mellohi",
71+
  if nostalgiamode then
72-
	"music_disc.otherside",
72+
    optionsText("N", "Disable nostalgia mode", 4)
73-
	"music_disc.pigstep",
73+
  else
74-
	"music_disc.stal",
74+
    optionsText("N", "Enable nostalgia mode", 4)
75-
	"music_disc.strad",
75+
76-
	"music_disc.wait",
76+
  optionsText("B", "Back to main menu", 5)
77-
	"music_disc.ward"
77+
  optionsText("Q", "Exit", 6)
78
end
79
80
-- Array of all the songs available.
81-
	"Shuffle creative music",
81+
82-
	"C418 - Alpha",
82+
    "music.creative",
83-
	"C418 - Dragon Fight",
83+
    "music.credits",
84-
	"C418 - The End",
84+
    "music.dragon",
85-
	"Shuffle survival music",
85+
    "music.end",
86-
	"Shuffle menu music",
86+
    "music.game",
87-
	"Shuffle Nether Basalt Deltas music",
87+
    "music.menu",
88-
	"Shuffle Nether Crimson Forest music",
88+
    "music.nether.basalt_deltas",
89-
	"Shuffle Nether Nether Wastes music",
89+
    "music.nether.crimson_forest",
90-
	"Shuffle Nether Soul Sand Valley music",
90+
    "music.nether.nether_wastes",
91-
	"Shuffle Nether Warped Forest music",
91+
    "music.nether.soul_sand_valley",
92-
	"Shuffle underwater music",
92+
    "music.nether.warped_forest",
93-
	"Shuffle Deep Dark music",
93+
    "music.overworld.deep_dark",
94-
	"Shuffle Dripstone Caves music",
94+
    "music.overworld.dripstone_caves",
95-
	"Shuffle Frozen Peaks music",
95+
    "music.overworld.frozen_peaks",
96-
	"Shuffle Grove music",
96+
    "music.overworld.grove",
97-
	"Shuffle Jagged Peaks music",
97+
    "music.overworld.jagged_peaks",
98-
	"Shuffle Lush Caves music",
98+
    "music.overworld.lush_caves",
99-
	"Shuffle Meadow music",
99+
    "music.overworld.meadow",
100-
	"Shuffle Old Growth Taiga music",
100+
    "music.overworld.old_growth_taiga",
101-
	"Shuffle Snowy Slopes music",
101+
    "music.overworld.snowy_slopes",
102-
	"Shuffle Stony Peaks music",
102+
    "music.overworld.stony_peaks",
103-
	"Shuffle Swamp music",
103+
    "music.overworld.swamp",
104-
	"C418 - 11",
104+
    "music.under_water",
105-
	"C418 - 13",
105+
    "music_disc.11",
106-
	"Samuel Aberg - 5",
106+
    "music_disc.13",
107-
	"C418 - Blocks",
107+
    "music_disc.5",
108-
	"C418 - Cat",
108+
    "music_disc.blocks",
109-
	"C418 - Chirp",
109+
    "music_disc.cat",
110-
	"C418 - Far",
110+
    "music_disc.chirp",
111-
	"C418 - Mall",
111+
    "music_disc.far",
112-
	"C418 - Mellohi",
112+
    "music_disc.mall",
113-
	"Lena Raine - Otherside",
113+
    "music_disc.mellohi",
114-
	"Lena Raine - Pigstep",
114+
    "music_disc.otherside",
115-
	"C418 - Stal",
115+
    "music_disc.pigstep",
116-
	"C418 - Strad",
116+
    "music_disc.stal",
117-
	"C418 - Wait",
117+
    "music_disc.strad",
118-
	"C418 - Ward"
118+
    "music_disc.wait",
119
    "music_disc.ward"
120
}
121
122
song_titles = {
123
    "Shuffle creative music",
124
    "C418 - Alpha",
125
    "C418 - Dragon Fight",
126
    "C418 - The End",
127
    "Shuffle survival music",
128
    "Shuffle menu music",
129
    "Shuffle Nether Basalt Deltas music",
130
    "Shuffle Nether Crimson Forest music",
131
    "Shuffle Nether Nether Wastes music",
132-
	if i > #songs then
132+
    "Shuffle Nether Soul Sand Valley music",
133-
	  break
133+
    "Shuffle Nether Warped Forest music",
134-
	end
134+
    "Shuffle Deep Dark music",
135-
	optionsText(i, song_titles[i], y)
135+
    "Shuffle Dripstone Caves music",
136-
	y = y + 1
136+
    "Shuffle Frozen Peaks music",
137
    "Shuffle Grove music",
138
    "Shuffle Jagged Peaks music",
139-
	optionsText("p", "Previous page", y)
139+
    "Shuffle Lush Caves music",
140
    "Shuffle Meadow music",
141
    "Shuffle Old Growth Taiga music",
142-
	optionsText("n", "Next page", y + 1)
142+
    "Shuffle Snowy Slopes music",
143
    "Shuffle Stony Peaks music",
144-
  optionsText("b", "Back to options", y + 2)
144+
    "Shuffle Swamp music",
145
    "Shuffle underwater music",
146
    "C418 - 11",
147
    "C418 - 13",
148
    "Samuel Aberg - 5",
149
    "C418 - Blocks",
150
    "C418 - Cat",
151-
  centerText("Now playing", 1)
151+
    "C418 - Chirp",
152-
  centerText(song_titles[song], 3)
152+
    "C418 - Far",
153-
  term.setCursorPos(1, 5)
153+
    "C418 - Mall",
154-
  term.write("Press Enter to stop playback")
154+
    "C418 - Mellohi",
155-
  local handle = peripheral.find("speaker")
155+
    "Lena Raine - Otherside",
156-
  handle.playDisk(songs[song])
156+
    "Lena Raine - Pigstep",
157
    "C418 - Stal",
158-
	local event, key = os.pullEvent("key")
158+
    "C418 - Strad",
159-
	if key == keys.enter then
159+
    "C418 - Wait",
160-
	  handle.stop()
160+
    "C418 - Ward"
161-
	  break
161+
162-
	end
162+
163
-- Draw music list, paginated
164
local function drawMusicList(page)
165
  term.clear()
166
  term.setCursorPos(1, 1)
167
  centerText("Choose a song", 1)
168
  local i = 1
169
  local y = 3
170-
	local event, key = os.pullEvent("key")
170+
171-
	if key == keys.enter then
171+
172-
	  drawOptionsMenu()
172+
173-
	  while true do
173+
  local j = 0
174-
		local event, key = os.pullEvent("key")
174+
175-
		if key == keys["1"] then
175+
    if i > #songs then
176-
		  local page = 1
176+
      break
177-
		  while true do
177+
    end
178-
			drawMusicList(page)
178+
    optionsText(j, song_titles[i], y)
179-
			local event, key = os.pullEvent("key")
179+
    y = y + 1
180-
			if key == keys["p"] then
180+
    j = j + 1
181-
			  if page > 1 then
181+
182-
				page = page - 1
182+
  y = y + 1
183-
			  end
183+
184-
			elseif key == keys["n"] then
184+
    optionsText("P", "Previous page", y)
185-
			  if page < math.ceil(#songs / 10) then
185+
    y = y + 1
186-
				page = page + 1
186+
187-
			  end
187+
188-
			elseif key == keys["b"] then
188+
    optionsText("N", "Next page", y)
189-
			  break
189+
190-
			else
190+
  optionsText("B", "Back to main menu", y + 1)
191-
			  if key >= 1 and key <= #songs then
191+
192-
				playSong(key)
192+
193-
			  end
193+
194-
			end
194+
195-
		  end
195+
  local speakers = {peripheral.find "speaker"}
196-
		elseif key == keys["2"] then
196+
  for _, speaker in ipairs(speakers) do
197-
		  local handle = peripheral.find("speaker")
197+
    if nostalgiamode then
198-
		  handle.playDisk("music.creative")
198+
      speaker.playSound(songs[song], 1.1, 0.84)
199-
		elseif key == keys["3"] then
199+
    else
200-
		  local handle = peripheral.find("speaker")
200+
      speaker.playSound(songs[song], 1.0, 1.0)
201-
		  handle.stop()
201+
    end
202-
		elseif key == keys["4"] then
202+
203-
		  drawMenu()
203+
  nowplaying = song
204-
		  break
204+
205-
		elseif key == keys["5"] then
205+
206-
		  return
206+
207-
		end
207+
208-
	  end
208+
209-
	end
209+
210
    local event, key = os.pullEvent("key")
211
    if key == keys.enter then
212
      drawOptionsMenu()
213
      while true do
214
        local event, key = os.pullEvent("key")
215
        if key == keys.p then
216
          local page = 1
217
          while true do
218
            drawMusicList(page)
219
            local event, key = os.pullEvent("key")
220
            if key == keys.p then
221
              if page > 1 then
222
                page = page - 1
223
              end
224
            elseif key == keys.n then
225
              if page < math.ceil(#songs / 10) then
226
                page = page + 1
227
              end
228
            elseif key == keys.b then
229
              drawMenu()
230
              break
231
            else
232
              -- Check if the key is a number
233
              local num = numberKey(key)
234
              if num ~= nil then
235
                local song = (page - 1) * 10 + num + 1
236
                playSong(song)
237
                -- Back to main menu
238
                drawMenu()
239
                break
240
              end
241
            end
242
          end
243
          break
244
        elseif key == keys.b then
245
          drawMenu()
246
          break
247
        elseif key == keys.n then
248
          nostalgiamode = not nostalgiamode
249
          drawOptionsMenu()
250
        elseif key == keys.q then
251
          -- Clear the screen and exit
252
          term.clear()
253
          return
254
        end
255
      end
256
    end
257
  end
258
end
259
260
main()
261