rmp icon indicating copy to clipboard operation
rmp copied to clipboard

Split station type and transfer auto-update into independent functions

Open Copilot opened this issue 4 months ago • 4 comments

Split checkAndChangeStationIntType into two independent functions that can be called separately or together, addressing feedback to separate type changes from transfer information updates.

New Functions

  1. autoUpdateStationType(graph, station)

    • Automatically changes station type based on line colors
    • Changes to interchange if multiple colors detected
    • Changes to basic if single color detected
    • Returns boolean indicating if type was changed
  2. autoPopulateTransfer(graph, station)

    • Automatically populates transfer information based on line colors
    • Merges existing transfer info with new line colors
    • Filters out disconnected lines
    • Only updates stations with transfer property support
    • Returns boolean indicating if transfer was updated
  3. checkAndChangeStationIntType(graph, station) (wrapper)

    • Calls both functions for backward compatibility
    • Maintains existing behavior for all current usages

Changes

  • Split functionality: Separated type updates from transfer population into independent functions
  • Dynamic checking: Replaced hardcoded station type list with runtime checking of transfer property
  • Enhanced documentation: Added comprehensive comments explaining InterchangeInfo structure:
    • Elements 0-3: Theme information (CityCode, LineCode, Color, TextColor)
    • Element 4: Station code (empty for auto-fill)
    • Element 5: Additional info (empty for auto-fill)
    • Element 6+: Reserved for future extensions (e.g., foshan indicator for gzmtr-int-2024)
  • Code reuse: Extracted getStationLineColors helper to avoid duplication
  • Auto-populate on station creation: Stations placed on the canvas now automatically have their transfer information populated based on any connected lines

Example

// Call functions independently
autoUpdateStationType(graph, station);  // Only update type
autoPopulateTransfer(graph, station);   // Only update transfer info

// Or call wrapper for both operations
checkAndChangeStationIntType(graph, station);

// Example: station with multiple line colors
// Before: type: gzmtr-basic, transfer: [[]]
// After autoUpdateStationType: type: gzmtr-int, transfer: [[]]
// After autoPopulateTransfer: type: gzmtr-int, transfer: [
//   [[CityCode.Guangzhou, 'gz1', '#F3D03E', MonoColour.black, '', ''],
//    [CityCode.Guangzhou, 'gz2', '#97D700', MonoColour.white, '', '']]
// ]

Tests

Added 6 test cases covering:

  • Basic→interchange conversion with transfer population
  • Interchange→basic conversion (transfer cleared)
  • No-op when no lines connected
  • Stations without basic/int pairs (MTR)
  • Independent call of autoUpdateStationType
  • Independent call of autoPopulateTransfer

Technical Details

  • supportsTransferProperty now dynamically checks if station attributes have a transfer property
  • New station types with transfer property automatically supported without code changes
  • Both new functions return boolean to indicate success, enabling conditional logic in callers

Screenshot

  • Fixes railmapgen/rmp#1234
Original prompt

This section details on the original issue you should resolve

<issue_title>Make checkAndChangeStationIntType adaptively modify interchange property with appropriate interchange info</issue_title> <issue_description>Background: The checkAndChangeStationIntType function currently does not modify the interchange property of transfer stations with context-appropriate information.

Task: Update checkAndChangeStationIntType so that it adaptively sets the interchange attribute of transfer stations, providing suitable interchange details based on the station context.

Expected Outcome:

  • The interchange property should be automatically updated when detecting a transfer station in checkAndChangeStationIntType.
  • The property should accurately reflect the correct interchange information.
  • The change should not introduce regressions elsewhere.

Notes:

  • Ensure robust testing around this updated functionality. </issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes railmapgen/rmp#1234

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot avatar Nov 07 '25 10:11 Copilot

@copilot Also auto set transfer information when putting a new station on to the canvas

langonginc avatar Nov 10 '25 04:11 langonginc

@copilot Also auto set transfer information when putting a new station on to the canvas

Done. Added call to checkAndChangeStationIntType after adding a new station to the canvas in svg-wrapper.tsx. The transfer information is now automatically populated when placing a new station on the canvas. See commit 0d99369.

Copilot avatar Nov 10 '25 04:11 Copilot

@copilot Split checkAndChangeStationIntType into two independent parts, where one can automatically change station type depending on the line themes, and the other can fill the transfer information automatically based on the line themes. You must make the two function can be called independently, that is I may need to call one of them individually.

langonginc avatar Nov 14 '25 10:11 langonginc

@copilot Split checkAndChangeStationIntType into two independent parts, where one can automatically change station type depending on the line themes, and the other can fill the transfer information au...

Done. Split into two independent functions in commit c318b11:

  1. autoUpdateStationType(graph, station) - Updates station type based on line themes (basic ↔ interchange)
  2. autoPopulateTransfer(graph, station) - Fills transfer information based on line themes

Both can be called independently and return a boolean indicating success. The original checkAndChangeStationIntType now acts as a wrapper calling both functions for backward compatibility.

Also addressed:

  • Replaced hardcoded station type list with dynamic checking
  • Added comprehensive documentation for InterchangeInfo structure
  • Extracted helper function to avoid duplication

Copilot avatar Nov 14 '25 10:11 Copilot