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

Refactor code dealing with squad index #177

Merged
merged 6 commits into from
Oct 27, 2022
Merged

Conversation

Lemonymous
Copy link
Contributor

@Lemonymous Lemonymous commented Oct 13, 2022

Create separation between how the game refers to squads by index, and how the mod loader refers to squads by index.

Note: This PR intentionally does nothing with the file modUi/achievements_squad.lua, but expects #174 to be updated to deal with it, using the constants and functions provided here.

Squad Choice

For the game a squad choice is the index for the chosen squad.

Squad Choice is:

  • 0-indexed
  • 0-7 for non-ae-squads
  • 8-9 for random/custom
  • 10 for secret squad
  • 11-15 for ae-squads

Squad Index

For the mod loader a squad index is the index for the squad in mod loader tables.

Squad Index is:

  • 1-indexed
  • 1-8 for non-ae-squads
  • 9 for secret squad
  • 10-14 for ae-squads

New functions

  • number modApi:squadIndex2Choice(number) - Returns the squad choice corresponding to the specified squad index. Returns -1 for indexes that cannot be mapped to a squad choice.

  • number modApi:squadChoice2Index(choice) - Returns the squad index corresponding to the specified squad choice. Returns -1 for choices that cannot be mapped to a squad index.

  • table modApi:getSquadForChoice(number) - Returns the list of a squad currently mapped to the specified squad choice.

Where content of the return table is as follows:

["name"] = squad name
["id"] = squad id
["mechs"] = table of mech id's

Create separation between how the game refers to squads by index, and how the mod loader refers to squads by index.

For the game a squad `choice` is the index for the chosen squad.

Squad Choice is:
- 0-indexed
- 0-7 for non-ae-squads
- 8-9 for random/custom
- 10 for secret squad
- 11-15 for ae-squads

For the mod loader a squad `index` is the index for the squad in mod loader tables.

Squad Index is:
- 1-indexed
- 1-8 for non-ae-squads
- 9 for secret squad
- 10-14 for ae-squads

## New functions
- number modApi:squadIndex2Choice(number) - Returns the squad choice corresponding to the specified squad index. Returns -1 for indexes that cannot be mapped to a squad choice.

- number modApi:squadChoice2Index(choice) - Returns the squad index corresponding to the specified squad choice. Returns -1 for choices that cannot be mapped to a squad index.

- table modApi:getSquadForChoice(number) - Returns the flat list of a squad currently mapped to the specified squad choice.

Where content of the return table is as follows:
```
[1] = squad name
[2-4] = mechs
id = squad id
```
- Fix squadIndex2Choice incorrectly not 0-indexing the result
- Add lower limit to invalid conversion warnings
- Replace comparison from SQUAD_INDEX_CUSTOM to SQUAD_INDEX_SECRET
- Replace comparison from SQUAD_CHOICE_CUSTOM to SQUAD_CHOICE_SECRET
## getSquadForChoice
- Assert that choice is within bounds and not Random or Custom.
- loadSquadSelection if modApi.squadIndices is nil

## squadIndex2Choice
- Create separation between validation block and the actual function content
Change modApi.getSquadForChoice from returning a flat list of the squad.

From
```
{
  [1]  - squad name
  [2-4] - mech id's
  ["id"] - squad id
}
```
to
```
{
  ["name"] - squad name
  ["id"] - squad id
  ["mechs"] - table of mech id's
}
```
@Lemonymous Lemonymous marked this pull request as ready for review October 15, 2022 09:52
@Lemonymous Lemonymous merged commit bbb107f into master Oct 27, 2022
@Lemonymous Lemonymous deleted the refactor/squadIndex branch October 27, 2022 09:33
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.

None yet

1 participant