Skip to content

Commit

Permalink
Don't show the extension when streamer isn't playing Noita
Browse files Browse the repository at this point in the history
  • Loading branch information
halfbro committed Jun 28, 2022
1 parent 64a1583 commit 194ac1e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
22 changes: 19 additions & 3 deletions public/videoOverlayStrap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let app = {};
let auth = {};
var app = {};
var auth = {};
var gameName = "";

function log(...x) {
window.Twitch.ext.rig.log(x);
Expand Down Expand Up @@ -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
}
});
};

Expand All @@ -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);
}
});
23 changes: 20 additions & 3 deletions ui/src/VideoOverlay.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import Types exposing (..)
port twitchBroadcastPort : (String -> msg) -> Sub msg


port gameChangedPort : (String -> msg) -> Sub msg



---------------------

Expand All @@ -37,6 +40,7 @@ subscriptions _ =
Err e ->
BadWandUpdate e
)
, gameChangedPort GameChanged
]


Expand All @@ -55,6 +59,7 @@ type alias Flags =
, settings : Value
, spellData : Value
, wandSprites : Value
, initialGameName : String
}


Expand All @@ -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 )
Expand All @@ -96,6 +102,7 @@ type Msg
| ShowHoverBoxes
| HideHoverBoxes
| BadWandUpdate Error
| GameChanged String


type alias Model =
Expand All @@ -105,6 +112,7 @@ type alias Model =
, spellData : SpellData
, wandSprites : WandSprites
, isShowingHoverBoxes : Bool
, isPlayingNoita : Bool
}


Expand All @@ -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 ""
]


Expand All @@ -148,13 +163,15 @@ viewTopSection model =
, Css.marginRight (Css.pct 0.45)
]
[]

-- unused for now, but has width
itemsSection =
styled div
[ Css.width (Css.pct 15.5)
, 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)
Expand All @@ -176,9 +193,9 @@ viewTopSection model =
, Css.displayFlex
]
[]
[ wandsSection <| [viewWands model]
[ wandsSection <| [ viewWands model ]
, itemsSection <| []
, inventorySection <| [viewInventory model]
, inventorySection <| [ viewInventory model ]
]


Expand Down

0 comments on commit 194ac1e

Please sign in to comment.