Class: GameLoader

gameloader~GameLoader()

new GameLoader()

Runs all loading behavior. That includes: Keeping track of what game to currently load Transitioning into loaded games Playing/animating transitions from games using the Animation Manager.
Source:

Members

(private) alreadyPlayedGames

Uses localStorage to arbitrarily set difficulty if games are wholly new to the user. Is a list, should also probably be a set. So if a game isn’t in the list in this.transition(), then the difficulty is set to 1 and the game is added to this list. Initialized in setupGameLoader.
Source:

currGame

String of the game ID (the game’s folder name) to load. Set in loadGameHTML. Primarily meant for debugging.
Source:

(private) debug_index

If DEBUG_TEST is set to “sequential”, this will be used for the index of the current game played.
Source:

(readonly) game

Read-only accessor for module:gameloader~GameLoader#gameToLoad.
Source:

(private) gameLoaded

Did the gameStarted function get called? Set to false on transition
Source:

(private) gameNames

Dictionary to associate game IDs (how they’re stored in folders) with their actual names. Initialized in setupGameLoader. Stores the dictionary [Games] from config.ini
Source:

(readonly) gameNames

Public read-only accessor of module:gameloader~GameLoader#gameNames
Source:

(private) gameToLoad

A private reference for the current game we’re going to load throughout this.animateTransition(). Set using pickGameToLoad. Used in loadGameHTML.
Source:

(private) gamesConfig

Dictionary of games with special loading conditions. Initialized in setupGameLoader. Stores the dictionary [Games] from config.ini
Source:

(private) gamesList

The dictionary of games to load. Initialized in setupGameLoader. Stores the dictionary [Games] from config.ini
Source:
Tutorials:

(readonly) inGame

Read-only property for module:gameloader~GameLoader#gameLoaded. Used by input.js.
Source:

masterVolume

Set by MicrogameJam to control the overall volume of the GAME LOADER’s volume. Has no effect on the volume of the games being loaded.
Source:

picoInterface

Reference to picointerface.js. Created if a PICO-8 game is detected in module:gameloader~GameLoader#iframeLoaded. Updated in module:gameloader~GameLoader#loadUpdate if it exists.
Source:

(private) recentGamesLoaded

A list (should probably be a set) of the games that were recently loaded to avoid loading them again. Initialized in setupGameLoader. Items are arbitrarily removed in pickGameToLoad.
Source:

(private) setupPromise

This WAS supposed to be for loading the ini file. configloader.js does this instead, so I’m pretty sure this is useless.
Source:

(private) totalGamesPlayed

Used to set a difficulty curve. Modified in transition. Look for the ridiculous max/min/floor/log monstrosity and that’s the difficulty curve.
Source:

Methods

animateTransition(transitionName)

Gets everything ready to animate (like hiding the timer, showing the transition div, etc.) Prepares the life counter (calling this.setupLifeCounter()). Then uses GlobalAnimationManager.playKeyframedAnimation using all these settings. Sets animation to loop until the game is loaded, or unless it has specific configurations in this.#gamesConfig. Once the animation is configured to play, runs this.#loadGameHTML() (should probably just be moved to this.transition()? Although this would break this.loseGameTransition() behavior).
Parameters:
Name Type Description
transitionName string The name to use in the saved GlobalAnimationManager when calling module:animationmanager~CCSSGlobalAnimation#playKeyframedAnimation.
Source:

(private) clearGameHTML()

Set the source of the iframe with ID “game” (in index.html) to “about:blank” for resetting purposes. Called only in module:gameloader~GameLoader#animateTransition.
Source:

gameStarted()

Called by MicrogameJam#gameStarted. Hides the timer and game and sets GameLoader#gameLoaded to true.
Source:

(private) iframeLoaded()

Callback initialized in setupGameLoader. Fiddles with Unity and PICO-8 games if detected (initializes module:picointerface if detected), and tries to fix their behavior to work correctly.
Source:

(private) loadGameHTML(gameToLoad)

Sets the iframe with ID “game” (in index.html) to point to the new game’s .html.
Parameters:
Name Type Description
gameToLoad string The name of the game’s folder to use.
Source:

loadUpdate()

Called by MicrogameJam#update. Only calls module:picointerface~PicoInterface#picoUpdate if the current game is running PICO-8.
Source:
To Do:
  • Should we call this.picoInterface.picoUpdate(this.picoInterface)???

loseGameTransition()

Special function called by animateTransition for animating a complete loss of the game (1 or 0 lives remaining). Should probably be merged with animateTransition at some point? Uses module:animationmanager to do custom loss behavior (like removing lives, and exiting back to the home screen on a finished game). Other than that, it mostly acts like exactly how animateTransition would play out, if allowed to continue.
Source:

pickGameToLoad()

Pick a random game to load using Math.random, as long as it isn’t module:gameloader~GameLoader#recentGamesLoaded.
Source:

removeLives(numLives, lostLife)

Called by module:gameloader~GameLoader#animationTransition to tweak CSS settings for the intactLifeDiv s to remove them if they’ve been lost. And to hide them after the animation has finished.
Parameters:
Name Type Description
numLives number How many lives we have left
lostLife boolean Whether or not one of those lives will be lost.
Source:

setUpLifeCounter(numLives, lostLife)

Show the number intactLifeDiv s (setup in config.ini) based on numLives. And play a loseLife animation with module:animationmanager if lostLife is true.
Parameters:
Name Type Description
numLives number How many lives we have left
lostLife boolean Whether or not one of those lives will be lost.
Source:

(private) setupGameLoader()

Initialize all the properties we need. Set the iframe with ID “game” (in index.html) to call module:gameloader~GameLoader#iframeLoaded on load.
Source:

transition(didWin) → {number}

Main function where all the loading actually happens. Call module:gameloader~GameLoader#animateTransition according to didWin, and increase the difficulty accordingly.
Parameters:
Name Type Description
didWin boolean Are we meant to treat this as a loss (false) or a win (true)?
Source:
To Do:
  • Make game picking more robust, add difficulty increases, etc.
Returns:
The difficulty number.
Type
number