diff --git a/public/videoOverlayStrap.js b/public/videoOverlayStrap.js index 25ca259..104b727 100644 --- a/public/videoOverlayStrap.js +++ b/public/videoOverlayStrap.js @@ -1,5 +1,6 @@ -let app = {}; -let auth = {}; +var app = {}; +var auth = {}; +var gameName = ""; function log(...x) { window.Twitch.ext.rig.log(x); @@ -35,7 +36,13 @@ const configureElm = (channelId) => { streamerSettings = JSON.parse(window.Twitch.ext.configuration.broadcaster.content); app = Elm.VideoOverlay.init({ node: document.getElementById('elm'), - flags: {channelId: channelId, settings: streamerSettings, spellData: spellData, wandSprites: wandSprites} + flags: { + channelId: channelId, + settings: streamerSettings, + spellData: spellData, + wandSprites: wandSprites, + initialGameName: gameName + } }); }; @@ -54,3 +61,12 @@ window.Twitch.ext.onAuthorized(newAuth => { window.Twitch.ext.onError((err) => { log('TWITCH EXT ERROR', err); }); + +window.Twitch.ext.onContext((context, changed) => { + if (changed.includes("game")) { + log('Context changed: ', changed, context); + gameName = context.game; + log('Game changed: ', gameName); + app.ports.gameChangedPort.send(context.game); + } +}); diff --git a/ui/src/VideoOverlay.elm b/ui/src/VideoOverlay.elm index 66c0beb..3c52a9d 100644 --- a/ui/src/VideoOverlay.elm +++ b/ui/src/VideoOverlay.elm @@ -18,6 +18,9 @@ import Types exposing (..) port twitchBroadcastPort : (String -> msg) -> Sub msg +port gameChangedPort : (String -> msg) -> Sub msg + + --------------------- @@ -37,6 +40,7 @@ subscriptions _ = Err e -> BadWandUpdate e ) + , gameChangedPort GameChanged ] @@ -55,6 +59,7 @@ type alias Flags = , settings : Value , spellData : Value , wandSprites : Value + , initialGameName : String } @@ -71,6 +76,7 @@ init flags = , spellData = withDefault empty <| decodeValue (dict decodeSpell) flags.spellData , wandSprites = withDefault empty <| decodeValue (dict string) flags.wandSprites , isShowingHoverBoxes = False + , isPlayingNoita = flags.initialGameName == "Noita" } in ( m, flashHoverBoxes ) @@ -96,6 +102,7 @@ type Msg | ShowHoverBoxes | HideHoverBoxes | BadWandUpdate Error + | GameChanged String type alias Model = @@ -105,6 +112,7 @@ type alias Model = , spellData : SpellData , wandSprites : WandSprites , isShowingHoverBoxes : Bool + , isPlayingNoita : Bool } @@ -130,11 +138,18 @@ update msg model = in ( model, Cmd.none ) + GameChanged gameName -> + ( { model | isPlayingNoita = gameName == "Noita" }, flashHoverBoxes ) + view : Model -> Html Msg view model = div [] - [ viewTopSection model + [ if model.isPlayingNoita then + viewTopSection model + + else + text "" ] @@ -148,6 +163,7 @@ viewTopSection model = , Css.marginRight (Css.pct 0.45) ] [] + -- unused for now, but has width itemsSection = styled div @@ -155,6 +171,7 @@ viewTopSection model = , Css.margin4 (Css.pct 0.9) (Css.pct 1.7) (Css.pct 0.9) (Css.pct 0.45) ] [] + inventorySection = styled div [ Css.flex (Css.num 1) @@ -176,9 +193,9 @@ viewTopSection model = , Css.displayFlex ] [] - [ wandsSection <| [viewWands model] + [ wandsSection <| [ viewWands model ] , itemsSection <| [] - , inventorySection <| [viewInventory model] + , inventorySection <| [ viewInventory model ] ]