Skip to content

Commit acfe3ab

Browse files
authored
Merge pull request code-dot-org#10153 from code-dot-org/planter
Add new Planter Subtype
2 parents 4c2ada7 + 80e995f commit acfe3ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+619
-28
lines changed

apps/i18n/maze/en_us.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"cornTooltip": "Harvest some corn",
1919
"didNotCollectAllCrops": "Make sure you don't leave any crops behind!",
2020
"didNotCollectEverything": "Make sure you don't leave any nectar or honey behind!",
21+
"didNotPlantEverywhere": "Make sure you plant something in every soil patch!",
2122
"dig": "remove 1",
2223
"digTooltip": "remove 1 unit of dirt",
2324
"dirE": "E",
@@ -80,6 +81,9 @@
8081
"pathRight": "if path to the right",
8182
"pick": "pick",
8283
"pilePresent": "there is a pile",
84+
"plant": "plant",
85+
"plantInNonSoilError": "I can only plant something in fresh soil.",
86+
"plantTooltip": "Plant a sprout",
8387
"pumpkin": "pumpkin",
8488
"pumpkinTooltip": "Harvest a pumpkin",
8589
"putdownTower": "put down tower",
@@ -92,6 +96,8 @@
9296
"repeatUntil": "repeat until",
9397
"repeatUntilBlocked": "while path ahead",
9498
"repeatUntilFinish": "repeat until finish",
99+
"soil": "soil",
100+
"sprout": "sprout",
95101
"step": "Step",
96102
"totalHoney": "total honey",
97103
"totalNectar": "total nectar",

apps/src/code-studio/components/GridEditor.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
/* global dashboard */
77
import React from 'react';
88
var HarvesterCell = require('@cdo/apps/maze/harvesterCell');
9+
var PlanterCell = require('@cdo/apps/maze/planterCell');
910
var BeeCell = require('@cdo/apps/maze/beeCell');
1011
var Cell = require('@cdo/apps/maze/cell');
1112
var StudioCell = require('@cdo/apps/studio/cell');
1213
var mazeUtils = require('@cdo/apps/maze/mazeUtils');
1314

1415
var HarvesterCellEditor = require('./HarvesterCellEditor');
16+
var PlanterCellEditor = require('./PlanterCellEditor');
1517
var BeeCellEditor = require('./BeeCellEditor');
1618
var CellEditor = require('./CellEditor');
1719
var StudioCellEditor = require('./StudioCellEditor');
@@ -81,6 +83,8 @@ var GridEditor = React.createClass({
8183
return BeeCell;
8284
} else if (mazeUtils.isHarvesterSkin(this.props.skin)) {
8385
return HarvesterCell;
86+
} else if (mazeUtils.isPlanterSkin(this.props.skin)) {
87+
return PlanterCell;
8488
}
8589
return Cell;
8690
},
@@ -92,6 +96,8 @@ var GridEditor = React.createClass({
9296
return BeeCellEditor;
9397
} else if (mazeUtils.isHarvesterSkin(this.props.skin)) {
9498
return HarvesterCellEditor;
99+
} else if (mazeUtils.isPlanterSkin(this.props.skin)) {
100+
return PlanterCellEditor;
95101
}
96102
return CellEditor;
97103
},
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @overview React component to allow for easy editing and creation of
3+
* PlanterCells
4+
* @see @cdo/apps/maze/harvesterCell
5+
*/
6+
7+
var React = require('react');
8+
var ReactDOM = require('react-dom');
9+
var PlanterCell = require('@cdo/apps/maze/planterCell');
10+
var tiles = require('@cdo/apps/maze/tiles');
11+
var SquareType = tiles.SquareType;
12+
13+
var PlanterCellEditor = React.createClass({
14+
propTypes: {
15+
cell: React.PropTypes.object.isRequired,
16+
row: React.PropTypes.number.isRequired,
17+
col: React.PropTypes.number.isRequired,
18+
onUpdate: React.PropTypes.func.isRequired,
19+
},
20+
21+
handleChange: function (event) {
22+
var serializedArray = $(ReactDOM.findDOMNode(this)).serializeArray();
23+
var values = serializedArray.reduce((prev, curr) => {
24+
var value = isNaN(curr.value) ? undefined : Number(curr.value);
25+
prev[curr.name] = value;
26+
return prev;
27+
}, {});
28+
this.props.onUpdate(values);
29+
},
30+
31+
/**
32+
* Focus and select the input that contains this cell's serialized
33+
* JSON representation on creation or update, to provide a convenient
34+
* copy/paste update route.
35+
*/
36+
render: function () {
37+
var values = this.props.cell.serialize();
38+
39+
// We want undefined values that are going to be in <selects> to
40+
// actually be the STRING 'undefined' rather than the value.
41+
['tileType'].forEach(function (value) {
42+
if (values[value] === undefined) {
43+
values[value] = 'undefined';
44+
}
45+
});
46+
47+
return (
48+
<form className="span4 offset1">
49+
<header>
50+
<strong>Editing Cell ({this.props.row}, {this.props.col})</strong>
51+
</header>
52+
53+
<label htmlFor="tileType">Tile Type (required):</label>
54+
<select name="tileType" value={values.tileType} onChange={this.handleChange}>
55+
{Object.keys(SquareType).map(type => (
56+
<option key={type} value={SquareType[type]}>{type.toLowerCase()}</option>
57+
))}
58+
</select>
59+
60+
<label htmlFor="featureType">Feature Type:</label>
61+
<select name="featureType" value={values.featureType} disabled={this.props.cell.getTile() !== SquareType.OPEN} onChange={this.handleChange}>
62+
{Object.keys(PlanterCell.FeatureType).map(type => (
63+
<option key={type} value={PlanterCell.FeatureType[type]}>{type.toLowerCase()}</option>
64+
))}
65+
</select>
66+
67+
</form>
68+
);
69+
},
70+
});
71+
72+
module.exports = PlanterCellEditor;

apps/src/maze/api.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,19 @@ exports.hasPumpkin = API_FUNCTION(function (id) {
339339
exports.hasBean = API_FUNCTION(function (id) {
340340
return Maze.subtype.hasBean(id);
341341
});
342+
343+
/**
344+
* Planter
345+
*/
346+
347+
exports.plant = API_FUNCTION(function (id) {
348+
Maze.subtype.plant(id);
349+
});
350+
351+
exports.atSoil = API_FUNCTION(function (id) {
352+
return Maze.subtype.atSoil(id);
353+
});
354+
355+
exports.atSprout = API_FUNCTION(function (id) {
356+
return Maze.subtype.atSprout(id);
357+
});

apps/src/maze/blocks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ exports.install = function (blockly, blockInstallOptions) {
3939
require('./collectorBlocks').install(blockly, blockInstallOptions);
4040
} else if (mazeUtils.isHarvesterSkin(skin.id)) {
4141
require('./harvesterBlocks').install(blockly, blockInstallOptions);
42+
} else if (mazeUtils.isPlanterSkin(skin.id)) {
43+
require('./planterBlocks').install(blockly, blockInstallOptions);
4244
}
4345

4446
var SimpleMove = {

apps/src/maze/gatherer.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,6 @@ export default class Gatherer extends Subtype {
77
this.maze_.map.resetDirt();
88
}
99

10-
/**
11-
* @param {Number} row
12-
* @param {Number} col
13-
* @returns {Number} val
14-
*/
15-
getValue(row, col) {
16-
return this.getCell(row, col).getCurrentValue();
17-
}
18-
19-
/**
20-
* @param {Number} row
21-
* @param {Number} col
22-
* @param {Number} val
23-
*/
24-
setValue(row, col, val) {
25-
this.getCell(row, col).setCurrentValue(val);
26-
}
27-
28-
/**
29-
* @param {Number} row
30-
* @param {Number} col
31-
* @returns {Object} cell
32-
*/
33-
getCell(row, col) {
34-
return this.maze_.map.currentStaticGrid[row][col];
35-
}
36-
3710
/**
3811
* @return {boolean}
3912
*/

apps/src/maze/maze.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import WordSearch from './wordsearch';
4848
import Scrat from './scrat';
4949
import Farmer from './farmer';
5050
import Harvester from './harvester';
51+
import Planter from './planter';
5152

5253
var ExecutionInfo = require('./executionInfo');
5354

@@ -417,6 +418,8 @@ Maze.init = function (config) {
417418
Maze.subtype = new Scrat(Maze, studioApp, config);
418419
} else if (mazeUtils.isHarvesterSkin(config.skinId)) {
419420
Maze.subtype = new Harvester(Maze, studioApp, config);
421+
} else if (mazeUtils.isPlanterSkin(config.skinId)) {
422+
Maze.subtype = new Planter(Maze, studioApp, config);
420423
} else {
421424
Maze.subtype = new Farmer(Maze, studioApp, config);
422425
}
@@ -1245,6 +1248,9 @@ function animateAction(action, spotlightBlocks, timePerStep) {
12451248
case 'get_bean':
12461249
Maze.subtype.animateGetBean();
12471250
break;
1251+
case 'plant':
1252+
Maze.subtype.animatePlant();
1253+
break;
12481254
default:
12491255
// action[0] is null if generated by studioApp.checkTimeout().
12501256
break;

apps/src/maze/mazeMap.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ class MazeMap {
2424
});
2525
}
2626

27+
/**
28+
* Returns a flattened list of all cells in this map. Good for
29+
* situations where we want to map or reduce the cells without caring
30+
* about their position
31+
* @return {Cell[]}
32+
*/
33+
getAllCells() {
34+
return this.currentStaticGrid.reduce(
35+
(prev, curr) => prev.concat(curr), []
36+
);
37+
}
38+
2739
getCell(x, y) {
2840
return this.currentStaticGrid[x] && this.currentStaticGrid[x][y];
2941
}

apps/src/maze/mazeUtils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ exports.isScratSkin = function (skinId) {
2626
return (/scrat/).test(skinId);
2727
};
2828

29+
exports.isPlanterSkin = function (skinId) {
30+
return (/planter/).test(skinId);
31+
};
32+
2933
exports.isHarvesterSkin = function (skinId) {
3034
return (/harvester/).test(skinId);
3135
};

0 commit comments

Comments
 (0)