mirror of
https://github.com/scratchfoundation/scratchjr.git
synced 2024-11-28 18:15:37 -05:00
Merge pull request #428 from yueyuzhao/fix-story-save
fix story saving for PBS
This commit is contained in:
commit
3cffccf182
4 changed files with 32 additions and 10 deletions
|
@ -83,6 +83,10 @@ export default class ScratchJr {
|
|||
changed = newChanged;
|
||||
}
|
||||
|
||||
static get changed () {
|
||||
return changed;
|
||||
}
|
||||
|
||||
static set storyStarted (newStoryStarted) {
|
||||
storyStarted = newStoryStarted;
|
||||
}
|
||||
|
@ -128,6 +132,10 @@ export default class ScratchJr {
|
|||
return currentProject;
|
||||
}
|
||||
|
||||
static set currentProject (md5) {
|
||||
currentProject = md5;
|
||||
}
|
||||
|
||||
static get editmode () {
|
||||
return editmode;
|
||||
}
|
||||
|
@ -342,10 +350,11 @@ 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.localize('SAMPLE_' + Project.metadata.name);
|
||||
var sampleName = Localization.localizeSampleName(Project.metadata.name);
|
||||
// Get the new project name
|
||||
IO.uniqueProjectName({
|
||||
name: sampleName
|
||||
|
|
|
@ -335,10 +335,10 @@ 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);
|
||||
var sampleName = Localization.localizeSampleName(Project.metadata.name);
|
||||
IO.uniqueProjectName({
|
||||
name: sampleName
|
||||
}, function (jsonData) {
|
||||
|
@ -369,7 +369,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');
|
||||
|
@ -388,6 +387,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.onclick = UI.hideInfoBox;
|
||||
|
@ -420,7 +422,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;
|
||||
}
|
||||
|
|
|
@ -53,10 +53,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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue