singe/testScripts/scene100.singe

89 lines
3.4 KiB
Text

-- Forge: the picture at a point, and the light sensor that judges a shot by it. pictureAt is the
-- condition a rule asks -- bright, dark, or neither -- and lightSensor is the behaviour built on
-- the same read, the ActionMax way of judging a shot over video. Both are the framework's own
-- words, so this scene is what covers them from the repository alone: the description compiles,
-- the emitted Lua calls the runtime, and the answers are the documented ones. Run plain, where
-- no video is playing and every frame must read dark; run with -v, where the picture is a moving
-- one and bright frames must appear.
dofile("Forge/AuthorCompile.singe")
local font = fontLoad("Singe/FreeSansBold.ttf", 18)
fontSelect(font)
fontQuality(FONT_QUALITY_BLENDED)
local built = authorBuild("testScripts/author/picture.forge", singeGetDataPath() .. "picture.singe")
local file = built and io.open(singeGetDataPath() .. "picture.singe", "r")
local text = file and file:read("a") or ""
if file then
file:close()
end
if not built then
debugPrint("PICTURE FAIL the description did not compile")
singeQuit()
return
end
if text:find("authorPictureIs", 1, true) == nil then
debugPrint("PICTURE FAIL the built game does not call authorPictureIs")
end
if AUTHOR.behaviours.lightSensor == nil then
debugPrint("PICTURE FAIL the framework has no lightSensor behaviour")
end
dofile(singeGetDataPath() .. "picture.singe")
local gameUpdate = onOverlayUpdate
local frames = 0
local FRAMES = 120
-- The read on its own, beside the condition's: the runtime answers one of three words, and a
-- point outside the picture is still answered rather than failing.
local function checkRead()
local here = authorPictureState(200, 120)
local far = authorPictureState(-50, -50)
if (here ~= "dark") and (here ~= "bright") and (here ~= "unknown") then
debugPrint("PICTURE FAIL authorPictureState answered '" .. tostring(here) .. "'")
end
if far == nil then
debugPrint("PICTURE FAIL a point off the picture answered nothing")
end
end
function onOverlayUpdate()
local result = gameUpdate and gameUpdate() or OVERLAY_UPDATED
local dark = AUTHOR_VARS.dark or 0
local bright = AUTHOR_VARS.bright or 0
local other = AUTHOR_VARS.neither or 0
frames = frames + 1
if frames == 1 then
checkRead()
end
overlayPrint(1, 1, string.format("pictureAt at 200,120: dark %d bright %d neither %d of %d frames", dark, bright, other, frames))
overlayPrint(1, 2, "lightSensor and pictureAt are the framework's own words now")
if frames == 60 then
singeScreenshot()
elseif frames == FRAMES then
debugPrint(string.format("PICTURE RESULT dark %d, bright %d, neither %d, of %d frames", dark, bright, other, frames))
if (dark + bright + other) ~= frames then
debugPrint("PICTURE FAIL the three answers do not add up to the frames drawn")
end
-- No video: the count of frames on the disc is zero, which is how a script tells.
if discGetFrameCount() == 0 then
if dark ~= frames then
debugPrint("PICTURE FAIL with no video playing every frame should read dark")
end
elseif (bright + other) == 0 then
-- Over a picture the read must see something other than the zeroes a missing video
-- gives. Which of bright and neither it sees is the video's business: the menu's
-- backdrop is mid-tone, so it reads neither and never bright.
debugPrint("PICTURE FAIL over a moving picture every frame still read dark")
end
singeQuit()
end
return result
end