Skip to content

KcdMp.feed.visibility.subscribe

Registers a function that is told when the interface is drawn or hidden.

fn({ visible, reason }) is called with the latest value at once and again whenever it changes. It is the same news as KcdMp.onVisibility gives, from the feed’s list: use the feed when the frame lists visibility in its feeds, the handler when it does not.

The frame must list visibility in its feeds in ui.toml.

KcdMp.feed.visibility.subscribe(fn)
Parameter Type
fn (visibility: KcdMpVisibility) => void called with each value

() => void - a function that takes the handler off again

Whether the interface is drawn, and if not, why.

Field Type
visible boolean true while the interface is drawn over the game
reason "loading" | "menu" | "game_screen" | "panic" | "hidden" | "" why it is not drawn: "loading" (a level is loading), "menu" (a game menu is open), "game_screen" (one of the game’s own screens is up), "panic" (the player switched the interface off), "hidden" (it is turned off), and "" while it is drawn
KcdMp.feed.visibility.subscribe(({ visible, reason }) => {
document.body.classList.toggle("paused", !visible);
KcdMp.log.info(visible ? "drawn" : "hidden: " + reason);
});

KcdMp.onVisibility · KcdMp.feed · the Feeds group of the index