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

level editor: character change does not persist after road is randomly generated #1621

Open
evemartin opened this issue May 22, 2024 · 8 comments
Assignees
Labels
bug cadets volunteers Tasks that can be picked up by anyone

Comments

@evemartin
Copy link
Contributor

evemartin commented May 22, 2024

Describe the bug
In some cases, even after selecting a different character in the Level Editor, when the level is saved and played it displays the default Van character.

To Reproduce

  1. Log in as any user and open the Level Editor
  2. Go to the Character tab and select a character other than Van

image

  1. Go to the Random tab and randomly generate a map

image

  1. (at this point, if you go back to the Character tab, the image will still be of the new character you chose but the dropdown value will be blank)
  2. Save the level and, when prompted, choose to play the level
  3. The character will be the Van and not the new character you chose

Expected behaviour
The level editor should remember the character choice even when recreating a new random road.

Once this has been fixed, please also check if changing other settings through the level editor also overwrites the character setting.

Good places to start

It seems like the function to generate the random road might be resetting the value of the character to the default, i.e. the van.

random_road.py: https://github.com/ocadotechnology/rapid-router/blob/master/game/random_road.py

@evemartin evemartin changed the title Setting non-van character sometimes doesn't work Switching to a non-van character in the Level Editor sometimes doesn't work May 22, 2024
@evemartin evemartin changed the title Switching to a non-van character in the Level Editor sometimes doesn't work level editor: character change does not persist after road is randomly generated May 22, 2024
@faucomte97 faucomte97 added bug volunteers Tasks that can be picked up by anyone cadets labels Nov 11, 2024
@Noah-Bakr
Copy link
Contributor

Hey, I'm interested in this issue. I will happily be assigned :)

@Noah-Bakr
Copy link
Contributor

The code is fixed to ensure the Player selection data remains the same after generating a random road. While that problem is solved, I've found that after a road is generated, the dropdown menu is blank. I am finding a way to ensure the selected item remains consistent. I assume the "create" function should parse the dropdown item to reflect the UI.

Furthermore, I've noticed there's a similar issue with the scenery generation. I tried to fix this but, upon further observation, it seems that the generation code is hard-coded for the "grass" scenery. Is this done on purpose? It would make sense, to generate the road, then edit the scenery - but if the user changes the scenery to snow, they shouldn't have to change it again.

@Noah-Bakr
Copy link
Contributor

In the method declaration def create(episode=None): I have changed it to def create(episode):. This defines the episode but, it also allows for numerous random roads to be generated. This feature will be discussed in the next cadet meeting.

@SKairinos
Copy link
Contributor

@SKairinos
Copy link
Contributor

@SKairinos
Copy link
Contributor

SKairinos commented Feb 27, 2025

@Noah-Bakr, here's the code breakdown as promised:

  1. The callback for when the generate button is clicked is defined here.
  2. The frontend calls the backend api endpoint here.
  3. This calls this endpoint on the backend, which is handled by this function.
  4. The api endpoint handler-function returns a javascript object (JS refers to dicts as objects).
  5. When the frontend recieves the JS object (called mapData), it passes it to a function called restoreState().
  6. restoreState() attempts to change the selected character.

It seems this fails because the mapData does not contain the appropriate character info.
Image

You'll need to:

  1. Get the backend to include the character info in the returned JS object.
  2. Have restoreState() correctly find and use the character data from the JS object.

@SKairinos
Copy link
Contributor

@Noah-Bakr , how's it going? need any help? :)

@Noah-Bakr
Copy link
Contributor

Hi @SKairinos I've had some time investigating the issue with your insights. I tried a number of different approaches and code but unfortunately, I didn't get anywhere - I just learnt the ways that didn't work. Tomorrow I should have some time to put towards this issue and get it fixed.

What I have noticed is that there's a fair bit of grey area in regard to what methods generate the map itself and what methods generate the level. What this means: In both the python and js, there would be a method that creates the road itself, taking the random map params (curviness etc), this method would be inside another method that contains other data such as scenery etc. The grey area lies within the connection between python and js.

My focus has shifted towards the charactersetup() functions in the js file (tomorrow I will write my knowledge gained, alongside the file names). I discovered that if I called the set up function when the button is pressed (parsing the character), it did not update the character nor the dropdown. I feel that the character selection object is getting lost somewhere, which could explain the grey area between python and js, or I've missed a character == 1 hardcode somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cadets volunteers Tasks that can be picked up by anyone
Projects
Status: In Progress
Development

No branches or pull requests

4 participants