-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
140 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/browser/graphics/components/nameplate/sync-display.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import gsap from "gsap"; | ||
import {ReactNode, createContext, useEffect, useState} from "react"; | ||
import {useReplicant} from "../../../use-replicant"; | ||
|
||
type DisplayLabel = "name" | "twitter" | "twitch" | "nico"; | ||
|
||
export const SyncDisplayContext = createContext<DisplayLabel>("name"); | ||
|
||
export const SyncDisplayProvider = ({children}: {children: ReactNode}) => { | ||
const [display, setDisplay] = useState<DisplayLabel>("name"); | ||
|
||
const currentRun = useReplicant("current-run"); | ||
|
||
const participantSocials = [ | ||
...(currentRun?.runners.map((runner) => | ||
[ | ||
runner.twitter ? "twitter" : null, | ||
runner.twitch ? "twitch" : null, | ||
runner.nico ? "nico" : null, | ||
].filter((v): v is DisplayLabel => v !== null), | ||
) ?? []), | ||
...(currentRun?.commentators.map((commentator) => | ||
[ | ||
commentator?.twitter ? "twitter" : null, | ||
commentator?.twitch ? "twitch" : null, | ||
commentator?.nico ? "nico" : null, | ||
].filter((v): v is DisplayLabel => v !== null), | ||
) ?? []), | ||
]; | ||
|
||
const displayTwitter = participantSocials.some((socials) => | ||
socials.includes("twitter"), | ||
); | ||
const displayTwitch = participantSocials.some((socials) => | ||
socials.includes("twitch"), | ||
); | ||
const displayNico = participantSocials.some((socials) => | ||
socials.includes("nico"), | ||
); | ||
|
||
useEffect(() => { | ||
const tl = gsap.timeline({repeat: -1}); | ||
const displays: DisplayLabel[] = [ | ||
displayTwitter ? "twitter" : null, | ||
displayTwitch ? "twitch" : null, | ||
displayNico ? "nico" : null, | ||
"name", | ||
].filter((v): v is DisplayLabel => v !== null); | ||
for (const social of displays) { | ||
tl.call( | ||
(s) => { | ||
setDisplay(s); | ||
}, | ||
[social], | ||
"+=31", // 表示時間の30秒と切り替え時間の1秒 | ||
); | ||
} | ||
return () => { | ||
tl.kill(); | ||
}; | ||
}, [displayTwitter, displayTwitch, displayNico]); | ||
|
||
return ( | ||
<SyncDisplayContext.Provider value={display}> | ||
{children} | ||
</SyncDisplayContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters