Skip to content

refactor(JortPob/Layout): break constructor into separate methods#104

Open
confusingstraw wants to merge 6 commits into
infernoplus:mainfrom
confusingstraw:confusingstraw/layout-refactor-part-2
Open

refactor(JortPob/Layout): break constructor into separate methods#104
confusingstraw wants to merge 6 commits into
infernoplus:mainfrom
confusingstraw:confusingstraw/layout-refactor-part-2

Conversation

@confusingstraw

Copy link
Copy Markdown
Collaborator

This PR refactors the Layout constructor so it isn't just a giant monolith. The code remains unchanged, it's just been broken up into separate methods to improve readability and make it easier to get a foothold when making changes.

Comment thread JortPob/Layout.cs Outdated
Comment thread JortPob/Layout.cs Outdated
Comment thread JortPob/Layout.cs
{
if (content is CharacterContent cc)
string contentId = content.id.ToLower().Trim();
if (allReferences.Contains(contentId) || content is CharacterContent || content is ItemContent || content is DoorContent || content.papyrus != null)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Checking against this many types is a bit confusing, especially since the contained switch/if checks are checking other child types. Is there any way to simplify this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

agree, but this PR is just me moving code into methods. aside from making sure i didn't miss any parameters, i wanted to leave the code as close to identical as possible.

Comment thread JortPob/Layout.cs Outdated
Comment thread JortPob/Layout.cs Outdated
Comment thread JortPob/Layout.cs Outdated
Comment thread JortPob/Layout.cs
if (npc == other) { continue; } // dont' self succ

// guards get bonus range because I said so
if (other.IsGuard() && System.Numerics.Vector3.Distance(npc.position, other.position) < 50) { npc.witness = CharacterContent.Witness.Guard; break; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It'd be good to put the magic numbers in this method into static vars. Perhaps citizenAlarmThreshold, guardChainingDistance, citizenChainingDistance.

Comment thread JortPob/Layout.cs

foreach (Tile tile in tiles) { CheckWitnesses(tile.npcs); }
foreach (InteriorGroup group in interiors) {
foreach (InteriorGroup.Chunk chunk in group.chunks) { CheckWitnesses(chunk.npcs); }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is it possible that the overlap of chunks could lead to nearby npcs placed in different chunks missing some of the witness chaining logic?

Comment thread JortPob/Layout.cs

/* Render an ASCII image of the tiles for verification! */
Lort.Log("Drawing ASCII art of worldspace map...", Lort.Type.Debug);
private void RenderWorldspaceAscii()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should change this to a stringbuilder.

Comment thread JortPob/Layout.cs

// see if map point has already been made. some areas have multiple entrances or exits
var lowerName = name.ToLower().Trim();
if(pointNames.Contains(lowerName)) { continue; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should move this if above the previous if, but leave adding to the pointNames where it is. It's a lot cheaper to check if a collection contains a string than if compare vector distances on an n-sized collection.

confusingstraw and others added 5 commits June 1, 2026 10:01
Co-authored-by: Bret D. <horfius@users.noreply.github.com>
Co-authored-by: Bret D. <horfius@users.noreply.github.com>
Co-authored-by: Bret D. <horfius@users.noreply.github.com>
Co-authored-by: Bret D. <horfius@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants