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

raidboss: refactor trigger loading #5047

Closed
wants to merge 20 commits into from

Conversation

trim21
Copy link
Contributor

@trim21 trim21 commented Nov 1, 2022

this contains the change of #5045 and #5038, please review and merge them first

This PR seprated triggers loading into 3 seprated steps, loading, localizing and overriding for better maintenance

@trim21 trim21 force-pushed the refactor-trigger-loading branch from 4552be1 to eec49c3 Compare November 1, 2022 23:28
@trim21 trim21 marked this pull request as ready for review November 2, 2022 00:30
@trim21 trim21 marked this pull request as draft November 2, 2022 05:36
ui/raidboss/raidboss_options.ts Outdated Show resolved Hide resolved
ui/raidboss/popup-text.ts Outdated Show resolved Hide resolved
ui/raidboss/popup-text.ts Outdated Show resolved Hide resolved
ui/raidboss/popup-text.ts Outdated Show resolved Hide resolved
ui/raidboss/popup-text.ts Outdated Show resolved Hide resolved
//
// JavaScript dictionaries are *almost* ordered automatically as we would want,
// but want to handle missing ids and integer ids (you shouldn't, but just in case).
class OrderedTriggerList {
Copy link
Owner

Choose a reason for hiding this comment

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

What was wrong with OrderedTriggerList?

Copy link
Contributor Author

@trim21 trim21 Nov 2, 2022

Choose a reason for hiding this comment

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

Nothing, just it mix-up the localization step and override step, and now they are separated.

Copy link
Owner

Choose a reason for hiding this comment

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

I guess I don't really understand. You could replace ProcessedTrigger with LocalizedTrigger and this code would still work. Mostly I just know this existing code is working, and so I'd rather not replace it with something new, unless there's a reason to rewrite it.

Copy link
Owner

Choose a reason for hiding this comment

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

In particular, I think it's a little confusing from a user output error to have the override console messages come in the opposite order that they are overridden. If you have A B C triggers in order, this will print out C overrides B, and B overrides A, but in reality the load order is A B C.

ui/raidboss/popup-text.ts Outdated Show resolved Hide resolved
ui/raidboss/raidboss_config.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the test label Nov 2, 2022
@trim21 trim21 marked this pull request as ready for review November 2, 2022 20:32
@trim21
Copy link
Contributor Author

trim21 commented Nov 3, 2022

Should we add legacy field like regexDe to loose trigger?

There is a deprecated zoneRegex field, I think also need to add regexDe/netRegexDe fields

//
// JavaScript dictionaries are *almost* ordered automatically as we would want,
// but want to handle missing ids and integer ids (you shouldn't, but just in case).
class OrderedTriggerList {
Copy link
Owner

Choose a reason for hiding this comment

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

I guess I don't really understand. You could replace ProcessedTrigger with LocalizedTrigger and this code would still work. Mostly I just know this existing code is working, and so I'd rather not replace it with something new, unless there's a reason to rewrite it.

@@ -1453,20 +1464,23 @@ const userFileHandler: UserFileCallback = (
if (!baseOptions.Triggers)
return;

baseOptions.Triggers ??= [];
baseOptions.LoadedTriggers ??= [];
Copy link
Owner

Choose a reason for hiding this comment

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

I still think LoadedTriggers is an implementation detail and it doesn't make sense for it to be part of Options. It's not something set by a user or the config.

If filename is part of LooseTriggerSet, then Triggers can just be updated in place as it used to be, right? That's what I was trying to suggest before.

Copy link
Contributor Author

@trim21 trim21 Nov 4, 2022

Choose a reason for hiding this comment

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

I'm trying not to modified object in place 🤔

Copy link
Owner

@quisquous quisquous Nov 4, 2022

Choose a reason for hiding this comment

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

In general, I think "don't modify things in place" is a good approach, but usually that means there needs to be a clear data pipeline or data should be in temporary scoped variables. I think passing things through Options that shouldn't live in Options is strictly worse. If anything, you're also now modifying Options in place, which seems like the same issue.

(Also, this is already being modified in place on line 1336.)

Since there's already a lot going on here, what do you think about an approach of: (1) in this PR, keep modifying things in place / keep Options as-is without new members (2) follow up with a different PR to change how triggers are loaded here and maybe return different things from this function, make it better?

return [set.timeline, files[timelineFile]];
};

const flattenTimelinePlace = (
Copy link
Owner

Choose a reason for hiding this comment

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

Can this function delete set.timelineFile then if you've removed it from the other function, since it's overriding the timeline?

Comment on lines 75 to 76
timelineTriggers?: LooseTimelineTrigger[];
triggers?: LooseTrigger[];
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
timelineTriggers?: LooseTimelineTrigger[];
triggers?: LooseTrigger[];

Aren't these already defined in LooseTriggerSet? I'm not sure I understand why they need to be re-listed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LooseTriggerSet now is triggers?: (LooseTrigger & LegacyTrigger)[];

and

export type LegacyTrigger = {
  regexEn?: RegExp;
  regexDe?: RegExp;
  regexFr?: RegExp;
  regexCn?: RegExp;
  regexJa?: RegExp;
  regexKo?: RegExp;

  // @deprecated
  netRegexEn?: RegExp;
  netRegexFr?: RegExp;
  netRegexDe?: RegExp;
  netRegexCn?: RegExp;
  netRegexJa?: RegExp;
  netRegexKo?: RegExp;
};

@quisquous
Copy link
Owner

Should we add legacy field like regexDe to loose trigger?

Sure, sounds good!

/**
* @deprecated remove this after we don't support `netRegexCn` style triggers
*/
export type LegacyLangSuffix = 'En' | 'De' | 'Fr' | 'Ja' | 'Cn' | 'Ko';
Copy link
Owner

Choose a reason for hiding this comment

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

Where does this get used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

regex${lang as LegacyLangSuffix} netRegex${lang as LegacyLangSuffix}

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry, I don't see what you're referring to. Which file is that in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's used to get legacy regexDe/netRegexDe property in popup-text.ts

Copy link
Owner

Choose a reason for hiding this comment

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

$ git grep LegacyLangSuffix
resources/languages.ts:export type LegacyLangSuffix = 'En' | 'De' | 'Fr' | 'Ja' | 'Cn
' | 'Ko';

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry for the confusion, I just don't see what you mean. Did you mean to add these changes and they didn't save/commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's strange, I remembered I used it in popup-test.ts, maybe I lost it by mistake.

/**
* @deprecated
*/
export type LegacyTrigger = {
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 this could be combined into LooseTrigger. LooseTrigger is the "user trigger, that could be missing fields, and could have old deprecated fields in it" type. It's the same reason that LooseTriggerSet has zoneRegex in it.

ui/raidboss/raidboss_options.ts Outdated Show resolved Hide resolved
//
// JavaScript dictionaries are *almost* ordered automatically as we would want,
// but want to handle missing ids and integer ids (you shouldn't, but just in case).
class OrderedTriggerList {
Copy link
Owner

Choose a reason for hiding this comment

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

In particular, I think it's a little confusing from a user output error to have the override console messages come in the opposite order that they are overridden. If you have A B C triggers in order, this will print out C overrides B, and B overrides A, but in reality the load order is A B C.

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.

2 participants