mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 23:46:19 +00:00
feat: rare values panel + fortune wheel UI + prize editor
Toolbar buttons, FortuneWheelView (animated wheel, prize icons, recent winners), RareValuesView (diamond price guide + staff prize-editor tab), furni infostand value line, useFortuneWheel/useRareValues hooks, it/en text examples.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { IRareValue, RareValuesEvent, RequestRareValuesComposer } from '@nitrots/nitro-renderer';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useBetween } from 'use-between';
|
||||
import { SendMessageComposer } from '../../api';
|
||||
import { useMessageEvent } from '../events';
|
||||
|
||||
// spriteId -> catalog value, fetched once from the server (RareValuesComposer).
|
||||
// Shared across all consumers via useBetween so the request fires a single time.
|
||||
// Read by both the furni infostand and the toolbar "Valore Rari" panel.
|
||||
const useRareValuesState = () =>
|
||||
{
|
||||
const [ values, setValues ] = useState<Map<number, IRareValue>>(() => new Map());
|
||||
const [ loaded, setLoaded ] = useState(false);
|
||||
|
||||
useMessageEvent<RareValuesEvent>(RareValuesEvent, event =>
|
||||
{
|
||||
setValues(event.getParser().values);
|
||||
setLoaded(true);
|
||||
});
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
SendMessageComposer(new RequestRareValuesComposer());
|
||||
}, []);
|
||||
|
||||
const getValue = useCallback((spriteId: number): IRareValue => (values.get(spriteId) ?? null), [ values ]);
|
||||
|
||||
return { values, loaded, getValue };
|
||||
};
|
||||
|
||||
export const useRareValues = () => useBetween(useRareValuesState);
|
||||
Reference in New Issue
Block a user