From 20d5be5ced694feb316271e9e7a0a29f7a28f446 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Tue, 7 Sep 2021 10:14:24 +0200 Subject: [PATCH] added new change-of-scene event still very experimental --- HISTORY.md | 3 +++ snap.html | 6 +++--- src/blocks.js | 5 +++-- src/objects.js | 21 ++++++++++++++++++++- src/threads.js | 8 +++++--- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index ffac13e7..1f14d632 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -33,6 +33,9 @@ * German * Chinese, thanks, Simon! +### 2021-09-07 +* blocks, objects, threads: new change-of-scene event + ### 2021-09-06 * blocks: fixed exporting comment pics from inside the block editor, thanks, Jadga, for the report! * gui: fixed copying unattached comments among sprites, thanks, Jadga, for the report! diff --git a/snap.html b/snap.html index b31ec15e..5ead9c87 100755 --- a/snap.html +++ b/snap.html @@ -16,9 +16,9 @@ - - - + + + diff --git a/src/blocks.js b/src/blocks.js index 641b8f43..e6d47867 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -160,7 +160,7 @@ CustomCommandBlockMorph, ToggleButtonMorph, DialMorph, SnapExtensions*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2021-September-06'; +modules.blocks = '2021-September-07'; var SyntaxElementMorph; var BlockMorph; @@ -416,7 +416,8 @@ SyntaxElementMorph.prototype.labelParts = { 'mouse-departed' : ['mouse-departed'], 'scrolled-up' : ['scrolled-up'], 'scrolled-down' : ['scrolled-down'], - 'stopped' : ['stopped'] // experimental + 'stopped' : ['stopped'], // experimental + 'entering a scene' : ['entering a scene'] // experimental } }, '%dates': { diff --git a/src/objects.js b/src/objects.js index 29f40ae2..7aaf4eb9 100644 --- a/src/objects.js +++ b/src/objects.js @@ -86,7 +86,7 @@ AlignmentMorph, Process, WorldMap, copyCanvas, useBlurredShadows*/ /*jshint esversion: 6*/ -modules.objects = '2021-July-23'; +modules.objects = '2021-September-07'; var SpriteMorph; var StageMorph; @@ -8431,6 +8431,25 @@ StageMorph.prototype.processKeyPress = function (event) { StageMorph.prototype.inspectKeyEvent = CursorMorph.prototype.inspectKeyEvent; +StageMorph.prototype.fireChangeOfSceneEvent = function () { + var procs = []; + + this.children.concat(this).forEach(morph => { + if (isSnapObject(morph)) { + morph.allHatBlocksForInteraction( + 'entering a scene' + ).forEach(block => + procs.push(this.threads.startProcess( + block, + morph, + this.isThreadSafe + )) + ); + } + }); + return procs; +}; + StageMorph.prototype.fireGreenFlagEvent = function () { var procs = [], ide = this.parentThatIsA(IDE_Morph); diff --git a/src/threads.js b/src/threads.js index 6d550c86..75164dfd 100644 --- a/src/threads.js +++ b/src/threads.js @@ -60,11 +60,11 @@ IDE_Morph, ArgLabelMorph, localize, XML_Element, hex_sha512, TableDialogMorph, StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy, Map, isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, BLACK, TableFrameMorph, ColorSlotMorph, isSnapObject, newCanvas, Symbol, SVG_Costume, -SnapExtensions, AlignmentMorph, TextMorph*/ +SnapExtensions, AlignmentMorph, TextMorph, Cloud*/ /*jshint esversion: 6*/ -modules.threads = '2021-July-20'; +modules.threads = '2021-September-07'; var ThreadManager; var Process; @@ -3675,7 +3675,7 @@ Process.prototype.checkURLAllowed = function (url) { // Check only against the host -not the protocol, path or // port- of the domain new RegExp(`${(new URL(domain)).host}.*${pathPart}`, 'i')) - ) + ); } )) { throw new Error('Request blocked'); @@ -4735,6 +4735,7 @@ Process.prototype.doSwitchToScene = function (id) { break; } ide.switchToScene(scenes.at(idx)); + ide.stage.fireChangeOfSceneEvent(); return; } @@ -4748,6 +4749,7 @@ Process.prototype.doSwitchToScene = function (id) { } ide.switchToScene(scene); + ide.stage.fireChangeOfSceneEvent(); };