132 lines
5.3 KiB
Text
132 lines
5.3 KiB
Text
-- Engine calls no other scene exercised, checked against what the Reference says of them: the
|
|
-- collision helpers on known shapes (a concave polygon among them), the disc's transport state
|
|
-- through play, pause, a skip forward, a skip to a frame, and stop, the speed and frame rate calls
|
|
-- that do nothing, one soundtrack channel off and on, a sound channel paused and resumed, the
|
|
-- keyboard and mouse queries with nothing held, a loaded video paused, a sprite mirrored, and a
|
|
-- game packed from a script. Each check prints "CALLS ok" or "CALLS FAIL"; the screenshot shows
|
|
-- the arrows plain and mirrored over the disc. Run with -v Singe/menuBackground.mkv.
|
|
dofile("Singe/Framework.singe")
|
|
|
|
local lfs = require("lfs")
|
|
local font = fontLoad("Singe/FreeSansBold.ttf", 14)
|
|
local arrows = spriteLoad("testScripts/arrows.png")
|
|
local mirrored = spriteLoad("testScripts/arrows.png")
|
|
local crackle = soundLoad("testScripts/crackle.wav")
|
|
local clip = videoLoad("Singe/menuBackground.mkv")
|
|
local frames = 0
|
|
local failures = 0
|
|
local channel = nil
|
|
local held = 0
|
|
local clipAt = 0
|
|
local LAST = 60
|
|
local SCRIPT = "function onOverlayUpdate()\n\treturn OVERLAY_UPDATED\nend\n"
|
|
|
|
|
|
local function check(name, ok, detail)
|
|
if ok then
|
|
debugPrint("CALLS ok " .. name)
|
|
else
|
|
failures = failures + 1
|
|
debugPrint("CALLS FAIL " .. name .. (detail and (" (" .. detail .. ")") or ""))
|
|
end
|
|
end
|
|
|
|
|
|
-- A game of one script and its games.dat, written into the data directory and packed from here.
|
|
local function packOne()
|
|
local data = singeGetDataPath()
|
|
local folder = data .. "packMe"
|
|
local game = data .. "packMe.game"
|
|
local file = nil
|
|
|
|
lfs.mkdir(folder)
|
|
file = assert(io.open(folder .. "/packMe.singe", "w"))
|
|
file:write(SCRIPT)
|
|
file:close()
|
|
file = assert(io.open(folder .. "/games.dat", "w"))
|
|
file:write("GAMES = { { TITLE = \"Pack Me\", SCRIPT = \"packMe/packMe.singe\" } }\n")
|
|
file:close()
|
|
os.remove(game)
|
|
check("singePack answers true", singePack(folder, game) == true)
|
|
-- A .game is read through as a folder, so the packed script is opened inside it and must read
|
|
-- back as written.
|
|
file = io.open(game .. "/packMe/packMe.singe", "r")
|
|
check("singePack holds the script", (file ~= nil) and (file:read("a") == SCRIPT))
|
|
if file then
|
|
file:close()
|
|
end
|
|
end
|
|
|
|
|
|
fontSelect(font)
|
|
overlaySetResolution(720, 480)
|
|
spriteFlip(mirrored, true, false)
|
|
|
|
check("collideRects overlapping", collideRects(0, 0, 10, 10, 5, 5, 10, 10))
|
|
check("collideRects apart", not collideRects(0, 0, 10, 10, 20, 20, 5, 5))
|
|
check("collidePointRect on the edge", collidePointRect(0, 5, 0, 0, 10, 10))
|
|
check("collidePointRect outside", not collidePointRect(11, 5, 0, 0, 10, 10))
|
|
-- An L: the notch at the top right is outside it.
|
|
check("collidePointPolygon inside the L", collidePointPolygon(2, 8, { 0, 0, 10, 0, 10, 4, 4, 4, 4, 10, 0, 10 }))
|
|
check("collidePointPolygon in the notch", not collidePointPolygon(8, 8, { 0, 0, 10, 0, 10, 4, 4, 4, 4, 10, 0, 10 }))
|
|
check("collidePointPolygon two corners hold nothing", not collidePointPolygon(1, 0, { 0, 0, 10, 0 }))
|
|
check("keyboardIsDown with nothing held", keyboardIsDown(SCANCODE.A.value) == false)
|
|
check("keyboardGetModifiers with nothing held", (keyboardGetModifiers() & MODIFIER.SHIFT.value) == 0)
|
|
mouseSetMode(MOUSE_MANY)
|
|
mouseSetMode(MOUSE_SINGLE)
|
|
check("mouseSetMode both ways", true)
|
|
|
|
|
|
function onOverlayUpdate()
|
|
frames = frames + 1
|
|
overlayClear()
|
|
spriteDraw(arrows, 40, 60)
|
|
spriteDraw(mirrored, 40, 140)
|
|
fontPrint(8, 6, string.format("frame %d disc %d failures %d", frames, discGetFrame(), failures))
|
|
if frames == 2 then
|
|
discPlay()
|
|
videoPlay(clip)
|
|
channel = soundPlay(crackle)
|
|
elseif frames == 4 then
|
|
check("soundIsPlaying while it plays", soundIsPlaying(channel))
|
|
check("soundPause says it was playing", soundPause(channel))
|
|
check("soundIsPlaying false while paused", not soundIsPlaying(channel))
|
|
elseif frames == 6 then
|
|
check("soundResume says it was paused", soundResume(channel))
|
|
check("soundIsPlaying again", soundIsPlaying(channel))
|
|
elseif frames == 10 then
|
|
check("discGetState playing", discGetState() == DISC_PLAYING)
|
|
discPause()
|
|
videoPause(clip)
|
|
clipAt = videoGetFrame(clip)
|
|
videoSetVolume(clip, 50, 50)
|
|
videoSetVolume(64)
|
|
elseif frames == 14 then
|
|
check("discGetState paused", discGetState() == DISC_PAUSED)
|
|
check("videoPause holds the frame", videoGetFrame(clip) == clipAt, videoGetFrame(clip) .. " against " .. clipAt)
|
|
held = discGetFrame()
|
|
discSkipForward(50)
|
|
elseif frames == 18 then
|
|
check("discSkipForward moves 50 frames", discGetFrame() == held + 50, discGetFrame() .. " against " .. (held + 50))
|
|
check("discSkipForward keeps the pause", discGetState() == DISC_PAUSED)
|
|
discSkipToFrame(300)
|
|
elseif frames == 22 then
|
|
check("discSkipToFrame plays", discGetState() == DISC_PLAYING)
|
|
check("discSkipToFrame lands there", (discGetFrame() >= 300) and (discGetFrame() < 330), tostring(discGetFrame()))
|
|
discChangeSpeed(2)
|
|
discSetFPS(30)
|
|
discAudio(1, false)
|
|
discAudio(1, true)
|
|
check("discChangeSpeed, discSetFPS and discAudio take their arguments", true)
|
|
singeScreenshot("calls")
|
|
elseif frames == 26 then
|
|
discStop()
|
|
elseif frames == 28 then
|
|
check("discGetState stopped", discGetState() == DISC_STOPPED)
|
|
packOne()
|
|
elseif frames == LAST then
|
|
debugPrint(string.format("CALLS RESULT failures=%d", failures))
|
|
singeQuit()
|
|
end
|
|
return OVERLAY_UPDATED
|
|
end
|