Skip to content

Commit 8ef3134

Browse files
committed
remove unnessary data from attachment XML to save bandwidth
1 parent 36f5b47 commit 8ef3134

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎src/addons/addons/ai-integration/attachment.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ export default class Attachment {
1414
}
1515
Attachment._blockly = blockly;
1616
}
17+
static getAttachmentReady(attachment) {
18+
if (attachment && attachment.nodeType === Node.ELEMENT_NODE) {
19+
attachment = Attachment._blockly.Xml.domToText(attachment);
20+
}
21+
// Remove unnecessary attributes and whitespace
22+
return attachment
23+
.replace(/x="[^"]+"|y="[^"]+"|id="[^"]+"/g, "")
24+
.replace(/\s{2,}/g, " ")
25+
.replace(" >", ">");
26+
}
1727

1828
attachment(attachment, spriteName = "Sprite1") {
1929
if (Attachment._blockly === null) {

‎src/addons/addons/ai-integration/userscript.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ function popupFunctionality() {
408408

409409
var attachmentCode = "";
410410
if(attachmentType == "1"){
411-
attachmentCode = "\nAttached Code:" + Blockly.Xml.domToText(attachment.GetAttachment(Blockly.Xml.workspaceToDom(mainWorkspace)));
411+
attachmentCode = "\nAttached Code:" + Attachment.getAttachmentReady(attachment.GetAttachment(Blockly.Xml.workspaceToDom(mainWorkspace)));
412412
}else if(attachmentType == "2"){
413-
attachmentCode = "\nAttached Code:" + Blockly.Xml.domToText(Blockly.Xml.workspaceToDom(mainWorkspace));
413+
attachmentCode = "\nAttached Code:" + Attachment.getAttachmentReady(Blockly.Xml.workspaceToDom(mainWorkspace));
414414
}else if(attachmentType == "3"){
415-
attachmentCode = "\nAttached Code:" + helpers.returnEntireProjectAsXML(Gaddon);
415+
attachmentCode = "\nAttached Code:" + Attachment.getAttachmentReady(helpers.returnEntireProjectAsXML(Gaddon));
416416
}
417417
const messageContents = input.value + attachmentCode + "\n\n\nContext:\nSprite Customes: " + customNames + "\nSprite Sounds: " + soundNames + "\nAll Sprites Names: " + allSpriteNames + "\nCurrent Sprite Name:" + vm.runtime.getEditingTarget().sprite.name;
418418
input.value = '';
@@ -943,7 +943,6 @@ export default async function ({ addon, console }) {
943943
});
944944

945945
window.addEventListener('ai-button-clicked', function () {
946-
//HANDLE ATTACHMENT
947946
createBasePopup(2, "");
948947
});
949948
}

0 commit comments

Comments
 (0)