Skip to content

Commit

Permalink
Improves calling ini()'s ensures all are called exactly once
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed Oct 31, 2023
1 parent 22dc61a commit d5354e9
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions lib/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,31 @@ const ctrl = ( function() {

return false;
}

/** Private function. Ensure all ini()'s are called once. */
function callInis()
{
let ents = new Set();

// Add all locations and its objects
ctrl.places.locs.forEach( loc => {
ents.add( loc );
loc.objs.forEach( obj => ents.add( obj ) );
});

// Add all personas
ctrl.personas.personas.forEach( persona => {
ents.add( persona );
persona.objs.forEach( obj => ents.add( obj ) );
});

// Call ini()
for(const [ent, ent2] of ents.entries) {
ent.ini();
}

return;
}

/** This is the function to be called in order to start playing. */
function start()
Expand All @@ -2409,12 +2434,7 @@ const ctrl = ( function() {
// Call all the ini functions
ctrl.ini();
ctrl.places.setCurrentLoc( ctrl.places.getStart() );

ctrl.places.locs.forEach( l => {
l.ini();
l.objs.forEach( o => o.ini() );
l.personas.forEach( p => p.ini() );
});
callInis();

// Prepare web page
dvIntro.style.display = "block";
Expand Down

0 comments on commit d5354e9

Please sign in to comment.