Skip to content
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

Add sprite #4

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
82f8b65
feat: add a sprite
aquino-luane Oct 15, 2024
902eba6
feat: setup assets store + consume sprites and keep in store
aquino-luane Oct 23, 2024
0699607
feat: setup store for costumes + consume data from api
aquino-luane Oct 23, 2024
ccc0813
feat: update urls with real endpoints
aquino-luane Jan 21, 2025
3b15474
resolve merge conflicts with main
aquino-luane Jan 21, 2025
31913de
feat: update url to get a sprite by id
aquino-luane Jan 21, 2025
b81720f
feat: update url to get a assets by id
aquino-luane Jan 21, 2025
55b427d
refactor: remove changes to package.json
aquino-luane Jan 21, 2025
c9683e4
resolve merge conflicts with poc/user-session-v2
aquino-luane Jan 22, 2025
6e2e758
refactor: remove duplicated import
aquino-luane Jan 22, 2025
7339f3c
feat: retry when toke is expired when getting sprites and costumes
aquino-luane Jan 23, 2025
9bc54c2
feat: update url to https
aquino-luane Jan 24, 2025
c02f01b
feat: redirect to login page if retry fails
aquino-luane Jan 27, 2025
376dcc2
feat: create function getToken
aquino-luane Jan 28, 2025
e10411f
fix: move request to get token to another file
aquino-luane Jan 28, 2025
05efa7a
refactor: remove mock url
aquino-luane Jan 28, 2025
84d42d8
feat: add code to show sounds
aquino-luane Jan 29, 2025
5ae1ab0
fix: update url of get assets
aquino-luane Feb 5, 2025
264f495
merge with feature/save-project
aquino-luane Feb 5, 2025
ddaa6a6
fix: remove duplicates + add code to mock url
aquino-luane Feb 5, 2025
5c089e4
Merge branch 'main' into poc/add-sprite
aquino-luane Feb 5, 2025
0fcc389
Merge branch 'main' into poc/add-sprite
aquino-luane Feb 6, 2025
f07e463
Merge branch 'bugfix/remove-user-from-token' into poc/add-sprite
aquino-luane Feb 6, 2025
e726ea1
refactor(hash-parser-hoc): add FIXME
aquino-luane Feb 10, 2025
6184337
Merge branch 'main' into poc/add-sprite
aquino-luane Feb 14, 2025
991c4a4
fix: remove file format to fix display of sprites library
aquino-luane Feb 21, 2025
f3efab5
merge poc/add-sprite into feature/add-sounds
aquino-luane Feb 21, 2025
6fc6b9c
fix: adjust sounds url
aquino-luane Feb 21, 2025
38eb0af
feat: show projects list button
aquino-luane Feb 21, 2025
0186b43
fix: adjust error screen text
aquino-luane Feb 21, 2025
a908954
fix: remove audio format
aquino-luane Feb 25, 2025
b29a4d1
Merge pull request #13 from MacareuxDigital/feature/add-sounds
hissy Feb 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/crash-message/crash-message.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const CrashMessage = props => (
/>
</p>
)}
<a href={`${BASE_API_URL}/`} className={styles.textLink}>Go back to project list</a>
<a href={`${BASE_API_URL}/`} className={styles.textLink}>Go back to projects list</a>
</Box>
</div>
);
Expand Down
20 changes: 19 additions & 1 deletion src/components/menu-bar/menu-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import collectMetadata from '../../lib/collect-metadata';
import styles from './menu-bar.css';

import remixIcon from './icon--remix.svg';
import mystuffIcon from './icon--mystuff.png';
import dropdownCaret from './dropdown-caret.svg';
import languageIcon from '../language-selector/language-icon.svg';
import aboutIcon from './icon--about.svg';
Expand Down Expand Up @@ -629,6 +630,21 @@ class MenuBar extends React.Component {
)}
</div>
{this.props.sessionExists &&
<React.Fragment>
<a href={`${BASE_API_URL}`}>
<div
className={classNames(
styles.menuBarItem,
styles.hoverable,
styles.mystuffButton
)}
>
<img
className={styles.mystuffIcon}
src={mystuffIcon}
/>
</div>
</a>
<AccountNav
className={classNames(
styles.menuBarItem,
Expand All @@ -641,7 +657,9 @@ class MenuBar extends React.Component {
onClick={this.props.onClickAccount}
onClose={this.props.onRequestCloseAccount}
onLogOut={this.handleLogout}
/>}
/>
</React.Fragment>
}
</div>

{aboutButton}
Expand Down
16 changes: 12 additions & 4 deletions src/containers/costume-library.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
import React from 'react';
import {defineMessages, injectIntl, intlShape} from 'react-intl';
import VM from 'scratch-vm';
import {connect} from 'react-redux';

import costumeLibraryContent from '../lib/libraries/costumes.json';
import spriteTags from '../lib/libraries/sprite-tags';
import LibraryComponent from '../components/library/library.jsx';

Expand Down Expand Up @@ -36,14 +36,16 @@ class CostumeLibrary extends React.PureComponent {
}
render () {
return (
<LibraryComponent
data={costumeLibraryContent}
this.props.costumes
? <LibraryComponent
data={this.props.costumes}
id="costumeLibrary"
tags={spriteTags}
title={this.props.intl.formatMessage(messages.libraryTitle)}
onItemSelected={this.handleItemSelected}
onRequestClose={this.props.onRequestClose}
/>
: null
);
}
}
Expand All @@ -54,4 +56,10 @@ CostumeLibrary.propTypes = {
vm: PropTypes.instanceOf(VM).isRequired
};

export default injectIntl(CostumeLibrary);
const mapStateToProps = state => {
return {
costumes: state.assets.costumes,
};
};

export default injectIntl(connect(mapStateToProps,null)(CostumeLibrary));
29 changes: 16 additions & 13 deletions src/containers/costume-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import paintIcon from '../components/action-menu/icon--paint.svg';
import surpriseIcon from '../components/action-menu/icon--surprise.svg';
import searchIcon from '../components/action-menu/icon--search.svg';

import costumeLibraryContent from '../lib/libraries/costumes.json';
import backdropLibraryContent from '../lib/libraries/backdrops.json';

let messages = defineMessages({
Expand Down Expand Up @@ -168,16 +167,18 @@ class CostumeTab extends React.Component {
this.handleNewCostume(emptyCostume(name));
}
handleSurpriseCostume () {
const item = costumeLibraryContent[Math.floor(Math.random() * costumeLibraryContent.length)];
const vmCostume = {
name: item.name,
md5: item.md5ext,
rotationCenterX: item.rotationCenterX,
rotationCenterY: item.rotationCenterY,
bitmapResolution: item.bitmapResolution,
skinId: null
};
this.handleNewCostume(vmCostume, true /* fromCostumeLibrary */);
if(this.props.costumes){
const item = this.props.costumes[Math.floor(Math.random() * this.props.costumes.length)];
const vmCostume = {
name: item.name,
md5: item.md5ext,
rotationCenterX: item.rotationCenterX,
rotationCenterY: item.rotationCenterY,
bitmapResolution: item.bitmapResolution,
skinId: null
};
this.handleNewCostume(vmCostume, true /* fromCostumeLibrary */);
}
}
handleSurpriseBackdrop () {
const item = backdropLibraryContent[Math.floor(Math.random() * backdropLibraryContent.length)];
Expand Down Expand Up @@ -349,15 +350,17 @@ CostumeTab.propTypes = {
name: PropTypes.string.isRequired
}))
}),
vm: PropTypes.instanceOf(VM)
vm: PropTypes.instanceOf(VM),
costumes: PropTypes.arrayOf(PropTypes.object)
};

const mapStateToProps = state => ({
editingTarget: state.scratchGui.targets.editingTarget,
isRtl: state.locales.isRtl,
sprites: state.scratchGui.targets.sprites,
stage: state.scratchGui.targets.stage,
dragging: state.scratchGui.assetDrag.dragging
dragging: state.scratchGui.assetDrag.dragging,
costumes: state.assets.costumes
});

const mapDispatchToProps = dispatch => ({
Expand Down
64 changes: 61 additions & 3 deletions src/containers/gui.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
closeTelemetryModal,
openExtensionLibrary
} from '../reducers/modals';
import { setCostumes, setSounds, setSprites } from '../reducers/assets.js';
import { setSession } from "../reducers/session.js";

import FontLoaderHOC from '../lib/font-loader-hoc.jsx';
Expand All @@ -41,6 +42,8 @@ import cloudManagerHOC from '../lib/cloud-manager-hoc.jsx';

import GUIComponent from '../components/gui/gui.jsx';
import {setIsScratchDesktop} from '../lib/isScratchDesktop.js';
import { BASE_API_URL } from '../utils/constants.js';
import customFetch from '../apis/customFetch.js';
import { setModalExtension } from '../reducers/modal-choose-extension.js';

class GUI extends React.Component {
Expand All @@ -62,6 +65,47 @@ class GUI extends React.Component {
// At this time the project view in www doesn't need to know when a project is unloaded
this.props.onProjectLoaded();
}
if(this.props.token !== prevProps.token){
this.getSpritesFromApi();
this.getCostumesFromApi();
this.getSoundsFromApi();
}
}
getSpritesFromApi () {
this.props.onCustomFetch(`${BASE_API_URL}/md/api/sprites`, 'GET', this.props.token, this.props.onSetSession)
.then(response => {
this.props.onSetSprites(response);
})
.catch(error => {
console.error(
'There was a problem fetching the sprites:',
error
);
});
}
getCostumesFromApi () {
this.props.onCustomFetch(`${BASE_API_URL}/md/api/costumes`, 'GET', this.props.token, this.props.onSetSession)
.then(response => {
this.props.onSetCostumes(response);
})
.catch(error => {
console.error(
'There was a problem fetching the costumes:',
error
);
});
}
getSoundsFromApi () {
this.props.onCustomFetch(`${BASE_API_URL}/md/api/assets/sounds`, 'GET', this.props.token, this.props.onSetSession)
.then(response => {
this.props.onSetSounds(response);
})
.catch(error => {
console.error(
'There was a problem fetching the sounds:',
error
);
});
}
handleShowExtension(isFromButtonClick = false) {
if(isFromButtonClick) {
Expand Down Expand Up @@ -89,8 +133,12 @@ class GUI extends React.Component {
onStorageInit,
onUpdateProjectId,
onVmInit,
onSetSprites,
onSetCostumes,
onSetSounds,
onSetSession,
onProjectError,
onCustomFetch,
projectHost,
projectId,
showExtension,
Expand Down Expand Up @@ -131,22 +179,28 @@ GUI.propTypes = {
onStorageInit: PropTypes.func,
onUpdateProjectId: PropTypes.func,
onVmInit: PropTypes.func,
onSetSprites: PropTypes.func,
onSetCostumes: PropTypes.func,
onSetSounds: PropTypes.func,
onSetSession: PropTypes.func,
onProjectError: PropTypes.func,
onCustomFetch: PropTypes.func.isRequired,
projectHost: PropTypes.string,
projectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
setModalExtensionVisibility: PropTypes.func,
// showExtension: PropTypes.func,
telemetryModalVisible: PropTypes.bool,
vm: PropTypes.instanceOf(VM).isRequired
vm: PropTypes.instanceOf(VM).isRequired,
token: PropTypes.string
};

GUI.defaultProps = {
isScratchDesktop: false,
onStorageInit: storageInstance => storageInstance.addOfficialScratchWebStores(),
onProjectLoaded: () => {},
onUpdateProjectId: () => {},
onVmInit: (/* vm */) => {}
onVmInit: (/* vm */) => {},
onCustomFetch: customFetch,
};

const mapStateToProps = state => {
Expand Down Expand Up @@ -176,7 +230,8 @@ const mapStateToProps = state => {
),
telemetryModalVisible: state.scratchGui.modals.telemetryModal,
tipsLibraryVisible: state.scratchGui.modals.tipsLibrary,
vm: state.scratchGui.vm
vm: state.scratchGui.vm,
token: state.session.session.token
};
};

Expand All @@ -187,6 +242,9 @@ const mapDispatchToProps = dispatch => ({
onRequestCloseBackdropLibrary: () => dispatch(closeBackdropLibrary()),
onRequestCloseCostumeLibrary: () => dispatch(closeCostumeLibrary()),
onRequestCloseTelemetryModal: () => dispatch(closeTelemetryModal()),
onSetSprites: (sprites) => dispatch(setSprites(sprites)),
onSetCostumes: (costumes) => dispatch(setCostumes(costumes)),
onSetSounds: (sounds) => dispatch(setSounds(sounds)),
onSetSession: (token) => dispatch(setSession(token)),
onProjectError: error => dispatch(projectError(error)),
showExtension: () => dispatch(openExtensionLibrary()),
Expand Down
3 changes: 2 additions & 1 deletion src/containers/library-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react';
import {injectIntl} from 'react-intl';

import LibraryItemComponent from '../components/library-item/library-item.jsx';
import { BASE_API_URL } from '../utils/constants.js';

class LibraryItem extends React.PureComponent {
constructor (props) {
Expand Down Expand Up @@ -106,7 +107,7 @@ class LibraryItem extends React.PureComponent {
render () {
const iconMd5 = this.curIconMd5();
const iconURL = iconMd5 ?
`https://cdn.assets.scratch.mit.edu/internalapi/asset/${iconMd5}/get/` :
`${BASE_API_URL}/md/api/assets?assetID=${iconMd5.replace(".svg", '')}` :
this.props.iconRawURL;
return (
<LibraryItemComponent
Expand Down
34 changes: 19 additions & 15 deletions src/containers/sound-library.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import LibraryComponent from '../components/library/library.jsx';
import soundIcon from '../components/library-item/lib-icon--sound.svg';
import soundIconRtl from '../components/library-item/lib-icon--sound-rtl.svg';

import soundLibraryContent from '../lib/libraries/sounds.json';
import soundTags from '../lib/libraries/sound-tags';

import {connect} from 'react-redux';
Expand Down Expand Up @@ -147,6 +146,7 @@ class SoundLibrary extends React.PureComponent {
}
render () {
// @todo need to use this hack to avoid library using md5 for image
const soundLibraryContent = this.props.sounds
const soundLibraryThumbnailData = soundLibraryContent.map(sound => {
const {
md5ext,
Expand All @@ -160,18 +160,20 @@ class SoundLibrary extends React.PureComponent {
});

return (
<LibraryComponent
showPlayButton
data={soundLibraryThumbnailData}
id="soundLibrary"
setStopHandler={this.setStopHandler}
tags={soundTags}
title={this.props.intl.formatMessage(messages.libraryTitle)}
onItemMouseEnter={this.handleItemMouseEnter}
onItemMouseLeave={this.handleItemMouseLeave}
onItemSelected={this.handleItemSelected}
onRequestClose={this.props.onRequestClose}
/>
this.props.sounds
? <LibraryComponent
showPlayButton
data={soundLibraryThumbnailData}
id="soundLibrary"
setStopHandler={this.setStopHandler}
tags={soundTags}
title={this.props.intl.formatMessage(messages.libraryTitle)}
onItemMouseEnter={this.handleItemMouseEnter}
onItemMouseLeave={this.handleItemMouseLeave}
onItemSelected={this.handleItemSelected}
onRequestClose={this.props.onRequestClose}
/>
: null
);
}
}
Expand All @@ -181,11 +183,13 @@ SoundLibrary.propTypes = {
isRtl: PropTypes.bool,
onNewSound: PropTypes.func.isRequired,
onRequestClose: PropTypes.func,
vm: PropTypes.instanceOf(VM).isRequired
vm: PropTypes.instanceOf(VM).isRequired,
sounds: PropTypes.arrayOf(PropTypes.object)
};

const mapStateToProps = state => ({
isRtl: state.locales.isRtl
isRtl: state.locales.isRtl,
sounds: state.assets.sounds,
});

const mapDispatchToProps = () => ({});
Expand Down
7 changes: 5 additions & 2 deletions src/containers/sound-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import RecordModal from './record-modal.jsx';
import SoundEditor from './sound-editor.jsx';
import SoundLibrary from './sound-library.jsx';

import soundLibraryContent from '../lib/libraries/sounds.json';
import {handleFileUpload, soundUpload} from '../lib/file-uploader.js';
import errorBoundaryHOC from '../lib/error-boundary-hoc.jsx';
import DragConstants from '../lib/drag-constants';
Expand Down Expand Up @@ -111,6 +110,8 @@ class SoundTab extends React.Component {
}

handleSurpriseSound () {
// TODO: maybe wrap this code inside if statement this.props.sounds
const soundLibraryContent = this.props.sounds;
const soundItem = soundLibraryContent[Math.floor(Math.random() * soundLibraryContent.length)];
const vmSound = {
format: soundItem.dataFormat,
Expand Down Expand Up @@ -289,6 +290,7 @@ SoundTab.propTypes = {
onShowImporting: PropTypes.func.isRequired,
soundLibraryVisible: PropTypes.bool,
soundRecorderVisible: PropTypes.bool,
sounds: PropTypes.arrayOf(PropTypes.object),
sprites: PropTypes.shape({
id: PropTypes.shape({
sounds: PropTypes.arrayOf(PropTypes.shape({
Expand All @@ -310,7 +312,8 @@ const mapStateToProps = state => ({
sprites: state.scratchGui.targets.sprites,
stage: state.scratchGui.targets.stage,
soundLibraryVisible: state.scratchGui.modals.soundLibrary,
soundRecorderVisible: state.scratchGui.modals.soundRecorder
soundRecorderVisible: state.scratchGui.modals.soundRecorder,
sounds: state.assets.sounds
});

const mapDispatchToProps = dispatch => ({
Expand Down
Loading