preserve custom block instances’ block var values when editing their definition

dev
Jens Mönig 2016-01-17 23:44:30 +01:00
rodzic 71f4ca475a
commit 8001845706
2 zmienionych plików z 15 dodań i 6 usunięć

16
byob.js
Wyświetl plik

@ -104,11 +104,11 @@ contains, InputSlotMorph, ToggleButtonMorph, IDE_Morph, MenuMorph, copy,
ToggleElementMorph, Morph, fontHeight, StageMorph, SyntaxElementMorph, ToggleElementMorph, Morph, fontHeight, StageMorph, SyntaxElementMorph,
SnapSerializer, CommentMorph, localize, CSlotMorph, SpeechBubbleMorph, SnapSerializer, CommentMorph, localize, CSlotMorph, SpeechBubbleMorph,
MorphicPreferences, SymbolMorph, isNil, CursorMorph, VariableFrame, MorphicPreferences, SymbolMorph, isNil, CursorMorph, VariableFrame,
WatcherMorph*/ WatcherMorph, Variable*/
// Global stuff //////////////////////////////////////////////////////// // Global stuff ////////////////////////////////////////////////////////
modules.byob = '2016-January-11'; modules.byob = '2016-January-17';
// Declarations // Declarations
@ -420,11 +420,15 @@ CustomCommandBlockMorph.prototype.init = function (definition, isProto) {
} }
}; };
CustomCommandBlockMorph.prototype.initializeVariables = function () { CustomCommandBlockMorph.prototype.initializeVariables = function (oldVars) {
var myself = this; var myself = this;
this.variables = new VariableFrame(); this.variables = new VariableFrame();
this.definition.variableNames.forEach(function (name) { this.definition.variableNames.forEach(function (name) {
myself.variables.addVar(name); var v = oldVars ? oldVars[name] : null;
myself.variables.addVar(
name,
v instanceof Variable ? v.value : null
);
}); });
}; };
@ -463,8 +467,8 @@ CustomCommandBlockMorph.prototype.refresh = function (silently) {
}); });
// initialize block vars // initialize block vars
// to do: preserve values of unchanged variable names // preserve values of unchanged variable names
this.initializeVariables(); this.initializeVariables(this.variables.vars);
// make (double) sure I'm colored correctly // make (double) sure I'm colored correctly
this.forceNormalColoring(); this.forceNormalColoring();

Wyświetl plik

@ -2849,3 +2849,8 @@ end - bulk of 151215
160116 160116
------ ------
* Blocks: fixed a multi-line input slot layout glitch * Blocks: fixed a multi-line input slot layout glitch
160117
------
* BYOB: preserve custom block instances block var values when editing their definition