Skip to content

Commit 5dd4cbc

Browse files
committed
[#1091] create new global constants for Application and later other classes
1 parent ab448aa commit 5dd4cbc

File tree

4 files changed

+45
-30
lines changed

4 files changed

+45
-30
lines changed

src/application/application.js

+6-19
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,7 @@ import World from "./../physics/world.js";
99
import { onresize } from "./resize.js";
1010
import { defaultSettings } from "./settings.js";
1111
import { consoleHeader } from "./header.js";
12-
13-
/**
14-
* Select the HTML5 Canvas renderer
15-
* @constant
16-
*/
17-
const CANVAS = 0;
18-
19-
/**
20-
* Select the WebGL renderer
21-
* @constant
22-
*/
23-
const WEBGL = 1;
24-
25-
/**
26-
* Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
27-
* @constant
28-
*/
29-
const AUTO = 2;
12+
import { CANVAS, WEBGL, AUTO } from "../const.js";
3013

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

src/const.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* constant to select the HTML5 Canvas renderer
3+
* @type {number}
4+
* @static
5+
* @see Application
6+
*/
7+
export const CANVAS = 0;
8+
9+
/**
10+
* constant to select select the WebGL renderer
11+
* @type {number}
12+
* @static
13+
* @see Application
14+
*/
15+
export const WEBGL = 1;
16+
17+
/**
18+
* constant to auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
19+
* @static
20+
* @type (number)
21+
* @see Application
22+
*/
23+
export const AUTO = 2;

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ export {
175175
// Backward compatibility for deprecated method or properties
176176
export * from "./lang/deprecated.js";
177177

178+
// export all public constants
179+
export * from "./const.js";
178180

179181
/**
180182
* a flag indicating that melonJS is fully initialized

src/video/video.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,39 @@ import * as event from "./../system/event.js";
22
import { initialized, game } from "./../index.js";
33
import * as device from "./../system/device.js";
44
import utils from "./../utils/utils.js";
5+
import * as vc from "../const";
56

67
/**
78
* @namespace video
89
*/
910

11+
1012
/**
1113
* Select the HTML5 Canvas renderer
1214
* @memberof video
13-
* @constant
15+
* @static
1416
*/
15-
export const CANVAS = 0;
17+
export const CANVAS = vc.CANVAS;
1618

1719
/**
1820
* Select the WebGL renderer
1921
* @memberof video
20-
* @constant
22+
* @static
2123
*/
22-
export const WEBGL = 1;
24+
export const WEBGL = vc.WEBGL;
2325

2426
/**
2527
* Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
2628
* @memberof video
27-
* @constant
29+
* @static
2830
*/
29-
export const AUTO = 2;
31+
export const AUTO = vc.AUTO;
3032

31-
/**
32-
* A reference to the active Canvas or WebGL active renderer renderer
33-
* @memberof video
34-
* @type {CanvasRenderer|WebGLRenderer}
35-
*/
33+
/**
34+
* A reference to the active Canvas or WebGL active renderer renderer
35+
* @memberof video
36+
* @type {CanvasRenderer|WebGLRenderer}
37+
*/
3638
export let renderer = null;
3739

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

173175
/**
174176
* return a reference to the parent DOM element holding the main canvas
177+
* @memberof video
175178
* @returns {HTMLElement}
176179
*/
177180
export function getParent() {

0 commit comments

Comments
 (0)