mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 07:26:19 +00:00
feat(wired-ui): add upcounter clock controls and checks
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
import { FC, useEffect, useMemo, useState } from 'react';
|
||||
import { LocalizeText, WiredFurniType } from '../../../../api';
|
||||
import { Slider, Text } from '../../../../common';
|
||||
import { useWired } from '../../../../hooks';
|
||||
import { WiredSourcesSelector } from '../WiredSourcesSelector';
|
||||
import { WiredActionBaseView } from './WiredActionBaseView';
|
||||
|
||||
const COUNTER_INTERACTION_TYPES = [ 'game_upcounter' ];
|
||||
const MINUTES_MIN = 0;
|
||||
const MINUTES_MAX = 99;
|
||||
const HALF_SECONDS_MIN = 0;
|
||||
const HALF_SECONDS_MAX = 119;
|
||||
|
||||
const OPERATOR_OPTIONS = [
|
||||
{ value: 0, label: 'wiredfurni.params.operator.0' },
|
||||
{ value: 1, label: 'wiredfurni.params.operator.1' },
|
||||
{ value: 2, label: 'wiredfurni.params.operator.2' }
|
||||
];
|
||||
|
||||
const normalizeOperator = (value: number) =>
|
||||
{
|
||||
if(value < 0 || value > 2) return 2;
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
const normalizeMinutes = (value: number) => Math.max(MINUTES_MIN, Math.min(MINUTES_MAX, value));
|
||||
const normalizeHalfSeconds = (value: number) => Math.max(HALF_SECONDS_MIN, Math.min(HALF_SECONDS_MAX, value));
|
||||
|
||||
const formatSeconds = (halfSeconds: number) =>
|
||||
{
|
||||
const value = normalizeHalfSeconds(halfSeconds) / 2;
|
||||
const text = value.toFixed(1);
|
||||
|
||||
return text.endsWith('.0') ? text.slice(0, -2) : text;
|
||||
};
|
||||
|
||||
export const WiredActionAdjustClockView: FC<{}> = () =>
|
||||
{
|
||||
const { trigger = null, setIntParams = null, setAllowedInteractionTypes = null, setAllowedInteractionErrorKey = null } = useWired();
|
||||
const [ operator, setOperator ] = useState(2);
|
||||
const [ furniSource, setFurniSource ] = useState<number>(() =>
|
||||
{
|
||||
if(trigger?.intData?.length > 1) return trigger.intData[1];
|
||||
return (trigger?.selectedItems?.length ?? 0) > 0 ? 100 : 0;
|
||||
});
|
||||
const [ minutes, setMinutes ] = useState(0);
|
||||
const [ halfSeconds, setHalfSeconds ] = useState(0);
|
||||
|
||||
const secondsLabel = useMemo(() => formatSeconds(halfSeconds), [ halfSeconds ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
if(!trigger) return;
|
||||
|
||||
setOperator((trigger.intData.length > 0) ? normalizeOperator(trigger.intData[0]) : 2);
|
||||
setFurniSource((trigger.intData.length > 1) ? trigger.intData[1] : ((trigger.selectedItems?.length ?? 0) > 0 ? 100 : 0));
|
||||
setMinutes((trigger.intData.length > 2) ? normalizeMinutes(trigger.intData[2]) : 0);
|
||||
setHalfSeconds((trigger.intData.length > 3) ? normalizeHalfSeconds(trigger.intData[3]) : 0);
|
||||
}, [ trigger ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
setAllowedInteractionTypes(COUNTER_INTERACTION_TYPES);
|
||||
setAllowedInteractionErrorKey('wiredfurni.error.require_counter_furni');
|
||||
|
||||
return () =>
|
||||
{
|
||||
setAllowedInteractionTypes(null);
|
||||
setAllowedInteractionErrorKey(null);
|
||||
};
|
||||
}, [ setAllowedInteractionErrorKey, setAllowedInteractionTypes ]);
|
||||
|
||||
const save = () =>
|
||||
{
|
||||
setIntParams([
|
||||
operator,
|
||||
furniSource,
|
||||
normalizeMinutes(minutes),
|
||||
normalizeHalfSeconds(halfSeconds)
|
||||
]);
|
||||
};
|
||||
|
||||
return (
|
||||
<WiredActionBaseView
|
||||
hasSpecialInput={ true }
|
||||
requiresFurni={ WiredFurniType.STUFF_SELECTION_OPTION_BY_ID_BY_TYPE_OR_FROM_CONTEXT }
|
||||
save={ save }
|
||||
footer={ <WiredSourcesSelector showFurni={ true } furniSource={ furniSource } onChangeFurni={ setFurniSource } /> }>
|
||||
<div className="flex flex-col gap-2">
|
||||
{ OPERATOR_OPTIONS.map(option =>
|
||||
{
|
||||
return (
|
||||
<div key={ option.value } className="flex items-center gap-1">
|
||||
<input checked={ (operator === option.value) } className="form-check-input" id={ `adjustClockOperator${ option.value }` } name="adjustClockOperator" type="radio" onChange={ () => setOperator(option.value) } />
|
||||
<Text>{ LocalizeText(option.label) }</Text>
|
||||
</div>
|
||||
);
|
||||
}) }
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<Text bold>{ LocalizeText('wiredfurni.params.time.minute_selection') }</Text>
|
||||
<Slider
|
||||
max={ MINUTES_MAX }
|
||||
min={ MINUTES_MIN }
|
||||
step={ 1 }
|
||||
value={ minutes }
|
||||
onChange={ event => setMinutes(normalizeMinutes(event as number)) } />
|
||||
<Text small>{ minutes }</Text>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<Text bold>{ LocalizeText('wiredfurni.params.time.second_selection') }</Text>
|
||||
<Slider
|
||||
max={ HALF_SECONDS_MAX }
|
||||
min={ HALF_SECONDS_MIN }
|
||||
step={ 1 }
|
||||
value={ halfSeconds }
|
||||
onChange={ event => setHalfSeconds(normalizeHalfSeconds(event as number)) } />
|
||||
<Text small>{ secondsLabel }</Text>
|
||||
</div>
|
||||
</WiredActionBaseView>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
import { FC, useEffect, useState } from 'react';
|
||||
import { LocalizeText, WiredFurniType } from '../../../../api';
|
||||
import { Text } from '../../../../common';
|
||||
import { useWired } from '../../../../hooks';
|
||||
import { WiredSourcesSelector } from '../WiredSourcesSelector';
|
||||
import { WiredActionBaseView } from './WiredActionBaseView';
|
||||
|
||||
const COUNTER_INTERACTION_TYPES = [ 'game_upcounter' ];
|
||||
|
||||
const CONTROL_OPTIONS = [
|
||||
{ value: 0, label: 'wiredfurni.params.clock_control.0' },
|
||||
{ value: 1, label: 'wiredfurni.params.clock_control.1' },
|
||||
{ value: 2, label: 'wiredfurni.params.clock_control.2' },
|
||||
{ value: 3, label: 'wiredfurni.params.clock_control.3' },
|
||||
{ value: 4, label: 'wiredfurni.params.clock_control.4' }
|
||||
];
|
||||
|
||||
const normalizeControl = (value: number) =>
|
||||
{
|
||||
if(value < 0 || value > 4) return 0;
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
export const WiredActionControlClockView: FC<{}> = () =>
|
||||
{
|
||||
const { trigger = null, setIntParams = null, setAllowedInteractionTypes = null, setAllowedInteractionErrorKey = null } = useWired();
|
||||
const [ control, setControl ] = useState(0);
|
||||
const [ furniSource, setFurniSource ] = useState<number>(() =>
|
||||
{
|
||||
if(trigger?.intData?.length > 1) return trigger.intData[1];
|
||||
return (trigger?.selectedItems?.length ?? 0) > 0 ? 100 : 0;
|
||||
});
|
||||
|
||||
const save = () =>
|
||||
{
|
||||
setIntParams([
|
||||
control,
|
||||
furniSource
|
||||
]);
|
||||
};
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
if(!trigger) return;
|
||||
|
||||
setControl((trigger.intData.length > 0) ? normalizeControl(trigger.intData[0]) : 0);
|
||||
setFurniSource((trigger.intData.length > 1) ? trigger.intData[1] : ((trigger.selectedItems?.length ?? 0) > 0 ? 100 : 0));
|
||||
}, [ trigger ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
setAllowedInteractionTypes(COUNTER_INTERACTION_TYPES);
|
||||
setAllowedInteractionErrorKey('wiredfurni.error.require_counter_furni');
|
||||
|
||||
return () =>
|
||||
{
|
||||
setAllowedInteractionTypes(null);
|
||||
setAllowedInteractionErrorKey(null);
|
||||
};
|
||||
}, [ setAllowedInteractionErrorKey, setAllowedInteractionTypes ]);
|
||||
|
||||
return (
|
||||
<WiredActionBaseView
|
||||
hasSpecialInput={ true }
|
||||
requiresFurni={ WiredFurniType.STUFF_SELECTION_OPTION_BY_ID_BY_TYPE_OR_FROM_CONTEXT }
|
||||
save={ save }
|
||||
footer={ <WiredSourcesSelector showFurni={ true } furniSource={ furniSource } onChangeFurni={ setFurniSource } /> }>
|
||||
<div className="flex flex-col gap-2">
|
||||
{ CONTROL_OPTIONS.map(option =>
|
||||
{
|
||||
return (
|
||||
<div key={ option.value } className="flex items-center gap-1">
|
||||
<input checked={ (control === option.value) } className="form-check-input" id={ `controlClock${ option.value }` } name="controlClock" type="radio" onChange={ () => setControl(option.value) } />
|
||||
<Text>{ LocalizeText(option.label) }</Text>
|
||||
</div>
|
||||
);
|
||||
}) }
|
||||
</div>
|
||||
</WiredActionBaseView>
|
||||
);
|
||||
};
|
||||
@@ -1,6 +1,8 @@
|
||||
import { WiredActionLayoutCode } from '../../../../api';
|
||||
import { WiredActionBotChangeFigureView } from './WiredActionBotChangeFigureView';
|
||||
import { WiredActionAdjustClockView } from './WiredActionAdjustClockView';
|
||||
import { WiredActionFreezeView } from './WiredActionFreezeView';
|
||||
import { WiredActionControlClockView } from './WiredActionControlClockView';
|
||||
import { WiredActionFurniToFurniView } from './WiredActionFurniToFurniView';
|
||||
import { WiredActionSetAltitudeView } from './WiredActionSetAltitudeView';
|
||||
import { WiredActionSendSignalView } from './WiredActionSendSignalView';
|
||||
@@ -42,6 +44,8 @@ export const WiredActionLayoutView = (code: number) =>
|
||||
{
|
||||
case WiredActionLayoutCode.BOT_CHANGE_FIGURE:
|
||||
return <WiredActionBotChangeFigureView />;
|
||||
case WiredActionLayoutCode.ADJUST_CLOCK:
|
||||
return <WiredActionAdjustClockView />;
|
||||
case WiredActionLayoutCode.BOT_FOLLOW_AVATAR:
|
||||
return <WiredActionBotFollowAvatarView />;
|
||||
case WiredActionLayoutCode.BOT_GIVE_HAND_ITEM:
|
||||
@@ -64,6 +68,8 @@ export const WiredActionLayoutView = (code: number) =>
|
||||
return <WiredActionFleeView />;
|
||||
case WiredActionLayoutCode.FREEZE:
|
||||
return <WiredActionFreezeView />;
|
||||
case WiredActionLayoutCode.CONTROL_CLOCK:
|
||||
return <WiredActionControlClockView />;
|
||||
case WiredActionLayoutCode.FURNI_TO_USER:
|
||||
return <WiredActionTeleportView />;
|
||||
case WiredActionLayoutCode.FURNI_TO_FURNI:
|
||||
|
||||
Reference in New Issue
Block a user