Giter VIP home page Giter VIP logo

scratch-gui's Introduction

scratch-gui

Scratch GUI is a set of React components that comprise the interface for creating and running Scratch 3.0 projects

To open the current build in your browser on Github Pages:

https://scratchfoundation.github.io/scratch-gui/

Installation

This requires you to have Git and Node.js installed.

In your own node environment/application:

npm install https://github.com/scratchfoundation/scratch-gui.git

If you want to edit/play yourself:

git clone https://github.com/scratchfoundation/scratch-gui.git
cd scratch-gui
npm install

You may want to add --depth=1 to the git clone command because there are some large files in the git repository history.

Getting started

Running the project requires Node.js to be installed.

Running

Open a Command Prompt or Terminal in the repository and run:

npm start

Then go to http://localhost:8601/ - the playground outputs the default GUI component

Developing alongside other Scratch repositories

Getting another repo to point to this code

If you wish to develop scratch-gui alongside other scratch repositories that depend on it, you may wish to have the other repositories use your local scratch-gui build instead of fetching the current production version of the scratch-gui that is found by default using npm install.

Here's how to link your local scratch-gui code to another project's node_modules/scratch-gui.

Configuration

  1. In your local scratch-gui repository's top level:

    1. Make sure you have run npm install
    2. Build the dist directory by running BUILD_MODE=dist npm run build
    3. Establish a link to this repository by running npm link
  2. From the top level of each repository (such as scratch-www) that depends on scratch-gui:

    1. Make sure you have run npm install
    2. Run npm link scratch-gui
    3. Build or run the repository

Using npm run watch

Instead of BUILD_MODE=dist npm run build, you can use BUILD_MODE=dist npm run watch instead. This will watch for changes to your scratch-gui code, and automatically rebuild when there are changes. Sometimes this has been unreliable; if you are having problems, try going back to BUILD_MODE=dist npm run build until you resolve them.

Oh no! It didn't work!

If you can't get linking to work right, try:

  • Follow the recipe above step by step and don't change the order. It is especially important to run npm install before npm link as installing after the linking will reset the linking.
  • Make sure the repositories are siblings on your machine's file tree, like .../.../MY_SCRATCH_DEV_DIRECTORY/scratch-gui/ and .../.../MY_SCRATCH_DEV_DIRECTORY/scratch-www/.
  • Consistent node.js version: If you have multiple Terminal tabs or windows open for the different Scratch repositories, make sure to use the same node version in all of them.
  • If nothing else works, unlink the repositories by running npm unlink in both, and start over.

Testing

Documentation

You may want to review the documentation for Jest and Enzyme as you write your tests.

See jest cli docs for more options.

Running tests

NOTE: If you're a Windows user, please run these scripts in Windows cmd.exe instead of Git Bash/MINGW64.

Before running any tests, make sure you have run npm install from this (scratch-gui) repository's top level.

Main testing command

To run linter, unit tests, build, and integration tests, all at once:

npm test

Running unit tests

To run unit tests in isolation:

npm run test:unit

To run unit tests in watch mode (watches for code changes and continuously runs tests):

npm run test:unit -- --watch

You can run a single file of integration tests (in this example, the button tests):

$(npm bin)/jest --runInBand test/unit/components/button.test.jsx

Running integration tests

Integration tests use a headless browser to manipulate the actual HTML and javascript that the repo produces. You will not see this activity (though you can hear it when sounds are played!).

To run the integration tests, you'll first need to install Chrome, Chromium, or a variant, along with Chromedriver.

Note that integration tests require you to first create a build that can be loaded in a browser:

npm run build

Then, you can run all integration tests:

npm run test:integration

Or, you can run a single file of integration tests (in this example, the backpack tests):

$(npm bin)/jest --runInBand test/integration/backpack.test.js

If you want to watch the browser as it runs the test, rather than running headless, use:

USE_HEADLESS=no $(npm bin)/jest --runInBand test/integration/backpack.test.js

Troubleshooting

Ignoring optional dependencies

When running npm install, you can get warnings about optional dependencies:

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]

You can suppress them by adding the no-optional switch:

npm install --no-optional

Further reading: Stack Overflow

Resolving dependencies

When installing for the first time, you can get warnings that need to be resolved:

npm WARN [email protected] requires a peer of babel-eslint@^8.0.1 but none was installed.
npm WARN [email protected] requires a peer of eslint@^4.0 but none was installed.
npm WARN [email protected] requires a peer of react-intl-redux@^0.7 but none was installed.
npm WARN [email protected] requires a peer of react-responsive@^4 but none was installed.

You can check which versions are available:

npm view react-intl-redux@0.* version

You will need to install the required version:

npm install  --no-optional --save-dev react-intl-redux@^0.7

The dependency itself might have more missing dependencies, which will show up like this:

user@machine:~/sources/scratch/scratch-gui (491-translatable-library-objects)$ npm install  --no-optional --save-dev react-intl-redux@^0.7
[email protected] /media/cuideigin/Linux/sources/scratch/scratch-gui
├── [email protected]
└── UNMET PEER DEPENDENCY [email protected]

You will need to install those as well:

npm install  --no-optional --save-dev react-responsive@^5.0.0

Further reading: Stack Overflow

Troubleshooting

If you run into npm install errors, try these steps:

  1. run npm cache clean --force
  2. Delete the node_modules directory
  3. Delete package-lock.json
  4. run npm install again

Publishing to GitHub Pages

You can publish the GUI to github.io so that others on the Internet can view it. Read the wiki for a step-by-step guide.

Understanding the project state machine

Since so much code throughout scratch-gui depends on the state of the project, which goes through many different phases of loading, displaying and saving, we created a "finite state machine" to make it clear which state it is in at any moment. This is contained in the file src/reducers/project-state.js .

It can be hard to understand the code in src/reducers/project-state.js . There are several types of data and functions used, which relate to each other:

Loading states

These include state constant strings like:

  • NOT_LOADED (the default state),
  • ERROR,
  • FETCHING_WITH_ID,
  • LOADING_VM_WITH_ID,
  • REMIXING,
  • SHOWING_WITH_ID,
  • SHOWING_WITHOUT_ID,
  • etc.

Transitions

These are names for the action which causes a state change. Some examples are:

  • START_FETCHING_NEW,
  • DONE_FETCHING_WITH_ID,
  • DONE_LOADING_VM_WITH_ID,
  • SET_PROJECT_ID,
  • START_AUTO_UPDATING,

How transitions relate to loading states

Like this diagram of the project state machine shows, various transition actions can move us from one loading state to another:

Project state diagram

Note: for clarity, the diagram above excludes states and transitions relating to error handling.

Example

Here's an example of how states transition.

Suppose a user clicks on a project, and the page starts to load with URL https://scratch.mit.edu/projects/123456.

Here's what will happen in the project state machine:

Project state example

  1. When the app first mounts, the project state is NOT_LOADED.
  2. The SET_PROJECT_ID redux action is dispatched (from src/lib/project-fetcher-hoc.jsx), with projectId set to 123456. This transitions the state from NOT_LOADED to FETCHING_WITH_ID.
  3. The FETCHING_WITH_ID state. In src/lib/project-fetcher-hoc.jsx, the projectId value 123456 is used to request the data for that project from the server.
  4. When the server responds with the data, src/lib/project-fetcher-hoc.jsx dispatches the DONE_FETCHING_WITH_ID action, with projectData set. This transitions the state from FETCHING_WITH_ID to LOADING_VM_WITH_ID.
  5. The LOADING_VM_WITH_ID state. In src/lib/vm-manager-hoc.jsx, we load the projectData into Scratch's virtual machine ("the vm").
  6. When loading is done, src/lib/vm-manager-hoc.jsx dispatches the DONE_LOADING_VM_WITH_ID action. This transitions the state from LOADING_VM_WITH_ID to SHOWING_WITH_ID.
  7. The SHOWING_WITH_ID state. Now the project appears normally and is playable and editable.

Donate

We provide Scratch free of charge, and want to keep it that way! Please consider making a donation to support our continued engineering, design, community, and resource development efforts. Donations of any size are appreciated. Thank you!

scratch-gui's People

Contributors

adroitwhiz avatar apple502j avatar benjiwheeler avatar bogusred avatar chrisgarrity avatar cwillisf avatar dependabot-preview[bot] avatar ericrosenbaum avatar evhan55 avatar foobartles avatar fsih avatar greenkeeper[bot] avatar josiahneuberger avatar kchadha avatar lifaythegoblin avatar lifeinchords avatar mzgoddard avatar nikhiljha avatar paulkaplan avatar picklesrus avatar quachtina96 avatar renovate-bot avatar renovate[bot] avatar rschamp avatar semantic-release-bot avatar sjhuang26 avatar thisandagain avatar tmickel avatar towerofnix avatar zoebentley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scratch-gui's Issues

Costume Editing -- Feature Request

Expected Behavior

Should be able to edit costumes.

Actual Behavior

Functionality not added.

Operating System and Browser

Ubuntu 16.04, chrome 56.0.2924.76

I am sure you're already working on this, just adding an issue so I can share our first play test findings / complaints.

Import / Export to SB3

Expected Behavior

A drop down on the top of the screen should exist called file, that should have in it (among other things) Upload from your computer, Download to your computer. Upload from your computer should create a file picker that picks and then loads an xml file, while download should generate and download an xml file.

Actual Behavior

Feature not yet implemented.

I will need this as well for the demos & play tests over here. Should I make a pull request for this? Or is said feature on the way?

5 SpritesSelectorItems per row

  1. Fix space-between issue when either 2-3 sprite items are in a row [vs either 1, or 4]. This will also let us remove margin on the sprite item component, and add it to parent as a independent class.

  2. Refactor sprites from set width to PostCSS Lost grid (maybe)

Selecting new costumes/backdrops appears broken

Non-default costumes and backdrops are loading fine in the VM as far as I can tell, so something's up with the add/library situation. This is possibly in the VM functions to add these things, but will track here.

Sprite Area

Expected Behavior

Should be able to edit sprite name, draggable, location, visbility, and rotation style (manually)

Actual Behavior

Functionality not added

Operating System and Browser

Ubuntu 16.04, chrome 56.0.2924.76

I am sure you're already working on this, just adding an issue so I can share our first play test findings / complaints.

Drag-and-drop

Wanted to write down some of the ideas Chris and I discussed about drag-and-drop.

  • Since sprites need to be draggable outside of the stage area, they likely need to be rendered outside of the WebGL canvas during a drag.
  • One idea is to grab the rendered drawable and paint it to a canvas when the drag begins. The drawable inside the stage can be hidden simultaneously, so it should be transparent to the user. Separately, the VM pauses the scripts on that target.
  • The canvas could then be position:fixed/absolute, and dragged anywhere on the webpage (and dropped, for example, into the backpack, or whatever).
  • When the drag finishes, the canvas is destroyed and the original drawable is unhidden. The VM should update the position of the sprite. If the drop was inside the stage, move the sprite; otherwise, snap it back to its pre-drag position.

I suspect most of this should be handled by the VM/Scratch-wrapper combo. Things that the renderer will need:

  • Ability to hide a drawable (implemented in a PR).
  • Ability to render a single drawable to a canvas (or otherwise pull out its pixels and give it to something that can).
  • Anything else?

Moved from scratchfoundation/scratch-render#15
/cc @tmickel

Fix Libraries grid layout

screen shot 2017-02-13 at 11 39 16 am

2 things:

  • Need space between items across rows on hover
  • Width on items are not the same across rows

Implement sprite selector

There is a <CostumeCanvas /> component which should help with that. All the data from the VM should be present, except maybe the current costume per target.

Perceived lag in libraries

These seem to load very slowly.

The basic problem is that they require tons of network requests currently. The sprite library has to request one JSON file per sprite, and then separately one SVG/PNG. The costume library has to request all the images (no JSON), but there are many of them.

Two ways we could address this are packaging the metadata into scratch-gui, or by implementing lazy loading.

Hide "unfinished" blocks from the toolbox for EOY prototype

This is my accounting:

  • say
  • say for n secs
  • think
  • think for n secs
  • entire pen category
  • show variable/list, hide variable/list.
  • when "loudness"/"video motion" > _ (timer works).
  • ask and wait
  • answer (for ask and wait)
  • loudness
  • video motion reporter
  • turn video on/off
  • username
  • "more blocks" category

GUI Chrome

Iterate the application UI shell, aka, chrome, towards latest designs.

Not All the Backdrops Have Size / Resolution Info

The Backdrops Don't All Work Because Several of Them Are Missing Size / Resolution Info

I assume you already know this, but talking is fun.

Specifically:

  • atom playground
  • beach malibu
  • bedroom1
  • bedroom2
  • bench with view

and 74 others have empty "info".

Green flag/stop button

Copying this as it's a line item from the prototype plan. I'm assuming it just means getting the styling right.

Sound Editor

Updated by Paul, July 6th

First Iteration will include

  • Play / Stop
  • Renaming
  • Start / End Trimmer
  • Duplicate entire sound
  • Applying effects to an entire sound (chipmunk, monster, robot, echo, fuzz)

Not included this iteration

  • undo/redo
  • positive selection tool
  • pause
  • timing indications
  • zooming

Windows npm start error

I ran npm install, and then npm start, and got this error:

npm start

> [email protected] start C:\Users\johnr\Documents\scratch-gui
> webpack-dev-server --port $npm_package_config_port --content-base=./build

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES $npm_package_config_port
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at Server._listen2 (net.js:1249:19)
    at listen (net.js:1298:10)
    at Server.listen (net.js:1382:7)
    at Server.listen (C:\Users\johnr\Documents\scratch-gui\node_modules\webpack-dev-server\lib\Server.js:321:27)
    at Object.<anonymous> (C:\Users\johnr\Documents\scratch-gui\node_modules\webpack-dev-server\bin\webpack-dev-server.js:183:37)
    at Module._compile (module.js:573:32)
    at Object.Module._extensions..js (module.js:582:10)
    at Module.load (module.js:490:32)
    at tryModuleLoad (module.js:449:12)
    at Function.Module._load (module.js:441:3)
    at Module.runMain (module.js:607:10)
    at run (bootstrap_node.js:382:7)
    at startup (bootstrap_node.js:137:9)
    at bootstrap_node.js:497:3

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\johnr\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v7.0.0
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `webpack-dev-server --port $npm_package_config_port --content-base=./build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'webpack-dev-server --port $npm_package_config_port --content-base=./build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the scratch-gui package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack-dev-server --port $npm_package_config_port --content-base=./build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs scratch-gui
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls scratch-gui
npm ERR! There is likely additional logging output above.

Delete Sprite

Expected Behavior

Should be a button to delete a sprite

New Sprite Not Always Visible

Expected Behavior

After selecting new sprite, said sprite should appear.

Actual Behavior

Works sometimes, but not always. Eg. apple doesn't load.

Steps to Reproduce

Start blank project, click new sprite, click apple.

Operating System and Browser

Ubuntu 16.04, chrome 56.0.2924.76

Library Sorting

Expected Behavior

The costume and backdrop libraries are extensive, and there should be search, check boxes for tags wanted, or other sorting functionality to make them more usable.

Paint Editor

  • Design
    • Benchmarks
    • Existing use case documentation
    • Overall UX wires
    • Vector editor spec
    • Bitmap editor spec
  • Implementation
    • Add "costume" tab
    • Vector editor
    • Bitmap editor

Backdrop / Sprite Import

Expected Behavior

Should click new backdrop, and on the new screen, should be able to select import, then select a backdrop

Actual Behavior

No such import button / function

I will need to add this for the local play test over here. If you all have this in the works, let me know.

If on edge bounce broken

This block is intended to make the sprite turn in the opposite direction when it hits an edge.

What actually happens is that the sprite just keeps moving into the edge of the screen.

To view the error, just make a script saying: 'When green flag clicked, forever, move 10 steps. If on edge bounce.'

This error was viewed in Firefox on Mac OS X 10.6

Some scaling/positioning issues

Green flag/stop seem a little small and offset scratch-blocks
Sprite selector bounding box will sometimes cut off text
Sprite selector is not centered on sprite
No bounding box for stage.

Spacing between green flag and stop button.

Expected Behavior

There should be spacing between the green flag and stop button.

screenshot 2017-01-23 at 11 33 48 am

Actual Behavior

There is no spacing between them

Steps to Reproduce

Open Scratch GUI

Operating System and Browser

Chromebook

[ENA-235] Light/Dark modes

You should be able to toggle between "light mode" (as in the comp in #1) and "dark mode" (the current default look of scratch-blocks). The light mode should be defined as the default look in scratch-blocks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.