Skip to content

Commit ee1a648

Browse files
committed
Align meld markers with player perspective
1 parent 83bec80 commit ee1a648

4 files changed

Lines changed: 47 additions & 8 deletions

File tree

‎modules/mahjong-presentation/src/main/java/top/ellan/mahjong/presentation/UniversalTableLayout.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ private SceneTransform[][] precomputeMelds() {
292292
double baseZ = axis.outZ() * inset
293293
+ axis.tangentZ() * geometry.tableHalfLength();
294294
for (int index = 0; index < geometry.maxMeldTiles(); index++) {
295-
double distance = (index + 0.5D) * tileStep();
295+
int group = index / 4;
296+
int slot = index % 4;
297+
int railIndex = group * 4 + (3 - slot);
298+
double distance = (railIndex + 0.5D) * tileStep();
296299
result[seat][index] = transform(
297300
baseX - axis.tangentX() * distance,
298301
flatY(),

‎modules/mahjong-presentation/src/test/java/top/ellan/mahjong/presentation/SceneGraphTest.java‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import top.ellan.mahjong.spi.PrivateRuleView;
2929
import top.ellan.mahjong.spi.PublicRuleView;
3030
import top.ellan.mahjong.spi.RuleAction;
31+
import top.ellan.mahjong.spi.RuleMeldPresentation;
32+
import top.ellan.mahjong.spi.RuleMeldTileRole;
3133
import top.ellan.mahjong.spi.RuleTablePresentation;
3234
import top.ellan.mahjong.spi.RuleTilePresentation;
3335
import top.ellan.mahjong.spi.RuleViewTile;
@@ -337,6 +339,27 @@ void discardRiverWrapsAfterSixTiles() {
337339
assertEquals(firstTransform.y(), seventhTransform.y());
338340
}
339341

342+
@Test
343+
void sharedMeldSourceMarkersAreLeftMiddleRightFromTheOwnersView() {
344+
ResolvedTableLayout layout =
345+
new UniversalTableLayout(GEOMETRY).resolve(table(136));
346+
SceneTransform fromLeft = layout.tile(meldTile(
347+
1,
348+
RuleMeldPresentation.tile(
349+
0, 3, 4, 0, 3, RuleMeldTileRole.CLAIMED, -1)), 3);
350+
SceneTransform fromOpposite = layout.tile(meldTile(
351+
2,
352+
RuleMeldPresentation.tile(
353+
0, 3, 4, 0, 2, RuleMeldTileRole.CLAIMED, -1)), 3);
354+
SceneTransform fromRight = layout.tile(meldTile(
355+
3,
356+
RuleMeldPresentation.tile(
357+
0, 3, 4, 0, 1, RuleMeldTileRole.CLAIMED, -1)), 3);
358+
359+
assertTrue(fromLeft.x() < fromOpposite.x());
360+
assertTrue(fromOpposite.x() < fromRight.x());
361+
}
362+
340363
@Test
341364
void universalLayoutSupportsEveryOfficialWallShape() {
342365
UniversalTableLayout layout = new UniversalTableLayout(GEOMETRY);
@@ -578,6 +601,17 @@ private static RuleViewTile tile(
578601
RuleTilePresentation.natural(layoutIndex));
579602
}
580603

604+
private static RuleViewTile meldTile(long id, RuleTilePresentation presentation) {
605+
return new RuleViewTile(
606+
new TileInstanceId(id),
607+
new TileVisualId("mcr:tile/m1"),
608+
Optional.of(SEAT_ZERO),
609+
RuleViewZone.MELD,
610+
Math.toIntExact(id - 1),
611+
true,
612+
presentation);
613+
}
614+
581615
private static RuleTablePresentation table(int wallCapacity) {
582616
List<Integer> stacks = switch (wallCapacity) {
583617
case 108 -> List.of(14, 13, 14, 13);

‎modules/mahjong-rule-spi/src/main/java/top/ellan/mahjong/spi/RuleMeldPresentation.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ public static RuleTilePresentation tile(
9090
}
9191
displaySlot = claimedSlot;
9292
}
93+
int slotOffset = SLOTS_PER_MELD - baseTileCount;
9394
int layoutIndex = Math.addExact(
94-
Math.multiplyExact(meldIndex, SLOTS_PER_MELD), displaySlot);
95+
Math.multiplyExact(meldIndex, SLOTS_PER_MELD),
96+
slotOffset + displaySlot);
9597
return switch (role) {
9698
case ORDINARY -> RuleTilePresentation.natural(layoutIndex);
9799
case CLAIMED -> RuleTilePresentation.clockwise(layoutIndex);

‎modules/mahjong-rule-spi/src/test/java/top/ellan/mahjong/spi/RuleMeldPresentationTest.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ class RuleMeldPresentationTest {
1111

1212
@Test
1313
void sourceSeatSelectsLeftMiddleOrRightOnAFourPlayerTable() {
14-
assertClaimedSlot(0, new SeatId(3));
15-
assertClaimedSlot(1, new SeatId(2));
16-
assertClaimedSlot(2, new SeatId(1));
14+
assertClaimedSlot(1, new SeatId(3));
15+
assertClaimedSlot(2, new SeatId(2));
16+
assertClaimedSlot(3, new SeatId(1));
1717
}
1818

1919
@Test
2020
void ordinaryTilesFillAroundTheClaimedSlotWithoutGaps() {
2121
RuleTilePresentation first = ordinary(new SeatId(2), 0);
2222
RuleTilePresentation second = ordinary(new SeatId(2), 1);
23-
assertEquals(0, first.layoutIndex());
24-
assertEquals(2, second.layoutIndex());
23+
assertEquals(1, first.layoutIndex());
24+
assertEquals(3, second.layoutIndex());
2525
assertEquals(RuleTileRotation.NATURAL, first.rotation());
2626
assertEquals(RuleTileRotation.NATURAL, second.rotation());
2727
}
@@ -32,7 +32,7 @@ void addedKongUsesThreeBasePositionsAndStacksOnTheClaimedTile() {
3232
2, 3, 4, 0, 1, RuleMeldTileRole.CLAIMED, -1);
3333
RuleTilePresentation added = RuleMeldPresentation.tile(
3434
2, 3, 4, 0, 1, RuleMeldTileRole.ADDED, -1);
35-
assertEquals(10, claimed.layoutIndex());
35+
assertEquals(11, claimed.layoutIndex());
3636
assertEquals(claimed.layoutIndex(), added.layoutIndex());
3737
assertEquals(1, added.stackLevel());
3838
assertEquals(RuleTileRotation.CLOCKWISE, added.rotation());

0 commit comments

Comments
 (0)