More wired changes

This commit is contained in:
Bill 2022-03-23 22:44:43 -04:00
parent 93274670ce
commit f172442cbc
2 changed files with 9 additions and 17 deletions

View File

@ -11,7 +11,7 @@ export const WiredView: FC<{}> = props =>
const [ intParams, setIntParams ] = useState<number[]>([]); const [ intParams, setIntParams ] = useState<number[]>([]);
const [ stringParam, setStringParam ] = useState<string>(''); const [ stringParam, setStringParam ] = useState<string>('');
const [ furniIds, setFurniIds ] = useState<number[]>([]); const [ furniIds, setFurniIds ] = useState<number[]>([]);
const [ actionDelay, setActionDelay ] = useState<number>(null); const [ actionDelay, setActionDelay ] = useState<number>(0);
const saveWired = () => const saveWired = () =>
{ {

View File

@ -1,5 +1,5 @@
import { WiredActionDefinition } from '@nitrots/nitro-renderer'; import { WiredActionDefinition } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useState } from 'react'; import { FC, useEffect } from 'react';
import ReactSlider from 'react-slider'; import ReactSlider from 'react-slider';
import { GetWiredTimeLocale, LocalizeText, WiredFurniType } from '../../../../api'; import { GetWiredTimeLocale, LocalizeText, WiredFurniType } from '../../../../api';
import { Column, Text } from '../../../../common'; import { Column, Text } from '../../../../common';
@ -16,33 +16,25 @@ export interface WiredActionBaseViewProps
export const WiredActionBaseView: FC<WiredActionBaseViewProps> = props => export const WiredActionBaseView: FC<WiredActionBaseViewProps> = props =>
{ {
const { requiresFurni = WiredFurniType.STUFF_SELECTION_OPTION_NONE, save = null, hasSpecialInput = false, children = null } = props; const { requiresFurni = WiredFurniType.STUFF_SELECTION_OPTION_NONE, save = null, hasSpecialInput = false, children = null } = props;
const [ delay, setDelay ] = useState(-1); const { trigger = null, actionDelay = 0, setActionDelay = null } = useWiredContext();
const { trigger = null, setActionDelay = null } = useWiredContext();
useEffect(() => useEffect(() =>
{ {
setDelay((trigger as WiredActionDefinition).delayInPulses); setActionDelay((trigger as WiredActionDefinition).delayInPulses);
}, [ trigger ]); }, [ trigger, setActionDelay ]);
const onSave = useCallback(() =>
{
if(save) save();
setActionDelay(delay);
}, [ delay, save, setActionDelay ]);
return ( return (
<WiredBaseView wiredType="action" requiresFurni={ requiresFurni } save={ onSave } hasSpecialInput={ hasSpecialInput }> <WiredBaseView wiredType="action" requiresFurni={ requiresFurni } save={ save } hasSpecialInput={ hasSpecialInput }>
{ children } { children }
{ !!children && <hr className="m-0 bg-dark" /> } { !!children && <hr className="m-0 bg-dark" /> }
<Column> <Column>
<Text bold>{ LocalizeText('wiredfurni.params.delay', [ 'seconds' ], [ GetWiredTimeLocale(delay) ]) }</Text> <Text bold>{ LocalizeText('wiredfurni.params.delay', [ 'seconds' ], [ GetWiredTimeLocale(actionDelay) ]) }</Text>
<ReactSlider <ReactSlider
className={ 'nitro-slider' } className={ 'nitro-slider' }
min={ 0 } min={ 0 }
max={ 20 } max={ 20 }
value={ delay } value={ actionDelay }
onChange={ event => setDelay(event) } /> onChange={ event => setActionDelay(event) } />
</Column> </Column>
</WiredBaseView> </WiredBaseView>
); );