Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split into view, viewmodel, and factorio-blueprint #48

Merged
merged 10 commits into from
Dec 4, 2017
5 changes: 2 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Factorio</title>
<link rel="shortcut icon" href="icons/atomic-bomb.png">
<link rel="shortcut icon" href="vendor/factorio/icons/atomic-bomb.png">
<link rel="stylesheet" href="css/style.css">
</head>

Expand Down Expand Up @@ -40,8 +40,7 @@

<script src="https://unpkg.com/[email protected]/dist/tinyemitter.js"></script>
<script src="vendor/factorio-blueprint.min.js"></script>
<script src="vendor/pako.js"></script>
<script src="vendor/base64.js"></script>

<script src="js/view.js"></script>
<script src="js/viewmodel.js"></script>
<script src="js/script.js"></script>
Expand Down
9 changes: 5 additions & 4 deletions js/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ window.FBE = window.FBE || {};
grid.addEventListener('mousedown', function (evt) {
isDrawing = evt.button == 0;
isClearing = evt.button == 2;
var point = getPointFromTile(evt.target);
tileMouseOver(point, evt);
var point = getPointFromNode(evt.target);
if (point) { tileMouseOver(point, evt); }
});
grid.addEventListener('mouseup', function () {
isDrawing = isClearing = false;
Expand Down Expand Up @@ -68,8 +68,9 @@ window.FBE = window.FBE || {};
getTileFromPoint(event.point).innerHTML = '';
}

function getPointFromTile(tile) {
var coords = tile.dataset.point.split(':');
function getPointFromNode(node) {
if (!node.dataset.point) { return null; }
var coords = node.dataset.point.split(':');
return {
x: coords[0],
y: coords[1]
Expand Down
12 changes: 9 additions & 3 deletions js/viewmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ window.FBE = window.FBE || {};

function loadEntity(placeables, entity) {
var items = placeables
.filter(function (p) { return p.name === entity.name; }),
.filter(function (p) { return p.name === entity.name; }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this onto the previous line, or give item there it's own var statement.

item;

if (items.length === 2) {
Expand Down Expand Up @@ -157,7 +157,12 @@ window.FBE = window.FBE || {};
},
rawEntities[name],
// fix bad data in factorio-blueprint
name === 'steam_turbine' && {width: 5, height: 3}
name === 'steam_turbine' && { width: 5, height: 3 },
name === 'boiler' && { width: 3, height: 2 },
// fix spots where height/width are swapped
name === 'pump' && { width: 2, height: 1 },
name === 'decider_combinator' && { width: 2, height: 1 },
name === 'arithmetic_combinator' && { width: 2, height: 1 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move these into a switch statement? It took me a while to understand what these && were doing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

);
})
.filter(isPlaceable)
Expand All @@ -166,7 +171,8 @@ window.FBE = window.FBE || {};
}

function isPlaceable(entity) {
return (entity.type === "item" && entity.width);
return (entity.type === "item" && entity.width)
&& entity.name !== 'curved_rail'; // curved rail is strange
// TODO: support tiles
// || entity.type === "tile"
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "factorio_blueprint_editor",
"version": "1.0.0",
"version": "1.1.0",
"description": "Online Editor for Elxeno's Factorio Blueprint Editor",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "./node_modules/.bin/eslint js/**/*.js"
"lint": "eslint js/**/*.js"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should keep using the project's version of eslint instead of relying on a globally specified version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm handles this already, the ./node_modules/.bin is redundant.

It basically puts ./node_modules/.bin at the front of your PATH so we are using project's dependencies before anything installed system wide.

The official docs are very terse on this: https://docs.npmjs.com/misc/scripts#path

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I did not know that. Nvm then

},
"repository": {
"type": "git",
Expand Down