Skip to content

Commit

Permalink
debug tools #15: tree shows current costume, see also #22
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLeoni committed Sep 6, 2020
1 parent 59afa86 commit 5547ded
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/components/botch/botch-life-tree-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import {injectIntl} from 'react-intl';
import getCostumeUrl from '../../lib/get-costume-url';
import log from '../../lib/log.js';


import LibraryItemComponent from '../../components/library-item/library-item.jsx';
Expand All @@ -23,10 +24,15 @@ class BotchLifeTreeItem extends React.PureComponent {
'startRotatingIcons',
'stopRotatingIcons'
]);

this.state = {
iconIndex: 0,
// iconIndex: 0,
// TO DO Botch: we added it, but don't like this
// https://github.com/CoderDojoTrento/botch-gui/issues/22
iconIndex: this.props.currentCostume,
isRotatingIcon: false
};
log.log('BotchLifeTreeItem state', this.state, 'props', this.props);
}
componentWillUnmount () {
clearInterval(this.intervalId);
Expand Down Expand Up @@ -58,7 +64,9 @@ class BotchLifeTreeItem extends React.PureComponent {
if (this.props.icons && this.props.icons.length) {
this.stopRotatingIcons();
this.setState({
isRotatingIcon: true
// TO DO Botch: we added it, but don't like this
// https://github.com/CoderDojoTrento/botch-gui/issues/22
// isRotatingIcon: true // disabled
}, this.startRotatingIcons);
}
}
Expand All @@ -81,8 +89,10 @@ class BotchLifeTreeItem extends React.PureComponent {
this.props.onMouseLeave(this.props.id);
}
startRotatingIcons () {
this.rotateIcon();
this.intervalId = setInterval(this.rotateIcon, 300);
// TO DO Botch: temporarily removed, but don't like this
// https://github.com/CoderDojoTrento/botch-gui/issues/22
// this.rotateIcon();
// this.intervalId = setInterval(this.rotateIcon, 300);
}
stopRotatingIcons () {
if (this.intervalId) {
Expand All @@ -109,9 +119,12 @@ class BotchLifeTreeItem extends React.PureComponent {

let iconURL;
let costume = this.props.icons[0];

if (costume.asset){ // Botch: our sprites have full asset data
if (this.props.icons &&
this.state.isRotatingIcon &&
// TO DO Botch: we added it, but don't like this
// https://github.com/CoderDojoTrento/botch-gui/issues/22
// this.state.isRotatingIcon &&
this.state.iconIndex < this.props.icons.length){
costume = this.props.icons[this.state.iconIndex];
}
Expand Down Expand Up @@ -164,8 +177,11 @@ BotchLifeTreeItem.propTypes = {
extensionId: PropTypes.string,
featured: PropTypes.bool,
hidden: PropTypes.bool,

iconMd5: PropTypes.string,
iconRawURL: PropTypes.string,
// TO DO Botch: we added it, but don't like this, right costume should be the first
currentCostume: PropTypes.number.isRequired,
icons: PropTypes.arrayOf(
PropTypes.shape({
asset: PropTypes.object, // Botch
Expand Down
4 changes: 4 additions & 0 deletions src/components/botch/botch-life-tree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class BotchLifeTree extends React.Component {
* @since botch-0.3
*/
renderTreeItem (dataItem){

return (<BotchLifeTreeItem
bluetoothRequired={dataItem.bluetoothRequired}
collaborator={dataItem.collaborator}
Expand All @@ -339,6 +340,9 @@ class BotchLifeTree extends React.Component {
iconMd5={(dataItem.json && dataItem.json.costumes[0]) ?
dataItem.json.costumes[0].md5ext : dataItem.md5}
iconRawURL={dataItem.rawURL}
// TO DO Botch: we added it, but don't like this
// https://github.com/CoderDojoTrento/botch-gui/issues/22
currentCostume={dataItem.json && dataItem.json.currentCostume}
icons={dataItem.json && dataItem.json.costumes}
id={dataItem.md5}
insetIconURL={dataItem.insetIconURL}
Expand Down

0 comments on commit 5547ded

Please sign in to comment.