-
Notifications
You must be signed in to change notification settings - Fork 40
#1310 Import saves from other tools #1309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds functionality to import railway map projects from the AARC (Another Awesome Rail Creator) platform into Rail Map Painter. The implementation includes a conversion utility that transforms AARC's data format into RMP's graph structure, and a multi-step UI modal that allows users to upload AARC files and select their preferred station style.
Changes:
- Added AARC-to-RMP conversion utility with support for stations, lines, text tags, and interchange detection
- Created a two-step import modal with file upload and station style selection
- Added internationalization support for 8 city-specific station styles
- Integrated the import feature into the existing "Open" menu
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| src/util/import-from-aarc.ts | Core conversion logic that transforms AARC save format to RMP graph structure, including station creation, line rendering, and interchange detection |
| src/components/page-header/import-from-aarc.tsx | Multi-step modal component for uploading AARC files and selecting station styles |
| src/components/page-header/open-actions.tsx | Integration of new import modal into the existing "Open" menu |
| src/i18n/translations/en.json | English translations for the import feature UI, including city names and user messages |
| * Simple modal that accepts pasted/imported text in a textarea. | ||
| * - Close button simply closes the modal. | ||
| * - Import button calls onImport(text) and then closes the modal. |
Copilot
AI
Jan 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This JSDoc comment is outdated and doesn't accurately describe the component's functionality. The component is a multi-step modal with file upload, station type selection, and confirmation steps, not a simple textarea-based modal. The comment should be updated to reflect the actual implementation.
| * Simple modal that accepts pasted/imported text in a textarea. | |
| * - Close button simply closes the modal. | |
| * - Import button calls onImport(text) and then closes the modal. | |
| * Modal for importing a rail map from AARC data in a two-step flow. | |
| * | |
| * Step 1: | |
| * - User pastes AARC data into a textarea and triggers import. | |
| * - The data is converted into a temporary graph instance and the node/edge | |
| * counts are calculated for preview. | |
| * | |
| * Step 2: | |
| * - On confirmation, the temporary graph replaces the current graph, | |
| * the SVG viewBox/zoom are reset, runtime state is refreshed, and the | |
| * updated graph is saved. | |
| * | |
| * @param isOpen Controls whether the modal is visible. | |
| * @param onClose Callback invoked to close the modal; also used after a | |
| * successful import and confirmation. |
src/util/import-from-aarc.ts
Outdated
| export const convertAarcToRmp = ( | ||
| aarc: string, | ||
| graph: MultiDirectedGraph<NodeAttributes, EdgeAttributes, GraphAttributes>, | ||
| stationTypeOption: StationTypeOption = StationTypeOption.Suzhou | ||
| ) => { | ||
| stationIds.clear(); | ||
| stationPoints.clear(); | ||
| interchangeGroups.clear(); | ||
| const aarcSave = JSON.parse(aarc); | ||
|
|
||
| if (!isAarcSave(aarcSave)) { | ||
| return false; | ||
| } | ||
|
|
||
| // Create stations and virtual nodes. | ||
| aarcSave.points.forEach(point => { | ||
| stationPoints.set(point.id, point); | ||
| if (point.sta === 1) { | ||
| createStation(graph, point, stationTypeOptions[stationTypeOption].basic); | ||
| } else { | ||
| createMiscNode(graph, point, MiscNodeType.Virtual); | ||
| } | ||
| }); | ||
|
|
||
| // Create lines. | ||
| aarcSave.lines.forEach(line => { | ||
| createLine(graph, line); | ||
| }); | ||
|
|
||
| // Update interchanges. | ||
| const groups = findInterchangeGroups(graph); | ||
|
|
||
| let index = 0; | ||
| groups.forEach(ids => { | ||
| createInterchange(graph, index, ids, stationTypeOption); | ||
| index++; | ||
| }); | ||
|
|
||
| // Create text tags. | ||
| aarcSave.textTags.forEach(tag => { | ||
| if (tag.forId === undefined) { | ||
| handleTextTag(graph, tag, aarcSave.config); | ||
| } else { | ||
| const forId = tag.forId!; | ||
| const line = aarcSave.lines.find(l => l.id === forId); | ||
| if (line) { | ||
| const { theme } = generateLineStyleType(line.type, line.colorPre ?? 0, line.color); | ||
| if (line.type === 1) { | ||
| handleTextTag(graph, tag, aarcSave.config, theme); | ||
| } else { | ||
| createMiscNode(graph, { id: tag.id, pos: tag.pos }, MiscNodeType.GzmtrLineBadge, { | ||
| names: [tag.text ?? (line.name || ''), tag.textS ?? (line.nameSub || '')], | ||
| color: theme, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| // Update station types and populate transfers. | ||
| stationIds.forEach(id => { | ||
| if (graph.hasNode(id) && id.startsWith('stn')) { | ||
| autoUpdateStationType(graph, id as StnId); | ||
| autoPopulateTransfer(graph, id as StnId); | ||
| } | ||
| }); | ||
|
|
||
| return true; | ||
| }; |
Copilot
AI
Jan 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new import functionality lacks test coverage. Given that other utility functions in this directory have comprehensive test files (e.g., change-types.test.ts, save.test.ts, to-rmg.test.ts), a test file should be added to verify the AARC import conversion logic, including edge cases like malformed JSON, invalid data structures, and various station type configurations.
thekingofcity
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fix #1310