Skip to content

Commit dbbda79

Browse files
feat(targets/sprites): comment in constructor for targets +sprite duplicate method
1 parent 4761d48 commit dbbda79

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/engine/target.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ class Target extends EventEmitter {
2020
/**
2121
* @param {Runtime} runtime Reference to the runtime.
2222
* @param {?Blocks} blocks Blocks instance for the blocks owned by this target.
23+
* @param {?Object.<string, *>} comments Array of comments owned by this target.
2324
* @constructor
2425
*/
25-
constructor (runtime, blocks) {
26+
constructor (runtime, blocks, comments) {
2627
super();
2728

2829
if (!blocks) {
@@ -55,7 +56,7 @@ class Target extends EventEmitter {
5556
* Key is the comment id.
5657
* @type {Object.<string,*>}
5758
*/
58-
this.comments = {};
59+
this.comments = comments || {};
5960
/**
6061
* Dictionary of custom state for this target.
6162
* This can be used to store target-specific custom state for blocks which need it.

src/sprites/rendered-target.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RenderedTarget extends Target {
1515
* @constructor
1616
*/
1717
constructor (sprite, runtime) {
18-
super(runtime, sprite.blocks);
18+
super(runtime, sprite.blocks, sprite.comments);
1919

2020
/**
2121
* Reference to the sprite that this is a render of.

src/sprites/sprite.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class Sprite {
5454
if (this.runtime && this.runtime.audioEngine) {
5555
this.soundBank = this.runtime.audioEngine.createBank();
5656
}
57+
/**
58+
* Dictionary of comments for this target.
59+
* Key is the comment id.
60+
* @type {Object.<string.*>}
61+
*/
62+
this.comments = {};
5763
}
5864

5965
/**
@@ -145,7 +151,11 @@ class Sprite {
145151
newSprite.blocks.createBlock(block);
146152
});
147153

148-
154+
Object.keys(this.comments).forEach(commentId => {
155+
const newComment = this.comments[commentId];
156+
newSprite.comments[newComment.id] = newComment;
157+
});
158+
149159
const allNames = this.runtime.targets.map(t => t.sprite.name);
150160
newSprite.name = StringUtil.unusedName(this.name, allNames);
151161

0 commit comments

Comments
 (0)