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

Add type property to every unit #2441

Closed
wants to merge 6 commits into from
Closed

Conversation

allmtz
Copy link
Contributor

@allmtz allmtz commented Jul 19, 2023

This will simplify code in game.ts as unit.type will no longer need to be dynamically generated. It also makes the CreatureType type more accurate since it now includes only the unit.type values that are being used and not all possible combinations of unit.type

@vercel
Copy link

vercel bot commented Jul 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
ancientbeast ✅ Ready (Inspect) Visit Preview Jul 19, 2023 9:42pm

@ghost
Copy link

ghost commented Jul 19, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@@ -3927,8 +3977,9 @@ export const unitData = [
id: 50,
name: 'Shadow Leech',
playable: false,
level: '1',
level: 1,
Copy link
Member

Choose a reason for hiding this comment

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

Single quotes missing on this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are the single quotes intentional? The only other unit that has a string level is Dark Priest level: '-'. All other units have a number level

Copy link
Member

Choose a reason for hiding this comment

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

Seemed lighter and easier to type I guess.

Copy link
Contributor Author

@allmtz allmtz Jul 21, 2023

Choose a reason for hiding this comment

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

I changed it to a number as it made the Level type defined in units.ts cleaner and I think easier to understand.

before : type Level = "-" | 1 | 3 | 2 | 4 | 5 | 6 | 7 | "1"
after: type Level = "-" | 1 | 3 | 2 | 4 | 5 | 6 | 7

This also simplifies type checking once these types are implemented in game.ts, as now if Level is a string the only possibility is '-' versus '-' | '1'

However, it's your call, I'll just wait for clarification and then close this PR

@DreadKnight
Copy link
Member

DreadKnight commented Jul 20, 2023

I appreciate the effort, but one important thing about me: I'll never want to go for manual entry data when stuff is simply formula based with like one exception, I see this PR going a bit backwards. We'll be aiming for 150 units in the long run.

@DreadKnight
Copy link
Member

@andretchen0 Hey, what's your take on this PR? Keep in mind my above comment as well...

@DreadKnight DreadKnight marked this pull request as draft July 20, 2023 10:42
@andretchen0
Copy link
Contributor

Thanks @allmtz for the commit. Keep it up!

@andretchen0 Hey, what's your take on this PR? Keep in mind my above comment as well...

I'm not familiar with this part of the codebase. I don't know what to make of it entirely. But since I was asked to comment, here we go (somewhat blindly):

On the one hand:

  • TypeScript additions that make using the editor faster/less error-prone are certainly welcomed by me.

On the other:

  • Looking at the additions, the field is a concatenation of two other fields, so it can be derived. Writing down derived data means some step is going to have to continue deriving it in the future, whenever the underlying data changes. If that step is "the dev has to derive it" then it better be really explicit. And ideally it'd throw if the data is wrong or out of sync. Maybe a good middle ground is making the derivation part of a build step. That way TS can refer to it and type check.

To see the problems of "writing down" derived data in action, have a look at the old creatureQueue compared to the new one. The creatureQueue is responsible for ordering creatures in the current and upcoming round.

At some point, it was decided that queue should hold arrays of creatures. That meant that any time a creature was created, waited, was delayed, finished a turn, or died, queue.update() or a similar creatureQueue method had to be called. That led to bugs where devs forgot to update the queue in the "right" way following a creature action.

And even when the dev remembered, the "right" code was just extra bookkeeping. It wouldn't need to exist if the data were derived on the fly.


As part of the larger picture, a sore point with the current codebase is that it relies on these "you-just-have-to-know" strings. Creature types are one example. E.g.:

You want to make a priest. You have to

player.summon('--', pos);`

or

const data = game.retrieveCreatureStats('--');
new Creature(data, game);`

But '--' is completely random and says nothing about the creature type. You just have to know.

I'd really like to see the codebase move in the direction of new Priest() or new new Creature(CreatureTypes.Priest).

Same thing with abilities. Here's how an ability file begins: G.abilities[7] = [. The 7 also represents a kind of creature type, but again, it's completely disconnected from, in this case, "Abolished".

But, simplifying is hard. Code structures that got built around the old way of doing things will all need changed, and that'll mean errors and debugging in the short term, but hopefully more and happier developpers in the long term.


Just my 2 cents. ✌️😀

@allmtz
Copy link
Contributor Author

allmtz commented Jul 20, 2023

I appreciate the effort, but one important thing about me: I'll never want to go for manual entry data when stuff is simply formula based

Got it. I thought this would simplify accessing creature.type but given whats been said I see how "writing down" this information could lead to problems in the future.

As part of the larger picture, a sore point with the current codebase is that it relies on these "you-just-have-to-know" strings.

I'll open a PR soon implementing the types created from units.ts that should help address this issue.

@andretchen0
Copy link
Contributor

I'll open a PR soon implementing the types created from units.ts that should help address this issue.

That would be great!

@allmtz allmtz requested a review from DreadKnight July 21, 2023 00:10
@allmtz allmtz mentioned this pull request Jul 25, 2023
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

3 participants