hackclub / sprig

🍃 Learn to code by making games in a JavaScript web-based game editor.
https://sprig.hackclub.com
MIT License
907 stars 1.09k forks source link

Map editor generates invalid syntax with sprites with backtick key #2297

Open MacaylaMarvelous81 opened 2 months ago

MacaylaMarvelous81 commented 2 months ago

Describe the bug When a sprite with a backtick (`) as its key is placed using the map editor, the editor places the backtick unescaped, ending the string literal causing invalid syntax which is not obvious until closing the map editor.

To Reproduce Steps to reproduce the behavior:

  1. Add a sprite with a backtick as a key to the legend
  2. Add the sprite to a map in the map editor

Expected behavior The sprite is placed on the map without breaking syntax, possibly through escaping the backtick.

Actual behavior
The backtick is placed in string and terminates the string early.

Screenshots

https://github.com/user-attachments/assets/efd36695-f586-497f-a4b7-77726b619ff2

Since escaping characters means that 1 character may not always = 1 tile, it might be better to just prevent using backtick for a sprite key.

(A separate issue where the map clicked on to edit is not the one that ends up being edited is also exhibited in the video but is not the subject of this issue.)

JosiasAurel commented 2 months ago

I think the editor should warn users against using backticks as sprite keys. What do you think @grymmy ?