From 064ee0cf4829f6cddc558942ca7636a98cb43aeb Mon Sep 17 00:00:00 2001 From: Yueyu Date: Thu, 27 May 2021 05:18:02 +0800 Subject: [PATCH 1/5] fix story saving for PBS --- src/editor/ScratchJr.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/editor/ScratchJr.js b/src/editor/ScratchJr.js index be266ff..780d521 100644 --- a/src/editor/ScratchJr.js +++ b/src/editor/ScratchJr.js @@ -128,6 +128,10 @@ export default class ScratchJr { return currentProject; } + static set currentProject (md5) { + currentProject = md5; + } + static get editmode () { return editmode; } From cc7b6ee88381f8f063de627bafcf79286b8d289d Mon Sep 17 00:00:00 2001 From: Yueyu Date: Fri, 28 May 2021 08:26:37 +0800 Subject: [PATCH 2/5] don't save project if project not changed --- src/editor/ScratchJr.js | 4 ++++ src/editor/ui/UI.js | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/editor/ScratchJr.js b/src/editor/ScratchJr.js index 780d521..dda1e3c 100644 --- a/src/editor/ScratchJr.js +++ b/src/editor/ScratchJr.js @@ -83,6 +83,10 @@ export default class ScratchJr { changed = newChanged; } + static get changed () { + return changed; + } + static set storyStarted (newStoryStarted) { storyStarted = newStoryStarted; } diff --git a/src/editor/ui/UI.js b/src/editor/ui/UI.js index 8ddf358..67e159f 100644 --- a/src/editor/ui/UI.js +++ b/src/editor/ui/UI.js @@ -336,7 +336,7 @@ export default class UI { static handleTextFieldSave (dontHide) { // Handle story-starter mode project - if (ScratchJr.isEditable() && ScratchJr.editmode == 'storyStarter' && !Project.error) { + if (ScratchJr.isEditable() && ScratchJr.editmode == 'storyStarter' && !Project.error && ScratchJr.changed) { OS.analyticsEvent('samples', 'story_starter_edited', Project.metadata.name); // Get the new project name var sampleName = Localization.localize('SAMPLE_' + Project.metadata.name); @@ -370,7 +370,6 @@ export default class UI { ScratchJr.storyStart('UI.handleTextFieldSave'); } Project.metadata.name = pname; - ScratchJr.changed = true; OS.setfield(OS.database, Project.metadata.id, 'name', pname); if (!dontHide) { ScratchAudio.sndFX('exittap.wav'); @@ -389,6 +388,9 @@ export default class UI { return; } + var canShare = ScratchJr.editmode != 'storyStarter' || ScratchJr.changed; + gn('infoboxParentsSectionButton').style.display = canShare ? 'block' : 'none'; + // Prevent button from thrashing setTimeout(function () { okclicky.ontouchend = UI.hideInfoBox; From fa6bf47b35b57d6a52fdb6ce9678b4a54a345b5a Mon Sep 17 00:00:00 2001 From: Yueyu Date: Fri, 28 May 2021 08:26:53 +0800 Subject: [PATCH 3/5] lint --- src/editor/engine/Sprite.js | 2 +- src/editor/ui/Library.js | 2 +- src/lobby/Home.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/editor/engine/Sprite.js b/src/editor/engine/Sprite.js index 68198eb..72c98c4 100755 --- a/src/editor/engine/Sprite.js +++ b/src/editor/engine/Sprite.js @@ -109,7 +109,7 @@ export default class Sprite { var img = document.createElement('img'); img.ondragstart = function () { return false; - } + }; img.src = dataurl; this.img = img; // Make a copy that is not affected by zoom transformation diff --git a/src/editor/ui/Library.js b/src/editor/ui/Library.js index 34ad766..5d42f75 100644 --- a/src/editor/ui/Library.js +++ b/src/editor/ui/Library.js @@ -200,7 +200,7 @@ export default class Library { img.style.height = (data.height * scale) + 'px'; img.ondragstart = function () { return false; - } + }; if (data.altmd5) { IO.getAsset(data.altmd5, drawMe); } diff --git a/src/lobby/Home.js b/src/lobby/Home.js index 36b290e..5d1577a 100755 --- a/src/lobby/Home.js +++ b/src/lobby/Home.js @@ -302,7 +302,7 @@ export default class Home { } img.ondragstart = function () { return false; - } + }; function drawMe (url) { img.src = url; } From 5c0d80f04826c181a18f951053c08f8d0924bdfe Mon Sep 17 00:00:00 2001 From: Yueyu Date: Sat, 31 Jul 2021 09:27:18 +0800 Subject: [PATCH 4/5] localize sample name in storyStarter mode --- src/editor/ScratchJr.js | 2 +- src/editor/ui/UI.js | 8 ++++++-- src/lobby/Samples.js | 5 +---- src/utils/Localization.js | 10 ++++++++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/editor/ScratchJr.js b/src/editor/ScratchJr.js index dda1e3c..eb02bec 100644 --- a/src/editor/ScratchJr.js +++ b/src/editor/ScratchJr.js @@ -355,7 +355,7 @@ export default class ScratchJr { if (ScratchJr.isEditable() && editmode == 'storyStarter' && storyStarted && !Project.error) { OS.analyticsEvent('samples', 'story_starter_edited', Project.metadata.name); // Localize sample project names - var sampleName = Localization.localize('SAMPLE_' + Project.metadata.name); + var sampleName = Localization.localizeSampleName(Project.metadata.name); // Get the new project name IO.uniqueProjectName({ name: sampleName diff --git a/src/editor/ui/UI.js b/src/editor/ui/UI.js index 67e159f..271c2d4 100644 --- a/src/editor/ui/UI.js +++ b/src/editor/ui/UI.js @@ -339,7 +339,7 @@ export default class UI { if (ScratchJr.isEditable() && ScratchJr.editmode == 'storyStarter' && !Project.error && ScratchJr.changed) { OS.analyticsEvent('samples', 'story_starter_edited', Project.metadata.name); // Get the new project name - var sampleName = Localization.localize('SAMPLE_' + Project.metadata.name); + var sampleName = Localization.localizeSampleName(Project.metadata.name); IO.uniqueProjectName({ name: sampleName }, function (jsonData) { @@ -423,7 +423,11 @@ export default class UI { } if (ScratchJr.isEditable()) { - (document.forms.projectname.myproject).value = Project.metadata.name; + var name = Project.metadata.name; + if (ScratchJr.editmode == 'storyStarter') { + name = Localization.localizeSampleName(name); + } + (document.forms.projectname.myproject).value = name; } else { gn('pname').textContent = Project.metadata.name; } diff --git a/src/lobby/Samples.js b/src/lobby/Samples.js index 82ae417..b4ab232 100644 --- a/src/lobby/Samples.js +++ b/src/lobby/Samples.js @@ -52,10 +52,7 @@ export default class Samples { var name = mt.childNodes[1]; // Localize sample project names - var sampleName = data.name; - sampleName = Localization.localize('SAMPLE_' + sampleName); - - name.textContent = sampleName; + name.textContent = Localization.localizeSampleName(data.name); var cnv = mt.childNodes[0].childNodes[1]; Samples.insertThumbnail(cnv, data.thumbnail); mt.onclick = function (evt) { diff --git a/src/utils/Localization.js b/src/utils/Localization.js index 6e95b81..894425f 100644 --- a/src/utils/Localization.js +++ b/src/utils/Localization.js @@ -112,6 +112,16 @@ export default class Localization { return 'String missing: ' + key; } + static localizeSampleName (key) { + var name = Localization.localizeOptional('SAMPLE_' + key); + // If the localized name is still started with 'SAMPLE_', + // it is not a preset name. + if (name.startsWith('SAMPLE_')) { + return key; + } + return name; + } + // Translate a particular message given the message key and info; // if key not found, assume it's just a raw text string without a translation, // and return that From 5ae6b2b7d154c0ba8d0266bad9426f9f80a6c54d Mon Sep 17 00:00:00 2001 From: Yueyu Date: Sat, 31 Jul 2021 09:46:40 +0800 Subject: [PATCH 5/5] only save the sample project if it's changed --- src/editor/ScratchJr.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/editor/ScratchJr.js b/src/editor/ScratchJr.js index eb02bec..bc9f559 100644 --- a/src/editor/ScratchJr.js +++ b/src/editor/ScratchJr.js @@ -352,7 +352,8 @@ export default class ScratchJr { } static saveProject (e, onDone) { - if (ScratchJr.isEditable() && editmode == 'storyStarter' && storyStarted && !Project.error) { + // Only save the sample project if it's changed. + if (ScratchJr.isEditable() && editmode == 'storyStarter' && storyStarted && !Project.error && changed) { OS.analyticsEvent('samples', 'story_starter_edited', Project.metadata.name); // Localize sample project names var sampleName = Localization.localizeSampleName(Project.metadata.name);