From f4aa21a2a6c911758a9d2dae7497a6da2a5545a6 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Fri, 19 Mar 2021 18:01:46 +0100 Subject: [PATCH] capture global settings in scenes --- HISTORY.md | 3 +++ src/gui.js | 17 +++-------------- src/scenes.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/store.js | 20 ++++++++++---------- 4 files changed, 58 insertions(+), 26 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 14cfbbdc..230b0a85 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,9 @@ ## in development: +### 2021-03-19 +* gui, store, scenes: capture global settings in scenes + ## 6.7.3 * **Notable Changes:** * hyperized "key _ pressed?" predicate diff --git a/src/gui.js b/src/gui.js index 03250142..b1c32a29 100644 --- a/src/gui.js +++ b/src/gui.js @@ -5316,6 +5316,7 @@ IDE_Morph.prototype.switchToScene = function (scene) { this.siblings().forEach(morph => morph.destroy() ); + this.scene.captureGlobalSettings(); this.scene = scene; this.projectName = scene.name; this.projectNotes = scene.notes || ''; @@ -5332,21 +5333,9 @@ IDE_Morph.prototype.switchToScene = function (scene) { this.createCorral(); this.selectSprite(sprites[0] || this.stage); this.fixLayout(); - - // +++ to do: de-globablize settings: - StageMorph.prototype.hiddenPrimitives = {}; - StageMorph.prototype.codeMappings = {}; - StageMorph.prototype.codeHeaders = {}; - StageMorph.prototype.enableCodeMapping = false; - StageMorph.prototype.enableInheritance = true; - StageMorph.prototype.enableSublistIDs = false; - StageMorph.prototype.enablePenLogging = false; - SpriteMorph.prototype.useFlatLineEnds = false; - Process.prototype.enableLiveCoding = false; - Process.prototype.enableHyperOps = true; + scene.applyGlobalSettings(); this.hasUnsavedEdits = false; - this.trash = []; - + this.trash = []; // +++ sceneify this.world().keyboardFocus = this.stage; }; diff --git a/src/scenes.js b/src/scenes.js index 78ac0bcf..01e90b83 100644 --- a/src/scenes.js +++ b/src/scenes.js @@ -47,9 +47,9 @@ // Global stuff //////////////////////////////////////////////////////// -/*global modules, VariableFrame, StageMorph, SpriteMorph*/ +/*global modules, VariableFrame, StageMorph, SpriteMorph, Process*/ -modules.scenes = '2021-March-18'; +modules.scenes = '2021-March-19'; // Scene ///////////////////////////////////////////////////////// @@ -67,6 +67,20 @@ function Scene(aStageMorph) { aStageMorph.globalVariables() : new VariableFrame(); this.stage = aStageMorph || new StageMorph(this.globalVariables); + // global settings (shared) + this.hiddenPrimitives = {}; + this.codeMappings = {}; + this.codeHeaders = {}; + + // global settings (copied) + this.enableCodeMapping = false; + this.enableInheritance = true; + this.enableSublistIDs = false; + this.enablePenLogging = false; + this.useFlatLineEnds = false; + this.enableLiveCoding = false; + this.enableHyperOps = true; + // for deserializing - do not persist this.sprites = {}; this.targetStage = null; @@ -82,3 +96,29 @@ Scene.prototype.addDefaultSprite = function () { this.stage.add(sprite); return sprite; }; + +Scene.prototype.captureGlobalSettings = function () { + this.hiddenPrimitives = StageMorph.prototype.hiddenPrimitives; + this.codeMappings = StageMorph.prototype.codeMappings; + this.codeHeaders = StageMorph.prototype.codeHeaders; + this.enableCodeMapping = StageMorph.prototype.enableCodeMapping; + this.enableInheritance = StageMorph.prototype.enableInheritance; + this.enableSublistIDs = StageMorph.prototype.enableSublistIDs; + this.enablePenLogging = StageMorph.prototype.enablePenLogging; + this.useFlatLineEnds = SpriteMorph.prototype.useFlatLineEnds; + this.enableLiveCoding = Process.prototype.enableLiveCoding; + this.enableHyperOps = Process.prototype.enableHyperOps; +}; + +Scene.prototype.applyGlobalSettings = function () { + StageMorph.prototype.hiddenPrimitives = this.hiddenPrimitives; + StageMorph.prototype.codeMappings = this.codeMappings; + StageMorph.prototype.codeHeaders = this.codeHeaders; + StageMorph.prototype.enableCodeMapping = this.enableCodeMapping; + StageMorph.prototype.enableInheritance = this.enableInheritance; + StageMorph.prototype.enableSublistIDs = this.enableSublistIDs; + StageMorph.prototype.enablePenLogging = this.enablePenLogging; + SpriteMorph.prototype.useFlatLineEnds = this.useFlatLineEnds; + Process.prototype.enableLiveCoding = this.enableLiveCoding; + Process.prototype.enableHyperOps = this.enableHyperOps; +}; diff --git a/src/store.js b/src/store.js index a8b806cd..feb53b38 100644 --- a/src/store.js +++ b/src/store.js @@ -60,7 +60,7 @@ SyntaxElementMorph, BooleanSlotMorph, normalizeCanvas, contains, Scene*/ // Global stuff //////////////////////////////////////////////////////// -modules.store = '2021-March-17'; +modules.store = '2021-March-19'; // XML_Serializer /////////////////////////////////////////////////////// @@ -393,7 +393,7 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode, remixID) { project.stage.pan = +model.stage.attributes.pan; } if (model.stage.attributes.penlog) { - StageMorph.prototype.enablePenLogging = + project.enablePenLogging = (model.stage.attributes.penlog === 'true'); } @@ -420,19 +420,19 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode, remixID) { Math.max(+model.stage.attributes.height, 180); } project.stage.setExtent(project.stage.dimensions); - SpriteMorph.prototype.useFlatLineEnds = + project.useFlatLineEnds = model.stage.attributes.lines === 'flat'; BooleanSlotMorph.prototype.isTernary = model.stage.attributes.ternary !== 'false'; - Process.prototype.enableHyperOps = + project.enableHyperOps = model.stage.attributes.hyperops !== 'false'; project.stage.isThreadSafe = model.stage.attributes.threadsafe === 'true'; - StageMorph.prototype.enableCodeMapping = + project.enableCodeMapping = model.stage.attributes.codify === 'true'; - StageMorph.prototype.enableInheritance = + project.enableInheritance = model.stage.attributes.inheritance !== 'false'; - StageMorph.prototype.enableSublistIDs = + project.enableSublistIDs = model.stage.attributes.sublistIDs === 'true'; model.hiddenPrimitives = model.project.childNamed('hidden'); @@ -440,7 +440,7 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode, remixID) { model.hiddenPrimitives.contents.split(' ').forEach( sel => { if (sel) { - StageMorph.prototype.hiddenPrimitives[sel] = true; + project.hiddenPrimitives[sel] = true; } } ); @@ -449,14 +449,14 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode, remixID) { model.codeHeaders = model.project.childNamed('headers'); if (model.codeHeaders) { model.codeHeaders.children.forEach( - xml => StageMorph.prototype.codeHeaders[xml.tag] = xml.contents + xml => project.codeHeaders[xml.tag] = xml.contents ); } model.codeMappings = model.project.childNamed('code'); if (model.codeMappings) { model.codeMappings.children.forEach( - xml => StageMorph.prototype.codeMappings[xml.tag] = xml.contents + xml => project.codeMappings[xml.tag] = xml.contents ); }