r/javaScriptStudyGroup • • Apr 10 '16

Midas Gold Plus - bear with me

So for the last 2 months I've become hooked on Midas Gold Plus; an idle game on Kongregate.
Midas Gold Plus

This is relevant because I've become known in the community because I made them a skill calculator for part of the game that I've since expanded on several times. The game creators even gave me like $20 of premium currency in recognition :)

Left it on codepen where it has had almost 4k views.
Some of it clearly only makes sense if you dig into the game but leaving it here because, as always, I would welcome any sort of feedback etc. It qualifies as my most relevant / used / purposeful thing I've made and actually got out there :)
Skill Calculator

2 Upvotes

9 comments sorted by

1

u/ForScale Apr 12 '16

This is pretty sweet, man! Nice work!

I haven't played this particular game... What kind is it? Is it like a Clash of Clans or something? Or more of a traditional tower defense type?

2

u/Volv Apr 12 '16

Is an idle game. Closer to Cookie Clicker / Trimps / Realm Grinder / Wall Destroyer / loads of others :)

1

u/ForScale Apr 12 '16

Interesting... Thanks!

I'm gonna keep digging through the code. Looks like you have some interesting stuff going on in there.

If you don't mind, remind me again why you use Babel... I've never used any preprocessors with js. I've only used scss with css.

2

u/Volv Apr 12 '16

Thanks :) Glad to hear any thoughts. I used Babel to start using some of the ES6 stuff. Arrow functions and such. Spread operators were another that didn't work initially.
What has happened since I started using it is that my browser (Chrome) supports a lot of it by default now anyway so I think most times I can actually get away without it.
Have kept it out of habit thus far - I think maybe also it will make my samples work on older / non compliant browsers when other people look at them on Codepen

1

u/ForScale Apr 12 '16

Ah... okay. Cool!

1

u/Volv Apr 13 '16

Quite a big update today. Reworked calculations on 3rd tab. Made it easy to add new production multipliers, used filters and such to make a fancy live updating table and now only update tabs the user is looking at.

2

u/ForScale Apr 13 '16

Fantastic!

Looking through it line by line... thinking of some questions...

Why do you store all of your elems/nodes in a saved vars array? Is that just to give the collection array methods like forEach or something?

let armoryMult = (armoryLvl === 0) ? 1 : // 5% per lvl. 10%/lvl when lvl 20
(armoryLvl === 20) ? ((armoryLvl*10)/100)+1:((armoryLvl*5)/100)+1;

What's a when statement do?

`+${numberWithCommas(incWithout.toFixed(2))}%`;

What in the world are the special chars doing there?

Working with localStorage there... very nice! Maybe we should do a weekly focus on cookies/localStorage! I haven't done much with either...

localStorage.getItem(each) || 0);

Is that valid syntax? Looks like it's missing an (...

outString += <tr><th>Upgrade</th>;

There it is again! What do the ```s do?

skillCalc.init();

Really basic/common and I feel I should already know this, but... Why wrap the whole thing in an init() function? And... init() is a method of skillCalc?.. which is itself a function?

...

Obviously, feel free to answer my questions or not! :) They're just kind of what popped in to my head as I was reading through it.

Really cool, man! And you said that the community of players appreciated it too? That's great! Solid work!!

2

u/Volv Apr 13 '16

Awesome.
The variables that I add to savedVars are later used by the save and load from local storage functions so that the text boxes remain filled in between visits. Saves me copying their names to each function as well as the declaration. Just declare and add to that array. You've given me an idea to simplify even further mind you.
 
That when statement is a comment :)
 
Template Literals - we used them before in that multiline string comment stuff

=`+${numberWithCommas(incWithout.toFixed(2))}%`;  

is equiv to

="+" +numberWithCommas(incWithout.toFixed(2))+ "%";  

 

It totally does look like invalid syntax. but is part of
savedVars.forEach((each) => volv$(each).value = localStorage.getItem(each) || 0);
and so opening bracket is from forEach.
 
Template Literals - I'm getting into the habit os using them. Allows me to use both kinds of quote marks in strings without jumping through hoops. And more usefully any expression's value can be made part of the output string. Like a bit further down where the class is set based on disabled/best
 
That the whole thing is wrapped up is a good coding practice thing. Otherwise every main function or variable I created would be global and attached to the window object. This way only one variable is exposed to the outside world (skillCalc) and so does not litter the global space. Has the side effect of making the variables private too.
 
Thanks for taking a look - I liked how my table and such came out after the reworking. And yeh people seem to like it, get asked about it relatively often and it's weird to see it being shared around the chat rooms and such. Will always field more questions. Might keep bumping it here when I add anything decent if you don't mind :)
And yeh. localstorage and template literals could definitely be added to the focus TODO list.

1

u/ForScale Apr 13 '16

That when statement is a comment :)

Lol! Whoops! :)

Template Literals - we used them before in that multiline string

comment stuff

Oh... yeah, okay. Interesting. Thanks for the reminder!

opening bracket is from forEach.

I see it now!

...

Nice, yeah, I think I'll start experimenting with those template literals. Thanks again for reminding me about those!

and so does not litter the global space

Aha! Makes sense.

Might keep bumping it here when I add anything decent if you don't mind :)

I don't mind at all!