Skip to content

Conversation

@langonginc
Copy link
Member

@langonginc langonginc commented Jan 24, 2026

Fix #1310

Copilot AI review requested due to automatic review settings January 24, 2026 12:18
Copy link
Contributor

Copilot AI left a 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

Comment on lines 38 to 40
* 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.
Copy link

Copilot AI Jan 24, 2026

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.

Suggested change
* 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.

Copilot uses AI. Check for mistakes.
Comment on lines 604 to 672
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;
};
Copy link

Copilot AI Jan 24, 2026

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.

Copilot uses AI. Check for mistakes.
@thekingofcity thekingofcity self-requested a review January 24, 2026 12:39
@langonginc langonginc changed the title Import saves from other platforms Import saves from other tools Jan 25, 2026
@thekingofcity thekingofcity changed the title Import saves from other tools #1310 Import saves from other tools Jan 25, 2026
Copy link
Member

@thekingofcity thekingofcity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thekingofcity thekingofcity merged commit c095a41 into main Jan 25, 2026
1 check passed
@thekingofcity thekingofcity deleted the aarc branch January 25, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Import saves from other tools

3 participants