Skip to content

Commit abbfd98

Browse files
committed
small improvements
1 parent 9a42725 commit abbfd98

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎src/serialization/sb3.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ const replaceUnsafeCharsInVariableIds = function (targets) {
15421542
* @returns {void|Promise<void>} Resolves when the user has acknowledged any compatibilities, if any exist.
15431543
*/
15441544
const checkPlatformCompatibility = (json, runtime) => {
1545-
if (!json.meta || !json.meta.platform) {
1545+
if (!json.meta || !json.meta.platform || !runtime.platform) {
15461546
return;
15471547
}
15481548

‎src/util/math-util.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ class MathUtil {
6464
}
6565
}
6666

67+
/**
68+
* Removes an element from the given array at the specified index and inserts it at a new index.
69+
* @param {Array} array - The index of the element to remove.
70+
* @param {number} fromIndex - The original index of the element to be swapped.
71+
* @param {number} toIndex - The index to insert the removed element into.
72+
*/
73+
static moveArrayElement (array, fromIndex, toIndex) {
74+
fromIndex = MathUtil.clamp(fromIndex, 0, array.length - 1);
75+
toIndex = MathUtil.clamp(toIndex, 0, array.length - 1);
76+
if (fromIndex === toIndex) {
77+
return {array, item: array[fromIndex], fromIndex, toIndex};
78+
}
79+
const newArr = [...array];
80+
const deletedItem = newArr.splice(fromIndex, 1);
81+
newArr.splice(toIndex, 0, deletedItem[0]);
82+
return {array: newArr, item: deletedItem[0], fromIndex, toIndex};
83+
}
84+
6785
/**
6886
* Given an array of unique numbers,
6987
* returns a reduced array such that each element of the reduced array

‎test/integration/tw_very_long_comments.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const path = require('path');
1010
test('serializes very long comments', t => {
1111
const rt = new Runtime();
1212
const sprite = new Sprite();
13-
const target = new RenderedTarget(sprite);
13+
const target = new RenderedTarget(sprite, rt);
1414
rt.addTarget(target);
1515

1616
target.createComment('id_short', null, 'short comment', 0, 0, 20, 20, false);

0 commit comments

Comments
 (0)