fix input bug

This commit is contained in:
John Alanbrook 2024-05-30 12:05:51 -05:00
parent b2a45fcfdd
commit 1ff46c3975
5 changed files with 27 additions and 18 deletions

View file

@ -535,10 +535,8 @@ Object.unhide = function(obj, ...props)
{ {
for (var prop of props) { for (var prop of props) {
var p = Object.getOwnPropertyDescriptor(obj,prop); var p = Object.getOwnPropertyDescriptor(obj,prop);
if (!p) { if (!p)
console.warn(`No property of name ${prop}.`); continue;
return;
}
p.enumerable = true; p.enumerable = true;
Object.defineProperty(obj, prop, p); Object.defineProperty(obj, prop, p);
} }

View file

@ -354,6 +354,7 @@ function process()
var st = profile.now(); var st = profile.now();
prosperon.window_render(window.rendersize); prosperon.window_render(window.rendersize);
prosperon.draw(); prosperon.draw();
prosperon.debug();
prosperon.gui(); prosperon.gui();
prosperon.screengui(); prosperon.screengui();
prosperon.hookend?.(); prosperon.hookend?.();

View file

@ -300,15 +300,20 @@ var Player = {
raw_input(cmd, state, ...args) { raw_input(cmd, state, ...args) {
for (var pawn of this.pawns.reversed()) { for (var pawn of this.pawns.reversed()) {
if (typeof pawn.inputs?.any === 'function') { if (!pawn.inputs) {
console.error(`pawn no longer has inputs object.`);
continue;
}
if (typeof pawn.inputs.any === 'function') {
pawn.inputs.any(cmd); pawn.inputs.any(cmd);
if (!pawn.inputs.fallthru) if (!pawn.inputs.fallthru)
return; return;
} }
if (!pawn.inputs?.[cmd]) { if (!pawn.inputs[cmd]) {
if (pawn.inputs?.block) return; if (pawn.inputs.block) return;
continue; continue;
} }
@ -316,21 +321,22 @@ var Player = {
switch (state) { switch (state) {
case 'pressed': case 'pressed':
fn = pawn.inputs[cmd]; fn = pawn.inputs[cmd];
break; break;
case 'rep': case 'rep':
fn = pawn.inputs[cmd].rep ? pawn.inputs[cmd] : null; fn = pawn.inputs[cmd].rep ? pawn.inputs[cmd] : null;
break; break;
case 'released': case 'released':
fn = pawn.inputs[cmd].released; fn = pawn.inputs[cmd].released;
break; break;
case 'down': case 'down':
fn = pawn.inputs[cmd].down; fn = pawn.inputs[cmd].down;
} }
if (typeof fn === 'function') { if (typeof fn === 'function') {
fn.call(pawn, ... args); fn.call(pawn, ... args);
pawn.inputs.post?.call(pawn); if (!pawn.inputs) continue; // TODO: OK? Checking if the call uncontrolled the pawn
pawn.inputs.post?.call(pawn);
} }
switch (state) { switch (state) {
@ -370,6 +376,10 @@ var Player = {
pawns: [], pawns: [],
control(pawn) { control(pawn) {
if (!pawn.inputs) {
console.warn(`attempted to control a pawn without any input object.`);
return;
}
this.pawns.push_unique(pawn); this.pawns.push_unique(pawn);
}, },

View file

@ -354,7 +354,7 @@ render.device.doc = `Device resolutions given as [x,y,inches diagonal].`;
/* All draw in screen space */ /* All draw in screen space */
render.point = function(pos,size,color = Color.blue) { render.point = function(pos,size,color = Color.blue) {
render.circle(pos,size,size,color); render.circle(pos,size,size,color);
}; };
render.cross = function(pos, size, color = Color.red) { render.cross = function(pos, size, color = Color.red) {

View file

@ -92,7 +92,7 @@ void mYughLog(int category, int priority, int line, const char *file, const char
printf("\n"); printf("\n");
} }
if (priority >= LOG_ERROR) { if (priority >= LOG_PANIC) {
js_stacktrace(); js_stacktrace();
#ifdef __WIN32 #ifdef __WIN32
DebugBreak(); DebugBreak();