Skip to content

Commit 2a24ff0

Browse files
committed
move the debug panel into its own repository (initial commit)
0 parents  commit 2a24ff0

File tree

14 files changed

+1716
-0
lines changed

14 files changed

+1716
-0
lines changed

.eslintrc.json

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"env": {
3+
"es6" : true,
4+
"browser" : true,
5+
"node" : true
6+
},
7+
"globals": {
8+
"globalThis": false
9+
},
10+
"parser": "@babel/eslint-parser",
11+
"parserOptions": {
12+
"ecmaVersion": 6,
13+
"sourceType": "module",
14+
"requireConfigFile": false,
15+
"babelOptions": {
16+
"plugins": [
17+
"@babel/plugin-syntax-import-assertions"
18+
]
19+
}
20+
},
21+
"plugins": ["eslint-plugin-jsdoc"],
22+
"extends": "eslint:recommended",
23+
"rules": {
24+
// http://eslint.org/docs/rules/
25+
"accessor-pairs": "error",
26+
"arrow-body-style": ["error", "as-needed"],
27+
"arrow-spacing": ["error", { "before": true, "after": true }],
28+
"block-spacing": ["error", "always"],
29+
"block-scoped-var": "error",
30+
"brace-style": ["off", "1tbs", { "allowSingleLine": true }],
31+
"camelcase": ["off", { "properties": "never" }],
32+
"comma-dangle": ["error", "never"],
33+
"comma-spacing": ["error", { "before": false, "after": true }],
34+
"comma-style": ["error", "last"],
35+
"constructor-super": "error",
36+
"curly": ["error", "multi-line"],
37+
"dot-location": ["error", "property"],
38+
"eol-last": "error",
39+
"eqeqeq": ["error", "allow-null"],
40+
"func-call-spacing": ["error", "never"],
41+
"handle-callback-err": ["error", "^(err|error)$" ],
42+
"indent": ["off", 4],
43+
"key-spacing": ["off", { "beforeColon": false, "afterColon": true }],
44+
"keyword-spacing": ["error", { "before": true, "after": true }],
45+
"new-cap": ["error", { "newIsCap": true, "capIsNew": false }],
46+
"new-parens": "error",
47+
"no-array-constructor": "error",
48+
"no-caller": "error",
49+
"no-class-assign": "error",
50+
"no-constructor-return": "error",
51+
"no-duplicate-imports": "error",
52+
"no-dupe-class-members": "error",
53+
"no-eval": "error",
54+
"no-extend-native": "error",
55+
"no-extra-bind": "error",
56+
"no-extra-parens": ["error", "functions"],
57+
"no-floating-decimal": "error",
58+
"no-implied-eval": "error",
59+
"no-implicit-coercion": "off",
60+
"no-implicit-globals": "error",
61+
"no-import-assign": "error",
62+
"no-iterator": "error",
63+
"no-label-var": "error",
64+
"no-labels": ["error", { "allowLoop": false, "allowSwitch": false }],
65+
"no-lone-blocks": "error",
66+
"no-loss-of-precision": "error",
67+
"no-mixed-spaces-and-tabs": "error",
68+
"no-multi-spaces": ["off", { "ignoreEOLComments": true }],
69+
"no-multi-str": "error",
70+
"no-multiple-empty-lines": ["off", { "max": 1 }],
71+
"no-native-reassign": "error",
72+
"no-negated-in-lhs": "error",
73+
"no-new": "error",
74+
"no-new-func": "error",
75+
"no-new-object": "error",
76+
"no-new-native-nonconstructor": "error",
77+
"no-new-require": "error",
78+
"no-new-wrappers": "error",
79+
"no-octal-escape": "error",
80+
"no-path-concat": "error",
81+
"no-proto": "error",
82+
"no-prototype-builtins": "off",
83+
"no-return-assign": ["error", "except-parens"],
84+
"no-self-compare": "error",
85+
"no-sequences": "off",
86+
"no-tabs": "error",
87+
"no-template-curly-in-string": "off",
88+
"no-this-before-super": "error",
89+
"no-throw-literal": "off",
90+
"no-trailing-spaces": "error",
91+
"no-undef-init": "error",
92+
"no-unmodified-loop-condition": "error",
93+
"no-unneeded-ternary": ["off", { "defaultAssignment": false }],
94+
"no-unreachable": "error",
95+
"no-unused-vars" : ["error", { "args": "after-used" }],
96+
"no-unused-private-class-members": "error",
97+
"no-useless-call": "off",
98+
"no-useless-computed-key": "error",
99+
"no-useless-constructor": "error",
100+
// used in RegExp
101+
"no-useless-escape" : "off",
102+
"no-useless-rename": "error",
103+
"no-whitespace-before-property": "error",
104+
"object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }],
105+
"one-var": ["off", { "initialized": "never" }],
106+
"operator-linebreak": ["off", "after", { "overrides": { "?": "before", ":": "before" } }],
107+
"padded-blocks": ["off", "never"],
108+
"prefer-arrow-callback" : "error",
109+
"quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }],
110+
"rest-spread-spacing": ["error", "never"],
111+
"semi": ["error", "always"],
112+
"semi-spacing": ["error", { "before": false, "after": true }],
113+
"space-before-blocks": ["error", "always"],
114+
"space-before-function-paren": ["off", "always"],
115+
"space-in-parens": "off", // ["error", "never"],
116+
"space-infix-ops": "off",
117+
"space-unary-ops": ["off", { "words": true, "nonwords": false }],
118+
"spaced-comment": ["off", "always", { "line": { "markers": ["*package", "!", ","] }, "block": { "balanced": true, "markers": ["*package", "!", ","], "exceptions": ["*"] } }],
119+
"template-curly-spacing": ["error", "never"],
120+
"unicode-bom": ["error", "never"],
121+
"valid-typeof": ["error", { "requireStringLiterals": true }],
122+
"yield-star-spacing": ["error", "both"],
123+
"yoda": ["error", "never"],
124+
"jsdoc/require-hyphen-before-param-description": 1
125+
}
126+
}

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Temp files
2+
.DS_Store
3+
Thumbs.db
4+
Desktop.ini
5+
npm-debug.log
6+
7+
# Project specific ignore
8+
node_modules/
9+
package-lock.json

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# melonJS Debug Plugin
2+
![melonJS Logo](https://github.com/melonjs/melonJS/raw/master/media/Banner/Banner%20-%20Billboard%20-%20Original%20Logo%20-%20horizontal.png)
3+
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/melonjs/es6-boilerplate/blob/master/LICENSE)
5+
6+
Installation
7+
-------------------------------------------------------------------------------
8+
`$ [sudo] npm install @melonjs/debug-plugin --save-dev`
9+
10+
Then import and instantiante the debug plugin in your project. For example:
11+
```JavaScript
12+
import { utils, plugin } from 'melonjs';
13+
// initialize the debug plugin in development mode.
14+
if (typeof process !== "undefined" && process.env.NODE_ENV === 'development') {
15+
import("melonjs-debug-plugin.js").then((debugPlugin) => {
16+
// automatically register the debug panel
17+
utils.function.defer(plugin.register, this, debugPlugin.DebugPanelPlugin, "debugPanel");
18+
});
19+
}
20+
```
21+
22+
Usage
23+
-------------------------------------------------------------------------------
24+
25+
The Debug Panel is hidden by default and can be displayed using the `S` key, it will then provide the below information :
26+
![debug-panel](https://user-images.githubusercontent.com/4033090/138006717-cf3165a4-a52d-4855-a7c7-16b2a09ed124.png)
27+
28+
* Amount of objects currently active in the current scene
29+
* Amount of draws operation
30+
* Amount of body shape (requires to enable the hitbox checkbox)
31+
* Amount of bounding box
32+
* Amount of sprites objects
33+
* Amount of objects currently inactive in the the object pool
34+
* Heap/memory usage
35+
* Frame update time (in ms)
36+
* Frame draw time (in ms)
37+
* Current fps rate vs target fps
38+
39+
> Note: Heap information requires starting Chrome [with](http://www.chromium.org/developers/how-tos/run-chromium-with-flags) `--enable-precise-memory-info`
40+
41+
Additionally, using the checkbox in the panel it is also possible to draw :
42+
* Shape and Bounding box for all objects
43+
* Current velocity vector
44+
* Quadtree spatial visualization
45+
46+
Questions, need help ?
47+
-------------------------------------------------------------------------------
48+
If you need technical support, you can contact us through the following channels :
49+
* Forums: with melonJS 2 we moved to a new discourse [forum](https://melonjs.discourse.group), but we can still also find the previous one [here](http://www.html5gamedevs.com/forum/32-melonjs/)
50+
* Chat: come and chat with us on [discord](https://discord.gg/aur7JMk), or [gitter](https://gitter.im/melonjs/public)
51+
* we tried to keep our [wikipage](https://github.com/melonjs/melonJS/wiki) up-to-date with useful links, tutorials, and anything related melonJS.

dist/melonjs-debug-plugin.js

Lines changed: 630 additions & 0 deletions
Large diffs are not rendered by default.

jsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2015",
4+
"target": "es6"
5+
},
6+
"exclude": ["node_modules"]
7+
}

package.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "@melonjs/debug-plugin",
3+
"version": "14.4.2",
4+
"description": "melonJS debug plugin",
5+
"type": "module",
6+
"keywords": [
7+
"2D",
8+
"HTML5",
9+
"javascript",
10+
"TypeScript",
11+
"es6",
12+
"Canvas",
13+
"WebGL",
14+
"WebGL2",
15+
"WebAudio",
16+
"game",
17+
"engine",
18+
"tiled",
19+
"tileset",
20+
"mapeditor",
21+
"browser",
22+
"electron",
23+
"mobile",
24+
"cordova"
25+
],
26+
"repository": {
27+
"type": "git",
28+
"url": "git+https://github.com/melonjs/debug-plugin.git"
29+
},
30+
"bugs": {
31+
"url": "https://github.com/melonjs/debug-plugin/issues"
32+
},
33+
"license": "MIT",
34+
"author": "Olivier Biot (AltByte Pte Ltd)",
35+
"funding": "https://github.com/sponsors/melonjs",
36+
"engines": {
37+
"node": ">= 19"
38+
},
39+
"main": "dist/melonjs-debug-plugin.js",
40+
"module": "dist/melonjs-debug-plugin.js",
41+
"sideEffects": false,
42+
"files": [
43+
"dist/melonjs-debug-plugin.js",
44+
"src/",
45+
"package.json",
46+
"README.md",
47+
"LICENSE"
48+
],
49+
"peerDependencies": {
50+
"melonjs": "^15.0.0"
51+
},
52+
"devDependencies": {
53+
"@babel/eslint-parser": "^7.21.3",
54+
"@babel/plugin-syntax-import-assertions": "^7.20.0",
55+
"@rollup/plugin-commonjs": "^24.0.1",
56+
"@rollup/plugin-image": "^3.0.2",
57+
"@rollup/plugin-node-resolve": "^15.0.1",
58+
"@rollup/plugin-replace": "^5.0.2",
59+
"del-cli": "^5.0.0",
60+
"eslint": "^8.36.0",
61+
"eslint-plugin-jsdoc": "^40.0.3",
62+
"rollup": "^3.19.1",
63+
"rollup-plugin-bundle-size": "^1.0.3",
64+
"rollup-plugin-string": "^3.0.0"
65+
},
66+
"scripts": {
67+
"build": "npm run lint && rollup -c --silent",
68+
"lint": "eslint src/**.js rollup.config.mjs",
69+
"prepublishOnly": "npm run build && npm run test",
70+
"clean": "del-cli --force build/*.*"
71+
}
72+
}

rollup.config.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { string } from "rollup-plugin-string";
2+
import replace from "@rollup/plugin-replace";
3+
import image from "@rollup/plugin-image";
4+
import bundleSize from "rollup-plugin-bundle-size";
5+
import commonjs from "@rollup/plugin-commonjs";
6+
import resolve from "@rollup/plugin-node-resolve";
7+
import pkg from "./package.json" assert { type: "json" };
8+
9+
// credit/license information
10+
const license = [
11+
"/*!",
12+
" * " + pkg.description + " - v" + pkg.version,
13+
" * http://www.melonjs.org",
14+
" * " + pkg.name + " is licensed under the MIT License.",
15+
" * http://www.opensource.org/licenses/mit-license",
16+
" * @copyright (C) 2011 - " + (new Date()).getFullYear() + " " + pkg.author,
17+
" */"
18+
].join("\n");
19+
20+
export default [{
21+
input: "src/index.js",
22+
plugins: [
23+
resolve({
24+
mainFields: ["module"],
25+
browser: true,
26+
preferBuiltins: false
27+
}),
28+
commonjs({
29+
include: "node_modules/**",
30+
sourceMap: false
31+
}),
32+
replace({
33+
values: {
34+
__VERSION__: pkg.version
35+
},
36+
preventAssignment: true
37+
}),
38+
string({
39+
include: [
40+
"**/*.fnt"
41+
]
42+
}),
43+
image(),
44+
bundleSize()
45+
],
46+
output: {
47+
file: "dist/melonjs-debug-plugin.js",
48+
banner: license,
49+
freeze: false,
50+
format: "es"
51+
},
52+
external: ["melonjs"],
53+
treeshake: false
54+
}];

src/counters.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Counters {
2+
constructor() {
3+
this.stats = [];
4+
}
5+
reset() {
6+
Object.keys(this.stats).forEach((stat) => {
7+
this.stats[stat] = 0;
8+
});
9+
}
10+
inc(stat, value) {
11+
this.stats[stat] += (value || 1);
12+
}
13+
get(stat) {
14+
return this.stats[stat] || 0;
15+
}
16+
}
17+
export default Counters;

0 commit comments

Comments
 (0)