--defining a function to make coloured text
function treesay(text)
  current_sprite:say("`%" .. text)
end

-- a function to one-shot SFX w/no looping
function oneshot(sound)
  return dink.playsound(sound, 0, 0, 0, false)
end

function main()
  treesay("Media test - Lua variant")
end

function hit()
  treesay("Ouch!")
end

function talk()

player:freeze()
-- picker
local menu = dink.create_choice_menu()
menu.title_color = 3
menu.title = "Pick something will ya"

local video = menu:add_choice("Play video")
local tracker = menu:add_choice("Play tracker module")
local spc = menu:add_choice("Play SNES SPC")
local wav = menu:add_choice("Repeating WAV with volume")
local ogg = menu:add_choice("Ogg Vorbis SFX")
local mpthree = menu:add_choice("MP3 SFX")

local result = menu:show()

if result == video then
  -- dink.playavi("anim/fireworks.mp4")
  treesay("Video playback doesn't work in Lua yet")
end

if result == tracker then
  dink.playmidi("Farewell.it")
  treesay("Patttern setting doesn't work yet")
end

if result == spc then
 dink.playmidi("prime.spc")
 treesay("If your build has MixerX you should be hearing it")
end

if result == wav then
  dink.stopmidi()
  local snd = dink.playsound(53, 0,0,0, true)
  dink.wait(2000)
  treesay("Attempting to attenuate (doesn't work)")
  -- snd.vol = - 1500
  -- doesn't work ree - something wrong with sounds
  -- print(snd.soundbank_number)
  dink.wait(14000)
  treesay("Killing off")
  snd:kill()
  dink.playmidi("octfalls.mid")
end

if result == ogg then
 dink.stopmidi()
 local sfx = dink.playsound(55, 0, 0, 0, true)
 -- sfx.survive = true
 treesay("This should loop indefinitely...")
 dink.wait(3000)
 treesay("And survive screen changes (but doesn't)")
end

if result == mpthree then
dink.stopmidi()
local ewql = oneshot(57)
treesay("MP3 as SFX, no looping")
end


player:unfreeze()

end
