Skip to content

Commit

Permalink
Added underground belts and underground pipes rotation fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
camerongillette committed Dec 3, 2017
1 parent 29044fd commit 7f2935f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion js/models/entity.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class Entity{
constructor(imagePath, rotation, direction,width,height){
constructor(imagePath, rotation, direction,width,height,mirrorFlippedHorizontal=0){
this.imagePath = imagePath;
this.rotation = rotation;
this.direction = direction;
this.width = width;
this.height = height;
this.mirrorFlippedHorizontal = mirrorFlippedHorizontal;
}
}
23 changes: 12 additions & 11 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ placeable[4] = height/length
placeable[5] = mirror flipped horizontal rotation
*/

var placeable = [
var placeable = factorioEntityObjectArrayFromMultiArray([
["assembling-machine-1.png", 1, 0, 3, 3],
["assembling-machine-2.png", 1, 0, 3, 3],
["assembling-machine-3.png", 1, 0, 3, 3],
Expand All @@ -48,16 +48,16 @@ var placeable = [
["roboport.png", 0, 0, 4, 4],
["lab.png", 0, 0, 3, 3],
["transport-belt.png", 1, 0, 1, 1],
["i-underground-belt.png", 1, 2, 1, 1],
["o-underground-belt.png", 1, 6, 1, 1],
["i-underground-belt.png", 1, 2, 1, 1, 1],
["o-underground-belt.png", 1, 6, 1, 1, 1],
["splitter.png", 1, 4, 2, 1],
["fast-transport-belt.png", 1, 0, 1, 1],
["i-fast-underground-belt.png", 1, 2, 1, 1],
["o-fast-underground-belt.png", 1, 6, 1, 1],
["i-fast-underground-belt.png", 1, 2, 1, 1, 1],
["o-fast-underground-belt.png", 1, 6, 1, 1, 1],
["fast-splitter.png", 1, 4, 2, 1],
["express-transport-belt.png", 1, 0, 1, 1],
["i-express-underground-belt.png", 1, 2, 1, 1],
["o-express-underground-belt.png", 1, 6, 1, 1],
["i-express-underground-belt.png", 1, 2, 1, 1, 1],
["o-express-underground-belt.png", 1, 6, 1, 1, 1],
["express-splitter.png", 1, 4, 2, 1],
["burner-mining-drill.png", 1, 4, 2, 2],
["electric-mining-drill.png", 1, 2, 3, 3],
Expand All @@ -66,7 +66,7 @@ var placeable = [
["heat-boiler.png", 1, 0, 3, 2],
["heat-pipe.png", 0, 0, 1, 1],
["pipe.png", 0, 0, 1, 1],
["pipe-to-ground.png", 1, 2, 1, 1],
["pipe-to-ground.png", 1, 2, 1, 1, 1],
["stone-furnace.png", 0, 0, 2, 2],
["steel-furnace.png", 0, 0, 2, 2],
["electric-furnace.png", 0, 0, 3, 3],
Expand Down Expand Up @@ -336,6 +336,7 @@ function rotatePreview() {
var dirStart = Number(preview.dataset.dirstart);
var w = (Number(preview.style.width.slice(0, -2)) + 2) / 32;
var h = (Number(preview.style.height.slice(0, -2)) + 2) / 32;
var mirrorflippedhorizontal = preview.dataset.mirrorflippedhorizontal;

var low;
var high;
Expand Down Expand Up @@ -375,7 +376,7 @@ function rotatePreview() {
preview.setAttribute("data-direction", direction);

//Handles usecases where entity should be horizontally flipped instead of rotated, like inserters. Rotation 4 = 270 degrees
if(rotation == 4){
if(rotation == 4 && mirrorflippedhorizontal == 1){
preview.style.transform = 'initial';
preview.style.transform = 'scale(-1,1)';
}
Expand Down Expand Up @@ -477,7 +478,7 @@ function createItems() {
item.setAttribute("data-direction", placeable[i].direction);
item.setAttribute("data-w", placeable[i].width);
item.setAttribute("data-h", placeable[i].height);
item.setAttribute("data-mirror-flipped-horizontal", (placeable[i].length == 6 && placeable[i][5] ==1));
item.setAttribute("data-mirror-flipped-horizontal", placeable[i].mirrorFlippedHorizontal);
item.addEventListener('click', itemClick);
insertImg(item, url);
grid.appendChild(item);
Expand Down Expand Up @@ -612,7 +613,7 @@ function encode(json) {
function factorioEntityObjectArrayFromMultiArray(sourceArray){
var objectArray = new Array();
for(var i = 0; i < sourceArray.length; i++){
objectArray.push(new Entity(sourceArray[i][0],sourceArray[i][1],sourceArray[i][2],sourceArray[i][3],sourceArray[i][4]));
objectArray.push(new Entity(sourceArray[i][0],sourceArray[i][1],sourceArray[i][2],sourceArray[i][3],sourceArray[i][4],sourceArray[i][5]));
}
return objectArray;
}

0 comments on commit 7f2935f

Please sign in to comment.