/tinyletter

The Programs of the Week of Christmas & Hanukkah

This Week’s Program: Dec 19 - Dec 23

🎄 Merry Christmas and Happy Hanukkah! 🕎

On Monday I fiddled around and added the restart-emacs package to my Emacs configuration. Then I spent the rest of the week effectively beginning a rewrite on hive-city.

fa20151e243573eb732e123192fecbfd31a0f0b1

I introduce the Campaign module. It’s basically a new Main. I’m going to start introducing functionality into it piece-by-piece, this time built around my new Game module and two players.

956641e723ebb114486f7d3eccabdb0b8d4fe876

One change with large ramifications is that I am now looking at both the window width and height for my window size state. I want this pass at Hive City to be fully responsive, and able to scale up and down to whatever resolution.

bcab1bc12eb3ed96674e4e01fd4f681919540032

This commit adds two things. The first is I’m using Elm to actually bring in a style block so that I can have some css (that works nicely in Elm Reactor). The other is that I change the messaging and control areas on the top and bottom of the screen to use flexbox. With this and some new-found knowledge on SVG’s preserveAspectRatio my game always fits just right in the browser window.

42aa5b5d953472e897ea811f5cd18ee629df8f10

I change the Model’s view function to have a colored circle, which makes for an easier click target.

21a749c146bc18ef73197d61856c3914adf4e949

I add Game.selectFriendlyModel. This is the first step into trying out how to do commands for the “active” player.

e84b1c3bfb2fcc22445a31f6d18f0643428c1b62

I bring the Select Model Msg into Campaign, using that new function. Player One is assumed to be the controlling player.

0e4420b446b9220b6f5a5627d21ebac88662e0b2

Back in the Game module, I create a new union type: ActivePlayer. The ActivePlayer can either be PlayerOne or PlayerTwo. This is paired with the Turn. Based on what the ActivePlayer of the Turn is, I can map over either player one or player two. This is awesome, because now as the Turn advances to the next player, they’ll automatically be able to do those actions without hardcoding “player 1” or “player 2” anywhere.

1efb4c548dddd487d2733e468c83aa27aa2389e9

The next action to come over from the old Main module is Hover Mouse.Position. Using the new activePlayer functionality this is straight forward. Because the game is now fully responsive, my tabletopPositionFromMousePosition function gets a little bit more complex, figuring out the dimensions of the game from the window and aspect ratio of the table.

The next thing to come over is the KeyPress Msg.

77e855eb1980f563a39418ae1fd5d9012a9f8834

When the screen is taller than it is wide, I need to make sure that I update my positioning math. On a wide screen, the height of the game is always 80% of the window, but it will scale to preserve the game’s aspect ratio.

b9c7f52d63c15a4f4ef3db252a4eb85376f9822b

Click is the next Msg to be brought in, and once again the activePlayer semantics make things just a bit simpler.

Was a fun week for refactoring and cleaning up some of hive-city. It’s a shame I’ll be abandoning it soon, but hopefully I’ll have something worth showing and a thinkpiece worth writing.

I hope you enjoy your holidays and hold your family close, whether they’re blood relatives or others of significance or furry companions or whoever.

May your days be merry and bright,
🎁 Mark

🕯🕯🕯🕯🕯🕯🕯🕯