Skip to content

Commit

Permalink
rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
KilledByAPixel committed Oct 4, 2024
1 parent f3a6465 commit e3d0a38
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 74 deletions.
11 changes: 11 additions & 0 deletions dist/littlejs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ declare module "littlejsengine" {
* @param {Array} [objects=engineObjects] - List of objects to check
* @memberof Engine */
export function engineObjectsCallback(pos?: Vector2, size?: number | Vector2, callbackFunction?: Function, objects?: any[]): void;
/** Add a new update function for a plugin
* @param {Function} [updateFunction]
* @param {Function} [renderFunction]
* @memberof Engine */
export function engineAddPlugin(updateFunction?: Function, renderFunction?: Function): void;
/**
* LittleJS Debug System
* - Press Esc to show debug overlay with mouse pick
Expand Down Expand Up @@ -470,6 +475,10 @@ declare module "littlejsengine" {
* @param {Number} scale
* @memberof Settings */
export function setParticleEmitRateScale(scale: number): void;
/** Set if touch input is allowed
* @param {Boolean} enable
* @memberof Settings */
export function setTouchInputEnable(enable: boolean): void;
/** Set if gamepads are enabled
* @param {Boolean} enable
* @memberof Settings */
Expand Down Expand Up @@ -1306,6 +1315,7 @@ declare module "littlejsengine" {
* - Tracks keyboard down, pressed, and released
* - Tracks mouse buttons, position, and wheel
* - Tracks multiple analog gamepads
* - Touch input is handled as mouse input
* - Virtual gamepad for touch devices
* @namespace Input
*/
Expand Down Expand Up @@ -1335,6 +1345,7 @@ declare module "littlejsengine" {
* - Tracks keyboard down, pressed, and released
* - Tracks mouse buttons, position, and wheel
* - Tracks multiple analog gamepads
* - Touch input is handled as mouse input
* - Virtual gamepad for touch devices
* @namespace Input
*/
Expand Down
70 changes: 46 additions & 24 deletions dist/littlejs.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,13 @@ let gamepadDirectionEmulateStick = true;
* @memberof Settings */
let inputWASDEmulateDirection = true;

/** True if touch input is enabled for mobile devices
* - Touch events will be routed to mouse events
* @type {Boolean}
* @default
* @memberof Settings */
let touchInputEnable = true;

/** True if touch gamepad should appear on mobile devices
* - Supports left analog stick, 4 face buttons and start button (button 9)
* - Must be set by end of gameInit to be activated
Expand Down Expand Up @@ -1715,6 +1722,11 @@ function setGamepadDirectionEmulateStick(enable) { gamepadDirectionEmulateStick
* @memberof Settings */
function setInputWASDEmulateDirection(enable) { inputWASDEmulateDirection = enable; }

/** Set if touch input is allowed
* @param {Boolean} enable
* @memberof Settings */
function setTouchInputEnable(enable) { touchInputEnable = enable; }

/** Set if touch gamepad should appear on mobile devices
* @param {Boolean} enable
* @memberof Settings */
Expand Down Expand Up @@ -2235,13 +2247,16 @@ class EngineObject
/** Render debug info for this object */
renderDebugInfo()
{
// show object info for debugging
const size = vec2(max(this.size.x, .2), max(this.size.y, .2));
const color1 = rgb(this.collideTiles?1:0, this.collideSolidObjects?1:0, this.isSolid?1:0, this.parent?.2:.5);
const color2 = this.parent ? rgb(1,1,1,.5) : rgb(0,0,0,.8);
drawRect(this.pos, size, color1, this.angle, false);
drawRect(this.pos, size.scale(.8), color2, this.angle, false);
this.parent && drawLine(this.pos, this.parent.pos, .1, rgb(0,0,1,.5), false);
if (debug)
{
// show object info for debugging
const size = vec2(max(this.size.x, .2), max(this.size.y, .2));
const color1 = rgb(this.collideTiles?1:0, this.collideSolidObjects?1:0, this.isSolid?1:0, this.parent?.2:.5);
const color2 = this.parent ? rgb(1,1,1,.5) : rgb(0,0,0,.8);
drawRect(this.pos, size, color1, this.angle, false);
drawRect(this.pos, size.scale(.8), color2, this.angle, false);
this.parent && drawLine(this.pos, this.parent.pos, .1, rgb(0,0,1,.5), false);
}
}
}
/**
Expand Down Expand Up @@ -2748,6 +2763,7 @@ function toggleFullscreen()
* - Tracks keyboard down, pressed, and released
* - Tracks mouse buttons, position, and wheel
* - Tracks multiple analog gamepads
* - Touch input is handled as mouse input
* - Virtual gamepad for touch devices
* @namespace Input
*/
Expand Down Expand Up @@ -2881,7 +2897,8 @@ function inputUpdate()
if (headlessMode) return;

// clear input when lost focus (prevent stuck keys)
isTouchDevice || document.hasFocus() || clearInput();
if(!(touchInputEnable && isTouchDevice) && !document.hasFocus())
clearInput();

// update mouse world space position
mousePos = screenToWorld(mousePosScreen);
Expand Down Expand Up @@ -2953,7 +2970,7 @@ function inputInit()
oncontextmenu = (e)=> false; // prevent right click menu

// init touch input
if (isTouchDevice)
if (isTouchDevice && touchInputEnable && !headlessMode)
touchInputInit();
}

Expand Down Expand Up @@ -3081,12 +3098,12 @@ function vibrateStop() { vibrate(0); }

/** True if a touch device has been detected
* @memberof Input */
const isTouchDevice = !headlessMode && window.ontouchstart !== undefined;
const isTouchDevice = window.ontouchstart !== undefined;

// touch gamepad internal variables
let touchGamepadTimer = new Timer, touchGamepadButtons, touchGamepadStick;

// try to enable touch mouse
// enable touch input mouse passthrough
function touchInputInit()
{
// add non passive touch event listeners
Expand Down Expand Up @@ -3195,6 +3212,7 @@ function touchInputInit()
// render the touch gamepad, called automatically by the engine
function touchGamepadRender()
{
if (!touchInputEnable || !isTouchDevice || headlessMode) return;
if (!touchGamepadEnable || !touchGamepadTimer.isSet())
return;

Expand Down Expand Up @@ -4599,7 +4617,8 @@ function medalsInit(saveName)
medalsForEach(medal=> medal.unlocked = (localStorage[medal.storageKey()] | 0));

// engine automatically renders medals
addPluginRender(function()
engineAddPlugin(undefined, medalsRender);
function medalsRender()
{
if (!medalsDisplayQueue.length)
return;
Expand All @@ -4623,7 +4642,7 @@ function medalsInit(saveName)
time > slideOffTime ? (time - slideOffTime) / medalDisplaySlideTime : 0;
medal.render(hidePercent);
}
});
}
}

/** Calls a function for each medal
Expand Down Expand Up @@ -5062,7 +5081,7 @@ const engineName = 'LittleJS';
* @type {String}
* @default
* @memberof Engine */
const engineVersion = '1.9.8';
const engineVersion = '1.9.9';

/** Frames per second to update
* @type {Number}
Expand Down Expand Up @@ -5121,14 +5140,14 @@ let frameTimeLastMS = 0, frameTimeBufferMS = 0, averageFPS = 0;
const pluginUpdateList = [], pluginRenderList = [];

/** Add a new update function for a plugin
* @param {Function} updateFunction
* @memberof Engine */
function addPluginUpdate(updateFunction) { pluginUpdateList.push(updateFunction); }

/** Add a new render function for a plugin
* @param {Function} renderFunction
* @param {Function} [updateFunction]
* @param {Function} [renderFunction]
* @memberof Engine */
function addPluginRender(renderFunction) { pluginRenderList.push(renderFunction); }
function engineAddPlugin(updateFunction, renderFunction)
{
updateFunction && pluginUpdateList.push(updateFunction);
renderFunction && pluginRenderList.push(renderFunction);
}

///////////////////////////////////////////////////////////////////////////////
// Main engine functions
Expand Down Expand Up @@ -5301,10 +5320,11 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
const styleBody =
'margin:0;overflow:hidden;' + // fill the window
'background:#000;' + // set background color
'touch-action:none;' + // prevent mobile pinch to resize
'user-select:none;' + // prevent mobile hold to select
'user-select:none;' + // prevent hold to select
'-webkit-user-select:none;' + // compatibility for ios
'-webkit-touch-callout:none'; // compatibility for ios
(!touchInputEnable ? '' : // no touch css setttings
'touch-action:none;' + // prevent mobile pinch to resize
'-webkit-touch-callout:none');// compatibility for ios
document.body.style.cssText = styleBody;
document.body.appendChild(mainCanvas = document.createElement('canvas'));
mainContext = mainCanvas.getContext('2d');
Expand Down Expand Up @@ -5645,6 +5665,7 @@ export {
engineObjectsUpdate,
engineObjectsDestroy,
engineObjectsCallback,
engineAddPlugin,

// Globals
debug,
Expand Down Expand Up @@ -5726,6 +5747,7 @@ export {
setObjectMaxSpeed,
setGravity,
setParticleEmitRateScale,
setTouchInputEnable,
setGamepadsEnable,
setGamepadDirectionEmulateStick,
setInputWASDEmulateDirection,
Expand Down
2 changes: 1 addition & 1 deletion dist/littlejs.esm.min.js

Large diffs are not rendered by default.

68 changes: 44 additions & 24 deletions dist/littlejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,13 @@ let gamepadDirectionEmulateStick = true;
* @memberof Settings */
let inputWASDEmulateDirection = true;

/** True if touch input is enabled for mobile devices
* - Touch events will be routed to mouse events
* @type {Boolean}
* @default
* @memberof Settings */
let touchInputEnable = true;

/** True if touch gamepad should appear on mobile devices
* - Supports left analog stick, 4 face buttons and start button (button 9)
* - Must be set by end of gameInit to be activated
Expand Down Expand Up @@ -1715,6 +1722,11 @@ function setGamepadDirectionEmulateStick(enable) { gamepadDirectionEmulateStick
* @memberof Settings */
function setInputWASDEmulateDirection(enable) { inputWASDEmulateDirection = enable; }

/** Set if touch input is allowed
* @param {Boolean} enable
* @memberof Settings */
function setTouchInputEnable(enable) { touchInputEnable = enable; }

/** Set if touch gamepad should appear on mobile devices
* @param {Boolean} enable
* @memberof Settings */
Expand Down Expand Up @@ -2235,13 +2247,16 @@ class EngineObject
/** Render debug info for this object */
renderDebugInfo()
{
// show object info for debugging
const size = vec2(max(this.size.x, .2), max(this.size.y, .2));
const color1 = rgb(this.collideTiles?1:0, this.collideSolidObjects?1:0, this.isSolid?1:0, this.parent?.2:.5);
const color2 = this.parent ? rgb(1,1,1,.5) : rgb(0,0,0,.8);
drawRect(this.pos, size, color1, this.angle, false);
drawRect(this.pos, size.scale(.8), color2, this.angle, false);
this.parent && drawLine(this.pos, this.parent.pos, .1, rgb(0,0,1,.5), false);
if (debug)
{
// show object info for debugging
const size = vec2(max(this.size.x, .2), max(this.size.y, .2));
const color1 = rgb(this.collideTiles?1:0, this.collideSolidObjects?1:0, this.isSolid?1:0, this.parent?.2:.5);
const color2 = this.parent ? rgb(1,1,1,.5) : rgb(0,0,0,.8);
drawRect(this.pos, size, color1, this.angle, false);
drawRect(this.pos, size.scale(.8), color2, this.angle, false);
this.parent && drawLine(this.pos, this.parent.pos, .1, rgb(0,0,1,.5), false);
}
}
}
/**
Expand Down Expand Up @@ -2748,6 +2763,7 @@ function toggleFullscreen()
* - Tracks keyboard down, pressed, and released
* - Tracks mouse buttons, position, and wheel
* - Tracks multiple analog gamepads
* - Touch input is handled as mouse input
* - Virtual gamepad for touch devices
* @namespace Input
*/
Expand Down Expand Up @@ -2881,7 +2897,8 @@ function inputUpdate()
if (headlessMode) return;

// clear input when lost focus (prevent stuck keys)
isTouchDevice || document.hasFocus() || clearInput();
if(!(touchInputEnable && isTouchDevice) && !document.hasFocus())
clearInput();

// update mouse world space position
mousePos = screenToWorld(mousePosScreen);
Expand Down Expand Up @@ -2953,7 +2970,7 @@ function inputInit()
oncontextmenu = (e)=> false; // prevent right click menu

// init touch input
if (isTouchDevice)
if (isTouchDevice && touchInputEnable && !headlessMode)
touchInputInit();
}

Expand Down Expand Up @@ -3081,12 +3098,12 @@ function vibrateStop() { vibrate(0); }

/** True if a touch device has been detected
* @memberof Input */
const isTouchDevice = !headlessMode && window.ontouchstart !== undefined;
const isTouchDevice = window.ontouchstart !== undefined;

// touch gamepad internal variables
let touchGamepadTimer = new Timer, touchGamepadButtons, touchGamepadStick;

// try to enable touch mouse
// enable touch input mouse passthrough
function touchInputInit()
{
// add non passive touch event listeners
Expand Down Expand Up @@ -3195,6 +3212,7 @@ function touchInputInit()
// render the touch gamepad, called automatically by the engine
function touchGamepadRender()
{
if (!touchInputEnable || !isTouchDevice || headlessMode) return;
if (!touchGamepadEnable || !touchGamepadTimer.isSet())
return;

Expand Down Expand Up @@ -4599,7 +4617,8 @@ function medalsInit(saveName)
medalsForEach(medal=> medal.unlocked = (localStorage[medal.storageKey()] | 0));

// engine automatically renders medals
addPluginRender(function()
engineAddPlugin(undefined, medalsRender);
function medalsRender()
{
if (!medalsDisplayQueue.length)
return;
Expand All @@ -4623,7 +4642,7 @@ function medalsInit(saveName)
time > slideOffTime ? (time - slideOffTime) / medalDisplaySlideTime : 0;
medal.render(hidePercent);
}
});
}
}

/** Calls a function for each medal
Expand Down Expand Up @@ -5062,7 +5081,7 @@ const engineName = 'LittleJS';
* @type {String}
* @default
* @memberof Engine */
const engineVersion = '1.9.8';
const engineVersion = '1.9.9';

/** Frames per second to update
* @type {Number}
Expand Down Expand Up @@ -5121,14 +5140,14 @@ let frameTimeLastMS = 0, frameTimeBufferMS = 0, averageFPS = 0;
const pluginUpdateList = [], pluginRenderList = [];

/** Add a new update function for a plugin
* @param {Function} updateFunction
* @memberof Engine */
function addPluginUpdate(updateFunction) { pluginUpdateList.push(updateFunction); }

/** Add a new render function for a plugin
* @param {Function} renderFunction
* @param {Function} [updateFunction]
* @param {Function} [renderFunction]
* @memberof Engine */
function addPluginRender(renderFunction) { pluginRenderList.push(renderFunction); }
function engineAddPlugin(updateFunction, renderFunction)
{
updateFunction && pluginUpdateList.push(updateFunction);
renderFunction && pluginRenderList.push(renderFunction);
}

///////////////////////////////////////////////////////////////////////////////
// Main engine functions
Expand Down Expand Up @@ -5301,10 +5320,11 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
const styleBody =
'margin:0;overflow:hidden;' + // fill the window
'background:#000;' + // set background color
'touch-action:none;' + // prevent mobile pinch to resize
'user-select:none;' + // prevent mobile hold to select
'user-select:none;' + // prevent hold to select
'-webkit-user-select:none;' + // compatibility for ios
'-webkit-touch-callout:none'; // compatibility for ios
(!touchInputEnable ? '' : // no touch css setttings
'touch-action:none;' + // prevent mobile pinch to resize
'-webkit-touch-callout:none');// compatibility for ios
document.body.style.cssText = styleBody;
document.body.appendChild(mainCanvas = document.createElement('canvas'));
mainContext = mainCanvas.getContext('2d');
Expand Down
2 changes: 1 addition & 1 deletion dist/littlejs.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit e3d0a38

Please sign in to comment.