Skip to content
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

add class name to object ID #675

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion metadrive/base_class/nameable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Nameable:
"""
def __init__(self, name=None):
# ID for object
self.name = random_string() if name is None else name
self.name = "{}_{}".format(self.class_name, random_string()) if name is None else name
self.id = self.name # name = id

@property
Expand Down
7 changes: 2 additions & 5 deletions metadrive/manager/scenario_light_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
class ScenarioLightManager(BaseManager):
CLEAR_LIGHTS = False

OBJECT_PREFIX = "traffic_light_"

def __init__(self):
super(ScenarioLightManager, self).__init__()
self._scenario_id_to_obj_id = {}
Expand Down Expand Up @@ -43,13 +41,12 @@ def after_reset(self):
)
lane_info = self.engine.current_map.road_network.graph[str(scenario_lane_id)]
position = self._get_light_position(light_info)
name = self.OBJECT_PREFIX + scenario_lane_id if self.engine.global_config["force_reuse_object_name"
] else None
name = scenario_lane_id if self.engine.global_config["force_reuse_object_name"] else None
traffic_light = self.spawn_object(ScenarioTrafficLight, lane=lane_info.lane, position=position, name=name)
self._scenario_id_to_obj_id[scenario_lane_id] = traffic_light.id
self._obj_id_to_scenario_id[traffic_light.id] = scenario_lane_id
if self.engine.global_config["force_reuse_object_name"]:
assert self.OBJECT_PREFIX + scenario_lane_id == traffic_light.id, (
assert "ScenarioTrafficLight_" + scenario_lane_id == traffic_light.id, (
"Original id should be assigned to traffic lights"
)
self._lane_index_to_obj[lane_info.lane.index] = traffic_light
Expand Down
Loading