@@ -4,6 +4,7 @@ import signals from '@/app/lib/data/signals.json'
44import signalsDlc from '@/app/lib/data/signals-dlc.json'
55import { usePostHog } from 'posthog-js/react'
66import { Song } from '@/app/lib/song'
7+ import { PlaybackMode } from '@/app/lib/factorio-blueprint-schema'
78
89/**
910 * @param text
@@ -29,13 +30,20 @@ const versionOptions: Record<Version, string> = {
2930 '2SA' : 'Factorio 2.x with Space Age DLC' ,
3031}
3132
33+ const playbackModeOptions : Record < PlaybackMode , [ string , string ] > = {
34+ 'global' : [ 'Global' , 'The song can be heard everywhere' ] ,
35+ 'surface' : [ 'Surface' , 'The song can be heard on speaker\'s surface' ] ,
36+ 'local' : [ 'Local' , 'The song can be heard within the audible range around the speaker' ] ,
37+ }
38+
3239export type ResultStageProps = {
3340 song : Song
3441}
3542export const ResultStage = ( { song } : ResultStageProps ) => {
3643 const postHog = usePostHog ( )
3744
3845 const [ targetVersion , setTargetVersion ] = useState < Version > ( '2' )
46+ const [ playbackMode , setPlaybackMode ] = useState < PlaybackMode > ( 'global' )
3947 const [ copySuccess , setCopySuccess ] = useState < boolean > ( false )
4048 const [ blueprintString , setBlueprintString ] = useState ( '' )
4149 const [ warnings , setWarnings ] = useState < string [ ] > ( [ ] )
@@ -44,7 +52,7 @@ export const ResultStage = ({ song }: ResultStageProps) => {
4452 setCopySuccess ( false )
4553 const signalSet = targetVersion === '2SA' ? signalsDlc : signals
4654
47- const { blueprint, warnings } = songToFactorio ( song , signalSet )
55+ const { blueprint, warnings } = songToFactorio ( song , signalSet , playbackMode )
4856 const copyAttempt = await copyToClipboard ( blueprint )
4957 setWarnings ( warnings )
5058 setCopySuccess ( copyAttempt )
@@ -53,11 +61,12 @@ export const ResultStage = ({ song }: ResultStageProps) => {
5361 Title : song . midi . name ,
5462 'Song Settings' : song . settings ,
5563 'Factorio Version' : targetVersion ,
64+ 'Playback Mode' : playbackMode ,
5665 Blueprint : blueprint ,
5766 Warnings : warnings ,
5867 'Clipboard Success' : copyAttempt ,
5968 } )
60- } , [ postHog , song , targetVersion ] )
69+ } , [ postHog , song , targetVersion , playbackMode ] )
6170
6271 return (
6372 < div className = "flex-column items-start gap-4" >
@@ -93,6 +102,28 @@ export const ResultStage = ({ song }: ResultStageProps) => {
93102 </ div >
94103 ) }
95104
105+ < div className = "flex-column gap-2" >
106+ < p > Playback mode:</ p >
107+ { Object . entries ( playbackModeOptions ) . map ( ( [ value , texts ] ) => (
108+ < div className = "flex gap-2 ml-4" key = { value } title = { texts [ 1 ] } >
109+ < label >
110+ < input
111+ type = "radio"
112+ name = "playback-mode"
113+ onChange = { ( { target : { value } } ) => {
114+ setCopySuccess ( false )
115+ setPlaybackMode ( value as PlaybackMode )
116+ } }
117+ value = { value }
118+ disabled = { targetVersion === '1' }
119+ checked = { value === playbackMode }
120+ />
121+ { texts [ 0 ] }
122+ </ label >
123+ </ div >
124+ ) ) }
125+ </ div >
126+
96127 < div className = "flex items-center gap-4" >
97128 < button
98129 className = { `button button-green box-border ${ targetVersion === '1' ? 'disabled' : '' } ` }
0 commit comments