mage-engine 3.23.15 → 3.23.20

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 CHANGED
@@ -55048,51 +55048,52 @@ var createElementFromSelector = function createElementFromSelector(selector) {
55048
55048
  };var DEFAULT_HEIGHT$2 = 600;
55049
55049
  var DEFAULT_WIDTH = 800;
55050
55050
  var DEFAULT_RATIO = DEFAULT_WIDTH / DEFAULT_HEIGHT$2;
55051
+ var DEFAULT_CONFIG = {
55052
+ tests: [],
55053
+ scripts: {// [scriptId]: Script
55054
+ // e.g. "BaseCar": BaseCar,
55055
+ // where at the top of the file we have:
55056
+ // import BaseCar from "../scripts/BaseCar.js";
55057
+ },
55058
+ levelsData: {// [levelId]: { url: URL, data: JSON, options: {} }
55059
+ },
55060
+ screen: {
55061
+ frameRate: 60,
55062
+ alpha: true
55063
+ },
55064
+ postprocessing: {
55065
+ enabled: false
55066
+ },
55067
+ fog: {
55068
+ enabled: false,
55069
+ density: 0,
55070
+ color: "#ffffff"
55071
+ },
55072
+ lights: {
55073
+ shadows: true,
55074
+ shadowType: SHADOW_TYPES.BASIC,
55075
+ textureAnisotropy: 16
55076
+ },
55077
+ physics: {
55078
+ enabled: false,
55079
+ path: "./mage.physics.js"
55080
+ },
55081
+ camera: {
55082
+ //handling useful informations about our camera.
55083
+ fov: 75,
55084
+ near: 0.1,
55085
+ far: 100
55086
+ },
55087
+ ui: {
55088
+ enabled: true
55089
+ }
55090
+ };
55051
55091
 
55052
55092
  var Config = /*#__PURE__*/function () {
55053
55093
  function Config() {
55054
55094
  _classCallCheck(this, Config);
55055
55095
 
55056
- this.default = {
55057
- tests: [],
55058
- scripts: {// [scriptId]: Script
55059
- // e.g. "BaseCar": BaseCar,
55060
- // where at the top of the file we have:
55061
- // import BaseCar from "../scripts/BaseCar.js";
55062
- },
55063
- levelsData: {// [levelId]: { url: URL }
55064
- },
55065
- screen: {
55066
- frameRate: 60,
55067
- alpha: true
55068
- },
55069
- postprocessing: {
55070
- enabled: false
55071
- },
55072
- fog: {
55073
- enabled: false,
55074
- density: 0,
55075
- color: "#ffffff"
55076
- },
55077
- lights: {
55078
- shadows: true,
55079
- shadowType: SHADOW_TYPES.BASIC,
55080
- textureAnisotropy: 16
55081
- },
55082
- physics: {
55083
- enabled: false,
55084
- path: "./mage.physics.js"
55085
- },
55086
- camera: {
55087
- //handling useful informations about our camera.
55088
- fov: 75,
55089
- near: 0.1,
55090
- far: 100
55091
- },
55092
- ui: {
55093
- enabled: true
55094
- }
55095
- };
55096
+ this.default = DEFAULT_CONFIG;
55096
55097
  this.isDefault = true;
55097
55098
  }
55098
55099
 
@@ -56834,6 +56835,7 @@ var Physics$1 = new Physics();var Scene = /*#__PURE__*/function () {
56834
56835
  var fog = Config$1.fog();
56835
56836
  this.scene = new Scene$2();
56836
56837
  this.scene.name = name;
56838
+ this.elements = [];
56837
56839
 
56838
56840
  if (fog.enabled) {
56839
56841
  this.fog(fog.color, fog.density);
@@ -56967,7 +56969,9 @@ var Physics$1 = new Physics();var Scene = /*#__PURE__*/function () {
56967
56969
  // destroy renderer
56968
56970
  this.renderer.dispose(); // remove listener to resize
56969
56971
 
56970
- this.detachListeners();
56972
+ this.detachListeners(); // clear elements array
56973
+
56974
+ this.elements = [];
56971
56975
  }
56972
56976
  }, {
56973
56977
  key: "createCamera",
@@ -58253,7 +58257,7 @@ function applyMiddleware() {
58253
58257
 
58254
58258
  var thunk = createThunkMiddleware();
58255
58259
  thunk.withExtraArgument = createThunkMiddleware;var name$1 = "mage-engine";
58256
- var version$1 = "3.23.15";
58260
+ var version$1 = "3.23.20";
58257
58261
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
58258
58262
  var main = "dist/mage.js";
58259
58263
  var author$1 = {
@@ -63764,9 +63768,6 @@ var Sprite = /*#__PURE__*/function (_Element) {
63764
63768
  _this.width = width;
63765
63769
  _this.height = height;
63766
63770
  _this.spriteTexture = spriteTexture;
63767
-
63768
- _this.setAnisotropy(anisotropy);
63769
-
63770
63771
  var material = new SpriteMaterial(_objectSpread2$1({
63771
63772
  map: texture
63772
63773
  }, rest));
@@ -63776,6 +63777,8 @@ var Sprite = /*#__PURE__*/function (_Element) {
63776
63777
  body: body
63777
63778
  });
63778
63779
 
63780
+ _this.setAnisotropy(anisotropy);
63781
+
63779
63782
  _this.setWidth(width);
63780
63783
 
63781
63784
  _this.setHeight(height);
@@ -90990,6 +90993,9 @@ var Level = /*#__PURE__*/function (_EventDispatcher) {
90990
90993
  }, {
90991
90994
  key: "onCreate",
90992
90995
  value: function onCreate() {}
90996
+ }, {
90997
+ key: "onStart",
90998
+ value: function onStart() {}
90993
90999
  }, {
90994
91000
  key: "onUpdate",
90995
91001
  value: function onUpdate() {}
@@ -92888,20 +92894,25 @@ var Importer = /*#__PURE__*/function () {
92888
92894
  _createClass(Importer, null, [{
92889
92895
  key: "importLevelSnapshot",
92890
92896
  // Importer gets config, containing either a level or a url
92891
- value: function importLevelSnapshot(_ref) {
92892
- var url = _ref.url,
92893
- data = _ref.data;
92897
+ value: function importLevelSnapshot() {
92898
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
92899
+ url = _ref.url,
92900
+ data = _ref.data,
92901
+ _ref$options = _ref.options,
92902
+ options = _ref$options === void 0 ? {} : _ref$options;
92894
92903
 
92895
92904
  if (getWindow() && url) {
92896
92905
  return fetch$1(url).then(function (res) {
92897
92906
  return res.json();
92898
92907
  }).then(function (data) {
92899
92908
  return data || {};
92900
- }).then(Importer.parseLevelData).catch(function () {
92909
+ }).then(function (data) {
92910
+ return Importer.parseLevelData(data, options);
92911
+ }).catch(function () {
92901
92912
  return Promise.resolve();
92902
92913
  });
92903
92914
  } else if (data) {
92904
- return Promise.resolve(Importer.parseLevelData(data));
92915
+ return Promise.resolve(Importer.parseLevelData(data, options));
92905
92916
  }
92906
92917
 
92907
92918
  console.warn(NO_VALID_LEVEL_DATA_PROVIDED);
@@ -92924,7 +92935,9 @@ var Importer = /*#__PURE__*/function () {
92924
92935
  _options$skipName = options.skipName,
92925
92936
  skipName = _options$skipName === void 0 ? false : _options$skipName,
92926
92937
  _options$skipWorldTra = options.skipWorldTransform,
92927
- skipWorldTransform = _options$skipWorldTra === void 0 ? false : _options$skipWorldTra; /// position
92938
+ skipWorldTransform = _options$skipWorldTra === void 0 ? false : _options$skipWorldTra,
92939
+ _options$skipTags = options.skipTags,
92940
+ skipTags = _options$skipTags === void 0 ? false : _options$skipTags; /// position
92928
92941
 
92929
92942
  if (!skipPosition) element.setPosition(elementData.position); // rotation
92930
92943
 
@@ -92962,12 +92975,16 @@ var Importer = /*#__PURE__*/function () {
92962
92975
 
92963
92976
  Object.keys(elementData.data).forEach(function (k) {
92964
92977
  element.setData(k, elementData.data[k]);
92965
- });
92978
+ }); // setting tags
92979
+
92980
+ if (!skipTags && elementData.tags) {
92981
+ element.addTags(elementData.tags);
92982
+ }
92966
92983
  }
92967
92984
  }, {
92968
92985
  key: "completeElementCreation",
92969
- value: function completeElementCreation(element, elementData) {
92970
- Importer.completeCommonCreationSteps(element, elementData); // setting material
92986
+ value: function completeElementCreation(element, elementData, options) {
92987
+ Importer.completeCommonCreationSteps(element, elementData, options); // setting material
92971
92988
 
92972
92989
  if (elementData.materials.length) {
92973
92990
  var defaultMaterialOptionKeys = MATERIAL_PROPERTIES_MAP[elementData.materialType];
@@ -92988,10 +93005,11 @@ var Importer = /*#__PURE__*/function () {
92988
93005
  }
92989
93006
  }, {
92990
93007
  key: "completeLightCreation",
92991
- value: function completeLightCreation(light, lightData) {
92992
- Importer.completeCommonCreationSteps(light, lightData, {
93008
+ value: function completeLightCreation(light, lightData, options) {
93009
+ // always setting skipOpacity to true
93010
+ Importer.completeCommonCreationSteps(light, lightData, _objectSpread2$1(_objectSpread2$1({}, options), {}, {
92993
93011
  skipOpacity: true
92994
- }); // setting color and intensity
93012
+ })); // setting color and intensity
92995
93013
 
92996
93014
  light.setColor(lightData.color);
92997
93015
  light.setIntensity(lightData.intensity); // setting light-specific properties
@@ -93041,17 +93059,17 @@ var Importer = /*#__PURE__*/function () {
93041
93059
  var targetElement = new Element$1({
93042
93060
  body: new Object3D()
93043
93061
  });
93044
- Importer.completeCommonCreationSteps(targetElement, lightData.target);
93062
+ Importer.completeCommonCreationSteps(targetElement, lightData.target, options);
93045
93063
  light.setTarget(targetElement);
93046
93064
  }
93047
93065
  }
93048
93066
  }, {
93049
93067
  key: "completeSkyCreation",
93050
- value: function completeSkyCreation(sky, skyData) {
93068
+ value: function completeSkyCreation(sky, skyData, options) {
93051
93069
  // calling completeElementCreation to set position, rotation, quaternion, scale, opacity, name, material, textures, scripts, and data
93052
- Importer.completeCommonCreationSteps(sky, skyData, {
93070
+ Importer.completeCommonCreationSteps(sky, skyData, _objectSpread2$1(_objectSpread2$1({}, options), {}, {
93053
93071
  skipScale: true
93054
- });
93072
+ }));
93055
93073
  var _skyData$options = skyData.options,
93056
93074
  turbidity = _skyData$options.turbidity,
93057
93075
  rayleigh = _skyData$options.rayleigh,
@@ -93088,9 +93106,9 @@ var Importer = /*#__PURE__*/function () {
93088
93106
  }
93089
93107
  }, {
93090
93108
  key: "completeSpriteCreation",
93091
- value: function completeSpriteCreation(sprite, spriteData) {
93109
+ value: function completeSpriteCreation(sprite, spriteData, options) {
93092
93110
  // calling completeElementCreation to set position, rotation, quaternion, scale, opacity, name, material, textures, scripts, and data
93093
- Importer.completeElementCreation(sprite, spriteData);
93111
+ Importer.completeElementCreation(sprite, spriteData, options);
93094
93112
  var width = spriteData.width,
93095
93113
  height = spriteData.height,
93096
93114
  spriteTexture = spriteData.spriteTexture,
@@ -93131,6 +93149,7 @@ var Importer = /*#__PURE__*/function () {
93131
93149
  key: "parseLevelData",
93132
93150
  value: function parseLevelData() {
93133
93151
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
93152
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
93134
93153
  var _data$elements = data.elements,
93135
93154
  elements = _data$elements === void 0 ? [] : _data$elements,
93136
93155
  _data$lights = data.lights,
@@ -93138,52 +93157,52 @@ var Importer = /*#__PURE__*/function () {
93138
93157
  elements.forEach(function (data) {
93139
93158
  try {
93140
93159
  if (data.entitySubType === ENTITY_TYPES.MODEL.TYPE) {
93141
- var options = data.options;
93160
+ var _options2 = data.options;
93142
93161
 
93143
- var name = options.name,
93144
- rest = _objectWithoutProperties(options, _excluded$4);
93162
+ var name = _options2.name,
93163
+ rest = _objectWithoutProperties(_options2, _excluded$4);
93145
93164
 
93146
- Importer.completeElementCreation(Models$1.create(name, rest), data);
93165
+ Importer.completeElementCreation(Models$1.create(name, rest), data, _options2);
93147
93166
  } else {
93148
93167
  switch (data.entitySubType) {
93149
93168
  case ENTITY_TYPES.MESH.SUBTYPES.CUBE:
93150
- Importer.completeElementCreation(Cube.create(data), data);
93169
+ Importer.completeElementCreation(Cube.create(data), data, options);
93151
93170
  break;
93152
93171
 
93153
93172
  case ENTITY_TYPES.MESH.SUBTYPES.LINE:
93154
- Importer.completeElementCreation(Line.create(data), data);
93173
+ Importer.completeElementCreation(Line.create(data), data, options);
93155
93174
  break;
93156
93175
 
93157
93176
  case ENTITY_TYPES.MESH.SUBTYPES.SPHERE:
93158
- Importer.completeElementCreation(Sphere.create(data), data);
93177
+ Importer.completeElementCreation(Sphere.create(data), data, options);
93159
93178
  break;
93160
93179
 
93161
93180
  case ENTITY_TYPES.MESH.SUBTYPES.CYLINDER:
93162
- Importer.completeElementCreation(Cylinder.create(data), data);
93181
+ Importer.completeElementCreation(Cylinder.create(data), data, options);
93163
93182
  break;
93164
93183
 
93165
93184
  case ENTITY_TYPES.MESH.SUBTYPES.CONE:
93166
- Importer.completeElementCreation(Cone.create(data), data);
93185
+ Importer.completeElementCreation(Cone.create(data), data, options);
93167
93186
  break;
93168
93187
 
93169
93188
  case ENTITY_TYPES.MESH.SUBTYPES.BOX:
93170
- Importer.completeElementCreation(Box.create(data), data);
93189
+ Importer.completeElementCreation(Box.create(data), data, options);
93171
93190
  break;
93172
93191
 
93173
93192
  case ENTITY_TYPES.MESH.SUBTYPES.CURVE_LINE:
93174
- Importer.completeElementCreation(CurveLine.create(data), data);
93193
+ Importer.completeElementCreation(CurveLine.create(data), data, options);
93175
93194
  break;
93176
93195
 
93177
93196
  case ENTITY_TYPES.MESH.SUBTYPES.PLANE:
93178
- Importer.completeElementCreation(Plane.create(data), data);
93197
+ Importer.completeElementCreation(Plane.create(data), data, options);
93179
93198
  break;
93180
93199
 
93181
93200
  case ENTITY_TYPES.SPRITE.SUBTYPES.DEFAULT:
93182
- Importer.completeSpriteCreation(Sprite.create(data), data);
93201
+ Importer.completeSpriteCreation(Sprite.create(data), data, options);
93183
93202
  break;
93184
93203
 
93185
93204
  case ENTITY_TYPES.SCENERY.SUBTYPES.SKY:
93186
- Importer.completeSkyCreation(Sky.create(data), data);
93205
+ Importer.completeSkyCreation(Sky.create(data), data, options);
93187
93206
  break;
93188
93207
 
93189
93208
  default:
@@ -93207,7 +93226,7 @@ var Importer = /*#__PURE__*/function () {
93207
93226
  var childData = elements.find(function (e) {
93208
93227
  return e.uuid === uuid;
93209
93228
  });
93210
- Importer.completeCommonCreationSteps(child, childData);
93229
+ Importer.completeCommonCreationSteps(child, childData, options);
93211
93230
  }
93212
93231
  });
93213
93232
  }
@@ -93216,23 +93235,23 @@ var Importer = /*#__PURE__*/function () {
93216
93235
  try {
93217
93236
  switch (data.entitySubType) {
93218
93237
  case ENTITY_TYPES.LIGHT.SUBTYPES.POINT:
93219
- Importer.completeLightCreation(PointLight$1.create(data), data);
93238
+ Importer.completeLightCreation(PointLight$1.create(data), data, options);
93220
93239
  break;
93221
93240
 
93222
93241
  case ENTITY_TYPES.LIGHT.SUBTYPES.AMBIENT:
93223
- Importer.completeLightCreation(AmbientLight$1.create(data), data);
93242
+ Importer.completeLightCreation(AmbientLight$1.create(data), data, options);
93224
93243
  break;
93225
93244
 
93226
93245
  case ENTITY_TYPES.LIGHT.SUBTYPES.SPOT:
93227
- Importer.completeLightCreation(SpotLight$1.create(data), data);
93246
+ Importer.completeLightCreation(SpotLight$1.create(data), data, options);
93228
93247
  break;
93229
93248
 
93230
93249
  case ENTITY_TYPES.LIGHT.SUBTYPES.HEMISPHERE:
93231
- Importer.completeLightCreation(HemisphereLight$1.create(data), data);
93250
+ Importer.completeLightCreation(HemisphereLight$1.create(data), data, options);
93232
93251
  break;
93233
93252
 
93234
93253
  case ENTITY_TYPES.LIGHT.SUBTYPES.SUN:
93235
- Importer.completeLightCreation(SunLight$1.create(data), data);
93254
+ Importer.completeLightCreation(SunLight$1.create(data), data, options);
93236
93255
  break;
93237
93256
 
93238
93257
  default:
@@ -93294,18 +93313,25 @@ var Importer = /*#__PURE__*/function () {
93294
93313
  _this.getCurrentLevel().init();
93295
93314
 
93296
93315
  storage.load().then(Importer.parseLevelData).then(function () {
93297
- return resolve(_this.getCurrentLevel());
93316
+ if (_this.getCurrentLevel().onStart instanceof Function) {
93317
+ _this.getCurrentLevel().onStart();
93318
+ }
93319
+
93320
+ resolve(_this.getCurrentLevel());
93298
93321
  });
93299
93322
  } else {
93300
93323
  Physics$1.waitForState(PHYSICS_STATES.READY).then(function () {
93301
93324
  _this.getCurrentLevel().prepareScene();
93302
93325
 
93303
- _this.getCurrentLevel().init(); // const levelURL = config.getLevelData(this.getCurrentLevel().getPath())?.url;
93304
-
93326
+ _this.getCurrentLevel().init();
93305
93327
 
93306
- var levelData = Config$1.getLevelData(_this.getCurrentLevel().getPath());
93328
+ var levelData = Config$1.getLevelData(_this.getCurrentLevel().getPath()) || {};
93307
93329
  Importer.importLevelSnapshot(levelData).then(function () {
93308
- return resolve(_this.getCurrentLevel());
93330
+ if (_this.getCurrentLevel().onStart instanceof Function) {
93331
+ _this.getCurrentLevel().onStart();
93332
+ }
93333
+
93334
+ resolve(_this.getCurrentLevel());
93309
93335
  }).catch(reject);
93310
93336
  });
93311
93337
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.23.15",
3
+ "version": "3.23.20",
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": {
@@ -1 +0,0 @@
1
- {}