The troll under the bridge

Hao Chen
Haorc
Published in
2 min readMar 17, 2018

This week, I had the opportunity to contribute to project similar to Pokemon Go. Bridge Troll is a geolocation based project created by my professor David Humphrey.

He is requesting a new feature to be added, where the program will change theme based on the time of the day.

Suncalc is a library to calculate sunlight times. I looked around and found this:

Great! getTimes() will return sunrise, which can be used for swapping themes. Below is my logic in theme.js:

This function call will made in the same file to return the correct theme base on whether the sun is out.

I’m using the dark tile for this issue, more can be found here. In svg-marker.js, I make the call to IsNightTime to use the appropriate set of icons:

This is what it looks like after:

Concluding thoughts:

This issue was really fun to tackle. I got to work with two of my peers and bounce ideas and solutions off of one another. Also, the code base was quite small, so I had an easy time navigating and understanding the structure of the software.

I approached the problem with the intention of making things modular. I had to consider which existing calls could be refactored out into my theme.js class so when I add new functionality, the class will be decoupled.

As an added bonus, using prettier at the recommendation of professor Humphrey enjoyable!

--

--