Added electrification resolver step mode
+Added electrification resolver step mode. It can be enabled using the appropriate Constant
This commit is contained in:
parent
709b279147
commit
647a324357
@ -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 (
|
||||
<SceneryContext.Provider value={{ isLoading, scenery, sceneryListData, loadScenery, loadCustomScenery }}>
|
||||
<SceneryContext.Provider value={{ isLoading, scenery, sceneryListData, loadScenery, loadCustomScenery, electrificationStepModeStep }}>
|
||||
{props.children}
|
||||
</SceneryContext.Provider>
|
||||
);
|
||||
|
||||
21
src/components/toolbar/ElectrificationStepMode.js
Normal file
21
src/components/toolbar/ElectrificationStepMode.js
Normal file
@ -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 (
|
||||
<button onClick={onStepClick}>
|
||||
STEP
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@ -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() {
|
||||
<SceneryList />
|
||||
or
|
||||
<CustomFileSelect />
|
||||
<ElectrificationStepMode />
|
||||
<div className='toolbar-spacer'></div>
|
||||
<SideMenuToggle />
|
||||
</div>
|
||||
|
||||
@ -25,7 +25,8 @@ const Constants = {
|
||||
attachSignsGridSize: 10,
|
||||
logAttachedSigns: false,
|
||||
skipBaseMisc: true,
|
||||
skipPlatforms: false
|
||||
skipPlatforms: false,
|
||||
resolveElectrificationStepMode: false,
|
||||
},
|
||||
warnings: {
|
||||
all: false, // enable all warnings
|
||||
|
||||
@ -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 });
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user