fix input down

This commit is contained in:
John Alanbrook 2024-07-11 16:37:24 -05:00
parent bb5e6b883a
commit 805c9298e6
7 changed files with 60 additions and 33 deletions

View file

@ -17,6 +17,7 @@ var fullrect = [0,0,1,1];
var sprite = { var sprite = {
loop: true, loop: true,
rect: fullrect,
anim:{}, anim:{},
playing: 0, playing: 0,
play(str = 0) { play(str = 0) {

View file

@ -238,6 +238,13 @@ debug.log.time = function(fn, name, avg=0)
debug.log.time[name].push(profile.now()-start); debug.log.time[name].push(profile.now()-start);
} }
debug.kill = function()
{
assert = function() {};
debug.build = function() {};
debug.fn_break = function() {};
}
return { return {
debug, debug,
Gizmos, Gizmos,

View file

@ -326,6 +326,14 @@ game.engine_start = function (s) {
game.startengine = 0; game.startengine = 0;
var frames = []; var frames = [];
prosperon.release_mode = function()
{
prosperon.debug = false;
mum.debug = false;
debug.kill();
}
prosperon.debug = true;
function process() { function process() {
var startframe = profile.now(); var startframe = profile.now();
var dt = profile.secs(profile.now()) - frame_t; var dt = profile.secs(profile.now()) - frame_t;
@ -573,7 +581,9 @@ Register.add_cb("update", true).doc = "Called once per frame.";
Register.add_cb("physupdate", true); Register.add_cb("physupdate", true);
Register.add_cb("gui", true); Register.add_cb("gui", true);
Register.add_cb("hud", true); Register.add_cb("hud", true);
Register.add_cb("debug", true); Register.add_cb("draw_dbg", true);
Register.add_cb("gui_dbg", true);
Register.add_cb("hud_dbg", true);
Register.add_cb("draw", true); Register.add_cb("draw", true);
var Event = { var Event = {

View file

@ -40,6 +40,7 @@ function keycode(name) { return charCodeAt(name); }
function keyname_extd(key) function keyname_extd(key)
{ {
if (typeof key === 'string') return key;
if (key > 289 && key < 302) { if (key > 289 && key < 302) {
var num = key-289; var num = key-289;
return `f${num}`; return `f${num}`;
@ -56,7 +57,7 @@ function keyname_extd(key)
return undefined; return undefined;
} }
prosperon.keys = []; var downkeys = {};
function modstr() function modstr()
{ {
@ -69,7 +70,7 @@ function modstr()
prosperon.keydown = function(key, repeat) prosperon.keydown = function(key, repeat)
{ {
prosperon.keys[key] = true; downkeys[key] = true;
if (key == 341 || key == 345) if (key == 341 || key == 345)
mod.ctrl = 1; mod.ctrl = 1;
@ -91,7 +92,8 @@ prosperon.keydown = function(key, repeat)
prosperon.keyup = function(key) prosperon.keyup = function(key)
{ {
prosperon.keys[key] = false; delete downkeys[key];
if (key == 341 || key == 345) if (key == 341 || key == 345)
mod.ctrl = 0; mod.ctrl = 0;
@ -127,9 +129,11 @@ prosperon.mousescroll = function(dx){
}; };
prosperon.mousedown = function(b){ prosperon.mousedown = function(b){
player[0].raw_input(modstr() + input.mouse.button[b], "pressed"); player[0].raw_input(modstr() + input.mouse.button[b], "pressed");
downkeys[input.mouse.button[b]] = true;
}; };
prosperon.mouseup = function(b){ prosperon.mouseup = function(b){
player[0].raw_input(input.mouse.button[b], "released"); player[0].raw_input(input.mouse.button[b], "released");
delete downkeys[input.mouse.button[b]];
}; };
input.mouse = {}; input.mouse = {};
@ -181,8 +185,8 @@ input.mouse.normal.doc = "Set the mouse to show again after hiding.";
input.keyboard = {}; input.keyboard = {};
input.keyboard.down = function(code) { input.keyboard.down = function(code) {
if (typeof code === 'number') return prosperon.keys[code]; if (typeof code === 'number') return downkeys[code];
if (typeof code === 'string') return (prosperon.keys[code.uc().charCodeAt()] || prosperon.keys[code.lc().charCodeAt()]); if (typeof code === 'string') return (downkeys[code.uc().charCodeAt()] || downkeys[code.lc().charCodeAt()]);
return undefined; return undefined;
} }
@ -210,10 +214,8 @@ input.print_pawn_kbm = function(pawn) {
input.procdown = function() input.procdown = function()
{ {
for (var k of prosperon.keys) { for (var k in downkeys)
if (!k) continue; player[0].raw_input(keyname_extd(k), "down");
player[0].raw_input(keyname_extd(k), "down");
}
} }
input.print_md_kbm = function(pawn) { input.print_md_kbm = function(pawn) {
@ -330,7 +332,10 @@ var Player = {
fn = pawn.inputs[cmd].released; fn = pawn.inputs[cmd].released;
break; break;
case 'down': case 'down':
fn = pawn.inputs[cmd].down; if (typeof pawn.inputs[cmd].down === 'function')
fn = pawn.inputs[cmd].down;
else if (pawn.inputs[cmd].down)
fn = pawn.inputs[cmd];
} }
if (typeof fn === 'function') { if (typeof fn === 'function') {

View file

@ -15,17 +15,19 @@ mum.inputs.lm = function()
mum.base = { mum.base = {
padding:[0,0], /* Each element inset with this padding on all sides */ padding:[0,0], /* Each element inset with this padding on all sides */
offset:[0,0], offset:[0,0],
pos: [0,0], pos: null,
font: "fonts/c64.ttf", font: "fonts/c64.ttf",
selectable: false, selectable: false,
selected: false, selected: false,
font_size: 16, font_size: 16,
scale: 1, scale: 1,
angle: 0, angle: 0,
anchor: [0,1], anchor: [0,1], // where to draw the item from.
background_image: null, background_image: null,
slice: null, slice: null,
hovered: {}, hover: {
color: Color.red,
},
text_shadow: { text_shadow: {
pos: [0,0], pos: [0,0],
color: Color.white, color: Color.white,
@ -45,12 +47,16 @@ mum.base = {
tooltip: null, tooltip: null,
} }
function show_debug() { return prosperon.debug && mum.debug; }
mum.debug = false; mum.debug = false;
var post = function() {}; var post = function() {};
var posts = []; var posts = [];
var context = mum.base; mum.style = mum.base;
var context = mum.style;
var contexts = []; var contexts = [];
var cursor = [0,0]; var cursor = [0,0];
@ -58,11 +64,12 @@ var cursor = [0,0];
var pre = function(data) var pre = function(data)
{ {
if (data.hide) return true; if (data.hide) return true;
data.__proto__ = mum.base; data.__proto__ = mum.style;
if (context) if (context)
contexts.push(context); contexts.push(context);
context = data; context = data;
if (context.pos) cursor = context.pos.slice();
} }
var end = function() var end = function()
@ -87,7 +94,7 @@ mum.list = function(fn, data = {})
context.bb.t += context.padding.y; context.bb.t += context.padding.y;
context.bb.b -= context.padding.y; context.bb.b -= context.padding.y;
if (mum.debug) if (show_debug())
render.boundingbox(context.bb); render.boundingbox(context.bb);
post = posts.pop(); post = posts.pop();
@ -113,10 +120,10 @@ mum.label = function(str, data = {})
context.bb = render.text_bb(str, context.scale, -1, cursor); context.bb = render.text_bb(str, context.scale, -1, cursor);
if (mum.debug) if (show_debug())
render.boundingbox(context.bb); render.boundingbox(context.bb);
if (bbox.pointin(context.bb, input.mouse.screenpos())) { if (context.action && bbox.pointin(context.bb, input.mouse.screenpos())) {
if (context.hover) { if (context.hover) {
context.hover.__proto__ = context; context.hover.__proto__ = context;
context = context.hover; context = context.hover;
@ -132,12 +139,16 @@ mum.label = function(str, data = {})
mum.image = function(path, data = {}) mum.image = function(path, data = {})
{ {
if (pre(data)) return; if (pre(data)) return;
var tex = path;
if (typeof path === 'string')
tex = game.texture(path);
var tex = game.texture(path);
if (context.slice) if (context.slice)
render.slice9(tex, cursor, context.slice, context.scale); render.slice9(tex, cursor, context.slice, context.scale);
else else {
context.bb = render.image(tex, cursor, context.scale); cursor.y -= tex.height*context.scale;
context.bb = render.image(tex, cursor, [context.scale*tex.width, context.scale*tex.height]);
}
end(); end();
} }
@ -148,7 +159,7 @@ var btnpost = function()
btnbb = context.bb; btnbb = context.bb;
} }
mum.button = function(str, data = {padding:[4,4], color:Color.black, hover:{color:Color.red}}) mum.button = function(str, data = {padding:[4,4], color:Color.black})
{ {
if (pre(data)) return; if (pre(data)) return;
posts.push(post); posts.push(post);
@ -158,7 +169,7 @@ mum.button = function(str, data = {padding:[4,4], color:Color.black, hover:{colo
else else
str(); str();
if (data.hover && bbox.pointin(btnbb, input.mouse.screenpos())) { if (data.action && data.hover && bbox.pointin(btnbb, input.mouse.screenpos())) {
data.hover.__proto__ = data; data.hover.__proto__ = data;
context = data.hover; context = data.hover;
} }
@ -178,7 +189,6 @@ mum.window = function(fn, data = {})
if (pre(data)) return; if (pre(data)) return;
cursor = context.pos;
render.rectangle(cursor, cursor.add(context.size), context.color); render.rectangle(cursor, cursor.add(context.size), context.color);
cursor.y += context.height; cursor.y += context.height;
cursor = cursor.add(context.padding); cursor = cursor.add(context.padding);
@ -186,10 +196,3 @@ mum.window = function(fn, data = {})
fn(); fn();
end(); end();
} }
mum.div = function(fn, data = {})
{
if (pre(data)) return;
fn();
end();
}

View file

@ -541,7 +541,7 @@ render.rectangle = function(lowerleft, upperright, color) {
render.box = function(pos, wh, color = Color.white) { render.box = function(pos, wh, color = Color.white) {
var lower = pos.sub(wh.scale(0.5)); var lower = pos.sub(wh.scale(0.5));
var upper = pos.add(wh.scale(0.5)); var upper = pos.add(wh.scale(0.5));
render.recteangle(lower,upper,color); render.rectangle(lower,upper,color);
}; };
render.window = function(pos, wh, color) { render.window = function(pos, wh, color) {

View file

@ -14,6 +14,7 @@ if (os.sys() === 'macos') {
appy.inputs['S-g'] = os.gc; appy.inputs['S-g'] = os.gc;
} }
appy.inputs.f12 = function() { mum.debug = !mum.debug; }
appy.inputs.f11 = window.toggle_fullscreen; appy.inputs.f11 = window.toggle_fullscreen;
appy.inputs['M-f4'] = prosperon.quit; appy.inputs['M-f4'] = prosperon.quit;