Closes the game view and shows the menu where failed indicates whether the game was lost before
Source
closeGameView(bool failed) async {
// Reset Game
_gameLayer.setInnerHtml("");
get("startGame").setInnerHtml(failed ? "RETRY!" : _levelManager.current > 0 ? "CONTINUE!" : "ENTER!");
if (_levelManager.unlocked > 0) {
show(get("showLevels"));
final levelSelection = get("levelSelection");
for (var i = 0; i <= _levelManager.unlocked && i < _levelManager.size; i++) {
if (get("level-${i}") == null) {
final lvlidx = i;
levelSelection.appendHtml("<button class='btn' id='level-${i}'>Level ${i + 1}</button>");
get("level-${i}").onClick.listen((e) => _selectLevelEvent.add(lvlidx));
}
}
}
clearCache();
// Toggle States
hide(_gameLayer);
show(_menuLayer);
activate(_menuLayer);
deactivate(_gameLayer);
deactivate(_inputLayer);
await nextFrame(); // Waiting for the next frame, otherwise the css activation animations wouldn't play.
deactivate(_mainElement);
}