singe/testScripts/scene82.singe
2026-09-14 14:20:17 -05:00

111 lines
3.3 KiB
Text

-- The 2D canvas's turn handle and the kinds panel's thumbnails (FORGE.md): the selected entity
-- carries a yellow arm the way its rz points, dragged round it to turn it, as the scene's ry arm
-- does; and each kind in the panel shows what it looks like beside its name.
FORGE_LIBRARY = true
dofile("Forge/Forge.singe")
local font = fontLoad("Singe/FreeSansBold.ttf", 15)
local out = singeGetDataPath()
local work = out .. "turn.game"
fontSelect(font)
fontQuality(FONT_QUALITY_BLENDED)
overlaySetResolution(720, 480)
local source = assert(io.open("testScripts/author/tail.game", "r"))
local copy = assert(io.open(work, "w"))
copy:write(source:read("a"))
source:close()
copy:close()
if not forgeBegin(work) then
debugPrint("TURN FAIL could not open " .. work)
singeQuit()
end
local frames = 0
local stage = 0
local function selectEntity(id)
for index, entry in ipairs(forgeRoom().entities) do
if entry.id == id then
forgeSelect(index)
end
end
end
local function step()
if stage == 1 then
selectEntity("spinner")
local arm = forgeTurnHandle()
debugPrint(string.format("TURN the spinner, rz 45, shows its handle at %.0f, %.0f from %.0f, %.0f", arm and arm.tx or -1, arm and arm.ty or -1, arm and arm.sx or -1, arm and arm.sy or -1))
if (arm == nil) or (arm.tx <= arm.sx) or (arm.ty <= arm.sy) then
debugPrint("TURN FAIL a handle at 45 degrees lies down and right of the entity")
end
elseif stage == 2 then
-- A quarter turn clockwise round the entity: the handle's offset turned 90 degrees.
local entry = forgeRoom().entities[FORGE.selected]
local arm = forgeTurnHandle()
local dx, dy = arm.tx - arm.sx, arm.ty - arm.sy
forgePress(arm.tx, arm.ty)
forgeDrag(arm.sx - dy, arm.sy + dx)
forgeRelease()
debugPrint(string.format("TURN a quarter turn clockwise took rz from 45 to %s", tostring(entry.rz)))
if (entry.rz == nil) or (math.abs(entry.rz - 135) > 3) then
debugPrint("TURN FAIL expected about 135")
end
elseif stage == 3 then
-- Undo puts it back, and a sheet entity with an rz draws its first frame turned.
forgeKey(0, SCANCODE.U.value)
local back = forgeRoom().entities[FORGE.selected]
debugPrint("TURN undone, rz " .. tostring(back.rz))
if back.rz ~= 45 then
debugPrint("TURN FAIL undo should give 45 back")
end
selectEntity("tilted")
elseif stage == 4 then
-- The kinds panel: a thumbnail in front of every name.
while FORGE.mode ~= "kinds" do
forgeKey(0, SCANCODE.TAB.value)
end
forgeRefresh()
local rml = rmlui.contexts["gui" .. FORGE.gui].documents["forge"]:GetElementById("list").inner_rml
local images = select(2, rml:gsub("<img", ""))
local swatch = select(2, rml:gsub("swatch", ""))
debugPrint(string.format("TURN the kinds panel shows %d sprite thumbnails and %d swatches", images, swatch))
if (images < 2) or (swatch < 1) then
debugPrint("TURN FAIL the sprite kinds want images and the fire wants a swatch")
end
debugPrint("TURN RESULT done")
end
end
function onOverlayUpdate()
frames = frames + 1
if frames % 14 == 0 and stage < 5 then
stage = stage + 1
step()
end
forgeDraw(nil, nil)
colorForeground(255, 255, 255, 255)
fontPrint(210, 8, "2D turn handle, stage " .. stage)
if frames == 20 or frames == 62 then
singeScreenshot()
end
if frames > 80 then
singeQuit()
end
return OVERLAY_UPDATED
end