Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Marielle committed Mar 6, 2024
2 parents d53358a + 6ba6f2f commit 2087da4
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 76 deletions.
2 changes: 1 addition & 1 deletion ext/codecast/7.4/index.js

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions pemFioi/assortElements-1.0.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
function AssortElements(params) {
let { paper, elemW, elemH, elements, dropZones, attr, dropCallback, ordered, displayHelper } = params;
let { paper, elemW, elemH, elements, dropZones, attr, dropCallback, ordered, ghostBackOpacity, drawElement, displayHelper } = params;
let zoneIDs = [];
let elementsObject = {};

this.dragAndDrop;
this.test = 3;
drawElement = drawElement || defaultDrawElement;
let self = this;
init();

Expand Down Expand Up @@ -37,17 +38,22 @@ function AssortElements(params) {
}
},
actionIfDropped : function(srcCont, srcPos, dstCont, dstPos, dropType) {
let id = this.getObjects(srcCont)[srcPos];
// console.log(id)
if(!ordered && zoneIDs.includes(dstCont)){
let currObj = this.getObjects(dstCont);
for(var pos = 0; pos <= dstPos; pos++){
if(currObj[pos] == null){
if(srcCont == dstCont){
return DragAndDropSystem.action(dstCont,pos - 1,'replace');
}

return DragAndDropSystem.action(dstCont,pos,'replace');
}
}
}else if(dstCont == null){
return DragAndDropSystem.action(id,0,'replace');
}else if(!zoneIDs.includes(dstCont)){
return false
}
return true
},
Expand All @@ -67,6 +73,9 @@ function AssortElements(params) {
let cx = elem.pos.x + w/2;
let cy = elem.pos.y + h/2;
let background = (attr.srcCont) ? paper.rect(-w/2,-h/2,w,h).attr(attr.srcCont) : null;
if(ghostBackOpacity){
background = drawElement(elem,0,0).attr("opacity",ghostBackOpacity);
}
self.dragAndDrop.addContainer({
ident: id, cx, cy,
widthPlace : w,
Expand Down Expand Up @@ -125,7 +134,7 @@ function AssortElements(params) {
}
};

function drawElement(elem,cx,cy) {
function defaultDrawElement(elem,cx,cy) {
let w = elemW, h = elemH;
let x = cx - w/2;
let y = cy - h/2;
Expand Down
52 changes: 52 additions & 0 deletions pemFioi/blocklyCrane_lib-1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,58 @@
var dustUrl = "crane/dust.png";
var spotlightUrl = "crane/spotlight.png";

/* variant functions */

function swapColumns(grid, col1, col2) {
for (var row = 0; row < grid.length; row++) {
tmp = grid[row][col1];
grid[row][col1] = grid[row][col2];
grid[row][col2] = tmp;
}
return grid;
}
function swapRows(grid, row1, row2) {
tmp = grid[row1];
grid[row1] = grid[row2];
grid[row2] = tmp;
return grid;
}
function swapBricks(grid, type1, type2) {
for (var row = 0; row < grid.length; row++) {
for (var col = 0; col < grid[0].length; col++) {
var type = grid[row][col];
if (type == type1) {
type = type2;
} else if (grid[row][col] == type2) {
type = type1;
}
grid[row][col] = type;
}
}
return grid;
}
function revertHorizontal(grid) {
var nbCols = grid[0].length;
for (var row = 0; row < grid.length; row++) {
for (var col = 0; col < nbCols / 2; col++) {
var tmp = grid[row][col];
grid[row][col] = grid[row][nbCols - 1 - col];
grid[row][nbCols - 1 - col] = tmp;
}
}
return grid;
}
function removeRow(grid, row) {
grid.splice(row, 1);
return grid;
}
function removeColumn(grid, column) {
for (var row = 0; row < grid.length; row++) {
grid[row].splice(column, 1);
}
return grid;
}

var getContext = function(display, infos, curLevel) {
var localLanguageStrings = {
fr: {
Expand Down
5 changes: 4 additions & 1 deletion pemFioi/graph-mouse-1.4.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ function VertexDragAndConnect(settings) {
}

this.startHandler = function(x, y, event) {
// console.log("startHandler")
if(self.unselectAllEdges){
self.unselectAllEdges();
}
Expand Down Expand Up @@ -2827,11 +2828,13 @@ function GraphEditor(settings) {
});
};

this.writeContent = function(id) {
this.writeContent = function(id,cont) {
// console.log(id);
var info = graph.getVertexInfo(id);
var oldContent = info.content || "";
var newContent = (self.textEditor) ? self.textEditor.val().trim() : "";
if(cont)
newContent = cont;

var raphElement = visualGraph.getRaphaelsFromID(id);
if(oldContent !== newContent){
Expand Down
75 changes: 55 additions & 20 deletions pemFioi/quickpi/blocklyQuickPi_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -3657,7 +3657,7 @@ var getContext = function (display, infos, curLevel) {
if (area < 218700)
{
context.compactLayout = true;
}
}

if (context.sensorDivisions) {
context.sensorDivisions.remove();
Expand Down Expand Up @@ -3801,6 +3801,9 @@ var getContext = function (display, infos, curLevel) {
geometry = squareSize(paper.width, paper.height, nSensors, 2);
else
geometry = squareSize(paper.width, paper.height, nSensors, 1);

// console.log(geometry)
var cellW = paper.width / geometry.rows;

context.sensorSize = geometry.size * .10;

Expand All @@ -3822,7 +3825,7 @@ var getContext = function (display, infos, curLevel) {
});

for (var row = 0; row < geometry.rows; row++) {
var x = paper.width / geometry.rows * row;
var x = cellW * row;
var y1 = y + geometry.size / 4;
var y2 = y + geometry.size * 3 / 4;
var cells = 1;
Expand Down Expand Up @@ -3902,8 +3905,9 @@ var getContext = function (display, infos, curLevel) {
sensor.drawInfo = {
x: x,
y: y,
width: (paper.width / geometry.rows) * cells,
height: geometry.size
width: cellW * cells,
height: geometry.size,
// cellW: cellW
}

drawSensor(sensor);
Expand Down Expand Up @@ -6487,6 +6491,13 @@ var getContext = function (display, infos, curLevel) {
state1y = imgy;
stateanchor = 'start';
}
if(sensor.type == "buzzer"){
var sizeRatio = imgw/sensor.drawInfo.width;
if(sizeRatio > 0.75){
imgw = 0.75*sensor.drawInfo.width;
imgh = imgw;
}
}


var portx = state1x;
Expand All @@ -6504,6 +6515,9 @@ var getContext = function (display, infos, curLevel) {
var statesize = sensor.drawInfo.height * 0.10;

var namesize = sensor.drawInfo.height * 0.15;

var maxNameSize = 25;
var maxStateSize = 20;



Expand All @@ -6512,17 +6526,18 @@ var getContext = function (display, infos, curLevel) {

drawPortText = false;

if (!sensor.focusrect || isElementRemoved(sensor.focusrect))
if (!sensor.focusrect || isElementRemoved(sensor.focusrect)){
sensor.focusrect = paper.rect(imgx, imgy, imgw, imgh);
}

sensor.focusrect.attr({
"fill": "468DDF",
"fill-opacity": 0,
"opacity": 0,
"x": imgx,
"y": imgy,
"width": imgw,
"height": imgh,
"fill": "468DDF",
"fill-opacity": 0,
"opacity": 0,
"x": imgx,
"y": imgy,
"width": imgw,
"height": imgh,
});

if (context.autoGrading) {
Expand Down Expand Up @@ -6551,6 +6566,9 @@ var getContext = function (display, infos, curLevel) {
namesize = portsize;
nameanchor = "start";
}
namesize = Math.min(namesize,maxNameSize);
statesize = Math.min(statesize,maxStateSize);



if (sensor.type == "led") {
Expand Down Expand Up @@ -6635,8 +6653,7 @@ var getContext = function (display, infos, curLevel) {
findSensorDefinition(sensor).setLiveState(sensor, sensor.state, function(x) {});
}

} else if (sensor.type == "buzzer") {

} else if (sensor.type == "buzzer") {
if(typeof sensor.state == 'number' &&
sensor.state != 0 &&
sensor.state != 1) {
Expand All @@ -6653,10 +6670,11 @@ var getContext = function (display, infos, curLevel) {
}


var muteBtnSize = sensor.drawInfo.width * 0.15;
// var muteBtnSize = sensor.drawInfo.width * 0.15;
var muteBtnSize = imgw * 0.3;
sensor.muteBtn = paper.text(
imgx + imgw,
imgy + (imgh / 2),
imgx + imgw*0.8,
imgy + imgh*0.8,
buzzerSound.isMuted(sensor.name) ? "\uf6a9" : "\uf028"
);
sensor.muteBtn.node.style.fontWeight = "bold";
Expand All @@ -6667,8 +6685,11 @@ var getContext = function (display, infos, curLevel) {
"font-size": muteBtnSize + "px",
fill: buzzerSound.isMuted(sensor.name) ? "lightgray" : "#468DDF",
"font-family": '"Font Awesome 5 Free"',
'text-anchor': 'start'
});
'text-anchor': 'start',
"cursor": "pointer"
});
var bbox = sensor.muteBtn.getBBox();

sensor.muteBtn.click(function () {
if(buzzerSound.isMuted(sensor.name)) {
buzzerSound.unmute(sensor.name)
Expand All @@ -6677,6 +6698,7 @@ var getContext = function (display, infos, curLevel) {
}
drawSensor(sensor);
});
sensor.muteBtn.toFront();
}


Expand Down Expand Up @@ -8271,13 +8293,23 @@ var getContext = function (display, infos, curLevel) {
sensor.nameText = paper.text(namex, namey, sensor.name );
sensor.nameText.attr({ "font-size": namesize + "px", 'text-anchor': nameanchor, fill: "#7B7B7B" });
sensor.nameText.node.style = "-moz-user-select: none; -webkit-user-select: none;";
var bbox = sensor.nameText.getBBox();
if(bbox.width > sensor.drawInfo.width - 20){
namesize = namesize*(sensor.drawInfo.width - 20)/bbox.width;
namey += namesize*(1 - (sensor.drawInfo.width - 20)/bbox.width);
sensor.nameText.attr({
"font-size":namesize,
y: namey });
}
}
}


if (!donotmovefocusrect) {
// This needs to be in front of everything
sensor.focusrect.toFront();
if(sensor.muteBtn)
sensor.muteBtn.toFront();
}

saveSensorStateIfNotRunning(sensor);
Expand Down Expand Up @@ -10652,6 +10684,9 @@ function hideSlider(sensor) {
}


if (sensor.focusrect && sensor.focusrect.paper && sensor.focusrect.paper.canvas)
if (sensor.focusrect && sensor.focusrect.paper && sensor.focusrect.paper.canvas){
sensor.focusrect.toFront();
if(sensor.muteBtn)
sensor.muteBtn.toFront();
}
};
Loading

0 comments on commit 2087da4

Please sign in to comment.