mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-14 03:35:54 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { useMapState } from '@/hooks/Mapper/components/map/MapProvider.tsx';
|
||||
import { useCallback, useRef } from 'react';
|
||||
import {
|
||||
CommandCharacterAdded,
|
||||
CommandCharacterRemoved,
|
||||
CommandCharactersUpdated,
|
||||
CommandCharacterUpdated,
|
||||
CommandPresentCharacters,
|
||||
} from '@/hooks/Mapper/types';
|
||||
|
||||
export const useCommandsCharacters = () => {
|
||||
const { update } = useMapState();
|
||||
|
||||
const ref = useRef({ update });
|
||||
ref.current = { update };
|
||||
|
||||
const charactersUpdated = useCallback((characters: CommandCharactersUpdated) => {
|
||||
ref.current.update(() => ({ characters: characters.slice() }));
|
||||
}, []);
|
||||
|
||||
const characterAdded = useCallback((value: CommandCharacterAdded) => {
|
||||
ref.current.update(state => {
|
||||
return { characters: [...state.characters.filter(x => x.eve_id !== value.eve_id), value] };
|
||||
});
|
||||
}, []);
|
||||
|
||||
const characterRemoved = useCallback((value: CommandCharacterRemoved) => {
|
||||
ref.current.update(state => {
|
||||
return { characters: [...state.characters.filter(x => x.eve_id !== value.eve_id)] };
|
||||
});
|
||||
}, []);
|
||||
|
||||
const characterUpdated = useCallback((value: CommandCharacterUpdated) => {
|
||||
ref.current.update(state => {
|
||||
return { characters: [...state.characters.filter(x => x.eve_id !== value.eve_id), value] };
|
||||
});
|
||||
}, []);
|
||||
|
||||
const presentCharacters = useCallback((value: CommandPresentCharacters) => {
|
||||
ref.current.update(() => ({ presentCharacters: value }));
|
||||
}, []);
|
||||
|
||||
return { charactersUpdated, presentCharacters, characterAdded, characterRemoved, characterUpdated };
|
||||
};
|
||||
Reference in New Issue
Block a user