Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 10 additions & 3 deletions src/components/gui/gui.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import Alerts from '../../containers/alerts.jsx';
import DragLayer from '../../containers/drag-layer.jsx';
import ConnectionModal from '../../containers/connection-modal.jsx';

import {rubyCodesShape} from '../../reducers/ruby-codes.js';

import layout, {STAGE_SIZE_MODES} from '../../lib/layout-constants';
import {resolveStageSize} from '../../lib/screen-utils';

Expand Down Expand Up @@ -102,7 +104,7 @@ const GUIComponent = props => {
stageSizeMode,
targetIsStage,
tipsLibraryVisible,
rubyCode,
rubyCodes,
vm,
...componentProps
} = omit(props, 'dispatch');
Expand Down Expand Up @@ -308,7 +310,12 @@ const GUIComponent = props => {
{soundsTabVisible ? <SoundTab vm={vm} /> : null}
</TabPanel>
<TabPanel className={tabClassNames.tabPanel}>
{rubyTabVisible ? <RubyTab rubyCode={rubyCode} /> : null}
{rubyTabVisible ? (
<RubyTab
rubyCodes={rubyCodes}
vm={vm}
/>
) : null}
</TabPanel>
</Tabs>
{backpackOptions.visible ? (
Expand Down Expand Up @@ -380,7 +387,7 @@ GUIComponent.propTypes = {
onToggleLoginOpen: PropTypes.func,
onUpdateProjectTitle: PropTypes.func,
renderLogin: PropTypes.func,
rubyCode: PropTypes.string,
rubyCodes: rubyCodesShape,
rubyTabVisible: PropTypes.bool,
showComingSoon: PropTypes.bool,
soundsTabVisible: PropTypes.bool,
Expand Down
18 changes: 13 additions & 5 deletions src/containers/blocks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {updateToolbox} from '../reducers/toolbox';
import {activateColorPicker} from '../reducers/color-picker';
import {closeExtensionLibrary, openSoundRecorder, openConnectionModal} from '../reducers/modals';
import {activateCustomProcedures, deactivateCustomProcedures} from '../reducers/custom-procedures';
import {updateRubyCode} from '../reducers/ruby-code.js';
import {setGenerator, updateRubyCode} from '../reducers/ruby-codes.js';
import {setConnectionModalExtensionId} from '../reducers/connection-modal';

import {
Expand All @@ -52,6 +52,7 @@ class Blocks extends React.Component {
super(props);
this.ScratchBlocks = VMScratchBlocks(props.vm);
this.ScratchBlocks = RubyGenerator(this.ScratchBlocks);
this.props.setGeneratorState(this.ScratchBlocks.Ruby);
bindAll(this, [
'attachVM',
'detachVM',
Expand Down Expand Up @@ -171,7 +172,8 @@ class Blocks extends React.Component {
}
if (!this.props.blocksTabVisible) {
this.props.updateRubyCodeState(
this.ScratchBlocks.Ruby.workspaceToCode(this.workspace, this.props.vm.editingTarget)
this.props.vm.editingTarget,
this.workspace
);
}
}
Expand Down Expand Up @@ -279,7 +281,8 @@ class Blocks extends React.Component {
}
if (!this.props.blocksTabVisible) {
this.props.updateRubyCodeState(
this.ScratchBlocks.Ruby.workspaceToCode(this.workspace, this.props.vm.editingTarget)
this.props.vm.editingTarget,
this.workspace
);
}
}
Expand Down Expand Up @@ -449,6 +452,7 @@ class Blocks extends React.Component {
onOpenConnectionModal,
onOpenSoundRecorder,
updateToolboxState,
setGeneratorState,
updateRubyCodeState,
onActivateCustomProcedures,
onRequestCloseExtensionLibrary,
Expand Down Expand Up @@ -532,6 +536,7 @@ Blocks.propTypes = {
comments: PropTypes.bool,
collapse: PropTypes.bool
}),
setGeneratorState: PropTypes.func,
stageSize: PropTypes.oneOf(Object.keys(STAGE_DISPLAY_SIZES)).isRequired,
toolboxXML: PropTypes.string,
updateRubyCodeState: PropTypes.func,
Expand Down Expand Up @@ -606,8 +611,11 @@ const mapDispatchToProps = dispatch => ({
updateToolboxState: toolboxXML => {
dispatch(updateToolbox(toolboxXML));
},
updateRubyCodeState: code => {
dispatch(updateRubyCode(code));
setGeneratorState: generator => {
dispatch(setGenerator(generator));
},
updateRubyCodeState: (target, workspace) => {
dispatch(updateRubyCode(target, workspace));
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/containers/gui.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const mapStateToProps = state => {
soundsTabVisible: state.scratchGui.editorTab.activeTabIndex === SOUNDS_TAB_INDEX,
tipsLibraryVisible: state.scratchGui.modals.tipsLibrary,
rubyTabVisible: state.scratchGui.editorTab.activeTabIndex === RUBY_TAB_INDEX,
rubyCode: state.scratchGui.rubyCode.code,
rubyCodes: state.scratchGui.rubyCodes,
vm: state.scratchGui.vm
};
};
Expand Down
30 changes: 27 additions & 3 deletions src/containers/ruby-downloader.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 {connect} from 'react-redux';
import {projectTitleInitialState} from '../reducers/project-title';
import {rubyCodesShape} from '../reducers/ruby-codes';

class RubyDownloader extends React.Component {
constructor (props) {
Expand All @@ -12,7 +13,21 @@ class RubyDownloader extends React.Component {
]);
}
saveRuby () {
const code = `require "smalruby3"\n\n${this.props.rubyCode}`;
let code = 'require "smalruby3"\n';
const generator = this.props.rubyCodes.generator;
const sprites = [this.props.stage];
for (const id in this.props.sprites) {
const sprite = this.props.sprites[id];
sprites[sprite.order + 1] = sprite;
}
sprites.forEach(sprite => {
const rubyCode = this.props.rubyCodes.rubyCode[sprite.id];
if (rubyCode) {
const spriteNewCode = generator.spriteNew(rubyCode.target);
const bodyCode = rubyCode.code ? generator.prefixLines(rubyCode.code, generator.INDENT) : '';
code += `\n${spriteNewCode} do\n${bodyCode}end\n`;
}
});
return new Blob([code], {
type: 'text/x-ruby-script'
});
Expand Down Expand Up @@ -60,12 +75,21 @@ RubyDownloader.propTypes = {
children: PropTypes.func,
onSaveFinished: PropTypes.func,
projectFilename: PropTypes.string,
rubyCode: PropTypes.string
rubyCodes: rubyCodesShape,
sprites: PropTypes.objectOf(PropTypes.shape({
id: PropTypes.string.isRequired,
order: PropTypes.number.isRequired
})),
stage: PropTypes.shape({
id: PropTypes.string
})
};

const mapStateToProps = state => ({
projectFilename: getProjectFilename(state.scratchGui.projectTitle, projectTitleInitialState),
rubyCode: state.scratchGui.rubyCode.code
rubyCodes: state.scratchGui.rubyCodes,
sprites: state.scratchGui.targets.sprites,
stage: state.scratchGui.targets.stage
});

export default connect(
Expand Down
56 changes: 31 additions & 25 deletions src/containers/ruby-tab.jsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
import PropTypes from 'prop-types';
import React from 'react';
import AceEditor from 'react-ace';
import VM from 'scratch-vm';
import {rubyCodesShape} from '../reducers/ruby-codes.js';

import 'brace/mode/ruby';
import 'brace/theme/clouds';

const RubyTab = ({rubyCode}) => (
<AceEditor
readOnly
editorProps={{$blockScrolling: true}}
fontSize={16}
height="inherit"
mode="ruby"
name="ruby-editor"
setOptions={{
tabSize: 2,
useSoftTabs: true,
showInvisibles: true
}}
style={{
fontFamily: ['Monaco', 'Menlo', 'Consolas', 'source-code-pro', 'monospace'],
borderTopRightRadius: '0.5rem',
borderBottomRightRadius: '0.5rem',
border: '1px solid hsla(0, 0%, 0%, 0.15)'
}}
theme="clouds"
value={rubyCode}
width="100%"
/>
);
const RubyTab = function (props) {
const rubyCode = props.rubyCodes.rubyCode[props.vm.editingTarget.id];
return (
<AceEditor
readOnly
editorProps={{$blockScrolling: true}}
fontSize={16}
height="inherit"
mode="ruby"
name="ruby-editor"
setOptions={{
tabSize: 2,
useSoftTabs: true,
showInvisibles: true
}}
style={{
fontFamily: ['Monaco', 'Menlo', 'Consolas', 'source-code-pro', 'monospace'],
borderTopRightRadius: '0.5rem',
borderBottomRightRadius: '0.5rem',
border: '1px solid hsla(0, 0%, 0%, 0.15)'
}}
theme="clouds"
value={rubyCode ? rubyCode.code : ''}
width="100%"
/>
);
};

RubyTab.propTypes = {
rubyCode: PropTypes.string
rubyCodes: rubyCodesShape,
vm: PropTypes.instanceOf(VM).isRequired
};

export default RubyTab;
8 changes: 1 addition & 7 deletions src/lib/ruby-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ export default function (Blockly) {
}
}
}
if (!this.editingTarget &&
requires.length === 0 &&
if (requires.length === 0 &&
prepares.length === 0 &&
defs.length === 0 &&
code.length === 0) {
Expand All @@ -284,11 +283,6 @@ export default function (Blockly) {
allDefs += `${defs.join('\n')}\n\n`;
}

if (this.editingTarget) {
const body = code ? this.prefixLines(code, this.INDENT) : '';
code = `${this.spriteNew(this.editingTarget)} do\n${body}end`;
}

return allDefs + code;
};

Expand Down
6 changes: 3 additions & 3 deletions src/reducers/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import targetReducer, {targetsInitialState} from './targets';
import toolboxReducer, {toolboxInitialState} from './toolbox';
import vmReducer, {vmInitialState} from './vm';
import vmStatusReducer, {vmStatusInitialState} from './vm-status';
import rubyCodeReducer, {rubyCodeInitialState} from './ruby-code';
import rubyCodesReducer, {rubyCodesInitialState} from './ruby-codes';
import throttle from 'redux-throttle';

import decks from '../lib/libraries/decks/index.jsx';
Expand Down Expand Up @@ -53,7 +53,7 @@ const guiInitialState = {
toolbox: toolboxInitialState,
vm: vmInitialState,
vmStatus: vmStatusInitialState,
rubyCode: rubyCodeInitialState
rubyCodes: rubyCodesInitialState
};

const initPlayer = function (currentState) {
Expand Down Expand Up @@ -122,7 +122,7 @@ const guiReducer = combineReducers({
toolbox: toolboxReducer,
vm: vmReducer,
vmStatus: vmStatusReducer,
rubyCode: rubyCodeReducer
rubyCodes: rubyCodesReducer
});

export {
Expand Down
30 changes: 0 additions & 30 deletions src/reducers/ruby-code.js

This file was deleted.

Loading