Skip to content

Commit

Permalink
Handle "normal" vs "expensive" difficulty as introduced in Factorio 0…
Browse files Browse the repository at this point in the history
….15.x
  • Loading branch information
Andrew Brindamour committed Apr 30, 2017
1 parent c5f69db commit 6c5ee08
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
3 changes: 2 additions & 1 deletion calc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var Calc = React.createClass({
options: {
asslvl: "0.5",
smeltlvl: "1",
beltlvl: "5.7"
beltlvl: "5.7",
difficulty: "normal"
},
explainingRecipe: null,
bulkVisible: false
Expand Down
27 changes: 17 additions & 10 deletions calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ App.Calculator = {
var self = this;

var recipes = _.filter(_.map(inputs, function(input) {
var recipe = self._getRecipeTree(input.recipe, input.ips);
var recipe = self._getRecipeTree(input.recipe, input.ips, options.difficulty);
if (recipe.category == "unknown") {
return null;
}
Expand Down Expand Up @@ -42,7 +42,7 @@ App.Calculator = {
},


_getRecipe: function(name) {
_getRecipe: function(name, difficulty) {
var rawData = this.data[name];

if (name == "iron-ore" || name == "copper-ore" || name == "stone" || name == "coal") {
Expand All @@ -62,17 +62,24 @@ App.Calculator = {
};
}
recipe.name = rawData.name;
recipe.baseTime = rawData.energy_required || 0.5;
recipe.category = rawData.category;

if (rawData.results) {
var selfResult = _.findWhere(rawData.results, {name: recipe.name});
var rawDataForDifficulty;
if (rawData[difficulty]) {
rawDataForDifficulty = rawData[difficulty];
} else {
rawDataForDifficulty = rawData;
}

recipe.baseTime = rawDataForDifficulty.energy_required || 0.5;
if (rawDataForDifficulty.results) {
var selfResult = _.findWhere(rawDataForDifficulty.results, {name: recipe.name});
recipe.outputs = selfResult ? selfResult.amount : 1;
} else {
recipe.outputs = rawData.result_count || 1;
recipe.outputs = rawDataForDifficulty.result_count || 1;
}

recipe.ingredients = this._asArray(rawData.ingredients).map(function(rawIngredient) {
recipe.ingredients = this._asArray(rawDataForDifficulty.ingredients).map(function(rawIngredient) {
if (rawIngredient.name) {
return {name: rawIngredient.name, amount: rawIngredient.amount};
} else {
Expand All @@ -83,13 +90,13 @@ App.Calculator = {
return recipe;
},

_getRecipeTree: function(name, ips) {
var recipe = this._getRecipe(name);
_getRecipeTree: function(name, ips, difficulty) {
var recipe = this._getRecipe(name, difficulty);
recipe.ips = ips;
var self = this;
recipe.ingredients.forEach(function(ingredient) {
var ingredientIps = recipe.ips / recipe.outputs * ingredient.amount;
ingredient.recipe = self._getRecipeTree(ingredient.name, ingredientIps);
ingredient.recipe = self._getRecipeTree(ingredient.name, ingredientIps, difficulty);
});

return recipe;
Expand Down
10 changes: 10 additions & 0 deletions options.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,23 @@ App.Options = React.createClass({
<option value="1">Stone</option>
<option value="2">Steel / Electric</option>
</select>

<label>Belt speed:</label>
<select
value={this.props.options.beltlvl}
name="beltlvl"
onChange={this.setOption}>
{beltOptions}
</select>

<label>Difficulty:</label>
<select
value={this.props.options.difficulty}
name="difficulty"
onChange={this.setOption}>
<option value="normal">Normal</option>
<option value="expensive">Expensive</option>
</select>
</div>
</div>
);
Expand Down

0 comments on commit 6c5ee08

Please sign in to comment.