-
Notifications
You must be signed in to change notification settings - Fork 791
Add [scratchblocks] export #1646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Thank you!! I love this idea, it's wonderful to be able to convert Snap scripts into text-code that can then be pasted into the Scratch Forums. Did you know that one of my very first contributions to Scratch (way back when, I think it must have been v 1.2) was the ability to convert scripts to XML, and my example was always pasting blocks into the forums? This looks quite pullable. Just one question: Would it be possible - and perhaps even make sense - to just use Snap's built-in "Codification" mechanism for this, instead of hard-coding the Scratch-Forum block syntax into the Snap sources? That way we could offer any kind of stringification, and externalize it, too. The only new feature we'd have to add would be to pop-up an alert-box letting you copy the generated code out of Snap. Does that make sense at all? |
|
I'm glad you like it! :-) I thought about using codification to implement this, but I don't think it would make sense. Here's why: the scratchblocks syntax very closely mirrors the Morphic structure of the blocks. This PR is able to be so small because of this. It makes more sense to think about scratchblocks as an alternative "rendering" of the block morphs, than as a language that you can codify to! This means that I don't have to hard-code all of the blocks, in fact. So while it's a neat idea, I don't think it would make sense to combine scratchblocks and codification. Unless codification works very differently than I thought!
You know, I do remember that! It was called Chirp, wasn't it? :) |
|
Ah, okay, your explanation does make sense yes. Awesome, I'm going to pull this next up. Thank you so much! |
|
Great! I'm very pleased :D Thanks Jens! |
|
@tjvr, some bugs have been found. https://scratch.mit.edu/discuss/post/2423593/ |
|
thanks, fixed :) |
blocks.js
Outdated
| menu.addItem( | ||
| 'stringify...', | ||
| function() { | ||
| var code = myself.stringify(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, how about replacing this with a Morphic dialog box? Now that Morphic supports copy & paste of text, we can do this nicer :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make a generic one that has some text about how to copy and paste. C&P is only supported via keyboard shortcuts so it's non-obvious to many.
Anyway, there's a mostly correct dialog in #1084
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a lot of code just for copy/pasting scratchblocks!
If you don't mind I'm not going to do that here, and instead open a new issue for that improvement. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mostly just layout / morphic code.
And if we use it in 2 place, then we could create a CopySelectionDialogMorph and store it in widgets.js, so then it's like...no code. ;)
| "delete", | ||
| 'userDestroy' | ||
| ); | ||
| menu.addItem( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the word "stringify" is confusing. Namely many Snap! users aren't familiar with the term "string", but also, in my mind at least "stringify" implies are more generic use than Scratch Blocks syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That later comment also means I have reservations about using the function stringify for something like this, as opposed to say toScratchBlocks, which I think is much more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the best name, no! But has to be better than "scratchblocks"...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But has to be better than "scratchblocks"...
Wait, why? (or am I just missing something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name "scratchblocks" is really unhelpful; to someone unfamiliar with the term, it doesn't really help explain what it is. Maybe "export text" or something? The closest analogy I can think of is the export project summary feature from Scratch 1.x...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so, but "scratchblocks" is at least specific about what this is. If you google "scratchblocks" then your project at least comes up at the top so it's discoverable.
Also, since this is only for the Scratch forum (at the moment) we might just say "export for scratch forum" (and update it as needed in the future)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "as forum code"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forum code... is what I was thinking too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forum code sounds good to me!
| // SymbolMorph to "scratchblocks" | ||
|
|
||
| SymbolMorph.prototype.stringify = function () { | ||
| var symbol = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This format seems confusing to me, especially since there's only one option.
Why not just use a simple conditional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mapping Snap! icon names to scratchblocks icon names. We might add more icons in the future, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get what it's doing, but only after reading it like a few times. That reason makes sense, though it seems better, to me, to add complexity as needed, that's all.
blocks.js
Outdated
|
|
||
| TemplateSlotMorph.prototype.stringify = function () { | ||
| var category = this.parent.stringifyCategory() || ' :: grey'; | ||
| return '(' + this.children[0].stringify() + category + ')'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Snap, template variables are in doubled rings, like here: script variables ((a)::grey) ::grey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already done! Please try the demo version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your demo site either isn't updated to the newest code, or your code is still buggy, because I'm still getting incorrect results for rings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still getting incorrect results for rings
What specific examples don't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, it's working now.
|
Okay, I've renamed the methods & the menu item. :) I opened #1648 for the dialog enhancement. Other than that this should be ready to merge :) |
|
LGTM. (At least the code, I haven't had a chance to test it yet) |
blocks.js
Outdated
|
|
||
| SyntaxElementMorph.prototype.toScratchblocksCategory = function () { | ||
| // private. answers with scratchblocks category specifier | ||
| if (!this.category) return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Jens uses {return ''; } as the format of these things.
blocks.js
Outdated
| 'userDestroy' | ||
| ); | ||
| menu.addItem( | ||
| 'forum code...', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: space between n and (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote for "Scratchblocks" over "forum code." It really is quite Scratch-specific. When we have our own forum with Snap!blocks we can change the item name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to scratchblocks code.... :)
Speaking of which we should get on that. Remind me to bring this up next week! |
|
I've changed my mind about this, nice as it is. Basically, we will get another way to export scripts in our own format. For this we might make a forum plug-in that renders the exported scripts. But then we can also drag thoses shared scripts back into Snap, and use them as "real" ones. We need to ponder this some more.... |
|
Fair enough :-) Feel free to close! |
|
If the alleged our-own script-to-text format is > 1/2 year away, I would still argue for pulling this in the coming release. |
|
The format is mostly done, it's @bromagosa's PR #1746 |
Good morning! :)
This is a small PR to add a "stringify..." option to the menu. This opens a dialog box containing scratchblocks code, which can be copy/pasted into the Scratch Forums. (You can also try the test page, but since Snap! already has a "script pic" feature, the test page is less useful!)
Uploading pictures to the Snap! forums is quite time-consuming. Copy/pasting scratchblocks code is quicker, and might help to facilitate discussion on the User thread.
I've partly done this as an exercise in writing code in a Jens-approved style; please let me know what you think @jmoenig! :-)