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

Conversation

camerongillette
Copy link
Owner

No description provided.

setHeight(height){
this.height = height;
}
}
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Owner Author

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?

Copy link
Contributor

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

Copy link
Contributor

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.

@camerongillette camerongillette force-pushed the 42-placeable-into-object branch from d282618 to 081e865 Compare December 1, 2017 03:51
@camerongillette
Copy link
Owner Author

Note, this will need to updated to accomodate the horizontal mirror rotation updates to the js.

@camerongillette camerongillette changed the title Converted placeable multidimensional array into object WIP : Converted placeable multidimensional array into object Dec 1, 2017
@Zeragamba
Copy link
Contributor

Waiting on #47 as that includes eslint settings for es6

@camerongillette camerongillette force-pushed the 42-placeable-into-object branch from 081e865 to 7f2935f Compare December 3, 2017 17:07
@camerongillette camerongillette changed the title WIP : Converted placeable multidimensional array into object Converted placeable multidimensional array into object Dec 3, 2017
@camerongillette
Copy link
Owner Author

@SpyMaster356 Can review the changes in them most recent commit. They should fix the underground belt and underground pipe rotation issue.

@camerongillette camerongillette force-pushed the 42-placeable-into-object branch from 7f2935f to 11a163d Compare December 3, 2017 22:33
@Zeragamba
Copy link
Contributor

the lint errors can be fix automatically, use npm run lint -- --fix to fix them.

js/script.js Outdated
@@ -608,3 +609,11 @@ function encode(json) {
var bstring = "0" + base64;
return bstring;
}

function factorioEntityObjectArrayFromMultiArray(sourceArray){
Copy link
Contributor

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

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([
Copy link
Contributor

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;
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

@@ -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.

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.

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.

@camerongillette camerongillette force-pushed the 42-placeable-into-object branch from 11a163d to 3d8e3a0 Compare December 7, 2017 03:03
@camerongillette camerongillette force-pushed the 42-placeable-into-object branch from 3d8e3a0 to 3bb0232 Compare December 7, 2017 03:53
@camerongillette
Copy link
Owner Author

@SpyMaster356 Ready for re-review

Copy link
Contributor

@Zeragamba Zeragamba left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants