mage-engine 3.23.24 → 3.23.26

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.
Files changed (2) hide show
  1. package/dist/mage.js +276 -34
  2. package/package.json +1 -1
package/dist/mage.js CHANGED
@@ -34,6 +34,42 @@ function _typeof(obj) {
34
34
  }, _typeof(obj);
35
35
  }
36
36
 
37
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
38
+ try {
39
+ var info = gen[key](arg);
40
+ var value = info.value;
41
+ } catch (error) {
42
+ reject(error);
43
+ return;
44
+ }
45
+
46
+ if (info.done) {
47
+ resolve(value);
48
+ } else {
49
+ Promise.resolve(value).then(_next, _throw);
50
+ }
51
+ }
52
+
53
+ function _asyncToGenerator(fn) {
54
+ return function () {
55
+ var self = this,
56
+ args = arguments;
57
+ return new Promise(function (resolve, reject) {
58
+ var gen = fn.apply(self, args);
59
+
60
+ function _next(value) {
61
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
62
+ }
63
+
64
+ function _throw(err) {
65
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
66
+ }
67
+
68
+ _next(undefined);
69
+ });
70
+ };
71
+ }
72
+
37
73
  function _classCallCheck(instance, Constructor) {
38
74
  if (!(instance instanceof Constructor)) {
39
75
  throw new TypeError("Cannot call a class as a function");
@@ -55040,7 +55076,7 @@ var createElementFromSelector = function createElementFromSelector(selector) {
55040
55076
  }
55041
55077
 
55042
55078
  return element;
55043
- };var getWindow = function getWindow() {
55079
+ };var getWindow$1 = function getWindow() {
55044
55080
  try {
55045
55081
  var win = window || global.window;
55046
55082
  return win;
@@ -55160,7 +55196,7 @@ var Config = /*#__PURE__*/function () {
55160
55196
  }, {
55161
55197
  key: "getWindowSize",
55162
55198
  value: function getWindowSize() {
55163
- var win = getWindow();
55199
+ var win = getWindow$1();
55164
55200
  if (!win) return false;
55165
55201
  var height = win.innerHeight;
55166
55202
  var width = win.innerWidth;
@@ -55767,19 +55803,21 @@ var isLevelName = function isLevelName(level) {
55767
55803
 
55768
55804
  var loader = _this.getLoaderByType(loaderType);
55769
55805
 
55770
- return new Promise(function (resolve, reject) {
55806
+ return new Promise(function (resolve) {
55771
55807
  try {
55772
55808
  loader.load(path, function (asset) {
55773
55809
  _this.add(id, asset);
55774
55810
 
55775
55811
  resolve(asset);
55776
- }, function () {}, function () {
55777
- console.log(ERROR_LOADING_TEXTURE, name, path);
55778
- resolve();
55812
+ }, function () {}, function (error) {
55813
+ // Log warning but resolve anyway to allow other assets to continue loading
55814
+ console.warn("[Mage] ".concat(ERROR_LOADING_TEXTURE), name, path, (error === null || error === void 0 ? void 0 : error.message) || "");
55815
+ resolve(null);
55779
55816
  });
55780
55817
  } catch (e) {
55781
- console.log(ERROR_LOADING_TEXTURE, name, path);
55782
- reject();
55818
+ // Log warning but resolve anyway to allow other assets to continue loading
55819
+ console.warn("[Mage] ".concat(ERROR_LOADING_TEXTURE), name, path, (e === null || e === void 0 ? void 0 : e.message) || "");
55820
+ resolve(null);
55783
55821
  }
55784
55822
  });
55785
55823
  });
@@ -56950,7 +56988,7 @@ var Physics$1 = new Physics();var Scene = /*#__PURE__*/function () {
56950
56988
  }, {
56951
56989
  key: "listenToResizeEvent",
56952
56990
  value: function listenToResizeEvent() {
56953
- var win = getWindow();
56991
+ var win = getWindow$1();
56954
56992
 
56955
56993
  if (win) {
56956
56994
  win.addEventListener("resize", this.onResize);
@@ -56959,7 +56997,7 @@ var Physics$1 = new Physics();var Scene = /*#__PURE__*/function () {
56959
56997
  }, {
56960
56998
  key: "stopResizeListener",
56961
56999
  value: function stopResizeListener() {
56962
- var win = getWindow();
57000
+ var win = getWindow$1();
56963
57001
 
56964
57002
  if (win) {
56965
57003
  win.removeEventListener("resize", this.onResize);
@@ -58259,7 +58297,7 @@ function applyMiddleware() {
58259
58297
 
58260
58298
  var thunk = createThunkMiddleware();
58261
58299
  thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
58262
- var version$1 = "3.23.24";
58300
+ var version$1 = "3.23.26";
58263
58301
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
58264
58302
  var main = "dist/mage.js";
58265
58303
  var author$1 = {
@@ -62716,10 +62754,12 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
62716
62754
  }
62717
62755
  }, {
62718
62756
  key: "recordTexture",
62719
- value: function recordTexture(id, type, options) {
62757
+ value: function recordTexture(id, type, options, assetPath) {
62758
+ // assetPath is the relative path like "textures/mytexture.png"
62720
62759
  this.textures.set(type, {
62721
62760
  id: id,
62722
- options: options
62761
+ options: options,
62762
+ assetPath: assetPath
62723
62763
  });
62724
62764
  }
62725
62765
  }, {
@@ -62740,15 +62780,22 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
62740
62780
  y: 1
62741
62781
  } : _options$repeat,
62742
62782
  _options$wrap = options.wrap,
62743
- wrap = _options$wrap === void 0 ? RepeatWrapping$1 : _options$wrap;
62783
+ wrap = _options$wrap === void 0 ? RepeatWrapping$1 : _options$wrap,
62784
+ assetPath = options.assetPath;
62744
62785
  var textureOptions = {
62745
62786
  repeat: repeat,
62746
62787
  wrap: wrap
62747
62788
  };
62748
- this.recordTexture(textureId, textureType, textureOptions);
62789
+ this.recordTexture(textureId, textureType, textureOptions, assetPath);
62749
62790
 
62750
62791
  var applyTextureTo = function applyTextureTo(material) {
62751
62792
  var texture = Images$1.get(textureId);
62793
+
62794
+ if (!texture) {
62795
+ console.warn("[Mage] Texture not found: ".concat(textureId));
62796
+ return;
62797
+ }
62798
+
62752
62799
  texture.wrapS = textureOptions.wrap;
62753
62800
  texture.wrapT = textureOptions.wrap;
62754
62801
  texture.repeat.set(textureOptions.repeat.x, textureOptions.repeat.y);
@@ -70167,6 +70214,75 @@ var createConnect = function (ref) {
70167
70214
  };
70168
70215
  var connect = createConnect();var BaseUI = function BaseUI() {
70169
70216
  return null;
70217
+ };/**
70218
+ * Environment configuration module for mage-engine.
70219
+ * Centralizes all environment variables and their default values.
70220
+ *
70221
+ * Usage:
70222
+ * import env from './env';
70223
+ * const baseUrl = env.MAGE_ASSETS_BASE_URL;
70224
+ */
70225
+
70226
+ /**
70227
+ * Safe window access - returns undefined in non-browser environments
70228
+ */
70229
+ var getWindow = function getWindow() {
70230
+ return typeof window !== "undefined" ? window : undefined;
70231
+ };
70232
+ /**
70233
+ * Gets an environment variable from the window object with a fallback default.
70234
+ * @param {string} key - The environment variable name
70235
+ * @param {any} defaultValue - Default value if not set
70236
+ * @returns {any} - The environment variable value or default
70237
+ */
70238
+
70239
+
70240
+ var getEnv = function getEnv(key) {
70241
+ var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
70242
+ var win = getWindow();
70243
+ return win && win[key] !== undefined ? win[key] : defaultValue;
70244
+ };
70245
+ /**
70246
+ * Environment variables with their default values.
70247
+ * These are accessed as getters so they're evaluated at access time,
70248
+ * not at module load time (important for variables set after page load).
70249
+ */
70250
+
70251
+
70252
+ var env = {
70253
+ /**
70254
+ * Base URL for loading assets (textures, models, audio).
70255
+ * Set by mage-studio editor or deployed builds.
70256
+ * Default: empty string (paths used as-is for backwards compatibility)
70257
+ */
70258
+ get MAGE_ASSETS_BASE_URL() {
70259
+ return getEnv("MAGE_ASSETS_BASE_URL", "");
70260
+ },
70261
+
70262
+ /**
70263
+ * Enable debug mode for verbose logging.
70264
+ * Default: false
70265
+ */
70266
+ get MAGE_DEBUG() {
70267
+ return getEnv("MAGE_DEBUG", false);
70268
+ },
70269
+
70270
+ /**
70271
+ * Current project ID (set by mage-studio).
70272
+ * Default: empty string
70273
+ */
70274
+ get MAGE_PROJECT_ID() {
70275
+ return getEnv("MAGE_PROJECT_ID", "");
70276
+ },
70277
+
70278
+ /**
70279
+ * Current build ID (set by deployed builds).
70280
+ * Default: empty string
70281
+ */
70282
+ get MAGE_BUILD_ID() {
70283
+ return getEnv("MAGE_BUILD_ID", "");
70284
+ }
70285
+
70170
70286
  };var TIME_FOR_UPDATE = 5;
70171
70287
  var VOLUME = 2;
70172
70288
  var DEFAULT_AUDIO_NODE_VOLUME = 5;
@@ -70176,6 +70292,48 @@ var AUDIO_RAMPS = {
70176
70292
  LINEAR: "LINEAR",
70177
70293
  EXPONENTIAL: "EXPONENTIAL"
70178
70294
  };
70295
+ /**
70296
+ * Checks if a path is an absolute URL.
70297
+ * @param {string} path - The path to check
70298
+ * @returns {boolean} - True if path is an absolute URL
70299
+ */
70300
+
70301
+ var isURL$1 = function isURL(path) {
70302
+ try {
70303
+ new URL(path);
70304
+ return true;
70305
+ } catch (_) {
70306
+ return false;
70307
+ }
70308
+ };
70309
+ /**
70310
+ * Resolves an asset path to a full URL.
70311
+ * If path is already an absolute URL, returns it as-is.
70312
+ * If path is relative and MAGE_ASSETS_BASE_URL is set, prepends the base URL.
70313
+ * @param {string} path - The asset path (relative or absolute)
70314
+ * @returns {string} - The resolved full URL
70315
+ */
70316
+
70317
+
70318
+ var resolveAssetPath$1 = function resolveAssetPath(path) {
70319
+ // If it's already an absolute URL, use it as-is
70320
+ if (isURL$1(path)) {
70321
+ return path;
70322
+ } // If MAGE_ASSETS_BASE_URL is set, prepend it to the relative path
70323
+
70324
+
70325
+ var baseUrl = env.MAGE_ASSETS_BASE_URL;
70326
+
70327
+ if (baseUrl) {
70328
+ // Remove leading slash from path if present to avoid double slashes
70329
+ var cleanPath = path.startsWith("/") ? path.slice(1) : path;
70330
+ return "".concat(baseUrl, "/").concat(cleanPath);
70331
+ } // Fallback: return the path as-is (for backwards compatibility)
70332
+
70333
+
70334
+ return path;
70335
+ };
70336
+
70179
70337
  var Audio = /*#__PURE__*/function () {
70180
70338
  function Audio() {
70181
70339
  var _this = this;
@@ -70213,21 +70371,30 @@ var Audio = /*#__PURE__*/function () {
70213
70371
  });
70214
70372
 
70215
70373
  _defineProperty$1(this, "loadAssetByPath", function (path, id) {
70374
+ // Resolve the path using MAGE_ASSETS_BASE_URL if available
70375
+ var resolvedPath = resolveAssetPath$1(path);
70216
70376
  var request = new XMLHttpRequest();
70217
70377
  return new Promise(function (resolve) {
70218
- request.open("GET", path, true);
70378
+ request.open("GET", resolvedPath, true);
70219
70379
  request.responseType = "arraybuffer";
70220
70380
 
70221
70381
  request.onreadystatechange = function (e) {
70222
- if (request.readyState === 4 && request.status === 200) {
70223
- _this.context.decodeAudioData(request.response, function (buffer) {
70224
- _this.buffersMap[id] = buffer;
70225
- resolve();
70226
- }, function () {
70382
+ if (request.readyState === 4) {
70383
+ if (request.status === 200) {
70384
+ _this.context.decodeAudioData(request.response, function (buffer) {
70385
+ _this.buffersMap[id] = buffer;
70386
+ resolve();
70387
+ }, function () {
70388
+ _this.buffersMap[id] = null;
70389
+ console.error(ASSETS_AUDIO_FILE_LOAD_FAIL);
70390
+ resolve();
70391
+ });
70392
+ } else {
70393
+ // Handle HTTP errors (404, etc.) - log warning and continue
70394
+ console.warn("[Mage] Failed to load audio \"".concat(id, "\" from ").concat(resolvedPath, ": HTTP ").concat(request.status));
70227
70395
  _this.buffersMap[id] = null;
70228
- console.error(ASSETS_AUDIO_FILE_LOAD_FAIL);
70229
70396
  resolve();
70230
- });
70397
+ }
70231
70398
  }
70232
70399
  };
70233
70400
 
@@ -80710,6 +80877,33 @@ var isURL = function isURL(path) {
80710
80877
  return false;
80711
80878
  }
80712
80879
  };
80880
+ /**
80881
+ * Resolves an asset path to a full URL.
80882
+ * If path is already an absolute URL, returns it as-is.
80883
+ * If path is relative and MAGE_ASSETS_BASE_URL is set, prepends the base URL.
80884
+ * @param {string} path - The asset path (relative or absolute)
80885
+ * @returns {string} - The resolved full URL
80886
+ */
80887
+
80888
+
80889
+ var resolveAssetPath = function resolveAssetPath(path) {
80890
+ // If it's already an absolute URL, use it as-is
80891
+ if (isURL(path)) {
80892
+ return path;
80893
+ } // If MAGE_ASSETS_BASE_URL is set, prepend it to the relative path
80894
+
80895
+
80896
+ var baseUrl = env.MAGE_ASSETS_BASE_URL;
80897
+
80898
+ if (baseUrl) {
80899
+ // Remove leading slash from path if present to avoid double slashes
80900
+ var cleanPath = path.startsWith("/") ? path.slice(1) : path;
80901
+ return "".concat(baseUrl, "/").concat(cleanPath);
80902
+ } // Fallback: return the path as-is (for backwards compatibility)
80903
+
80904
+
80905
+ return path;
80906
+ };
80713
80907
 
80714
80908
  var extractExtension = function extractExtension(path) {
80715
80909
  var url = isURL(path);
@@ -80916,7 +81110,9 @@ var Models = /*#__PURE__*/function (_EventDispatcher) {
80916
81110
  _defineProperty$1(_assertThisInitialized(_this), "loadAssetByPath", function (path, name) {
80917
81111
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
80918
81112
  var level = options.level;
80919
- var id = buildAssetId(name, level);
81113
+ var id = buildAssetId(name, level); // Resolve the path using MAGE_ASSETS_BASE_URL if available
81114
+
81115
+ var resolvedPath = resolveAssetPath(path);
80920
81116
  var extension = extractExtension(path);
80921
81117
 
80922
81118
  var _getLoaderFromExtensi = getLoaderFromExtension(extension, options),
@@ -80933,7 +81129,7 @@ var Models = /*#__PURE__*/function (_EventDispatcher) {
80933
81129
  });
80934
81130
  });
80935
81131
  return new Promise(function (resolve) {
80936
- loader.load(path, function (model) {
81132
+ loader.load(resolvedPath, function (model) {
80937
81133
  var parsedModel = parser(model);
80938
81134
 
80939
81135
  if (parsedModel) {
@@ -80941,7 +81137,11 @@ var Models = /*#__PURE__*/function (_EventDispatcher) {
80941
81137
  }
80942
81138
 
80943
81139
  resolve(parsedModel);
80944
- }, NOOP, NOOP);
81140
+ }, NOOP, function (error) {
81141
+ // Log error but resolve anyway to allow other assets to continue loading
81142
+ console.warn("[Mage] Failed to load model \"".concat(name, "\" from ").concat(resolvedPath, ":"), (error === null || error === void 0 ? void 0 : error.message) || error);
81143
+ resolve(null);
81144
+ });
80945
81145
  });
80946
81146
  });
80947
81147
 
@@ -93686,7 +93886,7 @@ var Importer = /*#__PURE__*/function () {
93686
93886
  _ref$options = _ref.options,
93687
93887
  options = _ref$options === void 0 ? {} : _ref$options;
93688
93888
 
93689
- if (getWindow() && url) {
93889
+ if (getWindow$1() && url) {
93690
93890
  return fetch$1(url).then(function (res) {
93691
93891
  return res.json();
93692
93892
  }).then(function (data) {
@@ -93782,12 +93982,54 @@ var Importer = /*#__PURE__*/function () {
93782
93982
  if (elementData.textures) {
93783
93983
  var parsedTextures = JSON.parse(elementData.textures);
93784
93984
  element.setNormalScale();
93785
- Object.keys(parsedTextures).forEach(function (textureType) {
93786
- var _parsedTextures$textu = parsedTextures[textureType],
93787
- id = _parsedTextures$textu.id,
93788
- options = _parsedTextures$textu.options;
93789
- element.setTexture(id, textureType, options);
93790
- });
93985
+ Object.keys(parsedTextures).forEach( /*#__PURE__*/function () {
93986
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(textureType) {
93987
+ var _parsedTextures$textu, id, options, assetPath, baseUrl, fullUrl;
93988
+
93989
+ return regeneratorRuntime.wrap(function _callee$(_context) {
93990
+ while (1) {
93991
+ switch (_context.prev = _context.next) {
93992
+ case 0:
93993
+ _parsedTextures$textu = parsedTextures[textureType], id = _parsedTextures$textu.id, options = _parsedTextures$textu.options, assetPath = _parsedTextures$textu.assetPath; // If texture not already loaded and we have an assetPath, load it first
93994
+ // assetPath is relative like "textures/mytexture.png"
93995
+ // The actual URL is resolved based on the assets base URL
93996
+
93997
+ if (!(!Images$1.get(id) && assetPath)) {
93998
+ _context.next = 12;
93999
+ break;
94000
+ }
94001
+
94002
+ _context.prev = 2;
94003
+ // Use the assets base URL from env to build full URL
94004
+ baseUrl = env.MAGE_ASSETS_BASE_URL;
94005
+ fullUrl = baseUrl ? "".concat(baseUrl, "/").concat(assetPath) : assetPath;
94006
+ _context.next = 7;
94007
+ return Images$1.loadAssetByPath(fullUrl, id, Images$1.currentLevel);
94008
+
94009
+ case 7:
94010
+ _context.next = 12;
94011
+ break;
94012
+
94013
+ case 9:
94014
+ _context.prev = 9;
94015
+ _context.t0 = _context["catch"](2);
94016
+ console.warn("[Mage] Failed to load texture: ".concat(id, " from ").concat(assetPath));
94017
+
94018
+ case 12:
94019
+ element.setTexture(id, textureType, options);
94020
+
94021
+ case 13:
94022
+ case "end":
94023
+ return _context.stop();
94024
+ }
94025
+ }
94026
+ }, _callee, null, [[2, 9]]);
94027
+ }));
94028
+
94029
+ return function (_x) {
94030
+ return _ref2.apply(this, arguments);
94031
+ };
94032
+ }());
93791
94033
  } // setting shadow properties
93792
94034
 
93793
94035
 
@@ -95449,7 +95691,7 @@ var createPromiseWorker = function createPromiseWorker(task, message) {
95449
95691
  value: function _export() {
95450
95692
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
95451
95693
 
95452
- if (getWindow()) {
95694
+ if (getWindow$1()) {
95453
95695
  // only exporting the current level, each level needs to be instantiated to export it
95454
95696
  var level = GameRunner$1.getCurrentLevel();
95455
95697
  var content = JSON.stringify(level.toJSON());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.23.24",
3
+ "version": "3.23.26",
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": {