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 RegionDocumentPF2e and RegionBehaviorPF2e and implement RegionBehaviorPF2e#isOfType #14877

Merged
merged 1 commit into from
May 29, 2024

Conversation

In3luki
Copy link
Collaborator

@In3luki In3luki commented May 28, 2024

There might be a better way to do this but it works and nothing blows up.

@@ -271,9 +270,9 @@ function createEnvironmentRollOptions(actor: ActorPF2e): Record<string, boolean>
const top = region.elevation.top ?? Infinity;
if (token.elevation < bottom || token.elevation > top) continue;

for (const behavior of region.behaviors.filter((b) => b.type === "pf2eEnvironment")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

tbh the reason I'd prefer to filter like this is because I think having separate loops for environment or terrain or whatever we do would be easier to read. The performance impact is just the creation of new arrays, since looping twice with one if per is the same performance impact as looping once with two if statements per.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Filter is restored but I had to change the RegionBehaviorTypeInstances TParent to always have a Scene because apparently the token parent is narrowed to NonNullable somewhere. Tsc complains that ScenePF2e isn't ScenePF2e | null and I can't find a reason for that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think its because until the next ts version, you have to make all filters into type guards. so filter((b): b is whatever =>. The next TS version will make that unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

This is what I get when I don't change the RegionBehaviorTypeInstances and I've already spent an hour before trying to figure out why that happens. 🥲

Copy link
Collaborator Author

@In3luki In3luki May 28, 2024

Choose a reason for hiding this comment

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

But I agree that in TS 5.5 it would probably enough to filter on b.isOfType("pf2eEnvionment"). Can't wait for that release.

Copy link
Collaborator

@CarlosFdez CarlosFdez May 28, 2024

Choose a reason for hiding this comment

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

It seems to be because RegionBehaviorTypeInstances's definition uses ScenePF2e and not ScenePF2e | null. Given that it seems possible for scene to be null (such as if the actor isn't currently in a scene), shouldn't that be its type anyways?

Copy link
Collaborator Author

@In3luki In3luki May 28, 2024

Choose a reason for hiding this comment

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

The screenshot happens with RegionBehaviorTypeInstances<TParent extends RegionDocumentPF2e = RegionDocumentPF2e>. Explicitly setting RegionDocumentPF2e<ScenePF2e> fixes it.

@CarlosFdez CarlosFdez merged commit 1aee6d3 into foundryvtt:v12 May 29, 2024
1 check passed
@In3luki
Copy link
Collaborator Author

In3luki commented May 29, 2024

I forgot to mark this as a Draft after waking up. 😨
Shark suggested going in another direction for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants