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

Zoning UI cleanup 2 #179

Draft
wants to merge 14 commits into
base: feat/mom-0.10
Choose a base branch
from
Draft

Conversation

PeenScreeker
Copy link
Member

Closes momentum-mod/game/issues/

This is a draft I'm opening so that red changes can be tested during review if anyone wants to try them out.

Checks

  • I have thoroughly tested all of the code I have modified/added/removed to ensure something else did not break
  • I have followed semantic commit messages e.g. feat: Add foo, chore: Update bar, etc...
  • My branch has a clear history of changes that can be easy to follow when being reviewed commit-by-commit
  • My branch is functionally complete; the only changes to be done will be those potentially requested in code review
  • All changes requested in review have been fixuped into my original commits.
  • Fully tokenized all my strings (no hardcoded English strings!!) and supplied bulk JSON strings below

@PeenScreeker PeenScreeker self-assigned this Feb 5, 2025
Copy link
Member

@tsa96 tsa96 left a comment

Choose a reason for hiding this comment

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

I know this is still a draft but figured I'd have a quick skim over this. If you're having issues with null/undefined stuff I'd be happy to go over best practices more, they can be a real bastard to work with.

Could also enable TS strict mode specifically for this file, which will yell at you like crazy at first, but once you fix all the strict null check issues it can make getting null-checking
right much easier.

<include type="module" src="file://{scripts}/pages/zoning/zoning.ts" />
</scripts>

</root>
Copy link
Member

Choose a reason for hiding this comment

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

Nit: missing newline

this.createTrackEntry(this.panels.trackList, this.mapZoneData.tracks.main, $.Localize('#Zoning_Main'));

// if the first segment has no start zone, show text to create start zone until a start zone has been made
if (this.mapZoneData.tracks.main.zones.segments[0]?.checkpoints.length === 0) {
if (this.mapZoneData.tracks.main.zones?.segments?.length > 0 && this.mapZoneData.tracks.main.zones?.segments[0]?.checkpoints?.length) {
Copy link
Member

Choose a reason for hiding this comment

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

Don't think you need this length check. zones?.segments[0]?. is null if array is length 0, which ?.s carry to the end of the expression, so the final .length is either a number or null

zone: null
}
);
if (track.zones?.segments?.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't need this check. If you're worried about the array being null, you can do for (const [i, segment] of track.zones.segments?.entries() ?? []). Looks a bit weird, but saves a whole level of indentation.

});
}
const segmentCheckpointContainer = segmentChildContainer.FindChildTraverse<Panel>('CheckpointContainer');
if (segment?.checkpoints?.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

zone: zone
});
const segmentCancelContainer = segmentChildContainer.FindChildTraverse<Panel>('CancelContainer');
if (segment?.cancel?.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

Comment on lines +459 to 464
for (const [i, item] of array?.entries()) {
this.addOptionToDropdown(optionType || item, dropdown, i, optionType !== '');
}
Copy link
Member

Choose a reason for hiding this comment

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

This I don't think is safe, however. If array is null, your elvis will propagate it along, and you'll get a JS exception trying to iterate over null.

this.panels.regionBottom.text = (region?.bottom ?? 0).toFixed(2);
this.panels.regionHeight.text = (region?.height ?? 0).toFixed(2);
this.panels.regionSafeHeight.text = (region?.safeHeight ?? 0).toFixed(2);

const tpIndex = !region.teleDestTargetname
const tpIndex = (region.teleDestTargetname === undefined || region.teleDestTargetname === '')
Copy link
Member

Choose a reason for hiding this comment

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

Empty string (and only the empty string) is falsy so original seems fine? Unless you're concerned about it being null, in which case I'd maybe rethink this code since combining undefined and null like this tends to lead to very confusing code.

editing: validity.zone && region === this.selectedZone.zone.regions[regionIndex]
});

if (this.selectedZone.track.zones?.segments?.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Again you can save a bunch of indents using by skipping the length checks. Could also do some psycho flatMaps (though this is untested and absolutely not required)

const regionRegions =
  this.selectedZone.track.zones?.segments?.flatMap((segment, segmentNumber) => [
    ...(segment?.checkpoints?.flatMap((checkpoint, checkpointNumber) =>
      checkpoint.regions.map((region) => ({
        region: region,
        renderMode:
          checkpointNumber === 0
            ? segmentNumber === 0
              ? RegionRenderMode.START
              : RegionRenderMode.MAJOR_CHECKPOINT
            : RegionRenderMode.MINOR_CHECKPOINT,
        editing: validity.zone && region === this.selectedZone.region,
      })),
    ) ?? []),
    ...(segment?.cancel?.flatMap((cancel) =>
      cancel.regions.map((region) => ({
        region: region,
        renderMode: RegionRenderMode.CANCEL,
        editing: validity.zone && region === this.selectedZone.region,
      })),
    ) ?? []),
  ]) ?? [];

@PeenScreeker PeenScreeker force-pushed the feat/zoning-ui-cleanup-2 branch from 4989b80 to fa7f9d4 Compare February 25, 2025 06:01
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.

2 participants