mage-engine 3.25.1 → 3.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ const eslint = require("@eslint/js");
2
+ const prettier = require("eslint-plugin-prettier/recommended");
3
+ const globals = require("globals");
4
+
5
+ module.exports = [
6
+ {
7
+ ignores: [
8
+ "dist/",
9
+ "node_modules/",
10
+ "__mocks__/",
11
+ "config/",
12
+ "src/loaders/ColladaLoader.js",
13
+ "src/loaders/GLTFLoader.js",
14
+ "src/loaders/FBXLoader.js",
15
+ "src/lib/fflate.js",
16
+ "src/models/SkeletonUtils.js",
17
+ "src/controls/Orbit.js",
18
+ "src/controls/Transform.js",
19
+ "src/controls/TransformGizmo.js",
20
+ "src/fx/materials/Ocean.js",
21
+ "src/fx/materials/Water.old.js",
22
+ "src/fx/materials/Mirror.js",
23
+ "src/scripts/builtin/SmoothCameraFollow.js",
24
+ ],
25
+ },
26
+ eslint.configs.recommended,
27
+ prettier,
28
+ {
29
+ languageOptions: {
30
+ ecmaVersion: 2022,
31
+ sourceType: "module",
32
+ globals: {
33
+ ...globals.browser,
34
+ requestNextFrame: "readonly",
35
+ global: "readonly",
36
+ },
37
+ },
38
+ rules: {
39
+ "no-unused-vars": ["warn", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }],
40
+ "no-console": "off",
41
+ "no-dupe-class-members": "warn",
42
+ "no-empty": ["error", { allowEmptyCatch: true }],
43
+ "prettier/prettier": ["error", { endOfLine: "auto" }],
44
+ },
45
+ },
46
+ {
47
+ files: ["**/__tests__/**/*.js", "**/*.test.js"],
48
+ languageOptions: {
49
+ globals: {
50
+ ...globals.jest,
51
+ ...globals.commonjs,
52
+ },
53
+ },
54
+ },
55
+ {
56
+ files: ["src/physics/worker/**/*.js"],
57
+ languageOptions: {
58
+ globals: {
59
+ Ammo: "readonly",
60
+ postMessage: "readonly",
61
+ importScripts: "readonly",
62
+ },
63
+ },
64
+ },
65
+ {
66
+ files: ["src/lib/features.js"],
67
+ languageOptions: {
68
+ globals: {
69
+ ActiveXObject: "readonly",
70
+ },
71
+ },
72
+ },
73
+ ];
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ roots: ["<rootDir>/src"],
5
+
6
+ testMatch: [
7
+ "**/__tests__/**/*.test.js",
8
+ "**/*.test.js",
9
+ ],
10
+
11
+ transform: {
12
+ "^.+\\.js$": "babel-jest",
13
+ },
14
+
15
+ transformIgnorePatterns: [
16
+ "/node_modules/(?!three/)",
17
+ ],
18
+
19
+ collectCoverageFrom: [
20
+ "src/lib/**/*.js",
21
+ "src/entities/**/*.js",
22
+ "src/models/**/*.js",
23
+ "src/physics/**/*.js",
24
+ "src/images/**/*.js",
25
+ "!src/lib/fflate.js",
26
+ "!src/lib/workers.js",
27
+ "!src/physics/worker/index.js",
28
+ ],
29
+
30
+ testEnvironment: "node",
31
+ };
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "mage-engine",
3
+ "version": "3.25.1",
4
+ "description": "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.",
5
+ "main": "dist/mage.js",
6
+ "author": {
7
+ "name": "Marco Stagni",
8
+ "email": "marco@mage.studio"
9
+ },
10
+ "scripts": {
11
+ "preversion": "npm test",
12
+ "version": "npm run build",
13
+ "dev": "concurrently 'npm:build:live' 'npm:start'",
14
+ "start": "http-server ./ -p 8085",
15
+ "postversion:push": "git push --no-verify && git push --tags --no-verify",
16
+ "postversion": "npm run postversion:push && npm publish",
17
+ "prebuild": "rimraf dist/mage.js",
18
+ "build": "rollup --config config/index.js",
19
+ "build:live": "rollup --config config/index.js --watch",
20
+ "test": "jest",
21
+ "test:watch": "jest --watch",
22
+ "test:coverage": "jest --coverage",
23
+ "lint": "eslint src",
24
+ "lint:fix": "eslint src --fix"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git://github.com/MageStudio/Mage.git"
29
+ },
30
+ "license": "BSD-3-Clause",
31
+ "keywords": [
32
+ "mage",
33
+ "marco",
34
+ "stagni",
35
+ "three.js",
36
+ "webgl",
37
+ "game",
38
+ "engine",
39
+ "game engine",
40
+ "javascript",
41
+ "browser",
42
+ "shader"
43
+ ],
44
+ "dependencies": {
45
+ "@babel/plugin-transform-classes": "^7.9.5",
46
+ "@babel/plugin-transform-runtime": "7.5.0",
47
+ "@babel/runtime": "7.5.0",
48
+ "between.js": "0.1.2-fix.2",
49
+ "hotkeys-js": "^3.13.7",
50
+ "html-to-image": "^1.9.0",
51
+ "html2canvas": "^1.4.1",
52
+ "inferno": "7.3.2",
53
+ "inferno-create-element": "7.3.3",
54
+ "inferno-redux": "7.4.2",
55
+ "redux": "4.0.5",
56
+ "redux-thunk": "^2.3.0",
57
+ "rxjs": "6.5.3",
58
+ "three": "0.126.0",
59
+ "three.proton": "npm:three.proton.js@0.2.3",
60
+ "vivifyjs": "*",
61
+ "whatwg-fetch": "3.0.0",
62
+ "xstate": "^4.8.0"
63
+ },
64
+ "devDependencies": {
65
+ "@babel/cli": "7.17.3",
66
+ "@babel/core": "^7.29.0",
67
+ "@babel/node": "7.16.8",
68
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
69
+ "@babel/polyfill": "7.12.1",
70
+ "@babel/preset-env": "^7.29.0",
71
+ "@babel/register": "7.17.0",
72
+ "@eslint/js": "^9.39.3",
73
+ "@rollup/plugin-babel": "5.3.1",
74
+ "@rollup/plugin-commonjs": "21.0.2",
75
+ "@rollup/plugin-json": "4.1.0",
76
+ "@rollup/plugin-node-resolve": "13.1.3",
77
+ "@rollup/plugin-replace": "^2.3.4",
78
+ "babel-jest": "^29.7.0",
79
+ "babel-loader": "8.2.3",
80
+ "babel-plugin-inferno": "6.3.0",
81
+ "babel-plugin-syntax-jsx": "^6.18.0",
82
+ "concurrently": "^5.3.0",
83
+ "eslint": "^9.39.3",
84
+ "eslint-config-prettier": "^10.1.8",
85
+ "eslint-plugin-prettier": "^5.5.5",
86
+ "globals": "^17.4.0",
87
+ "http-server": "^0.12.3",
88
+ "jest": "^29.7.0",
89
+ "madge": "^5.0.1",
90
+ "prettier": "^3.8.1",
91
+ "rimraf": "^3.0.0",
92
+ "rollup": "2.69.0",
93
+ "rollup-plugin-terser": "7.0.2",
94
+ "rollup-plugin-web-worker-loader": "1.6.1"
95
+ }
96
+ }
package/dist/mage.js CHANGED
@@ -53720,7 +53720,8 @@ const LIGHT_NOT_FOUND = `${PREFIX} This light was not created properly.`;
53720
53720
  const LIGHT_HOLDER_MODEL_NOT_FOUND = `${PREFIX} This light holder model can't be found.`;
53721
53721
  const SOUND_HOLDER_MODEL_NOT_FOUND = `${PREFIX} This sound holder model can't be found.`;
53722
53722
  const LABEL_DOMELEMENT_MISSING = `${PREFIX} Could not create Label, domElement is missing. Did you forget to set the this.element ref on your component?`;
53723
- const NO_VALID_LEVEL_DATA_PROVIDED = `${PREFIX} No valid level data (json or url) provided`;/**!
53723
+ const NO_VALID_LEVEL_DATA_PROVIDED = `${PREFIX} No valid level data (json or url) provided`;
53724
+ const THIRD_PERSON_CONTROL_TARGET_MISSING = `${PREFIX} ThirdPersonControl requires a target element. Please provide a valid target.`;/**!
53724
53725
  * hotkeys-js v3.13.7
53725
53726
  * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
53726
53727
  *
@@ -56475,10 +56476,16 @@ let Physics = /*#__PURE__*/function (_EventDispatcher) {
56475
56476
  value: function init() {
56476
56477
  if (Config$1.physics().enabled) {
56477
56478
  this.createWorker();
56479
+
56480
+ // Resolve ammo.js using MAGE_ASSETS_BASE_URL (same as models,
56481
+ // images, and audio) so the path works identically in local
56482
+ // preview and production.
56483
+ const baseUrl = env.MAGE_ASSETS_BASE_URL;
56484
+ const host = baseUrl ? `${getHostURL()}/${baseUrl}` : getHostURL();
56478
56485
  this.worker.postMessage({
56479
56486
  event: PHYSICS_EVENTS.LOAD.AMMO,
56480
56487
  ...Config$1.physics(),
56481
- host: getHostURL()
56488
+ host
56482
56489
  });
56483
56490
  return new Promise(resolve => {
56484
56491
  const isWorkerReady = () => this.workerReady;
@@ -59038,6 +59045,10 @@ let ThirdPersonControl = /*#__PURE__*/function (_EventDispatcher) {
59038
59045
  return _createClass(ThirdPersonControl, [{
59039
59046
  key: "init",
59040
59047
  value: function init() {
59048
+ if (!this.character) {
59049
+ console.error(THIRD_PERSON_CONTROL_TARGET_MISSING);
59050
+ return;
59051
+ }
59041
59052
  this._onClick = this.onClick.bind(this);
59042
59053
  this._onMouseMove = this.onMouseMove.bind(this);
59043
59054
  this._onKeyDown = this.onKeyDown.bind(this);
@@ -59053,7 +59064,7 @@ let ThirdPersonControl = /*#__PURE__*/function (_EventDispatcher) {
59053
59064
 
59054
59065
  // In non-physics mode, use the character's starting Y as ground level
59055
59066
  // when no explicit value was provided, so it doesn't free-fall on start.
59056
- if (!this.hasPhysicsEnabled() && this.character) {
59067
+ if (!this.hasPhysicsEnabled()) {
59057
59068
  const startY = this.character.getPosition().y;
59058
59069
  if (this.options.groundLevel === 0.5 && startY > 1) {
59059
59070
  this.options.groundLevel = startY;
@@ -59061,7 +59072,7 @@ let ThirdPersonControl = /*#__PURE__*/function (_EventDispatcher) {
59061
59072
  // Start grounded so the first jump works
59062
59073
  this.canJump = true;
59063
59074
  }
59064
- if (this.hasPhysicsEnabled() && this.character) {
59075
+ if (this.hasPhysicsEnabled()) {
59065
59076
  this.addCharacterToPhysics();
59066
59077
  }
59067
59078
  }
@@ -59090,7 +59101,7 @@ let ThirdPersonControl = /*#__PURE__*/function (_EventDispatcher) {
59090
59101
  }, {
59091
59102
  key: "getCharacter",
59092
59103
  value: function getCharacter() {
59093
- return this.character || this.camera;
59104
+ return this.character;
59094
59105
  }
59095
59106
 
59096
59107
  // --- Pointer Lock ---
@@ -59410,7 +59421,7 @@ let ThirdPersonControl = /*#__PURE__*/function (_EventDispatcher) {
59410
59421
  }, {
59411
59422
  key: "physicsUpdate",
59412
59423
  value: function physicsUpdate() {
59413
- if (this.hasPhysicsEnabled() && this.character) {
59424
+ if (this.hasPhysicsEnabled()) {
59414
59425
  // Re-enable jumping when grounded AND space is released
59415
59426
  const grounded = this.character.getPhysicsState("grounded");
59416
59427
  if (grounded && !this.spaceHeld) {
@@ -59440,9 +59451,7 @@ let ThirdPersonControl = /*#__PURE__*/function (_EventDispatcher) {
59440
59451
  }
59441
59452
 
59442
59453
  // Always position camera relative to character
59443
- if (this.character) {
59444
- this.updateCameraPosition();
59445
- }
59454
+ this.updateCameraPosition();
59446
59455
  }
59447
59456
  }]);
59448
59457
  }(EventDispatcher);let FlyControl = /*#__PURE__*/function (_EventDispatcher) {
@@ -59837,8 +59846,26 @@ let Controls = /*#__PURE__*/function (_EventDispatcher) {
59837
59846
  }
59838
59847
  }, {
59839
59848
  key: "setThirdPersonControls",
59840
- value: function setThirdPersonControls(options) {
59849
+ value: async function setThirdPersonControls(options) {
59841
59850
  this.disposePreviousControls([CONTROLS.FPS, CONTROLS.FLY, CONTROLS.ORBIT]);
59851
+
59852
+ // Ensure the global physics system is initialised when the control
59853
+ // requests physics. The builder/preview config may not have enabled
59854
+ // physics explicitly, so we enable it on-demand here.
59855
+ if (options.physicsEnabled && !Config$1.physics().enabled) {
59856
+ Config$1.physics().enabled = true;
59857
+ await Physics$1.init();
59858
+
59859
+ // Entities loaded before physics was enabled had their
59860
+ // enablePhysics() calls silently skipped. Now that the
59861
+ // worker is ready, add every entity that has pending
59862
+ // physics options to the world.
59863
+ Universe$1.forEach(element => {
59864
+ if (element._physicsEnabled && !Physics$1.hasElement(element)) {
59865
+ Physics$1.add(element, element.getPhysicsOptions());
59866
+ }
59867
+ });
59868
+ }
59842
59869
  this.controls[CONTROLS.TPS] = new ThirdPersonControl(Scene$1.getCamera(), Scene$1.getDOMElement(), options);
59843
59870
  this.controls[CONTROLS.TPS].init();
59844
59871
  return this.controls[CONTROLS.TPS];
@@ -61268,7 +61295,7 @@ function applyMiddleware() {
61268
61295
 
61269
61296
  var thunk = createThunkMiddleware();
61270
61297
  thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
61271
- var version$1 = "3.25.1";
61298
+ var version$1 = "3.25.3";
61272
61299
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
61273
61300
  var main = "dist/mage.js";
61274
61301
  var author$1 = {
@@ -64986,6 +65013,7 @@ let Element$1 = /*#__PURE__*/function (_Entity) {
64986
65013
  key: "enablePhysics",
64987
65014
  value: function enablePhysics(options = {}) {
64988
65015
  this.setPhysicsOptions(options);
65016
+ this._physicsEnabled = true;
64989
65017
  if (Config$1.physics().enabled) {
64990
65018
  Physics$1.add(this, options);
64991
65019
  }
@@ -97047,7 +97075,7 @@ let Importer = /*#__PURE__*/function () {
97047
97075
  }
97048
97076
  resolve(this.getCurrentLevel());
97049
97077
  }).catch(reject);
97050
- });
97078
+ }).catch(reject);
97051
97079
  });
97052
97080
  }
97053
97081
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.25.1",
3
+ "version": "3.25.3",
4
4
  "description": "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.",
5
5
  "main": "dist/mage.js",
6
6
  "author": {