EwenDC / root-automated-setup

Automated Advanced Setup for Leder Game's popular board game Root
https://ewendc.github.io/root-automated-setup/
5 stars 4 forks source link

Add ability to lock in a faction to be generated #35

Open Druthyn opened 1 year ago

Druthyn commented 1 year ago

Unless I missed the functionality on mobile, when selecting which factions to include/exclude in the generation, being able to lock in a faction (or two? I would need to check the setup options to know how viable this is) if a player really wanted to play said faction would be nice.

Druthyn commented 1 year ago

I'm open to giving a go at the implementation, but opened the issue here to discuss the idea, and get any pointers those more familiar with the codebase.

EwenDC commented 1 year ago

Hi @Druthyn, apologies for the late response. I no longer have the spare time to add new functionality to this app, as I already sunk a lot of time getting it to a state I am mostly happy with. However I'd be more than happy to answer any questions about the codebase and give guidance on how features might be implemented.

At a high level, the internal state of the app is entirely managed by a Redux store (created using Redux Toolkit), which is split into three slices. The flow slice manages the application flow (e.g. what current step you're on, what steps are in the undo/redo queue, what faction you selected during faction selection, etc.), think of it like an app router. The setup slice holds the settings for the setup itself (e.g. how many players are in the game, how do we want to set up the map suits, are we including hirelings, etc.)

The slice relevant to your proposed change, the components slice, is dedicated to tracking which components are being included in setup (including expansions), as well as a few component specific setup settings. All root expansions are always tracked in state, but the components for disabled expansions are excluded from state. We already have a "locked" state for each variable tracking components that can't be selected or deselected due to setup rules (e.g. a Vagabond after the Exile hireling is selected). Maybe something like "forced" could be added to track factions that must get included.

All of the actual setup logic lives in the nextStep Redux thunk. The nextStep code is split into a switch statement that contains the setup logic for each setup step (run after said step), including the logic for choosing which components will be set up. This is where I see the implementation getting trickier, as faction setup has a lot of edge cases which you must keep in mind (e.g. standard setup can have at most 4 factions that setup in a corner). It's definitely not insurmountable, just requires some testing to ensure the setup rules are still being followed.

The logic for rendering the component selector comes from the ComponentToggle React component. I have no ideas about what this functionality should look like visually, so you have carte blanche on that part of the solution. My only requests are that you match the style of the existing app, and that your solution is fully accessible.

On a final note, since so much of the component selecting logic is shared, it'd require very little work to extend it to other places where it makes sense (i.e. Landmarks and Hirelings). I think I'd like to see it implemented there too. Any further questions, feel free to reach out here, I'll do my best to reply more promptly.