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

Converted placeable multidimensional array into object #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Factorio</title>

<link rel="shortcut icon" href="vendor/factorio/icons/atomic-bomb.png">
<link rel="stylesheet" href="css/style.css">
</head>
Expand Down Expand Up @@ -43,6 +44,7 @@

<script src="js/view.js"></script>
<script src="js/viewmodel.js"></script>
<script src="js/models/entity.js"></script>
<script src="js/script.js"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions js/models/entity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Entity{
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 probably namespace our stuff at some point instead of overloading the window space. For now this is ok.

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

this property name is a bit long, but i'm not sure if there is a better name for this

}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

if you want to keep using the array of data, you could create a static method that returns a new Entity:

static function fromDataArray(dataArray) {
  var name = dataArray[0];
  var rotation = dataArray[1];
  //etc...
  return new Entity(name, rotation, //etc...
}

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ok, I'll add this. Eventually I'd like to get away from the array format and have a config file somewhere storing all of the entity information.

Loading