Don't remove special configuration comments
This commit is contained in:
2 files changed
+52
-3
No files matched your search
@@ -154,6 +154,7 @@ const optimizeSb3Json = (projectData) => {
|
||||
const newLists = {};
|
||||
const newBroadcasts = {};
|
||||
const newBlocks = {};
|
||||
const newComments = {};
|
||||
|
||||
for (const [variableId, variable] of Object.entries(target.variables)) {
|
||||
newVariables[variablePool.getNewId(variableId)] = variable;
|
||||
@@ -204,17 +205,26 @@ const optimizeSb3Json = (projectData) => {
|
||||
delete block.y;
|
||||
delete block.comment;
|
||||
}
|
||||
for (const [commentId, comment] of Object.entries(target.comments)) {
|
||||
const text = comment.text;
|
||||
const isSpecial = text.includes(' // _twconfig_') || text.includes(' // _gamepad_');
|
||||
if (isSpecial) {
|
||||
newComments[commentId] = comment;
|
||||
}
|
||||
}
|
||||
|
||||
target.variables = newVariables;
|
||||
target.lists = newLists;
|
||||
target.broadcasts = newBroadcasts;
|
||||
target.blocks = newBlocks;
|
||||
target.comments = {};
|
||||
target.comments = newComments;
|
||||
}
|
||||
|
||||
// Step 3 - Remove other unnecessary data
|
||||
delete projectData.meta.agent;
|
||||
delete projectData.meta.vm;
|
||||
if (projectData.meta) {
|
||||
delete projectData.meta.agent;
|
||||
delete projectData.meta.vm;
|
||||
}
|
||||
|
||||
return projectData;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,15 @@ import optimizeSb3 from '../../src/packager/minify/sb3';
|
||||
|
||||
const clone = (obj) => JSON.parse(JSON.stringify(obj));
|
||||
|
||||
const emptyTarget = () => ({
|
||||
name: '',
|
||||
blocks: {},
|
||||
comments: {},
|
||||
variables: {},
|
||||
lists: {},
|
||||
broadcasts: {},
|
||||
});
|
||||
|
||||
test('does not throw if project does not have monitors', () => {
|
||||
const data = {
|
||||
targets: [],
|
||||
@@ -9,3 +18,33 @@ test('does not throw if project does not have monitors', () => {
|
||||
};
|
||||
optimizeSb3(clone(data));
|
||||
});
|
||||
|
||||
test('removes comments', () => {
|
||||
const data = {
|
||||
targets: [
|
||||
{
|
||||
...emptyTarget(),
|
||||
comments: {
|
||||
"a": {
|
||||
"text": "wregoiujji"
|
||||
},
|
||||
"b": {
|
||||
"text": "Configuration for https://turbowarp.org/\nDo not edit by hand\n{\"framerate\":30,\"runtimeOptions\":{\"maxClones\":300,\"miscLimits\":false,\"fencing\":true},\"interpolation\":false,\"turbo\":false,\"hq\":true} // _twconfig_"
|
||||
},
|
||||
"c": {
|
||||
"text": " // _gamepad_"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
const optimized = optimizeSb3(clone(data));
|
||||
expect(Object.values(optimized.targets[0].comments)).toEqual([
|
||||
{
|
||||
"text": "Configuration for https://turbowarp.org/\nDo not edit by hand\n{\"framerate\":30,\"runtimeOptions\":{\"maxClones\":300,\"miscLimits\":false,\"fencing\":true},\"interpolation\":false,\"turbo\":false,\"hq\":true} // _twconfig_"
|
||||
},
|
||||
{
|
||||
text: " // _gamepad_"
|
||||
}
|
||||
]);
|
||||
});
|
||||
Reference in new issue
Block a user