diff --git a/CHANGELOG.md b/CHANGELOG.md index 06f4902..489fa6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ ## [Unreleased] +### Added + +### Fixed + +- fixed Switches and Crossing motors invalidated port when renaming a hub (https://github.com/Novakasa/brickrail/issues/163) + +### Changed + ## [v1.0.0-alpha.5] ### Added diff --git a/brickrail-gui/brickrail-layouts/test-hub-rename.brl b/brickrail-gui/brickrail-layouts/test-hub-rename.brl new file mode 100644 index 0000000..d1cd005 --- /dev/null +++ b/brickrail-gui/brickrail-layouts/test-hub-rename.brl @@ -0,0 +1,121 @@ +{ + "version": "1.0.0", + "devices": { + "trains": [ + + ], + "controllers": [ + { + "name": "city-blue", + "devices": { + "0": "switch_motor", + "1": null, + "2": null, + "3": null + } + } + ] + }, + "layout": { + "tracks": [ + { + "l_idx": 0, + "x_idx": 3, + "y_idx": 2, + "connections": { + "E": [ + "center", + "right" + ], + "W": [ + "center" + ] + }, + "switches": { + "E": { + "motor1": { + "controller": "city-blue", + "port": 0, + "storage": { + "0": 100, + "1": 600, + "2": 0 + } + } + } + } + }, + { + "l_idx": 0, + "x_idx": 2, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + + ] + } + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 2, + "connections": { + "E": [ + + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 2, + "connections": { + "S": [ + "left" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 3, + "connections": { + "N": [ + "left" + ], + "E": [ + + ] + } + } + ], + "blocks": [ + + ], + "trains": [ + + ] + } +} \ No newline at end of file diff --git a/brickrail-gui/devices/layout_devices/crossing_motor.gd b/brickrail-gui/devices/layout_devices/crossing_motor.gd index 1120c1f..0da9987 100644 --- a/brickrail-gui/devices/layout_devices/crossing_motor.gd +++ b/brickrail-gui/devices/layout_devices/crossing_motor.gd @@ -49,10 +49,12 @@ func set_hub(p_hub): if hub != null: hub.disconnect("responsiveness_changed", self, "_on_hub_responsiveness_changed") hub.disconnect("runtime_data_received", self, "_on_hub_runtime_data_received") + hub.disconnect("name_changed", self, "_on_hub_name_changed") hub = p_hub if hub != null: hub.connect("responsiveness_changed", self, "_on_hub_responsiveness_changed") hub.connect("runtime_data_received", self, "_on_hub_runtime_data_received") + hub.connect("name_changed", self, "_on_hub_name_changed") func set_position(p_position): if position == p_position: @@ -66,6 +68,10 @@ func _on_hub_runtime_data_received(_data): func _on_hub_responsiveness_changed(_responsiveness): pass +func _on_hub_name_changed(old_name, new_name): + assert(old_name == controllername) + controllername = new_name + func serialize(): var struct = {} struct["type"] = device_type diff --git a/brickrail-gui/devices/layout_devices/switch_motor.gd b/brickrail-gui/devices/layout_devices/switch_motor.gd index 5d89d27..e19efdd 100644 --- a/brickrail-gui/devices/layout_devices/switch_motor.gd +++ b/brickrail-gui/devices/layout_devices/switch_motor.gd @@ -54,10 +54,12 @@ func set_hub(p_hub): if hub != null: hub.disconnect("responsiveness_changed", self, "_on_hub_responsiveness_changed") hub.disconnect("runtime_data_received", self, "_on_hub_runtime_data_received") + hub.disconnect("name_changed", self, "_on_hub_name_changed") hub = p_hub if hub != null: hub.connect("responsiveness_changed", self, "_on_hub_responsiveness_changed") hub.connect("runtime_data_received", self, "_on_hub_runtime_data_received") + hub.connect("name_changed", self, "_on_hub_name_changed") func _on_hub_runtime_data_received(data): if data[0] == DATA_SWITCH_CONFIRM: @@ -92,6 +94,10 @@ func _on_hub_responsiveness_changed(value): else: set_unresponsive() +func _on_hub_name_changed(old_name, new_name): + assert(old_name == controllername) + controllername = new_name + func setup_on_hub(): # hub.rpc("add_switch", [port]) pass diff --git a/brickrail-gui/gui/main.tscn b/brickrail-gui/gui/main.tscn index 60631b0..b0cd252 100644 --- a/brickrail-gui/gui/main.tscn +++ b/brickrail-gui/gui/main.tscn @@ -86,7 +86,6 @@ tab_align = 0 use_hidden_tabs_for_min_size = true [node name="Trains" type="ScrollContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer"] -visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 5.0 @@ -139,6 +138,7 @@ size_flags_horizontal = 3 size_flags_vertical = 3 [node name="Settings" type="VBoxContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer"] +visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 5.0 diff --git a/brickrail-gui/layout/layout_devices/port_selector.gd b/brickrail-gui/layout/layout_devices/port_selector.gd index d95ca2a..e63a427 100644 --- a/brickrail-gui/layout/layout_devices/port_selector.gd +++ b/brickrail-gui/layout/layout_devices/port_selector.gd @@ -77,11 +77,17 @@ func setup_options(): controller_option.set_items(Devices.layout_controllers.keys(), Devices.layout_controllers.keys()) var port_option: Selector = $VBoxContainer/GridContainer/PortOption + + if not controllername in Devices.layout_controllers.keys(): + # the controller was probably renamed + # temp fix, on reselect valid controller should be updated + controllername = null + controller_option.select_meta(controllername) + if controllername == null: port_option.set_items([], []) return - var controller: LayoutController = Devices.layout_controllers[controllername] var num_ports = len(controller.devices)