Skip to content

Refactor MSB gen to consolidate interior/exterior code#97

Open
sbodegraven wants to merge 14 commits into
infernoplus:mainfrom
sbodegraven:msb-gen-refactor
Open

Refactor MSB gen to consolidate interior/exterior code#97
sbodegraven wants to merge 14 commits into
infernoplus:mainfrom
sbodegraven:msb-gen-refactor

Conversation

@sbodegraven

@sbodegraven sbodegraven commented May 10, 2026

Copy link
Copy Markdown

Created interfaces for Tiles and InteriorGroups/Chunks to consolidate a lot of MSB generation code used by both. Related issue: #47

I tried to keep the behaviour identical to before and it seems to be working correctly.

@horfius horfius left a comment

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.

I haven't reviewed the logic deeply for Main.cs, but in general for C# you can make a lot of these more straightforward interface functions into arrow operator style, e.g.
public int GetMap() => map;
or into property style

public interface IMSBCompilableGroup
{
    int Map { get; }
}

public class InteriorChunk : IMSBCompilableGroup
{
    int Map { get; set; } // can get rid of map member and change references to this
}

@sbodegraven

Copy link
Copy Markdown
Author

I haven't reviewed the logic deeply for Main.cs, but in general for C# you can make a lot of these more straightforward interface functions into arrow operator style, e.g. public int GetMap() => map; or into property style

public interface IMSBCompilableGroup
{
    int Map { get; }
}

public class InteriorChunk : IMSBCompilableGroup
{
    int Map { get; set; } // can get rid of map member and change references to this
}

Thanks, I forgot you could do that in C#. I've updated it to use the property style.

@sbodegraven

Copy link
Copy Markdown
Author

I've cleaned up some additional stuff, I'll leave it at that for now unless other changes are requested.

Comment thread JortPob/InteriorGroup.cs Outdated

warps = new();
positions = new();
Paths = [];

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.

You can do inline initialization of properties to clean this up a little,
public List<AssetContent> Assets { get; init; } = [] (this one might cause a compiler error if you are initializing in a constructor)
or
public List<AssetContent> Assets { get; } = [] if there are no constructors that do anything other than a simple init

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

Comment thread JortPob/Main.cs
Lort.NewTask("Generating MSB", layout.tiles.Count);

foreach (BaseTile tile in layout.all)
void GenerateMSB(IMSBCompilableGroup group)

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.

This whole section is well cleaned up, but I want @infernoplus to take a look and see if there are cases where the logic should be separated a bit.

Comment thread JortPob/Main.cs
bed.TalkID = character.GetESD(group.IdList(), msb, bedContent);

if (group.IsInterior) {
bed.CollisionPartName = rootCollision.Name;

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.

Why is this behind group.IsInterior now? I can't think of an exterior bed in all morrowind but we don't want to possibly exclude mods.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

All of the code blocks like this that reference rootCollision were previously only in the interior loop, so I had to add this check to maintain the same behaviour. It's possible that this is unnecessary and works fine for exteriors, but I don't know enough about it to make that call.

Comment thread JortPob/Main.cs Outdated
asset.UnkPartNames[5] = rootCollision.Name;
}
/* Asset tileload config */
else if (group.GetType() == typeof(HugeTile) || group.GetType() == typeof(BigTile))

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.

You should use this style instead of GetType and typeof.
else if (group is HugeTile || group is BigTile)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

Comment thread JortPob/Main.cs
asset.UnkPartNames[1] = rootCollision.Name;
asset.UnkPartNames[3] = rootCollision.Name;
asset.UnkPartNames[5] = rootCollision.Name;
if (group.IsInterior)

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.

Why put this behind group.IsInterior? Exteriors need collision assigned.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This was only done for interiors before so I kept that the same.

Comment thread JortPob/MSB.cs
int[] IdList();

bool IsEmpty();
bool IsInterior { get; }

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.

You should make these Is_Condition_ consistent, either functions or property style.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

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