Skip to content

Fix broken script when json is not in TF/O/M/D order#75

Merged
tchajed merged 1 commit intotchajed:mainfrom
louietyj:fix-script-order
Nov 19, 2025
Merged

Fix broken script when json is not in TF/O/M/D order#75
tchajed merged 1 commit intotchajed:mainfrom
louietyj:fix-script-order

Conversation

@louietyj
Copy link
Contributor

@louietyj louietyj commented Nov 2, 2025

Seems like this is a known issue from when parseJson was first implemented in #8.

Behavior is undefined if not entered in order of all characters of each category in order Townsfolk, Outsiders, Minion, Demon

It's an easy fix, just do a stable-sort in TF/O/M/D order. Tested with a randomly shuffled TB script:

http://localhost:5173/script.html?json=[{"id": "mayor"}, {"id": "poisoner"}, {"id": "investigator"}, {"id": "soldier"}, {"id": "undertaker"}, {"id": "spy"}, {"id": "virgin"}, {"id": "empath"}, {"id": "butler"}, {"id": "slayer"}, {"id": "monk"}, {"id": "_meta", "name": "Trouble Brewing"}, {"id": "recluse"}, {"id": "baron"}, {"id": "saint"}, {"id": "scarletwoman"}, {"id": "washerwoman"}, {"id": "fortuneteller"}, {"id": "chef"}, {"id": "ravenkeeper"}, {"id": "imp"}, {"id": "drunk"}, {"id": "librarian"}]

image

Copy link
Owner

@tchajed tchajed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!

I have one cleanup comment but I'm happy to merge even without that.

Comment on lines +7 to +15
const ROLE_TYPE_ORDER = [
"townsfolk",
"outsider",
"minion",
"demon",
"travellers",
"fabled",
] as const;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to ./botc/roles? It is related to display but the game consistently presents roles in this order.

Copy link
Contributor Author

@louietyj louietyj Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it looks like there is already a similar list there RolesTypes, just that it's fabled first and then travelers, which is consistent with how official script tool presents it so I'll follow suit and just use that list.

@louietyj
Copy link
Contributor Author

Done!

@tchajed tchajed merged commit 19d7d10 into tchajed:main Nov 19, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants