Skip to content

Implemented/Fixed Mine Door rotation#58

Open
KSunyo wants to merge 10 commits intoWarlander:masterfrom
KSunyo:master
Open

Implemented/Fixed Mine Door rotation#58
KSunyo wants to merge 10 commits intoWarlander:masterfrom
KSunyo:master

Conversation

@KSunyo
Copy link
Collaborator

@KSunyo KSunyo commented Jan 25, 2026

  • Created a new enum called DoorDirection
  • Added a new property to GroundData.cs called IsCaveDoor as the main condition for rotation related methods
    • I check if ShortName matches any predefined String.
  • Added DoorDirection public property in Ground.cs, which is by default DoorDirection.N, and added it to the ground constructor and to other methods as parameter.
  • Added doorDirectionsArray in GroundMesh.cs.
  • Added UpdateDoorDirection method being responsible of calculating the relevant orientation and RefreshDoorOrientation method which is called in the Refresh method.
  • Added ApplyUvRotation method in GroundMesh.cs, that when a rotation is applicable manipulates the meshUVs.
  • Extended SetGroundData in GroundMesh.cs.

This PR is related to issue #7 .

Issue Warlander/DeedPlanner3 Warlander#7
@KSunyo KSunyo linked an issue Jan 25, 2026 that may be closed by this pull request
@KSunyo KSunyo added bug Something isn't working enhancement New feature or request labels Jan 25, 2026
Copy link
Owner

@Warlander Warlander left a comment

Choose a reason for hiding this comment

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

I think door direction rotation should be happening on graphics level only, without Ground model needing to be aware of it as we only really need it for rendering - and it shouldn't be a performance issue given we only need this info if something is changing with the ground.

ground.data = newData;
ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection);
ground.DoorDirection = ground.Tile.UpdateDoorDirection();
ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection, ground.DoorDirection);
Copy link
Owner

Choose a reason for hiding this comment

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

Why do we need to serialize it?

@KSunyo KSunyo requested a review from Warlander January 27, 2026 04:09
Tex2d = tex2d;
Tex3d = tex3d;
Diagonal = diagonal;
IsCaveDoor = ShortName is "wcaDoor" or "gcaDoor" or "scaDoor" or "mcaDoor";
Copy link
Owner

Choose a reason for hiding this comment

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

I would lean more towards optional XML tag here, similar to how openings and diagonal-enabled ground types are defined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As cave doors are the only ground types that can rotate, I used the "Cave door" category name to set it to true

// Cave.Initialize(this, Database.DefaultCaveData);
}

public DoorDirection UpdateDoorDirection()
Copy link
Owner

Choose a reason for hiding this comment

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

Update would indicate something within the tile changes but it's not the case, the door direction seems to be calculated here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed it to CalculateDoorOrientation

// Rotating vectors based on DoorDirection
if (dir == DoorDirection.E)
{
(v00, v10, v11, v01) = (v10, v11, v01, v00);
Copy link
Owner

Choose a reason for hiding this comment

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

That's interesting syntax, honestly it makes lots of sense here! 👀

DoorDirection doorDir = doorDirectionsArray[x, y];
Vector2Int selfCoords = new Vector2Int(x, y);

int westSlot = vertexIndex;
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 syntax where these values are only initialized once would be easier to read here.

Copy link
Collaborator Author

@KSunyo KSunyo Jan 27, 2026

Choose a reason for hiding this comment

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

In the newest commit I changed it a bit:

var (wOffset, nOffset, eOffset, sOffset) = (data.IsCaveDoor ? doorOrientation : DoorOrientation.N) switch
{
DoorOrientation.E => (9, 0, 3, 6),
DoorOrientation.S => (6, 9, 0, 3),
DoorOrientation.W => (3, 6, 9, 0),
_ => (0, 3, 6, 9),
};
int westSlot = vertexIndex + wOffset;
int northSlot = vertexIndex + nOffset;
int eastSlot = vertexIndex + eOffset;
int southSlot = vertexIndex + sOffset;

private int[,] slopesArray;
private GroundData[,] dataArray;
private RoadDirection[,] directionsArray;
private DoorDirection[,] doorDirectionsArray;
Copy link
Owner

Choose a reason for hiding this comment

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

Just as a sanity check, is it guaranteed to be correct initially? All door directions will be set to N by default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For cave doors it is guaranteed to be incorrect almost always initially. But then it should almost immediately correct itself as of the current version.

private bool needsUvUpdate = false;

public void Initialize(int width, int height, OverlayMesh newOverlayMesh)
public void Initialize(Map map, int width, int height, OverlayMesh newOverlayMesh)
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not a fan of map knowing about GroundMesh and GroundMesh about the map, but this entire part of code needs later refactor anyway so I'm ok with it for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree.

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

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mine Doors flipped and flipped.

2 participants