CSSE 2 Final Week 19
Personal blog for CSSE 2 Final Week 19
Quick breakdown of my current stats…
Up to ~85 PRs total now!
Day 1:
- Got an alternate ending working and running (collecting coins to proceed with levels)
- Some merge conflict fixes
- Fixed someones auth errors with tech aura. I have to find that meme someday. Please someone find it for me. “tech aura”
Day 2:
- Added local user ID storage. Just storing the user ID the user sets in local storage
- Prototyping for saving level progression; although the variable logs work, it keeps resetting the level index to 4 for no apparent reason. Will have to fix this later.
- Updating ideation + notebooks for local storage
- Made PR but it’s integrated with the other LEAAAAM team’s commits because I made the PR using main (where we both committed to)
Day 3:
- Working on moving the last 2 commits made for ideation to another branch so we’re not pushing with the other LEAAAAM team’s content. Nearly erased 2 commits from history, but luckily I had it logged locally (
git reflog
). PSA: Don’t usegit reset --hard HEAD~2
andgit push --force
unless you no what you’re doing. - Seperated the PRs and pushed.
Behold!
Added this code to GameControl.js
:
// Save the current level index to localStorage
const currentLevelIndex = GameEnv.levels.indexOf(newLevel);
console.log("Set currentLevelIndex to localStorage:", currentLevelIndex);
localStorage.setItem('currentLevelIndex', currentLevelIndex);
I placed this under the async transitionToLevel(newLevel)
so that it logs the level that is transitioned to locally. Theoretically, it a player is transitioning to that level, they have completed the previous level, and thus progression is saved! Logged to local storage and debugging statement in console.
I then added this code to GameSetup.js
:
const savedLevelIndex = localStorage.getItem('currentLevelIndex');
if (savedLevelIndex !== null) {
GameEnv.currentLevel = GameEnv.levels[parseInt(savedLevelIndex)];
GameControl.transitionToLevel(GameEnv.levels[savedLevelIndex]);
console.log("Restored level index from localStorage:", savedLevelIndex);
} else {
console.log("No saved level index found in localStorage. Starting from the beginning.");
GameEnv.currentLevel = GameEnv.levels[1];
GameControl.transitionToLevel(GameEnv.levels[1]);
}
Basically, retrieve the locally stored level ID, then run the subroutine (more on that in a moment). GameSetup.js
sets up the game when the browser session is launched, so here we retrieve the local storage item. If it doesn’t exist, we just start from the beginning with level index 1. Else, we set the GameEnv.currentLevel
parameter to the savedLevelIndex
and transition to that level. That’s the subroutine.
Not sure why there was a bug in Srinaga’s level, but I think it has something to do with his level parameters (requirements to exit). As of now, you can’t exit the level because of a bug, so maybe that resets GameEnv.currentLevel
to ID 4, thus messing up the entire local storage logging. It is done, however! I got Srinaga working on fixing his level.
But I digress, locally saved progress seems to work correctly now!
Srinaga’s level resetting IDs for some reason be like:
Day 4:
-
Apparently I accidentally completely erased one of the other LEAAAAM member’s code. However, I was able to revert the revert by running
git cherry-pick
, fixing the conflicts, then pushing back to main. Please work on branches! -
The level local storage progression works, but is sometimes buggy. At first, when I integrated it to the production repo, it was logging an ID called
currentLevel
in local storage that was broken. Weird! I later reloaded it around 5 minutes later, but then the correct variablecurrentLevelIndex
was correctly created and the level progression saves worked as intended. Weird.
-
Next fix would be to fix and save the time. Reloading the level resets the time to 0.00 seconds, which is obviously bad if the leaderboard depends on time predominantly. I’m sure this fix would be easy, however.
-
On another note, some commit in the last 10 PRs is causing the end pipes (to exit the level) to spawn in the air, preventing the player from leaving the level.