Skip to content

Commit

Permalink
[#1091] create new global constants for Application and later other c…
Browse files Browse the repository at this point in the history
…lasses
  • Loading branch information
obiot committed Jan 3, 2023
1 parent ab448aa commit 5dd4cbc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
25 changes: 6 additions & 19 deletions src/application/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,7 @@ import World from "./../physics/world.js";
import { onresize } from "./resize.js";
import { defaultSettings } from "./settings.js";
import { consoleHeader } from "./header.js";

/**
* Select the HTML5 Canvas renderer
* @constant
*/
const CANVAS = 0;

/**
* Select the WebGL renderer
* @constant
*/
const WEBGL = 1;

/**
* Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
* @constant
*/
const AUTO = 2;
import { CANVAS, WEBGL, AUTO } from "../const.js";

/**
* @classdesc
Expand All @@ -40,7 +23,7 @@ const AUTO = 2;
* @param {number} height - The height of the canvas viewport
* @param {object} [options] - The optional video/renderer parameters.<br> (see Renderer(s) documentation for further specific options)
* @param {string|HTMLElement} [options.parent=document.body] - the DOM parent element to hold the canvas in the HTML file
* @param {number|Renderer} [options.renderer=video.AUTO] - renderer to use (me.video.CANVAS, me.video.WEBGL, me.video.AUTO), or a custom renderer class
* @param {number|Renderer} [options.renderer=AUTO] - renderer to use (CANVAS, WEBGL, AUTO), or a custom renderer class
* @param {number|string} [options.scale=1.0] - enable scaling of the canvas ('auto' for automatic scaling)
* @param {string} [options.scaleMethod="fit"] - screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
* @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
Expand All @@ -49,6 +32,10 @@ const AUTO = 2;
* @param {boolean} [options.antiAlias=false] - whether to enable or not video scaling interpolation
* @param {boolean} [options.consoleHeader=true] - whether to display melonJS version and basic device information in the console
* @throws Will throw an exception if it fails to instantiate a renderer
* @example
* var my game = new Application(640, 480, {renderer: me.video.AUTO}) {
* ....
* }
*/
constructor(width, height, options) {

Expand Down
23 changes: 23 additions & 0 deletions src/const.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* constant to select the HTML5 Canvas renderer
* @type {number}
* @static
* @see Application
*/
export const CANVAS = 0;

/**
* constant to select select the WebGL renderer
* @type {number}
* @static
* @see Application
*/
export const WEBGL = 1;

/**
* constant to auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
* @static
* @type (number)
* @see Application
*/
export const AUTO = 2;
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export {
// Backward compatibility for deprecated method or properties
export * from "./lang/deprecated.js";

// export all public constants
export * from "./const.js";

/**
* a flag indicating that melonJS is fully initialized
Expand Down
25 changes: 14 additions & 11 deletions src/video/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,39 @@ import * as event from "./../system/event.js";
import { initialized, game } from "./../index.js";
import * as device from "./../system/device.js";
import utils from "./../utils/utils.js";
import * as vc from "../const";

/**
* @namespace video
*/


/**
* Select the HTML5 Canvas renderer
* @memberof video
* @constant
* @static
*/
export const CANVAS = 0;
export const CANVAS = vc.CANVAS;

/**
* Select the WebGL renderer
* @memberof video
* @constant
* @static
*/
export const WEBGL = 1;
export const WEBGL = vc.WEBGL;

/**
* Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
* @memberof video
* @constant
* @static
*/
export const AUTO = 2;
export const AUTO = vc.AUTO;

/**
* A reference to the active Canvas or WebGL active renderer renderer
* @memberof video
* @type {CanvasRenderer|WebGLRenderer}
*/
/**
* A reference to the active Canvas or WebGL active renderer renderer
* @memberof video
* @type {CanvasRenderer|WebGLRenderer}
*/
export let renderer = null;

/**
Expand Down Expand Up @@ -172,6 +174,7 @@ export function createCanvas(width, height, returnOffscreenCanvas = false) {

/**
* return a reference to the parent DOM element holding the main canvas
* @memberof video
* @returns {HTMLElement}
*/
export function getParent() {
Expand Down

0 comments on commit 5dd4cbc

Please # to comment.