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

Blocks Update - Bug fixes #358

Merged
merged 7 commits into from
Sep 21, 2016
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
2 changes: 1 addition & 1 deletion funblocks-client/src/Blocks/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ blockTypes = [
,cwTranslucent
,cwRGBA
-- LOGIC
,conIf
-- ,conIf
,conAnd
,conOr
,conNot
Expand Down
13 changes: 13 additions & 0 deletions funblocks-client/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,18 @@ runOrError ws = do
liftIO $ js_cwcompile (pack code)


-- Update the hash on the workspace
-- Mainly so that broken programs can be shared
updateCode :: Workspace -> IO ()
updateCode ws = do
(code,errors) <- workspaceToCode ws
liftIO $ js_updateEditor (pack code)
liftIO $ js_cwcompilesilent (pack code)


btnRunClick ws = do
Just doc <- liftIO currentDocument
liftIO $ updateCode ws
blocks <- liftIO $ getTopBlocks ws
(block, w) <- liftIO $ isWarning ws
if T.length w > 0 then do
Expand Down Expand Up @@ -149,6 +159,9 @@ setRunFunc ws = do
foreign import javascript unsafe "compile($1)"
js_cwcompile :: JSString -> IO ()

foreign import javascript unsafe "compile($1,true)"
js_cwcompilesilent :: JSString -> IO ()

-- call blockworld.js run
-- run (xmlHash, codeHash, msg, error)
foreign import javascript unsafe "run()"
Expand Down
2 changes: 1 addition & 1 deletion third_party/blockly
1 change: 1 addition & 0 deletions web/blocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<script src="blockly/blocks/lists.js"></script>
<!-- CodeWorld blocks -->
<script src="js/blocks/cw-text.js"></script>
<script src="js/blocks/cw-logic.js"></script>
<script src="js/blocks/cw-tuples.js"></script>
<script src="js/blocks/cw-pictures.js"></script>
<script src="js/blocks/cw-math.js"></script>
Expand Down
1 change: 1 addition & 0 deletions web/help/blockframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<script src="../blockly/blocks/lists.js"></script>
<!-- CodeWorld blocks -->
<script src="../js/blocks/cw-text.js"></script>
<script src="../js/blocks/cw-logic.js"></script>
<script src="../js/blocks/cw-tuples.js"></script>
<script src="../js/blocks/cw-pictures.js"></script>
<script src="../js/blocks/cw-math.js"></script>
Expand Down
38 changes: 38 additions & 0 deletions web/js/blocks/cw-logic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2016 The CodeWorld Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

goog.provide('Blockly.Blocks.cwLogic');
goog.require('Blockly.Blocks');

var colorPoly = 180;

Blockly.Blocks['conIf'] = {
init: function() {
this.setColour(colorPoly);
this.appendValueInput('IF')
.appendField('if');
this.appendValueInput('THEN')
.appendField('then');
this.appendValueInput('ELSE')
.appendField('else');
this.setInputsInline(true);
this.setOutput(true);
Blockly.TypeInf.defineFunction("if", Type.fromList([Type.Lit("Truth"), Type.Var("a"), Type.Var("a"), Type.Var("a")]));
this.setAsFunction("if");
}
};
20 changes: 19 additions & 1 deletion web/js/blocks/cw-pictures.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,25 @@ Blockly.Blocks['cwCombine'] = {
tps.push(Type.Lit("Picture"));
this.arrows = Type.fromList(tps);
this.initArrows();

},
saveConnections: function(containerBlock) {
var itemBlock = containerBlock.getInputTargetBlock('STACK');
var x = 0;
while (itemBlock) {
var input = this.getInput('PIC' + x);
if(input && input.connection.targetConnection){
if(input.connection.targetBlock().isShadow_){
x++;
itemBlock = itemBlock.nextConnection &&
itemBlock.nextConnection.targetBlock();
continue;
}
}
itemBlock.valueConnection_ = input && input.connection.targetConnection;
x++;
itemBlock = itemBlock.nextConnection &&
itemBlock.nextConnection.targetBlock();
}
}
};

Expand Down
20 changes: 20 additions & 0 deletions web/js/blocks/cw-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@ Blockly.Blocks['txtConcat'] = {
this.arrows = Type.fromList(tps);
this.initArrows();
},

saveConnections: function(containerBlock) {
var itemBlock = containerBlock.getInputTargetBlock('STACK');
var x = 0;
while (itemBlock) {
var input = this.getInput('STR' + x);
if(input && input.connection.targetConnection){
if(input.connection.targetBlock().isShadow_){
x++;
itemBlock = itemBlock.nextConnection &&
itemBlock.nextConnection.targetBlock();
continue;
}
}
itemBlock.valueConnection_ = input && input.connection.targetConnection;
x++;
itemBlock = itemBlock.nextConnection &&
itemBlock.nextConnection.targetBlock();
}
}
};

Blockly.Blocks['text_combine_ele'] = {
Expand Down
3 changes: 3 additions & 0 deletions web/js/blocks/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ goog.require('Blockly.Blocks.cwEvent');
Blockly.Flyout.programBlockList = ["cwAnimationOf", "cwDrawingOf", "cwSimulationOf","cwInteractionOf" ];
// Automatically generate a type block for each of these
Blockly.UserTypes.builtinsStatic = ["Truth", "Number", "Color", "Picture", "Text"];

Blockly.UserTypes.userReservedNames = ['do','let','in','if','then','else','data','type','newtype','import','qualified']

// Add a these blockTypes to the toolbox
Blockly.UserTypes.builtinsDynamic = ["type_list"];
// Enable the Event drawer
Expand Down
23 changes: 13 additions & 10 deletions web/js/funblocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,17 @@ function run(xmlHash, codeHash, msg, error, dhash) {
document.getElementById('message').style.display = 'none';
}


var message = document.getElementById('message');
message.innerHTML = '';
addToMessage(msg);

if (error) {
message.classList.add('error');
} else {
message.classList.remove('error');

if(msg){
var message = document.getElementById('message');
message.innerHTML = '';
addToMessage(msg);

if (error) {
message.classList.add('error');
} else {
message.classList.remove('error');
}
}

document.getElementById('editButton').setAttribute('href','/#' + codeHash);
Expand Down Expand Up @@ -186,7 +188,7 @@ function isEditorClean()
return !containsUnsavedChanges();
}

function compile(src) {
function compile(src,silent) {
run('', '', 'Compiling...', false);

var xml_text = getWorkspaceXMLText();
Expand Down Expand Up @@ -228,6 +230,7 @@ function compile(src) {
} else if (request.status == 404) {
msg = "Sorry! Your program couldn't be run right now. Please try again.";
}
if(silent) msg = null;

if (success) {
run(xmlHash, hash, 'Running...\n\n' + msg, false, dhash);
Expand Down