Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Goessmann
logging-scratch-gui
Commits
717c7738
Commit
717c7738
authored
6 years ago
by
Christopher Willis-Ford
Browse files
Options
Downloads
Patches
Plain Diff
add block type check in `defineDynamicBlock`
parent
935a4520
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/containers/blocks.jsx
+32
-10
32 additions, 10 deletions
src/containers/blocks.jsx
with
32 additions
and
10 deletions
src/containers/blocks.jsx
+
32
−
10
View file @
717c7738
...
...
@@ -7,6 +7,7 @@ import React from 'react';
import
VMScratchBlocks
from
'
../lib/blocks
'
;
import
VM
from
'
scratch-vm
'
;
import
ArgumentType
from
'
scratch-vm/src/extension-support/argument-type
'
;
// :(
import
BlockType
from
'
scratch-vm/src/extension-support/block-type
'
;
// :(
import
log
from
'
../lib/log.js
'
;
import
Prompt
from
'
./prompt.jsx
'
;
...
...
@@ -50,7 +51,7 @@ const DroppableBlocks = DropAreaHOC([
// TODO: grow this until it can fully replace `_convertForScratchBlocks` in the VM runtime
// :( where should this live?
const
defineDynamicBlock
=
(
categoryInfo
,
extendedOpcode
)
=>
({
const
defineDynamicBlock
=
(
ScratchBlocks
,
categoryInfo
,
extendedOpcode
)
=>
({
init
:
function
()
{
const
blockJson
=
{
type
:
extendedOpcode
,
...
...
@@ -81,8 +82,29 @@ const defineDynamicBlock = (categoryInfo, extendedOpcode) => ({
const
blockInfo
=
JSON
.
parse
(
blockInfoText
);
this
.
interpolate_
(
blockInfo
.
text
,
[]);
this
.
setPreviousStatement
(
true
);
this
.
setNextStatement
(
!
blockInfo
.
isTerminal
);
switch
(
blockInfo
.
blockType
)
{
case
BlockType
.
COMMAND
:
case
BlockType
.
CONDITIONAL
:
case
BlockType
.
LOOP
:
this
.
setOutputShape
(
ScratchBlocks
.
OUTPUT_SHAPE_SQUARE
);
this
.
setPreviousStatement
(
true
);
this
.
setNextStatement
(
!
blockInfo
.
isTerminal
);
break
;
case
BlockType
.
REPORTER
:
this
.
setOutput
(
'
String
'
);
// TODO: distinguish number & string here?
this
.
setOutputShape
(
ScratchBlocks
.
OUTPUT_SHAPE_ROUND
);
break
;
case
BlockType
.
BOOLEAN
:
this
.
setOutput
(
'
Boolean
'
);
this
.
setOutputShape
(
ScratchBlocks
.
OUTPUT_SHAPE_HEXAGONAL
);
break
;
case
BlockType
.
HAT
:
case
BlockType
.
EVENT
:
this
.
setOutputShape
(
ScratchBlocks
.
OUTPUT_SHAPE_SQUARE
);
this
.
setNextStatement
(
true
);
break
;
}
}
});
...
...
@@ -469,13 +491,13 @@ class Blocks extends React.Component {
this
.
ScratchBlocks
.
defineBlocksWithJsonArray
(
staticBlocksJson
);
dynamicBlocksInfo
.
forEach
(
blockInfo
=>
{
// This is creating the block factory / constructor -- NOT a specific instance of the block.
// The factory should only know static info about the block:
specifically
category info and the opcode.
// Anything else will be picked up from the XML attached to the block instance.
const
extendedOpcode
=
`
${
categoryInfo
.
id
}
_
${
blockInfo
.
info
.
opcode
}
`
;
const
blockDefinition
=
defineDynamicBlock
(
categoryInfo
,
extendedOpcode
);
this
.
ScratchBlocks
.
Blocks
[
extendedOpcode
]
=
blockDefinition
;
});
// This is creating the block factory / constructor -- NOT a specific instance of the block.
// The factory should only know static info about the block:
the
category info and the opcode.
// Anything else will be picked up from the XML attached to the block instance.
const
extendedOpcode
=
`
${
categoryInfo
.
id
}
_
${
blockInfo
.
info
.
opcode
}
`
;
const
blockDefinition
=
defineDynamicBlock
(
this
.
ScratchBlocks
,
categoryInfo
,
extendedOpcode
);
this
.
ScratchBlocks
.
Blocks
[
extendedOpcode
]
=
blockDefinition
;
});
}
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment