Today I stayed home and did a good chunk of refactoring on the mob coding app, I visited my family for a July 4th BBQ with their friends, I returned downtown to see a bunch of fireworks exploding directly over my head right on my street, and then I finally played that game Portal!
Real-time notes:
8:23am: Sitting in bed, finishing up yesterday’s blog post. I was looking back at some of my previous notes. My workflow is basically a depth-first search algorithm! I dive deep into a task or topic, and then once I’m finished with it, I backtrack, right back up to the last split in the tree, and then I dive into another topic. Rinse and repeat. My past notes serve as breadcrumbs to help me find my way back. It’s interesting to see how some of them end up sort of resolving themselves, and others get left behind, often put on hold indefinitely because every answer I find just raises 20 more questions!
9:32am: Still in bed, feeling a bit sleepy, but I feel like messing with this code some more. First, the new logic for starting the game! And sending the entire game state to the client. Here’s the first small issue: I don’t want to send a timestamp to the clients, since time zone changes or whatever could mess up the timer. Better to just send the time remaining – something that isn’t dependent on each client’s date and time settings. But it does make sense to track time that way on the server. Or does it? Maybe I don’t even need it! Let’s take a look.
10:24am: Well that took forever! I learned how to reorder commits using interactive rebasing, which required me to resolve some merge conflicts and also squash two commits into one. But it worked! I changed my mind about some of the changes I made last night, so I wanted to clean up the commit history to make it look like I never changed my mind. The main thing is I removed the timerId
and turnDuration
from the gameState
object and left them as separate global variables, and I decided to use timeRemaining
everywhere on the server since I didn’t need it for anything except to send the latest state to the clients! So, I’m pretty happy with this now.
OK, now the game state is exactly what needs to be sent to initialize any new clients once they connect! So I need to make a couple changes on the server and a lot of changes on the client to remove a bunch of events that I won’t be using anymore.
…
11:36am: Took a break kind of by accident – I felt really emotional! Feeling better again now. Probably just a combination of sleep deprivation, lack of calories, and the week’s anxiety finally catching up to me. I do still want to work on this, though. I want to finish this main chunk of refactoring today, and then enjoy family time at the BBQ later today, and then maybe do something fun with friends back downtown again later tonight. Anyway, where did I leave off… Right, starting the game. Oh wow, the code looks so much nicer now!
…
12:27pm: Took a lunch break, did some more refactoring. Time to fix things on the client side!
1:05pm: Just realized that the client game state shouldn’t include the editor stuff, unless I move the Ace Editor object into the game state object on the client! Ah, I’m making a bunch of changes and feeling a bit concerned that I’m just going to break everything. But there’s no going back now! I’ll see how far I get with this.
1:53pm: Making progress! I think the last piece to change is implementing the new playerLeft
event on both the server and the clients.
2:45pm: I’m done! Lots of other refactoring tasks along the way, plus a couple quick breaks in between. Am I ready to test it now? I think so! Surely something will break, but I don’t think I’ll find it on my own without testing it first. Fingers crossed… Uh oh, that’s not right. Oh, I just forgot to initialize the SocketIO event listeners on the client for the new events! Silly me.
2:52pm: That’s much better, but I think I forgot to initialize the countdown timer on the clients! Oh wait, no, my previous attempt at refactoring actually broke the timer animation, because I forgot how it worked. (I saw what looked like redundant variables, but that’s the very mechanism that allows the animation to work! Oops!) I did another interactive rebase to remove that commit, which worked like a charm. Hurray for modular commits that are easy to undo, even if they happened a long time ago! Let’s try this again…
3:01pm: Yay, much better! Just one more small bug: each client sees a duplicate of their name and avatar in the player list view. I guess I accidentally duplicated something somewhere… Oh, I see it! Because each client now gets the entire game state when they log in, I can get rid of some other code that was a hacky way of displaying each client’s player data, which worked differently from how all the other players were displayed. I just forgot about all that code (probably because it was unintuitive!).
3:10pm: It works! But I found a couple more bugs: something isn’t updating correctly when the current player disconnects, and the countdown timer isn’t updating correctly when new players join. I already know the issue for that second bug… I can’t save a dynamic value inside an object; I need to broadcast a constantly-changing time value to all the clients, not a static game state object! So I might need to restructure my code a bit.
3:17pm: Well, time to stop for now. I need to get ready and drive over to my family’s house now before they head over to that July 4th BBQ.
Wrapping up: It was nice to see family, eat a ton of food, and then return downtown to see fireworks all over the place. Going for a walk and seeing them explode directly overhead was a tiny bit scary but exhilirating – that’s the closest I’ve ever been to fireworks! I also played that classic video game Portal for the first time, which was both fun and frustrating, as any good puzzle game should be.