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

Fighter II checkbox #3

Merged
merged 8 commits into from
Aug 1, 2024
Merged

Fighter II checkbox #3

merged 8 commits into from
Aug 1, 2024

Conversation

chelseaSchmidt
Copy link
Collaborator

Took a stab at this, check my logic though!

New budget inputs:

  • shipCapacityUsed
  • maxShipCapacity
  • spaceDockFighterBonus

New budget display field:

  • shipCapacityRemaining: maxShipCapacity + spaceDockFighterBonus - shipCapacityUsed - fighters added with the calculator
    • Fighter I: All fighters count against shipCapacityRemaining
    • Fighter II: Fighters count against shipCapacityRemaining until it reaches 0, then they begin to count against fleetSupplyRemaining

I realized there should also be a checkbox for "I'm building in a space-only system" for Saar (maybe others?), which would trigger ground forces to be subtracted from shipCapacityRemaining, but leaving that for another PR!

@chelseaSchmidt chelseaSchmidt added the enhancement New feature or request label Jul 31, 2024
@chelseaSchmidt chelseaSchmidt requested a review from sirrus233 July 31, 2024 00:10
Comment on lines 79 to 84
<Checkbox
label="Fighter II"
checked={isFighterUpgraded}
onChange={() =>
setIsFighterUpgraded(!isFighterUpgraded)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was on the fence about putting the checkbox inside BudgetModeInputs rather than adjacent, but I could foresee wanting to use the checkbox in both modes if we get fancier, and putting it here makes it easier to move around if that happens. Not married to it either way though!

Copy link
Owner

Choose a reason for hiding this comment

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

I think I lean (slightly) the other way, but that's because I only really imagine using this in the budget mode. Doesn't really make a difference to me as this is easy to refactor if we guess wrong.

💭 One thing I am considering though - I think with all this functionality, budget mode is getting a little complex. I like the functionality, but it's a lot of paperwork to do. What would you think about (in the future, not this PR) hiding some of the more complex options like capacity management or off-planet (read: Saar) production, under a dropdown tab for "advanced mode"? That way the options are there for anyone who wants to deal with them, and hidden (+inactive) for anyone who can't be bothered?

Copy link
Owner

Choose a reason for hiding this comment

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

Another example in support of an "advanced mode" - isn't the "Space Dock Fighter Bonus" the same value for almost every faction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, moved firmly into budget mode 👌

That's a great idea, all the form fields are making my eyes glaze over!

Copy link
Collaborator Author

@chelseaSchmidt chelseaSchmidt Aug 1, 2024

Choose a reason for hiding this comment

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

Oh dang didn't know that about the space dock bonus - the only two factions I've drafted have been different so I just assumed it varied! Should definitely make that a static number which you can change in advanced mode

Copy link
Owner

@sirrus233 sirrus233 left a comment

Choose a reason for hiding this comment

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

Solid stuff!!! Looks fantastic 😍

@@ -87,20 +87,36 @@ export function getTotalCost(unitCounts: UnitCounts): number {
);
}

function sumUnitCountEntries(unitCountEntries: [Unit, number][]): number {
Copy link
Owner

Choose a reason for hiding this comment

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

The weirdness of dealing directly with a [Unit, number][] type struck me. Try playing around with this function signature and see if you like what falls out!

function sumUnitCounts(
  unitCounts: UnitCounts, 
  unitFilter: (unit: Unit) => boolean = () => true): number
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sooo much cleaner, thank you, updated! I love this 🔥

}

export function getFleetSupplyRemaining(
currentFleetSupply: number,
maxFleetSupply: number,
unitCounts: UnitCounts
unitCounts: UnitCounts,
airborneFighterCount: number
Copy link
Owner

Choose a reason for hiding this comment

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

⛏️ Took just a sec to realize what this name meant. Maybe unsupportedFighters? What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's perfect, I was so stuck on this name and could only think of nonTransportedFighters but didn't like the negation. And airborne isn't even correct because they're in space? Lol, fixed now

Comment on lines 79 to 84
<Checkbox
label="Fighter II"
checked={isFighterUpgraded}
onChange={() =>
setIsFighterUpgraded(!isFighterUpgraded)
}
Copy link
Owner

Choose a reason for hiding this comment

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

I think I lean (slightly) the other way, but that's because I only really imagine using this in the budget mode. Doesn't really make a difference to me as this is easy to refactor if we guess wrong.

💭 One thing I am considering though - I think with all this functionality, budget mode is getting a little complex. I like the functionality, but it's a lot of paperwork to do. What would you think about (in the future, not this PR) hiding some of the more complex options like capacity management or off-planet (read: Saar) production, under a dropdown tab for "advanced mode"? That way the options are there for anyone who wants to deal with them, and hidden (+inactive) for anyone who can't be bothered?

Comment on lines 79 to 84
<Checkbox
label="Fighter II"
checked={isFighterUpgraded}
onChange={() =>
setIsFighterUpgraded(!isFighterUpgraded)
}
Copy link
Owner

Choose a reason for hiding this comment

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

Another example in support of an "advanced mode" - isn't the "Space Dock Fighter Bonus" the same value for almost every faction?

}: Props) {
const shipCapacityRemaining =
Copy link
Owner

Choose a reason for hiding this comment

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

⛏️ This variable name kinda bothers me, only because elsewhere you're careful to distinguish between "ship capacity" and the "space dock fighter bonus" (I'm guessing to later account for ground forces, which can't be supported by space docks?). But here it's all lumped together and called "ship capacity".

A few alternate proposals:
totalCapacityRemaining
capacityRemaining
fighterCapacityRemaining (I think maybe I dislike this one the least)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right guess on the future ground forces problem, and yes good point - I like fighterCapacityRemaining since that's the least ambiguous, and can handle renaming it when we add advanced mode!

value: capacityBudget - getTotalCapacity(unitCounts),
},
{
label: "Fleet Supply Remaining",
value: getFleetSupplyRemaining(
currentFleetSupply,
maxFleetSupply,
unitCounts
unitCounts,
isFighterUpgraded ? Math.max(0 - shipCapacityRemaining, 0) : 0
Copy link
Owner

Choose a reason for hiding this comment

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

Had to puzzle over this, and see it work in action, before I could convince myself it was correct (it is!). Probably just sleep-deprived ☕

But consider:
isFighterUpgraded && shipCapacityRemaining < 0 ? shipCapacityRemaining : 0

Neither is wrong, so pick your fave.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Honestly same, and I'm the one that wrote it 🤦‍♀️ yours is definitely easier on the brain! Updated to that with a teeny adjustment to flip the sign

),
},
{
label: "Ship Capacity Remaining",
value: isFighterUpgraded
Copy link
Owner

Choose a reason for hiding this comment

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

As above, check if you prefer:
isFighterUpgraded && shipCapacityRemaining < 0 ? 0 : shipCapacityRemaining

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Prefer yours, updated! I was playing around with a zeroFloor(num: number) { return Math.max(num, 0); } util to abstract out the Math.max(x, 0)s everywhere but it still ended up being hard to digest, I give up 🥲

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oooh and, did one more thing, the latest commit reduces the confusion even more - 47d71a6

@chelseaSchmidt
Copy link
Collaborator Author

@sirrus233 Aaah been out all day and just had time to check this out, these review comments are so on point, dude thank you!! Gonna see if I can get a jump on these before we call tomorrow!

@chelseaSchmidt
Copy link
Collaborator Author

@sirrus233 I think I got everything, you want to take one more look?

Each time I change any of the math I wish for unit tests, and yet am too lazy to set up Jest. I will simply complain about it endlessly

@sirrus233
Copy link
Owner

#6

Copy link
Owner

@sirrus233 sirrus233 left a comment

Choose a reason for hiding this comment

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

🚢

@@ -87,20 +87,34 @@ export function getTotalCost(unitCounts: UnitCounts): number {
);
}

export function getTotalCapacity(unitCounts: UnitCounts): number {
Copy link
Owner

Choose a reason for hiding this comment

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

Nice catch! I missed the equivalency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🎉

@chelseaSchmidt chelseaSchmidt merged commit d5b19e1 into main Aug 1, 2024
@chelseaSchmidt chelseaSchmidt deleted the fighter-checkbox branch August 1, 2024 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants