From 4f39a406da6dbbea1ae6a34cfcbc1026ef6ad6aa Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Wed, 15 Apr 2015 17:32:08 +0200 Subject: fixed #770 --- objects.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 66726a1..173be51 100644 --- a/objects.js +++ b/objects.js @@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2015-March-24'; +modules.objects = '2015-April-15'; var SpriteMorph; var StageMorph; @@ -2369,6 +2369,29 @@ SpriteMorph.prototype.freshPalette = function (category) { } }); + // inherited custom blocks: (under construction...) + + // y += unit * 1.6; + if (this.exemplar) { + this.exemplar.customBlocks.forEach(function (definition) { + var block; + if (definition.category === category || + (category === 'variables' + && contains( + ['lists', 'other'], + definition.category + ))) { + block = definition.templateInstance(); + y += unit * 0.3; + block.setPosition(new Point(x, y)); + palette.addContents(block); + block.ghost(); + x = 0; + y += block.height(); + } + }); + } + //layout palette.scrollX(palette.padding); @@ -3107,7 +3130,7 @@ SpriteMorph.prototype.setEffect = function (effect, value) { if (eff === 'ghost') { this.alpha = 1 - Math.min(Math.max(+value || 0, 0), 100) / 100; } else { - this.graphicsValues[eff] = value; + this.graphicsValues[eff] = +value; } this.drawNew(); this.changed(); @@ -3122,7 +3145,7 @@ SpriteMorph.prototype.changeEffect = function (effect, value) { if (eff === 'ghost') { this.setEffect(effect, this.getGhostEffect() + (+value || 0)); } else { - this.setEffect(effect, this.graphicsValues[eff] + value); + this.setEffect(effect, +this.graphicsValues[eff] + (+value)); } }; -- cgit v1.3.1 From 9e4b73eae9adcbad1cef270411b56d0676cf0006 Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Fri, 17 Apr 2015 15:27:29 +0200 Subject: OOP: Prototypal inheritance of sprite-local custom blocks (palette only) --- history.txt | 4 ++++ objects.js | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'objects.js') diff --git a/history.txt b/history.txt index b3b4da3..938213e 100755 --- a/history.txt +++ b/history.txt @@ -2498,3 +2498,7 @@ ______ ------ * Threads: flush Stage>>keysPressed when prompting the user * Objects: fixed #770 + +150415 +------ +* OOP: Objects, Prototypal inheritance of sprite-local custom blocks (palette only) diff --git a/objects.js b/objects.js index 173be51..52292ca 100644 --- a/objects.js +++ b/objects.js @@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2015-April-15'; +modules.objects = '2015-April-17'; var SpriteMorph; var StageMorph; @@ -2373,7 +2373,7 @@ SpriteMorph.prototype.freshPalette = function (category) { // y += unit * 1.6; if (this.exemplar) { - this.exemplar.customBlocks.forEach(function (definition) { + this.inheritedBlocks(true).forEach(function (definition) { var block; if (definition.category === category || (category === 'variables' @@ -4284,6 +4284,48 @@ SpriteMorph.prototype.deletableVariableNames = function () { ); }; +// SpriteMorph inheritance - custom blocks + +SpriteMorph.prototype.ownBlocks = function () { + var dict = {}; + this.customBlocks.forEach(function (def) { + dict[def.blockSpec()] = def; + }); + return dict; +}; + +SpriteMorph.prototype.allBlocks = function (valuesOnly) { + var dict = {}; + this.allExemplars().reverse().forEach(function (sprite) { + sprite.customBlocks.forEach(function (def) { + dict[def.blockSpec()] = def; + }); + }); + if (valuesOnly) { + return Object.keys(dict).map(function (key) {return dict[key]; }); + } + return dict; +}; + +SpriteMorph.prototype.inheritedBlocks = function (valuesOnly) { + var dict = {}, + own = Object.keys(this.ownBlocks()), + others = this.allExemplars().reverse(); + others.pop(); + others.forEach(function (sprite) { + sprite.customBlocks.forEach(function (def) { + var spec = def.blockSpec(); + if (!contains(own, spec)) { + dict[spec] = def; + } + }); + }); + if (valuesOnly) { + return Object.keys(dict).map(function (key) {return dict[key]; }); + } + return dict; +}; + // SpriteMorph highlighting SpriteMorph.prototype.addHighlight = function (oldHighlight) { -- cgit v1.3.1