Merge pull request #2427 from chrisgarrity/issue/sb2-mod-info

Add moderator info for sb2 projects
This commit is contained in:
chrisgarrity 2018-12-11 10:13:45 -05:00 committed by GitHub
commit 594ce06b5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 17 deletions

View file

@ -454,8 +454,8 @@ const PreviewPresentation = ({
</div> </div>
<ModInfo <ModInfo
revisedDate={revisedDate} revisedDate={revisedDate}
scripts={modInfo.scripts} scripts={modInfo.scriptCount}
sprites={modInfo.sprites} sprites={modInfo.spriteCount}
/> />
</React.Fragment> </React.Fragment>
@ -608,8 +608,8 @@ PreviewPresentation.propTypes = {
loveCount: PropTypes.number, loveCount: PropTypes.number,
loved: PropTypes.bool, loved: PropTypes.bool,
modInfo: PropTypes.shape({ modInfo: PropTypes.shape({
scripts: PropTypes.number, scriptCount: PropTypes.number,
sprites: PropTypes.number spriteCount: PropTypes.number
}), }),
moreCommentsToLoad: PropTypes.bool, moreCommentsToLoad: PropTypes.bool,
onAddComment: PropTypes.func, onAddComment: PropTypes.func,

View file

@ -99,8 +99,8 @@ class Preview extends React.Component {
justShared: false, justShared: false,
loveCount: 0, loveCount: 0,
modInfo: { modInfo: {
scripts: 0, scriptCount: 0,
sprites: 0 spriteCount: 0
}, },
projectId: parts[1] === 'editor' ? '0' : parts[1], projectId: parts[1] === 'editor' ? '0' : parts[1],
reportOpen: false, reportOpen: false,
@ -245,18 +245,28 @@ class Preview extends React.Component {
} }
}); });
} }
const sprites = projectData[0].targets.length - 1; // don't count stage let spriteCount = 0;
const scripts = projectData[0].targets let scriptCount = 0;
.map(target => if (projectData[0].projectVersion) {
Object.values(target.blocks) if (projectData[0].projectVersion === 3) {
.filter(block => block.topLevel).length spriteCount = projectData[0].targets.length - 1; // don't count stage
) scriptCount = projectData[0].targets
.reduce((accumulator, currentVal) => accumulator + currentVal, 0); .map(target =>
Object.values(target.blocks)
.filter(block => block.topLevel).length
)
.reduce((accumulator, currentVal) => accumulator + currentVal, 0);
} else if (projectData[0].projectVersion === 2) { // sb2 file
spriteCount = projectData[0].info.spriteCount;
scriptCount = projectData[0].info.scriptCount;
}
} // else sb (scratch 1.x) numbers will be zero
this.setState({ this.setState({
extensions: Array.from(extensionSet), extensions: Array.from(extensionSet),
modInfo: { modInfo: {
scripts: scripts, scriptCount: scriptCount,
sprites: sprites spriteCount: spriteCount
} }
}); });
}); });
@ -265,8 +275,8 @@ class Preview extends React.Component {
this.setState({ this.setState({
extensions: [], extensions: [],
modInfo: { modInfo: {
scripts: 0, scriptCount: 0,
sprites: 0 spriteCount: 0
} }
}); });
} }