mage-engine 3.23.24 → 3.23.25
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.
- package/dist/mage.js +249 -20
- 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;
|
|
@@ -56950,7 +56986,7 @@ var Physics$1 = new Physics();var Scene = /*#__PURE__*/function () {
|
|
|
56950
56986
|
}, {
|
|
56951
56987
|
key: "listenToResizeEvent",
|
|
56952
56988
|
value: function listenToResizeEvent() {
|
|
56953
|
-
var win = getWindow();
|
|
56989
|
+
var win = getWindow$1();
|
|
56954
56990
|
|
|
56955
56991
|
if (win) {
|
|
56956
56992
|
win.addEventListener("resize", this.onResize);
|
|
@@ -56959,7 +56995,7 @@ var Physics$1 = new Physics();var Scene = /*#__PURE__*/function () {
|
|
|
56959
56995
|
}, {
|
|
56960
56996
|
key: "stopResizeListener",
|
|
56961
56997
|
value: function stopResizeListener() {
|
|
56962
|
-
var win = getWindow();
|
|
56998
|
+
var win = getWindow$1();
|
|
56963
56999
|
|
|
56964
57000
|
if (win) {
|
|
56965
57001
|
win.removeEventListener("resize", this.onResize);
|
|
@@ -58259,7 +58295,7 @@ function applyMiddleware() {
|
|
|
58259
58295
|
|
|
58260
58296
|
var thunk = createThunkMiddleware();
|
|
58261
58297
|
thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
|
|
58262
|
-
var version$1 = "3.23.
|
|
58298
|
+
var version$1 = "3.23.25";
|
|
58263
58299
|
var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
|
|
58264
58300
|
var main = "dist/mage.js";
|
|
58265
58301
|
var author$1 = {
|
|
@@ -62716,10 +62752,12 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
|
|
|
62716
62752
|
}
|
|
62717
62753
|
}, {
|
|
62718
62754
|
key: "recordTexture",
|
|
62719
|
-
value: function recordTexture(id, type, options) {
|
|
62755
|
+
value: function recordTexture(id, type, options, assetPath) {
|
|
62756
|
+
// assetPath is the relative path like "textures/mytexture.png"
|
|
62720
62757
|
this.textures.set(type, {
|
|
62721
62758
|
id: id,
|
|
62722
|
-
options: options
|
|
62759
|
+
options: options,
|
|
62760
|
+
assetPath: assetPath
|
|
62723
62761
|
});
|
|
62724
62762
|
}
|
|
62725
62763
|
}, {
|
|
@@ -62740,15 +62778,22 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
|
|
|
62740
62778
|
y: 1
|
|
62741
62779
|
} : _options$repeat,
|
|
62742
62780
|
_options$wrap = options.wrap,
|
|
62743
|
-
wrap = _options$wrap === void 0 ? RepeatWrapping$1 : _options$wrap
|
|
62781
|
+
wrap = _options$wrap === void 0 ? RepeatWrapping$1 : _options$wrap,
|
|
62782
|
+
assetPath = options.assetPath;
|
|
62744
62783
|
var textureOptions = {
|
|
62745
62784
|
repeat: repeat,
|
|
62746
62785
|
wrap: wrap
|
|
62747
62786
|
};
|
|
62748
|
-
this.recordTexture(textureId, textureType, textureOptions);
|
|
62787
|
+
this.recordTexture(textureId, textureType, textureOptions, assetPath);
|
|
62749
62788
|
|
|
62750
62789
|
var applyTextureTo = function applyTextureTo(material) {
|
|
62751
62790
|
var texture = Images$1.get(textureId);
|
|
62791
|
+
|
|
62792
|
+
if (!texture) {
|
|
62793
|
+
console.warn("[Mage] Texture not found: ".concat(textureId));
|
|
62794
|
+
return;
|
|
62795
|
+
}
|
|
62796
|
+
|
|
62752
62797
|
texture.wrapS = textureOptions.wrap;
|
|
62753
62798
|
texture.wrapT = textureOptions.wrap;
|
|
62754
62799
|
texture.repeat.set(textureOptions.repeat.x, textureOptions.repeat.y);
|
|
@@ -70167,6 +70212,75 @@ var createConnect = function (ref) {
|
|
|
70167
70212
|
};
|
|
70168
70213
|
var connect = createConnect();var BaseUI = function BaseUI() {
|
|
70169
70214
|
return null;
|
|
70215
|
+
};/**
|
|
70216
|
+
* Environment configuration module for mage-engine.
|
|
70217
|
+
* Centralizes all environment variables and their default values.
|
|
70218
|
+
*
|
|
70219
|
+
* Usage:
|
|
70220
|
+
* import env from './env';
|
|
70221
|
+
* const baseUrl = env.MAGE_ASSETS_BASE_URL;
|
|
70222
|
+
*/
|
|
70223
|
+
|
|
70224
|
+
/**
|
|
70225
|
+
* Safe window access - returns undefined in non-browser environments
|
|
70226
|
+
*/
|
|
70227
|
+
var getWindow = function getWindow() {
|
|
70228
|
+
return typeof window !== "undefined" ? window : undefined;
|
|
70229
|
+
};
|
|
70230
|
+
/**
|
|
70231
|
+
* Gets an environment variable from the window object with a fallback default.
|
|
70232
|
+
* @param {string} key - The environment variable name
|
|
70233
|
+
* @param {any} defaultValue - Default value if not set
|
|
70234
|
+
* @returns {any} - The environment variable value or default
|
|
70235
|
+
*/
|
|
70236
|
+
|
|
70237
|
+
|
|
70238
|
+
var getEnv = function getEnv(key) {
|
|
70239
|
+
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
70240
|
+
var win = getWindow();
|
|
70241
|
+
return win && win[key] !== undefined ? win[key] : defaultValue;
|
|
70242
|
+
};
|
|
70243
|
+
/**
|
|
70244
|
+
* Environment variables with their default values.
|
|
70245
|
+
* These are accessed as getters so they're evaluated at access time,
|
|
70246
|
+
* not at module load time (important for variables set after page load).
|
|
70247
|
+
*/
|
|
70248
|
+
|
|
70249
|
+
|
|
70250
|
+
var env = {
|
|
70251
|
+
/**
|
|
70252
|
+
* Base URL for loading assets (textures, models, audio).
|
|
70253
|
+
* Set by mage-studio editor or deployed builds.
|
|
70254
|
+
* Default: empty string (paths used as-is for backwards compatibility)
|
|
70255
|
+
*/
|
|
70256
|
+
get MAGE_ASSETS_BASE_URL() {
|
|
70257
|
+
return getEnv("MAGE_ASSETS_BASE_URL", "");
|
|
70258
|
+
},
|
|
70259
|
+
|
|
70260
|
+
/**
|
|
70261
|
+
* Enable debug mode for verbose logging.
|
|
70262
|
+
* Default: false
|
|
70263
|
+
*/
|
|
70264
|
+
get MAGE_DEBUG() {
|
|
70265
|
+
return getEnv("MAGE_DEBUG", false);
|
|
70266
|
+
},
|
|
70267
|
+
|
|
70268
|
+
/**
|
|
70269
|
+
* Current project ID (set by mage-studio).
|
|
70270
|
+
* Default: empty string
|
|
70271
|
+
*/
|
|
70272
|
+
get MAGE_PROJECT_ID() {
|
|
70273
|
+
return getEnv("MAGE_PROJECT_ID", "");
|
|
70274
|
+
},
|
|
70275
|
+
|
|
70276
|
+
/**
|
|
70277
|
+
* Current build ID (set by deployed builds).
|
|
70278
|
+
* Default: empty string
|
|
70279
|
+
*/
|
|
70280
|
+
get MAGE_BUILD_ID() {
|
|
70281
|
+
return getEnv("MAGE_BUILD_ID", "");
|
|
70282
|
+
}
|
|
70283
|
+
|
|
70170
70284
|
};var TIME_FOR_UPDATE = 5;
|
|
70171
70285
|
var VOLUME = 2;
|
|
70172
70286
|
var DEFAULT_AUDIO_NODE_VOLUME = 5;
|
|
@@ -70176,6 +70290,48 @@ var AUDIO_RAMPS = {
|
|
|
70176
70290
|
LINEAR: "LINEAR",
|
|
70177
70291
|
EXPONENTIAL: "EXPONENTIAL"
|
|
70178
70292
|
};
|
|
70293
|
+
/**
|
|
70294
|
+
* Checks if a path is an absolute URL.
|
|
70295
|
+
* @param {string} path - The path to check
|
|
70296
|
+
* @returns {boolean} - True if path is an absolute URL
|
|
70297
|
+
*/
|
|
70298
|
+
|
|
70299
|
+
var isURL$1 = function isURL(path) {
|
|
70300
|
+
try {
|
|
70301
|
+
new URL(path);
|
|
70302
|
+
return true;
|
|
70303
|
+
} catch (_) {
|
|
70304
|
+
return false;
|
|
70305
|
+
}
|
|
70306
|
+
};
|
|
70307
|
+
/**
|
|
70308
|
+
* Resolves an asset path to a full URL.
|
|
70309
|
+
* If path is already an absolute URL, returns it as-is.
|
|
70310
|
+
* If path is relative and MAGE_ASSETS_BASE_URL is set, prepends the base URL.
|
|
70311
|
+
* @param {string} path - The asset path (relative or absolute)
|
|
70312
|
+
* @returns {string} - The resolved full URL
|
|
70313
|
+
*/
|
|
70314
|
+
|
|
70315
|
+
|
|
70316
|
+
var resolveAssetPath$1 = function resolveAssetPath(path) {
|
|
70317
|
+
// If it's already an absolute URL, use it as-is
|
|
70318
|
+
if (isURL$1(path)) {
|
|
70319
|
+
return path;
|
|
70320
|
+
} // If MAGE_ASSETS_BASE_URL is set, prepend it to the relative path
|
|
70321
|
+
|
|
70322
|
+
|
|
70323
|
+
var baseUrl = env.MAGE_ASSETS_BASE_URL;
|
|
70324
|
+
|
|
70325
|
+
if (baseUrl) {
|
|
70326
|
+
// Remove leading slash from path if present to avoid double slashes
|
|
70327
|
+
var cleanPath = path.startsWith("/") ? path.slice(1) : path;
|
|
70328
|
+
return "".concat(baseUrl, "/").concat(cleanPath);
|
|
70329
|
+
} // Fallback: return the path as-is (for backwards compatibility)
|
|
70330
|
+
|
|
70331
|
+
|
|
70332
|
+
return path;
|
|
70333
|
+
};
|
|
70334
|
+
|
|
70179
70335
|
var Audio = /*#__PURE__*/function () {
|
|
70180
70336
|
function Audio() {
|
|
70181
70337
|
var _this = this;
|
|
@@ -70213,9 +70369,11 @@ var Audio = /*#__PURE__*/function () {
|
|
|
70213
70369
|
});
|
|
70214
70370
|
|
|
70215
70371
|
_defineProperty$1(this, "loadAssetByPath", function (path, id) {
|
|
70372
|
+
// Resolve the path using MAGE_ASSETS_BASE_URL if available
|
|
70373
|
+
var resolvedPath = resolveAssetPath$1(path);
|
|
70216
70374
|
var request = new XMLHttpRequest();
|
|
70217
70375
|
return new Promise(function (resolve) {
|
|
70218
|
-
request.open("GET",
|
|
70376
|
+
request.open("GET", resolvedPath, true);
|
|
70219
70377
|
request.responseType = "arraybuffer";
|
|
70220
70378
|
|
|
70221
70379
|
request.onreadystatechange = function (e) {
|
|
@@ -80710,6 +80868,33 @@ var isURL = function isURL(path) {
|
|
|
80710
80868
|
return false;
|
|
80711
80869
|
}
|
|
80712
80870
|
};
|
|
80871
|
+
/**
|
|
80872
|
+
* Resolves an asset path to a full URL.
|
|
80873
|
+
* If path is already an absolute URL, returns it as-is.
|
|
80874
|
+
* If path is relative and MAGE_ASSETS_BASE_URL is set, prepends the base URL.
|
|
80875
|
+
* @param {string} path - The asset path (relative or absolute)
|
|
80876
|
+
* @returns {string} - The resolved full URL
|
|
80877
|
+
*/
|
|
80878
|
+
|
|
80879
|
+
|
|
80880
|
+
var resolveAssetPath = function resolveAssetPath(path) {
|
|
80881
|
+
// If it's already an absolute URL, use it as-is
|
|
80882
|
+
if (isURL(path)) {
|
|
80883
|
+
return path;
|
|
80884
|
+
} // If MAGE_ASSETS_BASE_URL is set, prepend it to the relative path
|
|
80885
|
+
|
|
80886
|
+
|
|
80887
|
+
var baseUrl = env.MAGE_ASSETS_BASE_URL;
|
|
80888
|
+
|
|
80889
|
+
if (baseUrl) {
|
|
80890
|
+
// Remove leading slash from path if present to avoid double slashes
|
|
80891
|
+
var cleanPath = path.startsWith("/") ? path.slice(1) : path;
|
|
80892
|
+
return "".concat(baseUrl, "/").concat(cleanPath);
|
|
80893
|
+
} // Fallback: return the path as-is (for backwards compatibility)
|
|
80894
|
+
|
|
80895
|
+
|
|
80896
|
+
return path;
|
|
80897
|
+
};
|
|
80713
80898
|
|
|
80714
80899
|
var extractExtension = function extractExtension(path) {
|
|
80715
80900
|
var url = isURL(path);
|
|
@@ -80916,7 +81101,9 @@ var Models = /*#__PURE__*/function (_EventDispatcher) {
|
|
|
80916
81101
|
_defineProperty$1(_assertThisInitialized(_this), "loadAssetByPath", function (path, name) {
|
|
80917
81102
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
80918
81103
|
var level = options.level;
|
|
80919
|
-
var id = buildAssetId(name, level);
|
|
81104
|
+
var id = buildAssetId(name, level); // Resolve the path using MAGE_ASSETS_BASE_URL if available
|
|
81105
|
+
|
|
81106
|
+
var resolvedPath = resolveAssetPath(path);
|
|
80920
81107
|
var extension = extractExtension(path);
|
|
80921
81108
|
|
|
80922
81109
|
var _getLoaderFromExtensi = getLoaderFromExtension(extension, options),
|
|
@@ -80933,7 +81120,7 @@ var Models = /*#__PURE__*/function (_EventDispatcher) {
|
|
|
80933
81120
|
});
|
|
80934
81121
|
});
|
|
80935
81122
|
return new Promise(function (resolve) {
|
|
80936
|
-
loader.load(
|
|
81123
|
+
loader.load(resolvedPath, function (model) {
|
|
80937
81124
|
var parsedModel = parser(model);
|
|
80938
81125
|
|
|
80939
81126
|
if (parsedModel) {
|
|
@@ -93686,7 +93873,7 @@ var Importer = /*#__PURE__*/function () {
|
|
|
93686
93873
|
_ref$options = _ref.options,
|
|
93687
93874
|
options = _ref$options === void 0 ? {} : _ref$options;
|
|
93688
93875
|
|
|
93689
|
-
if (getWindow() && url) {
|
|
93876
|
+
if (getWindow$1() && url) {
|
|
93690
93877
|
return fetch$1(url).then(function (res) {
|
|
93691
93878
|
return res.json();
|
|
93692
93879
|
}).then(function (data) {
|
|
@@ -93782,12 +93969,54 @@ var Importer = /*#__PURE__*/function () {
|
|
|
93782
93969
|
if (elementData.textures) {
|
|
93783
93970
|
var parsedTextures = JSON.parse(elementData.textures);
|
|
93784
93971
|
element.setNormalScale();
|
|
93785
|
-
Object.keys(parsedTextures).forEach(function (
|
|
93786
|
-
var
|
|
93787
|
-
|
|
93788
|
-
|
|
93789
|
-
|
|
93790
|
-
|
|
93972
|
+
Object.keys(parsedTextures).forEach( /*#__PURE__*/function () {
|
|
93973
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(textureType) {
|
|
93974
|
+
var _parsedTextures$textu, id, options, assetPath, baseUrl, fullUrl;
|
|
93975
|
+
|
|
93976
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
93977
|
+
while (1) {
|
|
93978
|
+
switch (_context.prev = _context.next) {
|
|
93979
|
+
case 0:
|
|
93980
|
+
_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
|
|
93981
|
+
// assetPath is relative like "textures/mytexture.png"
|
|
93982
|
+
// The actual URL is resolved based on the assets base URL
|
|
93983
|
+
|
|
93984
|
+
if (!(!Images$1.get(id) && assetPath)) {
|
|
93985
|
+
_context.next = 12;
|
|
93986
|
+
break;
|
|
93987
|
+
}
|
|
93988
|
+
|
|
93989
|
+
_context.prev = 2;
|
|
93990
|
+
// Use the assets base URL from env to build full URL
|
|
93991
|
+
baseUrl = env.MAGE_ASSETS_BASE_URL;
|
|
93992
|
+
fullUrl = baseUrl ? "".concat(baseUrl, "/").concat(assetPath) : assetPath;
|
|
93993
|
+
_context.next = 7;
|
|
93994
|
+
return Images$1.loadAssetByPath(fullUrl, id, Images$1.currentLevel);
|
|
93995
|
+
|
|
93996
|
+
case 7:
|
|
93997
|
+
_context.next = 12;
|
|
93998
|
+
break;
|
|
93999
|
+
|
|
94000
|
+
case 9:
|
|
94001
|
+
_context.prev = 9;
|
|
94002
|
+
_context.t0 = _context["catch"](2);
|
|
94003
|
+
console.warn("[Mage] Failed to load texture: ".concat(id, " from ").concat(assetPath));
|
|
94004
|
+
|
|
94005
|
+
case 12:
|
|
94006
|
+
element.setTexture(id, textureType, options);
|
|
94007
|
+
|
|
94008
|
+
case 13:
|
|
94009
|
+
case "end":
|
|
94010
|
+
return _context.stop();
|
|
94011
|
+
}
|
|
94012
|
+
}
|
|
94013
|
+
}, _callee, null, [[2, 9]]);
|
|
94014
|
+
}));
|
|
94015
|
+
|
|
94016
|
+
return function (_x) {
|
|
94017
|
+
return _ref2.apply(this, arguments);
|
|
94018
|
+
};
|
|
94019
|
+
}());
|
|
93791
94020
|
} // setting shadow properties
|
|
93792
94021
|
|
|
93793
94022
|
|
|
@@ -95449,7 +95678,7 @@ var createPromiseWorker = function createPromiseWorker(task, message) {
|
|
|
95449
95678
|
value: function _export() {
|
|
95450
95679
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
95451
95680
|
|
|
95452
|
-
if (getWindow()) {
|
|
95681
|
+
if (getWindow$1()) {
|
|
95453
95682
|
// only exporting the current level, each level needs to be instantiated to export it
|
|
95454
95683
|
var level = GameRunner$1.getCurrentLevel();
|
|
95455
95684
|
var content = JSON.stringify(level.toJSON());
|