kopia lustrzana https://github.com/backface/turtlestitch
refactor loading a project into the IDE
rodzic
1e54bcd4e7
commit
6cc4bf7193
|
@ -2,6 +2,9 @@
|
|||
|
||||
## in development:
|
||||
|
||||
### 2021-03-11
|
||||
* gui, store: refactor loading a project into the IDE
|
||||
|
||||
### 2021-03-09
|
||||
* new dev version
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Snap! 6.7.2 - dev - Build Your Own Blocks</title>
|
||||
<title>Snap! 7 - dev - Build Your Own Blocks</title>
|
||||
<link rel="icon" href="src/favicon.ico">
|
||||
<script src="src/morphic.js?version=2021-02-10"></script>
|
||||
<script src="src/symbols.js?version=2021-03-03"></script>
|
||||
|
|
60
src/gui.js
60
src/gui.js
|
@ -78,7 +78,7 @@ Animation, BoxMorph, BlockEditorMorph, BlockDialogMorph, Note, ZERO, BLACK*/
|
|||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.gui = '2021-March-09';
|
||||
modules.gui = '2021-March-11';
|
||||
|
||||
// Declarations
|
||||
|
||||
|
@ -4353,7 +4353,7 @@ IDE_Morph.prototype.aboutSnap = function () {
|
|||
module, btn1, btn2, btn3, btn4, licenseBtn, translatorsBtn,
|
||||
world = this.world();
|
||||
|
||||
aboutTxt = 'Snap! 6.7.2 - dev -\nBuild Your Own Blocks\n\n'
|
||||
aboutTxt = 'Snap! 7 - dev -\nBuild Your Own Blocks\n\n'
|
||||
+ 'Copyright \u24B8 2008-2021 Jens M\u00F6nig and '
|
||||
+ 'Brian Harvey\n'
|
||||
+ 'jens@moenig.org, bh@cs.berkeley.edu\n\n'
|
||||
|
@ -5102,17 +5102,15 @@ IDE_Morph.prototype.rawOpenProjectString = function (str) {
|
|||
this.hasUnsavedEdits = false;
|
||||
if (Process.prototype.isCatchingErrors) {
|
||||
try {
|
||||
this.serializer.openProject(
|
||||
this.serializer.load(str, this),
|
||||
this
|
||||
this.switchToScene(
|
||||
this.serializer.load(str, this)
|
||||
);
|
||||
} catch (err) {
|
||||
this.showMessage('Load failed: ' + err);
|
||||
}
|
||||
} else {
|
||||
this.serializer.openProject(
|
||||
this.serializer.load(str, this),
|
||||
this
|
||||
this.switchToScene(
|
||||
this.serializer.load(str, this)
|
||||
);
|
||||
}
|
||||
this.stopFastTracking();
|
||||
|
@ -5146,13 +5144,12 @@ IDE_Morph.prototype.rawOpenCloudDataString = function (str) {
|
|||
try {
|
||||
model = this.serializer.parse(str);
|
||||
this.serializer.loadMediaModel(model.childNamed('media'));
|
||||
this.serializer.openProject(
|
||||
this.switchToScene(
|
||||
this.serializer.loadProjectModel(
|
||||
model.childNamed('project'),
|
||||
this,
|
||||
model.attributes.remixID
|
||||
),
|
||||
this
|
||||
)
|
||||
);
|
||||
} catch (err) {
|
||||
this.showMessage('Load failed: ' + err);
|
||||
|
@ -5160,13 +5157,12 @@ IDE_Morph.prototype.rawOpenCloudDataString = function (str) {
|
|||
} else {
|
||||
model = this.serializer.parse(str);
|
||||
this.serializer.loadMediaModel(model.childNamed('media'));
|
||||
this.serializer.openProject(
|
||||
this.switchToScene(
|
||||
this.serializer.loadProjectModel(
|
||||
model.childNamed('project'),
|
||||
this,
|
||||
model.attributes.remixID
|
||||
),
|
||||
this
|
||||
)
|
||||
);
|
||||
}
|
||||
this.stopFastTracking();
|
||||
|
@ -5359,6 +5355,42 @@ IDE_Morph.prototype.openProject = function (name) {
|
|||
}
|
||||
};
|
||||
|
||||
IDE_Morph.prototype.switchToScene = function (scene) {
|
||||
var stage = this.stage,
|
||||
sprites = [],
|
||||
sprite;
|
||||
if (!scene || !scene.stage) {
|
||||
return;
|
||||
}
|
||||
this.siblings().forEach(morph =>
|
||||
morph.destroy()
|
||||
);
|
||||
this.projectName = scene.name;
|
||||
this.projectNotes = scene.notes || '';
|
||||
if (this.globalVariables) {
|
||||
this.globalVariables = scene.globalVariables;
|
||||
}
|
||||
if (stage) {
|
||||
stage.destroy();
|
||||
}
|
||||
this.add(scene.stage);
|
||||
this.stage = scene.stage;
|
||||
sprites = this.stage.children.filter(
|
||||
child => child instanceof SpriteMorph
|
||||
);
|
||||
sprites.sort((x, y) => x.idx - y.idx);
|
||||
|
||||
this.sprites = new List(sprites);
|
||||
sprite = sprites[0] || scene.stage;
|
||||
|
||||
this.stage.fixLayout();
|
||||
this.stage.pauseGenericHatBlocks();
|
||||
this.createCorral();
|
||||
this.selectSprite(sprite);
|
||||
this.fixLayout();
|
||||
this.world().keyboardFocus = this.stage;
|
||||
};
|
||||
|
||||
IDE_Morph.prototype.setURL = function (str) {
|
||||
// Set the URL to a project's XML contents
|
||||
location.hash = this.projectsInURLs ? str : '';
|
||||
|
|
55
src/store.js
55
src/store.js
|
@ -49,19 +49,18 @@
|
|||
|
||||
*/
|
||||
|
||||
/*global modules, XML_Element, VariableFrame, StageMorph, SpriteMorph,
|
||||
WatcherMorph, Point, CustomBlockDefinition, Context, ReporterBlockMorph,
|
||||
/*global modules, XML_Element, VariableFrame, StageMorph, SpriteMorph, console,
|
||||
WatcherMorph, Point, CustomBlockDefinition, Context, ReporterBlockMorph, Sound,
|
||||
CommandBlockMorph, detect, CustomCommandBlockMorph, CustomReporterBlockMorph,
|
||||
Color, List, newCanvas, Costume, Sound, Audio, IDE_Morph, ScriptsMorph,
|
||||
Color, List, newCanvas, Costume, Audio, IDE_Morph, ScriptsMorph, ArgLabelMorph,
|
||||
BlockMorph, ArgMorph, InputSlotMorph, TemplateSlotMorph, CommandSlotMorph,
|
||||
FunctionSlotMorph, MultiArgMorph, ColorSlotMorph, nop, CommentMorph, isNil,
|
||||
localize, sizeOf, ArgLabelMorph, SVG_Costume, MorphicPreferences, Process,
|
||||
SyntaxElementMorph, Variable, isSnapObject, console, BooleanSlotMorph,
|
||||
normalizeCanvas, contains*/
|
||||
localize, SVG_Costume, MorphicPreferences, Process, isSnapObject, Variable,
|
||||
SyntaxElementMorph, BooleanSlotMorph, normalizeCanvas, contains*/
|
||||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.store = '2021-March-09';
|
||||
modules.store = '2021-March-11';
|
||||
|
||||
|
||||
// XML_Serializer ///////////////////////////////////////////////////////
|
||||
|
@ -1617,48 +1616,6 @@ SnapSerializer.prototype.loadColor = function (colorString) {
|
|||
);
|
||||
};
|
||||
|
||||
SnapSerializer.prototype.openProject = function (project, ide) {
|
||||
var stage = ide.stage,
|
||||
sprites = [],
|
||||
sprite;
|
||||
if (!project || !project.stage) {
|
||||
return;
|
||||
}
|
||||
ide.siblings().forEach(morph =>
|
||||
morph.destroy()
|
||||
);
|
||||
ide.projectName = project.name;
|
||||
ide.projectNotes = project.notes || '';
|
||||
if (ide.globalVariables) {
|
||||
ide.globalVariables = project.globalVariables;
|
||||
}
|
||||
if (stage) {
|
||||
stage.destroy();
|
||||
}
|
||||
ide.add(project.stage);
|
||||
ide.stage = project.stage;
|
||||
sprites = ide.stage.children.filter(
|
||||
child => child instanceof SpriteMorph
|
||||
);
|
||||
sprites.sort((x, y) => x.idx - y.idx);
|
||||
|
||||
ide.sprites = new List(sprites);
|
||||
sprite = sprites[0] || project.stage;
|
||||
|
||||
if (sizeOf(this.mediaDict) > 0) {
|
||||
ide.hasChangedMedia = false;
|
||||
this.mediaDict = {};
|
||||
} else {
|
||||
ide.hasChangedMedia = true;
|
||||
}
|
||||
project.stage.fixLayout();
|
||||
project.stage.pauseGenericHatBlocks();
|
||||
ide.createCorral();
|
||||
ide.selectSprite(sprite);
|
||||
ide.fixLayout();
|
||||
ide.world().keyboardFocus = project.stage;
|
||||
};
|
||||
|
||||
// SnapSerializer XML-representation of objects:
|
||||
|
||||
// Generics
|
||||
|
|
Ładowanie…
Reference in New Issue