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 = {
loop: true,
rect: fullrect,
anim:{},
playing: 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.kill = function()
{
assert = function() {};
debug.build = function() {};
debug.fn_break = function() {};
}
return {
debug,
Gizmos,

View file

@ -326,6 +326,14 @@ game.engine_start = function (s) {
game.startengine = 0;
var frames = [];
prosperon.release_mode = function()
{
prosperon.debug = false;
mum.debug = false;
debug.kill();
}
prosperon.debug = true;
function process() {
var startframe = profile.now();
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("gui", 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);
var Event = {

View file

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

View file

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

View file

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