From 0891b0fc7a17e9e73aa6507254c2344b6a0982ad Mon Sep 17 00:00:00 2001 From: Cam Gillette Date: Wed, 29 Nov 2017 21:57:47 -0500 Subject: [PATCH 1/2] Converted placeable multidimensional array into object --- index.html | 2 + js/models/entity.js | 9 + js/script.js | 456 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 467 insertions(+) create mode 100644 js/models/entity.js diff --git a/index.html b/index.html index 7d16b0c..aa77420 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@ Factorio + @@ -43,6 +44,7 @@ + diff --git a/js/models/entity.js b/js/models/entity.js new file mode 100644 index 0000000..6457735 --- /dev/null +++ b/js/models/entity.js @@ -0,0 +1,9 @@ +class Entity{ + constructor(imagePath, rotation, direction,width,height){ + this.imagePath = imagePath; + this.rotation = rotation; + this.direction = direction; + this.width = width; + this.height = height; + } +} diff --git a/js/script.js b/js/script.js index ae8ca6e..263b30a 100644 --- a/js/script.js +++ b/js/script.js @@ -30,6 +30,162 @@ function GETfromUrl() { }, {}); } +var placeable = [ + + ["assembling-machine-1.png", 1, 0, 3, 3], + ["assembling-machine-2.png", 1, 0, 3, 3], + ["assembling-machine-3.png", 1, 0, 3, 3], + ["chemical-plant.png", 1, 0, 3, 3], + ["oil-refinery.png", 1, 0, 5, 5], + ["beacon.png", 0, 0, 3, 3], + ["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], + ["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], + ["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], + ["express-splitter.png", 1, 4, 2, 1], + ["burner-mining-drill.png", 1, 4, 2, 2], + ["electric-mining-drill.png", 1, 2, 3, 3], + ["pumpjack.png", 1, 0, 2, 2], + ["boiler.png", 1, 0, 3, 2], + ["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], + ["stone-furnace.png", 0, 0, 2, 2], + ["steel-furnace.png", 0, 0, 2, 2], + ["electric-furnace.png", 0, 0, 3, 3], + ["burner-inserter.png", 1, 6, 1, 1, 1], + ["inserter.png", 1, 6, 1, 1, 1], + ["long-handed-inserter.png", 1, 6, 1, 1, 1], + ["fast-inserter.png", 1, 6, 1, 1, 1], + ["filter-inserter.png", 1, 6, 1, 1, 1], + ["stack-filter-inserter.png", 1, 6, 1, 1, 1], + ["stack-inserter.png", 1, 6, 1, 1, 1], + ["wooden-chest.png", 0, 0, 1, 1], + ["iron-chest.png", 0, 0, 1, 1], + ["steel-chest.png", 0, 0, 1, 1], + ["storage-tank.png", 1, 0, 3, 3], + ["logistic-chest-active-provider.png", 0, 0, 1, 1], + ["logistic-chest-passive-provider.png", 0, 0, 1, 1], + ["logistic-chest-requester.png", 0, 0, 1, 1], + ["logistic-chest-storage.png", 0, 0, 1, 1], + ["small-electric-pole.png", 0, 0, 1, 1], + ["medium-electric-pole.png", 0, 0, 1, 1], + ["big-electric-pole.png", 0, 0, 2, 2], + ["substation.png", 0, 0, 2, 2], + ["solar-panel.png", 0, 0, 3, 3], + ["accumulator.png", 0, 0, 2, 2], + ["steam-engine.png", 1, 2, 5, 3], + ["steam-turbine.png", 1, 2, 5, 3], + ["centrifuge.png", 0, 0, 3, 3], + ["nuclear-reactor.png", 0, 0, 5, 5], + ["offshore-pump.png", 1, 6, 2, 1], + ["pump.png", 1, 2, 2, 1], + ["straight-rail.png", 1, 0, 2, 2], + ["train-stop.png", 1, 0, 2, 2], + ["rail-chain-signal.png", 1, 0, 1, 1], + ["rail-signal.png", 1, 0, 1, 1], + ["rocket-silo.png", 0, 0, 9, 10], + ["radar.png", 0, 0, 3, 3], + ["stone-wall.png", 0, 0, 1, 1], + ["gate.png", 2, 2, 1, 1], + ["gun-turret.png", 0, 0, 2, 2], + ["flamethrower-turret.png", 0, 0, 2, 2], + ["laser-turret.png", 0, 0, 2, 2], + ["constant-combinator.png", 0, 0, 1, 1], + ["decider-combinator.png", 1, 2, 2, 1], + ["arithmetic-combinator.png", 1, 2, 2, 1], + ["programmable-speaker.png", 0, 0, 1, 1], + ["power-switch.png", 0, 0, 2, 2]]); + +function createJSON() { + var jsonstring = '{"blueprint": {"icons": [{"signal": {"type": "item","name": "express-transport-belt"},"index": 1}],"entities": ['; + var entities = document.getElementsByClassName("entity"); + + if (entities.length === 0) { + return ""; + } else { + for (var i = 0; i < entities.length; i++) { + var number = i + 1; + var name = entities[i].dataset.name; + var type = ""; + if (name.slice(0, 2) === "i-" || name.slice(0, 2) === "o-") { + if (name.slice(0, 2) === "i-") { + type = '"type": "input",'; + } else { + type = '"type": "output",'; + } + name = name.slice(2); + } + var posx = Number(entities[i].dataset.x) + Number(entities[i].dataset.posoffsetx); + var posy = Number(entities[i].dataset.y) + Number(entities[i].dataset.posoffsety); + jsonstring = jsonstring + '{' + + '"entity_number": ' + number + ',' + + '"name": "' + name + '",' + + '"position": {' + + '"x": ' + posx + ',' + + '"y": ' + posy + + '},' + type + + '"direction":' + entities[i].dataset.direction + + '},'; + } + jsonstring = jsonstring.slice(0, -1) + '],' + + '"item": "blueprint",' + + '"version": 64426934272' + + '}' + + '}'; + return jsonstring; + } + +} + +function createEntitiesFromJSON(jsonobj){ + var entities = jsonobj.blueprint.entities; + var items = document.querySelectorAll('#sidebar div'); + + for (var ent = 0; ent < entities.length; ent++){ + var name = entities[ent].name; + var type = entities[ent].type; + if (type === "input"){ + name = "i-" + name; + }else if (type === "output"){ + name = "o-" + name; + } + for (var j = 0; j < items.length; j++){ + if(items[j].dataset.url === name+".png"){ + items[j].click(); + var edir = entities[ent].direction || 0; + var rotations = Number(edir) - Number(items[j].dataset.direction); + + if(rotations < 0){ + rotations = rotations + 8; + } + rotations = Math.round(rotations / 2); + for (var k = 0; k < rotations; k++){ + rotatePreview(); + } + var preview = document.querySelector('#preview div'); + var offsetx = Number(preview.dataset.posoffsetx); + var offsety = Number(preview.dataset.posoffsety); + var tilex = Number(entities[ent].position.x) - offsetx; + var tiley = Number(entities[ent].position.y) - offsety; + // rounded tile numbers because position or offset is wrong somewhere else. + document.querySelector('[data-x="' + Math.floor(tilex) + '"][data-y="' + Math.floor(tiley) + '"]').click(); + break; + } + } + } +} + // https://stackoverflow.com/questions/5999118/how-can-i-add-or-update-a-query-string-parameter function UpdateQueryString(key, value, url) { if (!url) { @@ -152,3 +308,303 @@ window.bpbtn = function () { document.getElementById("bp").value = "Grid is empty"; } }; + +function updatePreviewCopies(){ + if(!previewIsEmpty()){ + var staticPreview = document.querySelector('.preview__main').firstChild.cloneNode(true); + } + + var copies = document.getElementsByClassName('preview__copy'); + for(var i = 0; i < copies.length; i++){ + copies[i].innerHTML = ""; + + if(!previewIsEmpty()){ + copies[i].appendChild(staticPreview); + } + } +} + +function rotatePreview() { + var preview = document.querySelector('#preview div'); + if (preview !== null && preview.dataset.r !== 0) { + var direction = (Number(preview.dataset.direction) + 2) % 8; + 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 low; + var high; + if (w < h) { + low = w; + high = h; + } else { + low = h; + high = w; + } + var temp = preview.dataset.posoffsetx; + preview.dataset.posoffsetx = preview.dataset.posoffsety; + preview.dataset.posoffsety = temp; + var offsetx; + var offsety; + var rotation = direction - dirStart; + if (rotation < 0) { + rotation += 8; + } + if (rotation === 0) { + offsetx = low * 16; + offsety = low * 16; + } + if (rotation === 2) { + offsetx = low * 16; + offsety = low * 16; + } + if (rotation === 4) { + offsetx = high * 16; + offsety = low * 16; + } + if (rotation === 6) { + offsetx = high * 16; + offsety = high * 16; + } + + 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){ + preview.style.transform = 'initial'; + preview.style.transform = 'scale(-1,1)'; + } + else { + preview.style.transform = 'rotate(' + 45 * rotation + 'deg)'; + } + + preview.style.transformOrigin = offsetx + 'px ' + offsety + 'px'; + updatePreviewCopies(); + } +} + +function createPreview(dataset) { + var url = dataset.url; + var r = dataset.r; + var direction = dataset.direction; + var w = dataset.w; + var h = dataset.h; + var mirrorFlippedHorizontal = dataset.mirrorFlippedHorizontal; + + var preview = document.getElementById("preview"); + //document.getElementsByTagName("body")[0].style.cursor = "url('icons/placeable/"+url+"'), auto"; + clearPreview(); + var div = document.createElement("div"); + div.style.width = w * 32 - 2 + "px"; + div.style.height = h * 32 - 2 + "px"; + div.style.margin = "-1px 0 0 -1px"; + div.setAttribute("data-name", url.slice(0, -4)); + div.setAttribute("data-r", r); + div.setAttribute("data-x", 0); + div.setAttribute("data-y", 0); + div.setAttribute("data-posoffsetx", w / 2 - 0.5); + div.setAttribute("data-posoffsety", h / 2 - 0.5); + div.setAttribute("data-direction", direction); + div.setAttribute("data-mirrorFlippedHorizontal", mirrorFlippedHorizontal); + div.setAttribute("data-dirstart", direction); + + var span = document.createElement("span"); + span.setAttribute("class", "preview__image-helper"); + div.appendChild(span); + var img = document.createElement("img"); + img.src = "vendor/factorio/icons/placeable/" + url; + + img.setAttribute("class", "item__image pixelated-image preview__image"); + div.appendChild(img); + preview.appendChild(div); + updatePreviewCopies(); +} + +function clearPreview(){ + document.getElementById("preview").innerHTML = ""; + updatePreviewCopies(); +} + +function previewIsEmpty(){ + return document.getElementById("preview").innerHTML === ""; +} + +function createTiles() { + var grid = document.getElementById("grid"); + var row; + + for (var r = -9; r < 15; r++) { + row = document.createElement("div"); + row.setAttribute("class", "row"); + for (var d = -9; d < 25; d++) { + var tile = document.createElement("div"); + tile.setAttribute("data-x", d); + tile.setAttribute("data-y", r); + tile.setAttribute("data-status", 0); + tile.setAttribute("class", "tile"); + if (d === 0 && r === 0) { + tile.style.background = "darkgrey"; + } + tile.addEventListener('mouseover', tileMouseOver); + tile.addEventListener('mousedown', tileMouseOver); + //prevent context menu from appearing + tile.addEventListener('contextmenu', function(e) {e.preventDefault();}); + row.appendChild(tile); + } + grid.appendChild(row); + } +} + +window.clearGrid = function () { + document.getElementById("grid").innerHTML = ""; + createTiles(); +}; + +function createItems() { + var grid = document.getElementById("sidebar"); + var url; + for (var i = 0; i < placeable.length; i++) { + var item = document.createElement("div"); + item.setAttribute("class", "item"); + url = placeable[i].imagePath; + item.setAttribute("data-url", url); + item.setAttribute("data-r", placeable[i].rotation); + 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.addEventListener('click', itemClick); + insertImg(item, url); + grid.appendChild(item); + } +} + +function setPreviewLocation(Loc){ + var preview = document.getElementsByClassName("mouse__follow"); + for(var i = 0; i < preview.length; i++){ + preview[i].style.left = (Loc.x) + "px"; + preview[i].style.top = (Loc.y) + "px"; + } +} + +function itemClick() { + createPreview(this.dataset); + setActiveItem(this); +} + +function setActiveItem(item) { + var active = document.querySelectorAll('.activeitem'); + if (active.length > 0) { + for (var i = 0; i < active.length; i++) { + active[i].classList.remove("activeitem"); + } + } + item.classList.add("activeitem"); +} + +function setTile(tile){ + var previewdiv = document.querySelector('#preview div').cloneNode(true); + if ((tile.dataset.x % 2 === 0 || tile.dataset.y % 2 === 0) && (previewdiv.dataset.name === "straight-rail" || previewdiv.dataset.name === "train-stop")) { + var x = tile.dataset.x; + var y = tile.dataset.y; + if (x % 2 === 0) { + x -= 1; + } + if (y % 2 === 0) { + y -= 1; + } + document.querySelector('[data-x="' + x + '"][data-y="' + y + '"]').click(); + } else if (!isBlocked(previewdiv.dataset.name, tile.dataset.x, tile.dataset.y)) { + previewdiv.setAttribute("data-x", tile.dataset.x); + previewdiv.setAttribute("data-y", tile.dataset.y); + previewdiv.setAttribute("class", "entity"); + tile.appendChild(previewdiv); + } +} + +function clearTile(tile){ + tile.innerHTML = ""; +} + +function tileClick(event, tile) { + if(event.buttons === 2){ //right mouse button + clearTile(tile); + } + else if(event.buttons === 1 && !previewIsEmpty()){ //left mouse button and item is selected + setTile(tile); + } +} + +function isBlocked(name, x, y) { + var data = getPlaceableData(name); + for (var i = 0; i < data[3]; i++) { + for (var j = 0; j < data[4]; j++) { + var existingPlaceable = getPlaceableAt(+x + i, +y + j); + if (existingPlaceable) { + return true; + } + } + } + return false; +} + +function getPlaceableData(name) { + for (var i in placeable) { + if (placeable[i].imagePath.startsWith(name)) { + return placeable[i]; + } + } +} + +function getPlaceableAt(x, y) { + //TODO : Fix these magic numbers and prevent having scan the entire board everytime a new entity is wanted to be placed + for (var i = -9; i <= x; i++) { + for (var j = -9; j <= y; j++) { + var tile = document.querySelector("[data-x='" + i + "'][data-y='" + j + "']"); + if (!tile || !tile.innerHTML) { + continue; + } + var data = getPlaceableData(tile.children[0].dataset.name); + if (data && data[3] + i > x && data[4] + j > y) { + return data[0]; + } + } + } +} + +function tileMouseOver(event) { + if (event.buttons !== 0) { // any button is pressed + tileClick(event, this); + } + + var offset = this.getBoundingClientRect(); + var location = { x : offset.left, y : offset.top }; + setPreviewLocation(location); +} + +function insertImg(tile, url) { + var div = document.createElement("div"); + div.setAttribute("class", "itemdiv"); + var img = document.createElement("img"); + img.src = "vendor/factorio/icons/placeable/" + url; + img.setAttribute("class", "item__image pixelated-image"); + div.appendChild(img); + tile.appendChild(div); +} + +function encode(json) { + var string = json.replace(/\s/g, ""); + var enc = new TextEncoder("utf-8").encode(string); + var zip = pako.deflate(enc, { level: 9 }); + var base64 = Base64.encodeU(zip); + var bstring = "0" + base64; + return bstring; +} + +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])); + } + return objectArray; +} From 3bb0232a854186174ff8aa27f94ba29cc9c5245c Mon Sep 17 00:00:00 2001 From: Cam Gillette Date: Sun, 3 Dec 2017 12:07:46 -0500 Subject: [PATCH 2/2] Added underground belts and underground pipes rotation fix. --- js/models/entity.js | 3 +- js/script.js | 164 +++++++++++++++++++++----------------------- 2 files changed, 80 insertions(+), 87 deletions(-) diff --git a/js/models/entity.js b/js/models/entity.js index 6457735..265303f 100644 --- a/js/models/entity.js +++ b/js/models/entity.js @@ -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; } } diff --git a/js/script.js b/js/script.js index 263b30a..88903be 100644 --- a/js/script.js +++ b/js/script.js @@ -30,82 +30,81 @@ function GETfromUrl() { }, {}); } -var placeable = [ - - ["assembling-machine-1.png", 1, 0, 3, 3], - ["assembling-machine-2.png", 1, 0, 3, 3], - ["assembling-machine-3.png", 1, 0, 3, 3], - ["chemical-plant.png", 1, 0, 3, 3], - ["oil-refinery.png", 1, 0, 5, 5], - ["beacon.png", 0, 0, 3, 3], - ["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], - ["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], - ["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], - ["express-splitter.png", 1, 4, 2, 1], - ["burner-mining-drill.png", 1, 4, 2, 2], - ["electric-mining-drill.png", 1, 2, 3, 3], - ["pumpjack.png", 1, 0, 2, 2], - ["boiler.png", 1, 0, 3, 2], - ["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], - ["stone-furnace.png", 0, 0, 2, 2], - ["steel-furnace.png", 0, 0, 2, 2], - ["electric-furnace.png", 0, 0, 3, 3], - ["burner-inserter.png", 1, 6, 1, 1, 1], - ["inserter.png", 1, 6, 1, 1, 1], - ["long-handed-inserter.png", 1, 6, 1, 1, 1], - ["fast-inserter.png", 1, 6, 1, 1, 1], - ["filter-inserter.png", 1, 6, 1, 1, 1], - ["stack-filter-inserter.png", 1, 6, 1, 1, 1], - ["stack-inserter.png", 1, 6, 1, 1, 1], - ["wooden-chest.png", 0, 0, 1, 1], - ["iron-chest.png", 0, 0, 1, 1], - ["steel-chest.png", 0, 0, 1, 1], - ["storage-tank.png", 1, 0, 3, 3], - ["logistic-chest-active-provider.png", 0, 0, 1, 1], - ["logistic-chest-passive-provider.png", 0, 0, 1, 1], - ["logistic-chest-requester.png", 0, 0, 1, 1], - ["logistic-chest-storage.png", 0, 0, 1, 1], - ["small-electric-pole.png", 0, 0, 1, 1], - ["medium-electric-pole.png", 0, 0, 1, 1], - ["big-electric-pole.png", 0, 0, 2, 2], - ["substation.png", 0, 0, 2, 2], - ["solar-panel.png", 0, 0, 3, 3], - ["accumulator.png", 0, 0, 2, 2], - ["steam-engine.png", 1, 2, 5, 3], - ["steam-turbine.png", 1, 2, 5, 3], - ["centrifuge.png", 0, 0, 3, 3], - ["nuclear-reactor.png", 0, 0, 5, 5], - ["offshore-pump.png", 1, 6, 2, 1], - ["pump.png", 1, 2, 2, 1], - ["straight-rail.png", 1, 0, 2, 2], - ["train-stop.png", 1, 0, 2, 2], - ["rail-chain-signal.png", 1, 0, 1, 1], - ["rail-signal.png", 1, 0, 1, 1], - ["rocket-silo.png", 0, 0, 9, 10], - ["radar.png", 0, 0, 3, 3], - ["stone-wall.png", 0, 0, 1, 1], - ["gate.png", 2, 2, 1, 1], - ["gun-turret.png", 0, 0, 2, 2], - ["flamethrower-turret.png", 0, 0, 2, 2], - ["laser-turret.png", 0, 0, 2, 2], - ["constant-combinator.png", 0, 0, 1, 1], - ["decider-combinator.png", 1, 2, 2, 1], - ["arithmetic-combinator.png", 1, 2, 2, 1], - ["programmable-speaker.png", 0, 0, 1, 1], - ["power-switch.png", 0, 0, 2, 2]]); +var placeable = new Array(); +placeable.push(new Entity("assembling-machine-1.png", 1, 0, 3, 3)); +placeable.push(new Entity("assembling-machine-2.png", 1, 0, 3, 3)); +placeable.push(new Entity("assembling-machine-3.png", 1, 0, 3, 3)); +placeable.push(new Entity("chemical-plant.png", 1, 0, 3, 3)); +placeable.push(new Entity("oil-refinery.png", 1, 0, 5, 5)); +placeable.push(new Entity("beacon.png", 0, 0, 3, 3)); +placeable.push(new Entity("roboport.png", 0, 0, 4, 4)); +placeable.push(new Entity("lab.png", 0, 0, 3, 3)); +placeable.push(new Entity("transport-belt.png", 1, 0, 1, 1)); +placeable.push(new Entity("i-underground-belt.png", 1, 2, 1, 1, 1)); +placeable.push(new Entity("o-underground-belt.png", 1, 6, 1, 1, 1)); +placeable.push(new Entity("splitter.png", 1, 4, 2, 1)); +placeable.push(new Entity("fast-transport-belt.png", 1, 0, 1, 1)); +placeable.push(new Entity("i-fast-underground-belt.png", 1, 2, 1, 1, 1)); +placeable.push(new Entity("o-fast-underground-belt.png", 1, 6, 1, 1, 1)); +placeable.push(new Entity("fast-splitter.png", 1, 4, 2, 1)); +placeable.push(new Entity("express-transport-belt.png", 1, 0, 1, 1)); +placeable.push(new Entity("i-express-underground-belt.png", 1, 2, 1, 1, 1)); +placeable.push(new Entity("o-express-underground-belt.png", 1, 6, 1, 1, 1)); +placeable.push(new Entity("express-splitter.png", 1, 4, 2, 1)); +placeable.push(new Entity("burner-mining-drill.png", 1, 4, 2, 2)); +placeable.push(new Entity("electric-mining-drill.png", 1, 2, 3, 3)); +placeable.push(new Entity("pumpjack.png", 1, 0, 2, 2)); +placeable.push(new Entity("boiler.png", 1, 0, 3, 2)); +placeable.push(new Entity("heat-boiler.png", 1, 0, 3, 2)); +placeable.push(new Entity("heat-pipe.png", 0, 0, 1, 1)); +placeable.push(new Entity("pipe.png", 0, 0, 1, 1)); +placeable.push(new Entity("pipe-to-ground.png", 1, 2, 1, 1, 1)); +placeable.push(new Entity("stone-furnace.png", 0, 0, 2, 2)); +placeable.push(new Entity("steel-furnace.png", 0, 0, 2, 2)); +placeable.push(new Entity("electric-furnace.png", 0, 0, 3, 3)); +placeable.push(new Entity("burner-inserter.png", 1, 6, 1, 1, 1)); +placeable.push(new Entity("inserter.png", 1, 6, 1, 1, 1)); +placeable.push(new Entity("long-handed-inserter.png", 1, 6, 1, 1, 1)); +placeable.push(new Entity("fast-inserter.png", 1, 6, 1, 1, 1)); +placeable.push(new Entity("filter-inserter.png", 1, 6, 1, 1, 1)); +placeable.push(new Entity("stack-filter-inserter.png", 1, 6, 1, 1, 1)); +placeable.push(new Entity("stack-inserter.png", 1, 6, 1, 1, 1)); +placeable.push(new Entity("wooden-chest.png", 0, 0, 1, 1)); +placeable.push(new Entity("iron-chest.png", 0, 0, 1, 1)); +placeable.push(new Entity("steel-chest.png", 0, 0, 1, 1)); +placeable.push(new Entity("storage-tank.png", 1, 0, 3, 3)); +placeable.push(new Entity("logistic-chest-active-provider.png", 0, 0, 1, 1)); +placeable.push(new Entity("logistic-chest-passive-provider.png", 0, 0, 1, 1)); +placeable.push(new Entity("logistic-chest-requester.png", 0, 0, 1, 1)); +placeable.push(new Entity("logistic-chest-storage.png", 0, 0, 1, 1)); +placeable.push(new Entity("small-electric-pole.png", 0, 0, 1, 1)); +placeable.push(new Entity("medium-electric-pole.png", 0, 0, 1, 1)); +placeable.push(new Entity("big-electric-pole.png", 0, 0, 2, 2)); +placeable.push(new Entity("substation.png", 0, 0, 2, 2)); +placeable.push(new Entity("solar-panel.png", 0, 0, 3, 3)); +placeable.push(new Entity("accumulator.png", 0, 0, 2, 2)); +placeable.push(new Entity("steam-engine.png", 1, 2, 5, 3)); +placeable.push(new Entity("steam-turbine.png", 1, 2, 5, 3)); +placeable.push(new Entity("centrifuge.png", 0, 0, 3, 3)); +placeable.push(new Entity("nuclear-reactor.png", 0, 0, 5, 5)); +placeable.push(new Entity("offshore-pump.png", 1, 6, 2, 1)); +placeable.push(new Entity("pump.png", 1, 2, 2, 1)); +placeable.push(new Entity("straight-rail.png", 1, 0, 2, 2)); +placeable.push(new Entity("train-stop.png", 1, 0, 2, 2)); +placeable.push(new Entity("rail-chain-signal.png", 1, 0, 1, 1)); +placeable.push(new Entity("rail-signal.png", 1, 0, 1, 1)); +placeable.push(new Entity("rocket-silo.png", 0, 0, 9, 10)); +placeable.push(new Entity("radar.png", 0, 0, 3, 3)); +placeable.push(new Entity("stone-wall.png", 0, 0, 1, 1)); +placeable.push(new Entity("gate.png", 2, 2, 1, 1)); +placeable.push(new Entity("gun-turret.png", 0, 0, 2, 2)); +placeable.push(new Entity("flamethrower-turret.png", 0, 0, 2, 2)); +placeable.push(new Entity("laser-turret.png", 0, 0, 2, 2)); +placeable.push(new Entity("constant-combinator.png", 0, 0, 1, 1)); +placeable.push(new Entity("decider-combinator.png", 1, 2, 2, 1)); +placeable.push(new Entity("arithmetic-combinator.png", 1, 2, 2, 1)); +placeable.push(new Entity("programmable-speaker.png", 0, 0, 1, 1)); +placeable.push(new Entity("power-switch.png", 0, 0, 2, 2)); function createJSON() { var jsonstring = '{"blueprint": {"icons": [{"signal": {"type": "item","name": "express-transport-belt"},"index": 1}],"entities": ['; @@ -331,6 +330,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; @@ -370,7 +370,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)'; } @@ -472,7 +472,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); @@ -600,11 +600,3 @@ function encode(json) { var bstring = "0" + base64; return bstring; } - -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])); - } - return objectArray; -}