kopia lustrzana https://github.com/backface/turtlestitch
remember the sprite last edited when saving a project
rodzic
298f559775
commit
5816f1fbfe
|
@ -3,9 +3,14 @@
|
|||
## in development for v7:
|
||||
* **New Features:**
|
||||
* Scenes
|
||||
* **Notable Changes:**
|
||||
* saved projects remember the last edited srpite
|
||||
* **Notable Fixes:**
|
||||
* made scrollbars in the wardrobe and jukebox more responsive
|
||||
|
||||
### 2021-04-16
|
||||
* scenes, store, gui: remember last edited sprite in a scene / project
|
||||
|
||||
### 2021-04-14
|
||||
* scenes: new Project class
|
||||
* store: sceneified projects
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
<script src="src/blocks.js?version=2021-04-12"></script>
|
||||
<script src="src/threads.js?version=2021-04-12"></script>
|
||||
<script src="src/objects.js?version=2021-04-12"></script>
|
||||
<script src="src/scenes.js?version=2021-04-14"></script>
|
||||
<script src="src/gui.js?version=2021-04-14"></script>
|
||||
<script src="src/scenes.js?version=2021-04-16"></script>
|
||||
<script src="src/gui.js?version=2021-04-16"></script>
|
||||
<script src="src/paint.js?version=2021-03-17"></script>
|
||||
<script src="src/lists.js?version=2021-03-15"></script>
|
||||
<script src="src/byob.js?version=2021-03-05"></script>
|
||||
|
@ -21,7 +21,7 @@
|
|||
<script src="src/video.js?version=2019-06-27"></script>
|
||||
<script src="src/maps.js?version=2020-03-25"></script>
|
||||
<script src="src/xml.js?version=2020-04-27"></script>
|
||||
<script src="src/store.js?version=2021-04-14"></script>
|
||||
<script src="src/store.js?version=2021-04-16"></script>
|
||||
<script src="src/locale.js?version=2021-03-15"></script>
|
||||
<script src="src/cloud.js?version=2021-02-04"></script>
|
||||
<script src="src/api.js?version=2021-01-25"></script>
|
||||
|
|
14
src/gui.js
14
src/gui.js
|
@ -83,7 +83,7 @@ Animation, BoxMorph, BlockEditorMorph, BlockDialogMorph, Note, ZERO, BLACK*/
|
|||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.gui = '2021-April-14';
|
||||
modules.gui = '2021-April-16';
|
||||
|
||||
// Declarations
|
||||
|
||||
|
@ -246,7 +246,7 @@ IDE_Morph.prototype.init = function (isAutoFill) {
|
|||
// editor
|
||||
this.globalVariables = this.scene.globalVariables;
|
||||
this.currentSprite = this.scene.addDefaultSprite();
|
||||
this.sprites = new List([this.currentSprite]);
|
||||
this.sprites = this.scene.sprites;
|
||||
this.projectName = this.scene.name;
|
||||
this.projectNotes = this.scene.notes;
|
||||
this.currentCategory = 'motion';
|
||||
|
@ -2543,6 +2543,7 @@ IDE_Morph.prototype.selectSprite = function (sprite) {
|
|||
this.currentSprite.scripts.focus.stopEditing();
|
||||
}
|
||||
this.currentSprite = sprite;
|
||||
this.scene.currentSprite = sprite;
|
||||
this.createPalette();
|
||||
this.createSpriteBar();
|
||||
this.createSpriteEditor();
|
||||
|
@ -5398,7 +5399,6 @@ IDE_Morph.prototype.openScene = function (scene) {
|
|||
};
|
||||
|
||||
IDE_Morph.prototype.switchToScene = function (scene, refreshAlbum) {
|
||||
var sprites = [];
|
||||
if (!scene || !scene.stage) {
|
||||
return;
|
||||
}
|
||||
|
@ -5413,14 +5413,10 @@ IDE_Morph.prototype.switchToScene = function (scene, refreshAlbum) {
|
|||
this.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);
|
||||
this.sprites = scene.sprites;
|
||||
this.stage.pauseGenericHatBlocks();
|
||||
this.createCorral(!refreshAlbum); // keep scenes
|
||||
this.selectSprite(sprites[0] || this.stage);
|
||||
this.selectSprite(this.scene.currentSprite);
|
||||
this.fixLayout();
|
||||
this.corral.album.updateSelection();
|
||||
this.corral.album.contents.children.forEach(function (morph) {
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
|
||||
/*global modules, VariableFrame, StageMorph, SpriteMorph, Process, List*/
|
||||
|
||||
modules.scenes = '2021-April-14';
|
||||
modules.scenes = '2021-April-16';
|
||||
|
||||
|
||||
// Projecct /////////////////////////////////////////////////////////
|
||||
|
@ -85,6 +85,10 @@ function Scene(aStageMorph) {
|
|||
aStageMorph.globalVariables() : new VariableFrame();
|
||||
this.stage = aStageMorph || new StageMorph(this.globalVariables);
|
||||
|
||||
// cached IDE state
|
||||
this.sprites = new List();
|
||||
this.currentSprite = null;
|
||||
|
||||
// global settings (shared)
|
||||
this.hiddenPrimitives = {};
|
||||
this.codeMappings = {};
|
||||
|
@ -100,13 +104,33 @@ function Scene(aStageMorph) {
|
|||
this.enableHyperOps = true;
|
||||
|
||||
// for deserializing - do not persist
|
||||
this.sprites = {};
|
||||
this.spritesDict = {};
|
||||
this.targetStage = null;
|
||||
this.spriteIdx = null;
|
||||
|
||||
// for undeleting sprites - do not persist
|
||||
this.trash = [];
|
||||
}
|
||||
|
||||
Scene.prototype.initialize = function () {
|
||||
// initialize after deserializing
|
||||
// only to be called by store
|
||||
var objs = this.stage.children.filter(
|
||||
child => child instanceof SpriteMorph
|
||||
);
|
||||
objs.sort((x, y) => x.idx - y.idx);
|
||||
this.sprites = new List(objs);
|
||||
if (this.spriteIdx === null && this.sprites.length() > 0) {
|
||||
this.currentSprite = this.sprites.at(1);
|
||||
} else if (this.spriteIdx === 0) {
|
||||
this.currentSprite = this.stage;
|
||||
} else {
|
||||
this.currentSprite = this.sprites.at(this.spriteIdx) ||
|
||||
this.stage;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Scene.prototype.addDefaultSprite = function () {
|
||||
var sprite = new SpriteMorph(this.globalVariables);
|
||||
sprite.setPosition(
|
||||
|
@ -115,6 +139,8 @@ Scene.prototype.addDefaultSprite = function () {
|
|||
)
|
||||
);
|
||||
this.stage.add(sprite);
|
||||
this.sprites.add(sprite);
|
||||
this.currentSprite = sprite;
|
||||
return sprite;
|
||||
};
|
||||
|
||||
|
|
27
src/store.js
27
src/store.js
|
@ -60,7 +60,7 @@ SyntaxElementMorph, BooleanSlotMorph, normalizeCanvas, contains, Scene*/
|
|||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.store = '2021-April-14';
|
||||
modules.store = '2021-April-16';
|
||||
|
||||
|
||||
// XML_Serializer ///////////////////////////////////////////////////////
|
||||
|
@ -392,6 +392,9 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode, remixID) {
|
|||
if (model.stage.attributes.pan) {
|
||||
scene.stage.pan = +model.stage.attributes.pan;
|
||||
}
|
||||
if (model.stage.attributes.select) {
|
||||
scene.spriteIdx = +model.stage.attributes.select;
|
||||
}
|
||||
if (model.stage.attributes.penlog) {
|
||||
scene.enablePenLogging =
|
||||
(model.stage.attributes.penlog === 'true');
|
||||
|
@ -474,7 +477,7 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode, remixID) {
|
|||
/* Sprites */
|
||||
|
||||
model.sprites = model.stage.require('sprites');
|
||||
scene.sprites[scene.stage.name] = scene.stage;
|
||||
scene.spritesDict[scene.stage.name] = scene.stage;
|
||||
|
||||
model.sprites.childrenNamed('sprite').forEach(
|
||||
model => this.loadValue(model)
|
||||
|
@ -484,7 +487,7 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode, remixID) {
|
|||
this.scene.stage.children.forEach(sprite => {
|
||||
var exemplar, anchor;
|
||||
if (sprite.inheritanceInfo) { // only sprites can inherit
|
||||
exemplar = this.scene.sprites[
|
||||
exemplar = this.scene.spritesDict[
|
||||
sprite.inheritanceInfo.exemplar
|
||||
];
|
||||
if (exemplar) {
|
||||
|
@ -494,7 +497,7 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode, remixID) {
|
|||
sprite.updatePropagationCache();
|
||||
}
|
||||
if (sprite.nestingInfo) { // only sprites may have nesting info
|
||||
anchor = this.scene.sprites[sprite.nestingInfo.anchor];
|
||||
anchor = this.scene.spritesDict[sprite.nestingInfo.anchor];
|
||||
if (anchor) {
|
||||
anchor.attachPart(sprite);
|
||||
}
|
||||
|
@ -554,7 +557,7 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode, remixID) {
|
|||
target = Object.prototype.hasOwnProperty.call(
|
||||
model.attributes,
|
||||
'scope'
|
||||
) ? scene.sprites[model.attributes.scope] : null;
|
||||
) ? scene.spritesDict[model.attributes.scope] : null;
|
||||
|
||||
// determine whether the watcher is hidden, slightly
|
||||
// complicated to retain backward compatibility
|
||||
|
@ -623,7 +626,7 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode, remixID) {
|
|||
);
|
||||
|
||||
this.objects = {};
|
||||
return scene;
|
||||
return scene.initialize();
|
||||
};
|
||||
|
||||
SnapSerializer.prototype.loadBlocks = function (xmlString, targetStage) {
|
||||
|
@ -659,7 +662,7 @@ SnapSerializer.prototype.loadSprites = function (xmlString, ide) {
|
|||
|
||||
this.scene = new Scene(ide.stage);
|
||||
scene = this.scene;
|
||||
scene.sprites[scene.stage.name] = scene.stage;
|
||||
scene.spritesDict[scene.stage.name] = scene.stage;
|
||||
|
||||
model = this.parse(xmlString);
|
||||
if (+model.attributes.version > this.version) {
|
||||
|
@ -673,7 +676,7 @@ SnapSerializer.prototype.loadSprites = function (xmlString, ide) {
|
|||
}
|
||||
if (model.attributes.name) {
|
||||
sprite.name = ide.newSpriteName(model.attributes.name);
|
||||
scene.sprites[sprite.name] = sprite;
|
||||
scene.spritesDict[sprite.name] = sprite;
|
||||
}
|
||||
if (model.attributes.color) {
|
||||
sprite.color = this.loadColor(model.attributes.color);
|
||||
|
@ -707,7 +710,7 @@ SnapSerializer.prototype.loadSprites = function (xmlString, ide) {
|
|||
scene.stage.children.forEach(sprite => {
|
||||
var exemplar, anchor;
|
||||
if (sprite.inheritanceInfo) { // only sprites can inherit
|
||||
exemplar = scene.sprites[
|
||||
exemplar = scene.spritesDict[
|
||||
sprite.inheritanceInfo.exemplar
|
||||
];
|
||||
if (exemplar) {
|
||||
|
@ -715,7 +718,7 @@ SnapSerializer.prototype.loadSprites = function (xmlString, ide) {
|
|||
}
|
||||
}
|
||||
if (sprite.nestingInfo) { // only sprites may have nesting info
|
||||
anchor = scene.sprites[sprite.nestingInfo.anchor];
|
||||
anchor = scene.spritesDict[sprite.nestingInfo.anchor];
|
||||
if (anchor) {
|
||||
anchor.attachPart(sprite);
|
||||
}
|
||||
|
@ -1408,7 +1411,7 @@ SnapSerializer.prototype.loadValue = function (model, object) {
|
|||
}
|
||||
if (model.attributes.name) {
|
||||
v.name = model.attributes.name;
|
||||
this.scene.sprites[model.attributes.name] = v;
|
||||
this.scene.spritesDict[model.attributes.name] = v;
|
||||
}
|
||||
if (model.attributes.idx) {
|
||||
v.idx = +model.attributes.idx;
|
||||
|
@ -1672,6 +1675,7 @@ StageMorph.prototype.toXML = function (serializer) {
|
|||
'<thumbnail>$</thumbnail>' +
|
||||
'<stage name="@" width="@" height="@" ' +
|
||||
'costume="@" color="@,@,@,@" tempo="@" threadsafe="@" ' +
|
||||
'select="@" ' +
|
||||
'penlog="@" ' +
|
||||
'%' +
|
||||
'volume="@" ' +
|
||||
|
@ -1712,6 +1716,7 @@ StageMorph.prototype.toXML = function (serializer) {
|
|||
this.color.a,
|
||||
this.getTempo(),
|
||||
this.isThreadSafe,
|
||||
ide.sprites.asArray().indexOf(ide.currentSprite) + 1,
|
||||
this.enablePenLogging,
|
||||
this.instrument ?
|
||||
' instrument="' + parseInt(this.instrument) + '" ' : '',
|
||||
|
|
Ładowanie…
Reference in New Issue