-- The 2D canvas's turn handle and the types 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 type 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 types panel: a thumbnail in front of every name. -- A click on a row of the panel does what the arrows do, and a click on a field starts -- typing it, through the dispatcher the rows are wired to. -- Real clicks, dispatched on the rows as RmlUi would, so the engine's handler path is -- what is tested and not only the dispatcher behind it. local function click(id) rmlui.contexts["gui" .. FORGE.gui].documents["forge"]:GetElementById(id):DispatchEvent("click", {}) end forgeKey(0, SCANCODE.MAIN_2.value) click("t2") local lit = FORGE.typeName forgeKey(0, SCANCODE.MAIN_1.value) click("e2") local picked = FORGE.selected click("f3") local editing = FORGE.editing and FORGE.editing.key forgeKey(0, SCANCODE.ESCAPE.value) debugPrint(string.format("TURN clicks: type row 2 lit %s, entity row 2 selected %s, field row 3 typing %s", tostring(lit), tostring(picked), tostring(editing))) if (picked ~= 2) or (editing ~= "x") then debugPrint("TURN FAIL a click on a row should select it and a click on a field should start typing it") end forgeKey(0, SCANCODE.MAIN_2.value) while FORGE.mode ~= "types" 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(" 80 then singeQuit() end return OVERLAY_UPDATED end