Skip to content

Commit

Permalink
front: create node transitions in NGE
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Jul 16, 2024
1 parent d6012a7 commit 08d0301
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { AppDispatch } from 'store';

import type {
Node,
Port,
Trainrun,
TrainrunSection,
TrainrunCategory,
Expand Down Expand Up @@ -241,6 +242,18 @@ const importTimetable = async (
return port;
};

let transitionId = 0;
const createTransition = (port1Id: number, port2Id: number) => {
const transition = {
id: transitionId,
port1Id,
port2Id,
isNonStopTransit: false,
};
transitionId += 1;
return transition;
};

let trainrunSectionId = 0;
const trainrunSections: TrainrunSection[] = trainSchedules
.map((trainSchedule) => {
Expand All @@ -249,6 +262,7 @@ const importTimetable = async (
if (!foundAllOps) {
return [];
}
let prevPort: Port | null = null;
return ops.slice(0, -1).map((sourceOp, i) => {
const sourceNodeId = sourceOp!.obj_id;
const targetNodeId = ops[i + 1]!.obj_id;
Expand All @@ -269,7 +283,11 @@ const importTimetable = async (
sourceNode.ports.push(sourcePort);
targetNode.ports.push(targetPort);

// TODO: create transitions between ports
if (prevPort) {
const transition = createTransition(prevPort.id, sourcePort.id);
sourceNode.transitions.push(transition);
}
prevPort = targetPort;

const trainrunSection = {
id: trainrunSectionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type Node = {
positionX: number;
positionY: number;
ports: Port[];
transitions: unknown[];
transitions: Transition[];
connections: unknown[];
resourceId: number;
/** Number of tracks where train can stop */
Expand All @@ -34,6 +34,13 @@ export type Port = {
trainrunSectionId: number;
};

export type Transition = {
id: number;
port1Id: number;
port2Id: number;
isNonStopTransit: boolean;
};

export enum PortAlignment {
Top,
Bottom,
Expand Down

0 comments on commit 08d0301

Please sign in to comment.