-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: master
Are you sure you want to change the base?
Conversation
js/models/entity.js
Outdated
setHeight(height){ | ||
this.height = height; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is just a data class, can we forego the getters/setters? Someone more well versed in javascript standards should chime in, but this seems excessive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this time. I don't think the getters or setters are needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SpyMaster356 Just for my own knowledge, what is standard practice in js when it comes to getters/setters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I gathered on Mozilla's Javascript reference page, it adheres to generic object oriented standards, and since this is nothing more than a data-holding struct, we don't need to worry much about data hiding.
Fun fact: there's some syntax sugar for this
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, there isn't much need for getters and setters, but there are use cases such as:
- When you want do extra things when setting a value
- When the value is computed from other properties
- When you want to restrict setting a value.
d282618
to
081e865
Compare
Note, this will need to updated to accomodate the horizontal mirror rotation updates to the js. |
Waiting on #47 as that includes eslint settings for es6 |
081e865
to
7f2935f
Compare
@SpyMaster356 Can review the changes in them most recent commit. They should fix the underground belt and underground pipe rotation issue. |
7f2935f
to
11a163d
Compare
the lint errors can be fix automatically, use |
js/script.js
Outdated
@@ -608,3 +609,11 @@ function encode(json) { | |||
var bstring = "0" + base64; | |||
return bstring; | |||
} | |||
|
|||
function factorioEntityObjectArrayFromMultiArray(sourceArray){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that function name is a bit of a mouthful
js/script.js
Outdated
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],sourceArray[i][5])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use intermediate variable names here instead of directly passing each property. It's hard to understand what values are being passed around here.
Eg.
var entityData = sourceArray[i];
var name = entityData[0];
var rotation = entityData[1];
// etc...
js/script.js
Outdated
@@ -38,7 +38,7 @@ placeable[4] = height/length | |||
placeable[5] = mirror flipped horizontal rotation | |||
*/ | |||
|
|||
var placeable = [ | |||
var placeable = factorioEntityObjectArrayFromMultiArray([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of writing a function to turn these arrays into Entity objects, couldn't we just create Entity objects here?
this.direction = direction; | ||
this.width = width; | ||
this.height = height; | ||
this.mirrorFlippedHorizontal = mirrorFlippedHorizontal; |
There was a problem hiding this comment.
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
@@ -0,0 +1,10 @@ | |||
class Entity{ |
There was a problem hiding this comment.
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.
this.height = height; | ||
this.mirrorFlippedHorizontal = mirrorFlippedHorizontal; | ||
} | ||
} |
There was a problem hiding this comment.
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...
}
There was a problem hiding this comment.
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.
11a163d
to
3d8e3a0
Compare
3d8e3a0
to
3bb0232
Compare
@SpyMaster356 Ready for re-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll need to run npm run lint -- --fix
to fix the errors that Travis is throwing
No description provided.