mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-13 03:06:15 +00:00
fix: Updated character tracking
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
import { NodeSelectionMouseHandler } from '@/hooks/Mapper/components/contexts/types.ts';
|
||||||
|
import { SESSION_KEY } from '@/hooks/Mapper/constants.ts';
|
||||||
|
import { PingData, SolarSystemConnection, SolarSystemRawType } from '@/hooks/Mapper/types';
|
||||||
|
import { MapHandlers, OutCommand, OutCommandHandler } from '@/hooks/Mapper/types/mapHandlers.ts';
|
||||||
|
import { ctxManager } from '@/hooks/Mapper/utils/contextManager.ts';
|
||||||
|
import type { PanelPosition } from '@reactflow/core';
|
||||||
|
import clsx from 'clsx';
|
||||||
import { ForwardedRef, forwardRef, MouseEvent, useCallback, useEffect, useMemo } from 'react';
|
import { ForwardedRef, forwardRef, MouseEvent, useCallback, useEffect, useMemo } from 'react';
|
||||||
import ReactFlow, {
|
import ReactFlow, {
|
||||||
Background,
|
Background,
|
||||||
@@ -16,8 +23,6 @@ import ReactFlow, {
|
|||||||
import 'reactflow/dist/style.css';
|
import 'reactflow/dist/style.css';
|
||||||
import classes from './Map.module.scss';
|
import classes from './Map.module.scss';
|
||||||
import { MapProvider, useMapState } from './MapProvider';
|
import { MapProvider, useMapState } from './MapProvider';
|
||||||
import { useEdgesState, useMapHandlers, useNodesState, useUpdateNodes } from './hooks';
|
|
||||||
import { MapHandlers, OutCommand, OutCommandHandler } from '@/hooks/Mapper/types/mapHandlers.ts';
|
|
||||||
import {
|
import {
|
||||||
ContextMenuConnection,
|
ContextMenuConnection,
|
||||||
ContextMenuRoot,
|
ContextMenuRoot,
|
||||||
@@ -26,14 +31,9 @@ import {
|
|||||||
useContextMenuRootHandlers,
|
useContextMenuRootHandlers,
|
||||||
} from './components';
|
} from './components';
|
||||||
import { getBehaviorForTheme } from './helpers/getThemeBehavior';
|
import { getBehaviorForTheme } from './helpers/getThemeBehavior';
|
||||||
import { OnMapAddSystemCallback, OnMapSelectionChange } from './map.types';
|
import { useEdgesState, useMapHandlers, useNodesState, useUpdateNodes } from './hooks';
|
||||||
import { SESSION_KEY } from '@/hooks/Mapper/constants.ts';
|
|
||||||
import { PingData, SolarSystemConnection, SolarSystemRawType } from '@/hooks/Mapper/types';
|
|
||||||
import { ctxManager } from '@/hooks/Mapper/utils/contextManager.ts';
|
|
||||||
import { NodeSelectionMouseHandler } from '@/hooks/Mapper/components/contexts/types.ts';
|
|
||||||
import clsx from 'clsx';
|
|
||||||
import { useBackgroundVars } from './hooks/useBackgroundVars';
|
import { useBackgroundVars } from './hooks/useBackgroundVars';
|
||||||
import type { PanelPosition } from '@reactflow/core';
|
import { OnMapAddSystemCallback, OnMapSelectionChange } from './map.types';
|
||||||
|
|
||||||
const DEFAULT_VIEW_PORT = { zoom: 1, x: 0, y: 0 };
|
const DEFAULT_VIEW_PORT = { zoom: 1, x: 0, y: 0 };
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { MapData, useMapState } from '@/hooks/Mapper/components/map/MapProvider.tsx';
|
import { MapData, useMapState } from '@/hooks/Mapper/components/map/MapProvider.tsx';
|
||||||
|
import { useEventBuffer } from '@/hooks/Mapper/hooks';
|
||||||
|
import { SolarSystemConnection, SolarSystemRawType } from '@/hooks/Mapper/types';
|
||||||
import { CommandInit } from '@/hooks/Mapper/types/mapHandlers.ts';
|
import { CommandInit } from '@/hooks/Mapper/types/mapHandlers.ts';
|
||||||
import { useCallback, useRef } from 'react';
|
import { useCallback, useRef } from 'react';
|
||||||
import { useReactFlow } from 'reactflow';
|
import { useReactFlow } from 'reactflow';
|
||||||
@@ -11,6 +13,20 @@ export const useMapInit = () => {
|
|||||||
const ref = useRef({ rf, data, update });
|
const ref = useRef({ rf, data, update });
|
||||||
ref.current = { update, data, rf };
|
ref.current = { update, data, rf };
|
||||||
|
|
||||||
|
const updateSystems = useCallback((systems: SolarSystemRawType[]) => {
|
||||||
|
const { rf } = ref.current;
|
||||||
|
rf.setNodes(systems.map(convertSystem2Node));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const { handleEvent: handleUpdateSystems } = useEventBuffer<any>(updateSystems);
|
||||||
|
|
||||||
|
const updateEdges = useCallback((connections: SolarSystemConnection[]) => {
|
||||||
|
const { rf } = ref.current;
|
||||||
|
rf.setEdges(connections.map(convertConnection2Edge));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const { handleEvent: handleUpdateConnections } = useEventBuffer<any>(updateEdges);
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
({
|
({
|
||||||
systems,
|
systems,
|
||||||
@@ -24,7 +40,6 @@ export const useMapInit = () => {
|
|||||||
hubs,
|
hubs,
|
||||||
}: CommandInit) => {
|
}: CommandInit) => {
|
||||||
const { update } = ref.current;
|
const { update } = ref.current;
|
||||||
const { rf } = ref.current;
|
|
||||||
|
|
||||||
const updateData: Partial<MapData> = {};
|
const updateData: Partial<MapData> = {};
|
||||||
|
|
||||||
@@ -63,11 +78,13 @@ export const useMapInit = () => {
|
|||||||
update(updateData);
|
update(updateData);
|
||||||
|
|
||||||
if (systems) {
|
if (systems) {
|
||||||
rf.setNodes(systems.map(convertSystem2Node));
|
handleUpdateSystems(systems);
|
||||||
|
// rf.setNodes(systems.map(convertSystem2Node));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connections) {
|
if (connections) {
|
||||||
rf.setEdges(connections.map(convertConnection2Edge));
|
handleUpdateConnections(connections);
|
||||||
|
// rf.setEdges(connections.map(convertConnection2Edge));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useCallback, useEffect, useRef } from 'react';
|
|
||||||
import { Node, useOnViewportChange, useReactFlow } from 'reactflow';
|
|
||||||
import { useMapState } from '@/hooks/Mapper/components/map/MapProvider.tsx';
|
import { useMapState } from '@/hooks/Mapper/components/map/MapProvider.tsx';
|
||||||
import { SolarSystemRawType } from '@/hooks/Mapper/types';
|
import { SolarSystemRawType } from '@/hooks/Mapper/types';
|
||||||
|
import { useCallback, useEffect, useRef } from 'react';
|
||||||
|
import { Node, useOnViewportChange, useReactFlow } from 'reactflow';
|
||||||
|
|
||||||
const useThrottle = () => {
|
const useThrottle = () => {
|
||||||
const throttleSeed = useRef<number | null>(null);
|
const throttleSeed = useRef<number | null>(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user