From a17035c8127310f5d5a39af4021222cbcbcae4df Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Mon, 26 Oct 2020 19:56:00 +0100 Subject: [PATCH] Remove conditional chaining to increase compatiblity --- js/animations/animation.js | 23 ++++++++++++----------- js/animations/keyframe.js | 4 ++-- js/animations/timeline.js | 4 ++-- js/api.js | 4 ++-- js/interface/actions.js | 4 ++-- js/io/formats/bedrock.js | 2 +- js/io/formats/modded_entity.js | 2 +- js/io/formats/optifine_jem.js | 2 +- js/io/io.js | 2 +- js/preview/transformer.js | 5 +++-- js/transform.js | 3 ++- lib/GLTFExporter.js | 2 +- 12 files changed, 30 insertions(+), 27 deletions(-) diff --git a/js/animations/animation.js b/js/animations/animation.js index 5f1e2ec6..e564dafd 100644 --- a/js/animations/animation.js +++ b/js/animations/animation.js @@ -54,8 +54,8 @@ class Animation { let uuid = isUUID(key) && key; if (!uuid) { let lowercase_bone_name = key.toLowerCase(); - uuid = Group.all.find(group => group.name.toLowerCase() == lowercase_bone_name)?.uuid; - if (!uuid) uuid = guid(); + let group_match = Group.all.find(group => group.name.toLowerCase() == lowercase_bone_name) + uuid = group_match ? group_match.uuid : guid(); } animator = this.animators[uuid] = new BoneAnimator(uuid, this, animator_blueprint.name) } @@ -978,8 +978,8 @@ class EffectAnimator extends GeneralAnimator { this.sound.forEach(kf => { var diff = kf.time - Timeline.time; if (diff >= 0 && diff < (1/60) * (Timeline.playback_speed/100)) { - if (kf.data_points[0]?.file && !kf.cooldown) { - var media = new Audio(kf.data_points[0]?.file); + if (kf.data_points[0].file && !kf.cooldown) { + var media = new Audio(kf.data_points[0].file); media.playbackRate = Math.clamp(Timeline.playback_speed/100, 0.1, 4.0); media.volume = Math.clamp(settings.volume.value/100, 0, 1); media.play().catch(() => {}); @@ -1015,9 +1015,9 @@ class EffectAnimator extends GeneralAnimator { if (locator && locator.parent instanceof Group) { locator.parent.mesh.add(emitter.local_space); emitter.local_space.position.set( - locator.from[0] - (locator.parent.origin?.[0] || 0), - locator.from[1] - (locator.parent.origin?.[1] || 0), - locator.from[2] - (locator.parent.origin?.[2] || 0) + locator.from[0] - ((locator.parent.origin && locator.parent.origin[0]) || 0), + locator.from[1] - ((locator.parent.origin && locator.parent.origin[1]) || 0), + locator.from[2] - ((locator.parent.origin && locator.parent.origin[2]) || 0) ) emitter.parent_mode = 'locator'; } else { @@ -1035,10 +1035,10 @@ class EffectAnimator extends GeneralAnimator { startPreviousSounds() { if (!this.muted.sound) { this.sound.forEach(kf => { - if (kf.data_points[0]?.file && !kf.cooldown) { + if (kf.data_points[0].file && !kf.cooldown) { var diff = kf.time - Timeline.time; - if (diff < 0 && Timeline.waveforms[kf.data_points[0]?.file] && Timeline.waveforms[kf.data_points[0]?.file].duration > -diff) { - var media = new Audio(kf.data_points[0]?.file); + if (diff < 0 && Timeline.waveforms[kf.data_points[0].file] && Timeline.waveforms[kf.data_points[0].file].duration > -diff) { + var media = new Audio(kf.data_points[0].file); media.playbackRate = Math.clamp(Timeline.playback_speed/100, 0.1, 4.0); media.volume = Math.clamp(settings.volume.value/100, 0, 1); media.currentTime = -diff; @@ -1311,9 +1311,10 @@ const Animator = { Animator.updateMotionTrailScale(); }, updateMotionTrailScale() { + if (!Preview.selected) return; Animator.motion_trail.children.forEach((object) => { if (object.isLine) return; - let scale = Preview.selected?.calculateControlScale(object.position) * 0.6; + let scale = Preview.selected.calculateControlScale(object.position) * 0.6; object.scale.set(scale, scale, scale) }) }, diff --git a/js/animations/keyframe.js b/js/animations/keyframe.js index e96322fe..ec8cec51 100644 --- a/js/animations/keyframe.js +++ b/js/animations/keyframe.js @@ -671,7 +671,7 @@ BARS.defineActions(function() { resource_id: 'animation_particle', extensions: ['json'], type: 'Bedrock Particle', - startpath: Timeline.selected[0].data_points[0]?.file + startpath: Timeline.selected[0].data_points[0].file }, function(files) { let {path} = files[0]; @@ -691,7 +691,7 @@ BARS.defineActions(function() { resource_id: 'animation_audio', extensions: ['ogg'], type: 'Audio File', - startpath: Timeline.selected[0].data_points[0]?.file + startpath: Timeline.selected[0].data_points[0].file }, function(files) { // Todo: move to panel diff --git a/js/animations/timeline.js b/js/animations/timeline.js index a8075995..165b0872 100644 --- a/js/animations/timeline.js +++ b/js/animations/timeline.js @@ -397,7 +397,7 @@ const Timeline = { drag: function(event, ui) { var difference = Math.clamp((ui.position.left - ui.originalPosition.left - 8) / Timeline.vue._data.size, -256, 256); let [min, max] = Timeline.dragging_range; - let id = event.target?.id; + let id = event.target && event.target.id; let target = Timeline.selected.find(kf => kf.uuid == id); if (event.ctrlKey) { var time_factor = (target && target.time_before < (min + max) / 2) @@ -529,7 +529,7 @@ const Timeline = { if (Animation.selected && Timeline.time < (Animation.selected.length||1e3)) { var new_time; - if (Animation.selected?.anim_time_update) { + if (Animation.selected && Animation.selected.anim_time_update) { var new_time = Animator.MolangParser.parse(Animation.selected.anim_time_update); } if (new_time == undefined || new_time <= Timeline.time) { diff --git a/js/api.js b/js/api.js index 25dc71c3..54896f44 100644 --- a/js/api.js +++ b/js/api.js @@ -148,10 +148,10 @@ const Blockbench = { Blockbench.showQuickMessage(message) } }, - showMessageBox(options, cb) { + showMessageBox(options = 0, cb) { if (options.confirm === undefined) options.confirm = 0 - if (options.cancel === undefined) options.cancel = options?.buttons?.length ? options.buttons.length-1 : 0; + if (options.cancel === undefined) options.cancel = (options.buttons && options.buttons.length) ? options.buttons.length-1 : 0; if (!options.buttons) options.buttons = [tl('dialog.ok')] if (options.translateKey) { diff --git a/js/interface/actions.js b/js/interface/actions.js index 9326b151..2235f113 100644 --- a/js/interface/actions.js +++ b/js/interface/actions.js @@ -84,7 +84,7 @@ class BarItem { if (!tooltip.length) return; tooltip.css('margin-left', '0') - var offset = tooltip?.offset() + var offset = tooltip && tooltip.offset() offset.right = offset.left + parseInt(tooltip.css('width').replace(/px/, '')) - $(window).width() if (offset.right > 4) { @@ -95,7 +95,7 @@ class BarItem { if (!description.length) return; description.css('margin-left', '-5px') - var offset = description?.offset() + var offset = description.offset() offset.right = offset.left + parseInt(description.css('width').replace(/px/, '')) - $(window).width() if (offset.right > 4) { diff --git a/js/io/formats/bedrock.js b/js/io/formats/bedrock.js index d6827674..1cea442e 100644 --- a/js/io/formats/bedrock.js +++ b/js/io/formats/bedrock.js @@ -136,7 +136,7 @@ window.BedrockEntityManager = { }, initAnimations() { - var anim_list = BedrockEntityManager?.client_entity?.description?.animations + var anim_list = BedrockEntityManager.client_entity && BedrockEntityManager.client_entity.description && BedrockEntityManager.client_entity.description.animations; if (anim_list instanceof Object) { let animation_names = []; for (var key in anim_list) { diff --git a/js/io/formats/modded_entity.js b/js/io/formats/modded_entity.js index 4fc8ea77..39e2fc6c 100644 --- a/js/io/formats/modded_entity.js +++ b/js/io/formats/modded_entity.js @@ -156,7 +156,7 @@ const Templates = { } function getIdentifier() { - return Project.geometry_name?.replace(/[\s-]+/g, '_') || 'custom_model'; + return (Project.geometry_name && Project.geometry_name.replace(/[\s-]+/g, '_')) || 'custom_model'; } var codec = new Codec('modded_entity', { diff --git a/js/io/formats/optifine_jem.js b/js/io/formats/optifine_jem.js index b031b244..6fca92d1 100644 --- a/js/io/formats/optifine_jem.js +++ b/js/io/formats/optifine_jem.js @@ -8,7 +8,7 @@ var codec = new Codec('optifine_entity', { type: 'json', extensions: ['jem'], condition(file) { - return file?.models != undefined; + return file && file.models != undefined; } }, compile(options) { diff --git a/js/io/io.js b/js/io/io.js index 2a297b9f..cbb3abdd 100644 --- a/js/io/io.js +++ b/js/io/io.js @@ -322,7 +322,7 @@ class Codec { Codec.getAllExtensions = function() { let extensions = []; for (var id in Codecs) { - if (Codecs[id].load_filter?.extensions) { + if (Codecs[id].load_filter && Codecs[id].load_filter.extensions) { extensions.safePush(...Codecs[id].load_filter.extensions); } } diff --git a/js/preview/transformer.js b/js/preview/transformer.js index 5fb45b58..6e9ca0ae 100644 --- a/js/preview/transformer.js +++ b/js/preview/transformer.js @@ -824,8 +824,9 @@ this.isIKMovement = function() { return Modes.animate && Toolbox.selected.id === 'move_tool' - && Group.selected?.ik_enabled - && Group.selected?.ik_chain_length + && Group.selected + && Group.selected.ik_enabled + && Group.selected.ik_chain_length && Group.selected.parent instanceof Group; } this.center = function() { diff --git a/js/transform.js b/js/transform.js index 2e2329bc..0bf005ac 100644 --- a/js/transform.js +++ b/js/transform.js @@ -383,8 +383,9 @@ const Vertexsnap = { Vertexsnap.step1 = true }, updateVertexSize: function() { + if (!Preview.selected) return; Vertexsnap.vertexes.children.forEach(function(v,i) { - let scale = Preview.selected?.calculateControlScale(v.position) * 0.6; + let scale = Preview.selected.calculateControlScale(v.position) * 0.6; v.scale.set(scale, scale, scale); }) } diff --git a/lib/GLTFExporter.js b/lib/GLTFExporter.js index eacaf4c3..8f969a67 100644 --- a/lib/GLTFExporter.js +++ b/lib/GLTFExporter.js @@ -1807,7 +1807,7 @@ GLTFExporter.prototype = { function processNode( object ) { if (object.no_export) return null; - if (OutlinerElement.uuids[object.name]?.export == false) return null; + if (OutlinerElement.uuids[object.name] && OutlinerElement.uuids[object.name].export == false) return null; if ( ! outputJSON.nodes ) {