Skip to content

Commit

Permalink
address PR comments - dynamically change cows block
Browse files Browse the repository at this point in the history
  • Loading branch information
evemartin committed Sep 3, 2024
1 parent aa55222 commit f2231c9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
1 change: 0 additions & 1 deletion game/static/game/js/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ ocargo.Animation.prototype.addCows = function() {

for (let i = 0 ; i < cows.length ; i++){
let cow = cows[i];
console.log(cow.type);
for (let j = 0; j < cow.potentialNodes.length; j++) {
const cowImage = this.drawing.renderCow(cow.id, cow.potentialNodes[j].coordinate, cow.potentialNodes[j], 0, cow.type);
this.numberOfCowsOnMap++;
Expand Down
15 changes: 14 additions & 1 deletion game/static/game/js/blocklyCustomBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,26 @@ function initCustomBlocksDescription() {
init: function() {
this.setColour(210);
this.setOutput(true, 'Boolean');
console.log(ocargo.Drawing.animalType);
this.appendDummyInput()
.appendField(Blockly.Msg.COW_CROSSING_TITLE)
.appendField(ocargo.Drawing.animalType == "pigeon" ? "pigeons": Blockly.Msg.COW_CROSSING_TITLE)
.appendField(new Blockly.FieldImage(ocargo.Drawing.imageDir + ocargo.Drawing.whiteCowUrl,
ocargo.BlocklyControl.COW_WIDTH,
ocargo.BlocklyControl.BLOCK_HEIGHT), 'IMAGE');
}
};

Blockly.Blocks['pigeon_crossing_IMAGE_ONLY'] = {
init: function() {
this.setColour(210);
this.setOutput(true, 'Boolean');
this.appendDummyInput()
.appendField("pigeons")
.appendField(new Blockly.FieldImage(ocargo.Drawing.imageDir + ocargo.Drawing.pigeonUrl,
ocargo.BlocklyControl.COW_WIDTH,
ocargo.BlocklyControl.BLOCK_HEIGHT), 'IMAGE');
}
}
/****************/
/* Procedures */
/****************/
Expand Down
9 changes: 9 additions & 0 deletions game/static/game/js/drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ ocargo.Drawing = function (startingPosition) {
}

this.renderCow = function (id, coordinate, node, animationLength, type) {
console.log(type);
let res = this.determineCowOrientation(coordinate, node)
let image = paper.image(
ocargo.Drawing.raphaelImageDir + ocargo.Drawing.cowUrl(type),
Expand Down Expand Up @@ -1236,14 +1237,20 @@ ocargo.Drawing.renderCoins = function (coins) {
}

ocargo.Drawing.cowUrl = function (type) {
console.log(ocargo.Drawing.animalType)
//ocargo.Drawing.animalType = type;
switch (type) {
case ocargo.Cow.WHITE:
ocargo.Drawing.animalType = "white"
return ocargo.Drawing.whiteCowUrl
case ocargo.Cow.BROWN:
ocargo.Drawing.animalType = "brown"
return ocargo.Drawing.brownCowUrl
case ocargo.Cow.PIGEON:
ocargo.Drawing.animalType = "pigeon"
return ocargo.Drawing.pigeonUrl
default:
ocargo.Drawing.animalType = "white"
return ocargo.Drawing.whiteCowUrl
}
}
Expand Down Expand Up @@ -1290,3 +1297,5 @@ ocargo.Drawing.pigeonUrl = 'pigeon.svg'

ocargo.Drawing.imageDir = '/static/game/image/'
ocargo.Drawing.raphaelImageDir = '/static/game/raphael_image/'

ocargo.Drawing.animalType = 'WHITE'
19 changes: 19 additions & 0 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ ocargo.LevelEditor = function(levelId) {
for (var i = 0; i < BLOCKS.length; i++) {
var type = BLOCKS[i];
var block = Blockly.mainWorkspace.newBlock(type);
console.log(type);
block.initSvg();
block.render();

Expand Down Expand Up @@ -2959,6 +2960,24 @@ ocargo.LevelEditor = function(levelId) {
this.image.transform("t" + x + "," + y + " r" + r);
}

let cowsBlock = document.getElementById("cow_crossing_image");

let block = Blockly.mainWorkspace.newBlock("cow_crossing");

if (newType == ocargo.Cow.PIGEON) {
block = Blockly.mainWorkspace.newBlock("pigeon_crossing_IMAGE_ONLY");
}

block.initSvg();
block.render();
let svg = block.getSvgRoot();
let newContent = '<svg class="block_image">'
newContent += '<g transform="translate(10,0)"';
newContent += svg.innerHTML
newContent += '</g></svg>';

$("#cow_crossing_image").html(newContent);

setupCowListeners(this);
}

Expand Down
3 changes: 3 additions & 0 deletions game/templates/game/level_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ <h2 class="title"><img class="modal_image" src='{% static "game/image/icons/bloc
</div>

{% for block in blocks %}
<script>
console.log("{{block}}")
</script>
<div class="table_row">
<div class="table_cell">
<input type="checkbox" id="{{block}}_checkbox" class="block_checkbox" unchecked>
Expand Down

0 comments on commit f2231c9

Please sign in to comment.