diff --git a/src/components/SceneryManager.js b/src/components/SceneryManager.js index c0a6631..c1cba7e 100644 --- a/src/components/SceneryManager.js +++ b/src/components/SceneryManager.js @@ -8,6 +8,7 @@ import { resetHoveredTracksStack } from '../services/trackHoverInfoService'; import SceneryLoadedDialog from './scenery-loaded-dialog/SceneryLoadedDialog'; import Constants from '../helpers/constants'; import MiscHelper from '../helpers/miscHelper'; +import ElectrificationResolver from '../model/electrification-resolver'; export default function SceneryManager(props) { const [isLoading, setIsLoading] = useState(false); @@ -141,6 +142,14 @@ export default function SceneryManager(props) { setCamera(pos.x, -pos.z, 0, 0); }, [findSceneryInList, loadScenery, setCamera]); + const electrificationStepModeStep = useCallback(() => { + ElectrificationResolver.stepModeStep(); + setScenery((oldScenery) => { + if (!oldScenery) return null; + return { ...oldScenery }; + }); + }, [setScenery]); + useEffect(() => { if(Constants.sceneryFiles.fetchDisable) return; updateSceneryList(); @@ -155,7 +164,7 @@ export default function SceneryManager(props) { }, [checkLoadUrlScenery, sceneryListData, urlParamsLoaded]); return ( - + {props.children} ); diff --git a/src/components/toolbar/ElectrificationStepMode.js b/src/components/toolbar/ElectrificationStepMode.js new file mode 100644 index 0000000..e4b1023 --- /dev/null +++ b/src/components/toolbar/ElectrificationStepMode.js @@ -0,0 +1,21 @@ +import { useContext } from "react"; +import Constants from "../../helpers/constants"; +import SceneryContext from "../../contexts/SceneryContext"; + +export default function ElectrificationStepMode() { + const { electrificationStepModeStep } = useContext(SceneryContext); + + const onStepClick = () => { + electrificationStepModeStep(); + } + + if(!Constants.parser.resolveElectrificationStepMode) { + return null; + } + + return ( + + ); +} \ No newline at end of file diff --git a/src/components/toolbar/Toolbar.js b/src/components/toolbar/Toolbar.js index 0b8edca..b1a346e 100644 --- a/src/components/toolbar/Toolbar.js +++ b/src/components/toolbar/Toolbar.js @@ -3,6 +3,7 @@ import LoadingIndicator from './LoadingIndicator'; import CustomFileSelect from './CustomFileSelect'; import SideMenuToggle from './SideMenuToggle'; import SceneryList from './SceneryList'; +import ElectrificationStepMode from './ElectrificationStepMode'; export default function Toolbar() { return ( @@ -11,6 +12,7 @@ export default function Toolbar() { or +
diff --git a/src/helpers/constants.js b/src/helpers/constants.js index 581a57b..d585b18 100644 --- a/src/helpers/constants.js +++ b/src/helpers/constants.js @@ -25,7 +25,8 @@ const Constants = { attachSignsGridSize: 10, logAttachedSigns: false, skipBaseMisc: true, - skipPlatforms: false + skipPlatforms: false, + resolveElectrificationStepMode: false, }, warnings: { all: false, // enable all warnings diff --git a/src/model/electrification-resolver.js b/src/model/electrification-resolver.js index 65145e9..557113d 100644 --- a/src/model/electrification-resolver.js +++ b/src/model/electrification-resolver.js @@ -39,6 +39,19 @@ export default class ElectrificationResolver { scenery.electrificationResolved = ElectrificationResolutionStatus.RESOLVED; } + static stepModeStep() { + if (!Constants.parser.resolveElectrificationStepMode) return; + if (ElectrificationResolver.propagationQueue.length === 0) return; + + try { + ElectrificationResolver._runResolutionStep(); + } catch (error) { + console.error(error); + } + + return ElectrificationResolver.propagationQueue.length === 0; + } + static _passWarn(type, message) { ElectrificationResolver.hasWarnings = true; SceneryParserLog.warn(type, message); @@ -74,12 +87,18 @@ export default class ElectrificationResolver { } static _runResolution() { + if (Constants.parser.resolveElectrificationStepMode) return; + while(ElectrificationResolver.propagationQueue.length > 0) { - const { track, skipTrackId, status } = ElectrificationResolver.propagationQueue.pop(); - ElectrificationResolver._resolveTrack(track, skipTrackId, status); + ElectrificationResolver._runResolutionStep(); } } + static _runResolutionStep() { + const { track, skipTrackId, status } = ElectrificationResolver.propagationQueue.pop(); + ElectrificationResolver._resolveTrack(track, skipTrackId, status); + } + static _propagate(track, skipTrackId, status) { ElectrificationResolver.propagationQueue.push({ track, skipTrackId, status }); }