From b78f8755c54e22bd8db6c5d032c98b7f68a9662c Mon Sep 17 00:00:00 2001 From: freds Date: Sat, 5 Dec 2020 15:04:54 +0100 Subject: [PATCH] fixed gif export OOM improved location arrow removed mouse pointer scaling --- carts/main.lua | 5 +- carts/title.lua | 14 +++-- plates/fps.html | 138 ++++++++++++++++++++++++++++++++++-------------- 3 files changed, 107 insertions(+), 50 deletions(-) diff --git a/carts/main.lua b/carts/main.lua index 562661d..dd946c0 100644 --- a/carts/main.lua +++ b/carts/main.lua @@ -358,8 +358,7 @@ function draw_flats(v_cache,segs) end if otherside then -- visible other side walls? - otop=otherside[1].ceil>>4 - obottom=otherside[1].floor>>4 + otop,obottom=otherside[1].ceil>>4,otherside[1].floor>>4 -- offset animated walls (doors) yoffset=0 if ldef.dontpegtop then @@ -1360,7 +1359,7 @@ function _update() _update_state() -- capture video! - if(peek(0x5f83)==1) extcmd("video") poke(0x5f83) + if(peek(0x5f83)==1) poke(0x5f83,0) extcmd("video") _slow+=1 end diff --git a/carts/title.lua b/carts/title.lua index 71022cf..04e5536 100644 --- a/carts/title.lua +++ b/carts/title.lua @@ -41,7 +41,7 @@ function next_state(fn,...) u() -- gif capture handling - if(peek(0x5f83)==1) extcmd("video") poke(0x5f83) + if(peek(0x5f83)==1) poke(0x5f83,0) extcmd("video") end end @@ -279,7 +279,7 @@ function launch_state(skill,id,level_time,kills,secrets) rect(63-#s*2-2,texty-2,63+#s*2,texty+6,15) -- left or right anchor - local xanchor=x<64 and 63-#s*2-2 or 63+#s*2 + local xanchor=mid(x<64 and 63-#s*2-2 or 63+#s*2,32,96) line(xanchor,texty+6,xanchor,y,15) line(x,y) circfill(x,y,2) @@ -292,9 +292,7 @@ end function credits_state() - local ttl=0 - local dither_pat={0b1111111111111111,0b0111111111111111,0b0111111111011111,0b0101111111011111,0b0101111101011111,0b0101101101011111,0b0101101101011110,0b0101101001011110,0b0101101001011010,0b0001101001011010,0b0001101001001010,0b0000101001001010,0b0000101000001010,0b0000001000001010,0b0000001000001000,0b0000000000000000} - local t,creditsi={},0 + local ttl,t,creditsi=0,{},0 return -- update function() @@ -332,14 +330,14 @@ function credits_state() local j=max(flr(#st*t[i]/3))+1 sp=sp..sub(st,j,j) end - print(sp,64-#sp*2,80,4) + print(sp,64-#sp*2,80,15) - if(ttl>0 and time()%4<2) print("🅾️/❎\23MENU",44,122,4) + if(ttl>0 and time()%4<2) print("🅾️/❎\23MENU",44,122,15) pal(endgame_gfx.pal,1) end, function() - endgame_gfx.pal[15]=0 + endgame_gfx.pal[15]=1 unpack_gfx(endgame_gfx) end end diff --git a/plates/fps.html b/plates/fps.html index 8d5888c..ae5a200 100644 --- a/plates/fps.html +++ b/plates/fps.html @@ -229,35 +229,32 @@ } function track_mouse(e) { - // enable mouse reading pico8_gpio[0] = 1; // clamp value to -127/127 - var canvas = document.getElementById("canvas"); - var scale = 128 / canvas.width; - pico8_gpio[1] = 128 - Math.min(Math.max(-127,Math.round(scale * e.movementX)),127); - pico8_gpio[2] = 128 - Math.min(Math.max(-127,Math.round(scale * e.movementY)),127); + pico8_gpio[1] = 128 - Math.min(Math.max(-127,Math.round(e.movementX)),127); + pico8_gpio[2] = 128 - Math.min(Math.max(-127,Math.round(e.movementY)),127); } function track_click(e, step) { - if (!p8_is_running) return; + if (!p8_is_running) return; - // clear fire button - pico8_buttons[0] = 0; + // clear fire button + pico8_buttons[0] = 0; - // left (fire/ok) - if(e.buttons & 0x1) { - pico8_buttons[0] |= 0x10; - } - // right (open/cancel) - if(e.buttons & (0x2|0x8)) { - pico8_buttons[0] |= 0x20; - } - // middle - if(e.buttons & 0x4) { - pico8_buttons[0] |= 0x40; + // left (fire/ok) + if(e.buttons & 0x1) { + pico8_buttons[0] |= 0x10; + } + // right (open/cancel) + if(e.buttons & (0x2|0x8)) { + pico8_buttons[0] |= 0x20; + } + // middle + if(e.buttons & 0x4) { + pico8_buttons[0] |= 0x40; + } } - } // p8_update_layout_hash is used to decide when to update layout (expensive especially when part of a heavy page) var p8_update_layout_hash = -1; @@ -552,8 +549,8 @@ addEventListener("touchmove", function(event){ pico8_buttons_event(event, 1); }, {passive: false}); addEventListener("touchend", function(event){ pico8_buttons_event(event, 2); }, {passive: false}); - // https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API - if(!p8_touch_detected) { + // https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API + if(!p8_touch_detected) { // pointer lock object forking for cross browser var canvas = document.getElementById("canvas"); @@ -562,23 +559,24 @@ document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock; - - canvas.onclick = function() { - canvas.requestPointerLock(); - }; - + + canvas.addEventListener("click", function() { + // need to watch: https://www.chromestatus.com/feature/5723553087356928 + canvas.requestPointerLock(); + }); + // pointer lock event listeners function lockChangeAlert() { if (document.pointerLockElement === canvas || document.mozPointerLockElement === canvas) { - document.addEventListener("mousemove", track_mouse, false); - document.addEventListener("mousedown", function(event){ track_click(event, 0); }); - document.addEventListener("mouseup", function(event){ track_click(event, 1); }); + canvas.addEventListener("mousemove", track_mouse, false); + canvas.addEventListener("mousedown", function(event){ track_click(event, 0); }); + canvas.addEventListener("mouseup", function(event){ track_click(event, 1); }); } else { // reset mouse values pico8_gpio[0]=0 pico8_gpio[1]=0 - document.removeEventListener("mousemove", track_mouse, false); + canvas.removeEventListener("mousemove", track_mouse, false); // document.removeEventListener("click", function(event){ track_click(event, 0); }, false); } } @@ -586,6 +584,26 @@ // Hook pointer lock state change events for different browsers document.addEventListener('pointerlockchange', lockChangeAlert, false); document.addEventListener('mozpointerlockchange', lockChangeAlert, false); + + // gif clear handling + // https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver + // Select the node that will be observed for mutations + const gifsNode = document.getElementById('p8_desktop'); + const trashNode = document.getElementById('p8b_trash'); + + // Options for the observer (which mutations to observe) + const config = { childList: true }; + + // Callback function to execute when mutations are observed + const callback = function(mutationsList, observer) { + trashNode.style.display = gifsNode.childElementCount==0?"none":"table"; + }; + + // Create an observer instance linked to the callback function + const observer = new MutationObserver(callback); + + // Start observing the target node for configured mutations + observer.observe(gifsNode, config); } // load and run script @@ -671,13 +689,31 @@ // key blocker. prevent cursor keys from scrolling page while playing cart. // also don't act on M, R so that can mute / reset cart document.addEventListener('keydown', - function (event) { - event = event || window.event; - if (!p8_is_running) return; - if (pico8_state.has_focus == 1) - if ([32, 37, 38, 39, 40, 77, 82, 80, 9].indexOf(event.keyCode) > -1) // block cursors, M R P, tab - if (event.preventDefault) event.preventDefault(); - },{passive: false}); + function (event) { + event = event || window.event; + if (!p8_is_running) return; + if (pico8_state.has_focus == 1) { + if(event.keyCode==32) { + // gpio pin 3 contains "use" button code + pico8_buttons[0] |= pico8_gpio[3]; + } + + if ([37, 38, 39, 40, 77, 82, 80, 9].indexOf(event.keyCode) > -1) // block cursors, M R P, tab + if (event.preventDefault) event.preventDefault(); + } + + },{passive: false}); + + document.addEventListener('keyup', + function (event) { + event = event || window.event; + if (!p8_is_running) return; + if (pico8_state.has_focus == 1) + if(event.keyCode==32) { + pico8_buttons[0] &= ~pico8_gpio[3]; + if (event.preventDefault) event.preventDefault(); + } + },{passive: false}); // when using codo_textarea to determine focus, need to explicitly hand focus back when clicking a p8_menu_button function p8_give_focus() @@ -741,6 +777,26 @@ opacity:1.0; cursor:pointer; } + + .p8_trash_button{ + opacity:0.3; + padding:4px; + display:table; + width:24px; + height:24px; + float:right; + } + + @media screen and (min-width:512px) { + .p8_trash_button{ + width:24px; margin-left:12px; margin-bottom:8px; + } + } + + .p8_trash_button:hover{ + opacity:1.0; + cursor:pointer; + } canvas{ image-rendering: optimizeSpeed; @@ -787,7 +843,9 @@ -
+ +
+
@@ -820,6 +878,8 @@
+ +