Skip to content

Commit bed15e0

Browse files
committed
feat: preserve table interaction and overhead view feel
1 parent ee1a648 commit bed15e0

33 files changed

Lines changed: 2218 additions & 113 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The former session/controllers, mixed Java/Kotlin rule code, `mahjong-utils`, GB
1212

1313
Requirements: Java 21, Paper/Folia 1.20.1+, and CraftEngine 26.7+.
1414

15-
See the [Chinese architecture guide](docs/architecture.zh-CN.md), [installation guide](docs/installation.zh-CN.md), and [rule-pack guide](docs/rule-packs.zh-CN.md).
15+
See the [Chinese architecture guide](docs/architecture.zh-CN.md), [interaction contract](docs/interaction.zh-CN.md), [installation guide](docs/installation.zh-CN.md), and [rule-pack guide](docs/rule-packs.zh-CN.md).
1616

1717
GitHub Actions builds the plugin with:
1818

‎craftengine/configuration/mahjong.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ items:
169169
- {position: "1,-1.5,0", type: shulker, direction: up, scale: 1, peek: 0, blocks_building: true, interactive: false, interaction_entity: false}
170170
- {position: "1,-1.5,1", type: shulker, direction: up, scale: 1, peek: 0, blocks_building: true, interactive: false, interaction_entity: false}
171171
- {position: "0,0,2.25", type: interaction, width: 0.8, height: 1, blocks_building: false, interactive: true, invisible: true, seats: ["0,0,2.25 180"]}
172-
- {position: "2.25,0,0", type: interaction, width: 0.8, height: 1, blocks_building: false, interactive: true, invisible: true, seats: ["2.25,0,0 270"]}
172+
- {position: "2.25,0,0", type: interaction, width: 0.8, height: 1, blocks_building: false, interactive: true, invisible: true, seats: ["2.25,0,0 90"]}
173173
- {position: "0,0,-2.25", type: interaction, width: 0.8, height: 1, blocks_building: false, interactive: true, invisible: true, seats: ["0,0,-2.25 0"]}
174-
- {position: "-2.25,0,0", type: interaction, width: 0.8, height: 1, blocks_building: false, interactive: true, invisible: true, seats: ["-2.25,0,0 90"]}
174+
- {position: "-2.25,0,0", type: interaction, width: 0.8, height: 1, blocks_building: false, interactive: true, invisible: true, seats: ["-2.25,0,0 270"]}
175175

176176
mahjongpaper:hand_tile_hitbox:
177177
material: paper

‎docs/interaction.zh-CN.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 桌面交互与看牌契约
2+
3+
2.0 使用一套与玩法无关的交互手感。日麻、MCR、四川只通过规则包决定有哪些牌、牌的稳定顺序、当前合法动作以及动作优先级,不得各自实现点击器、镜头或桌面坐标。
4+
5+
## 手牌操作
6+
7+
- 第一次点击一张可出的手牌,只选择该牌;本人看到牌面上抬 `0.06` 格,不提交规则动作。
8+
- 超过 40ms 后再次点击同一张牌,才把 revision-bound token 提交给该桌 actor。
9+
- 40ms 内由同一次 CraftEngine 交互产生的重复事件会被丢弃,避免一次点击意外出牌。
10+
- 潜行点击已选择的同一张牌会取消;潜行点击另一张牌仍切换选择,保持原有操作习惯。
11+
- revision 更新、动作区重建、离桌或断线都会清除选择,旧 token 不可能作用于新状态。
12+
13+
选择路径只进行 O(1) 路由、无锁的玩家级 CAS 和一至两次客户端实体位移;它不调用规则包、SQL、布局器,也不重建整张桌面。本人真实牌面和选中位移都是 Sparrow 客户端私有投影,其他玩家只收到 CraftEngine 的牌背家具。
14+
15+
## 动作按钮
16+
17+
CraftEngine YAML 定义可复用的透明 hitbox、碰撞、家具与 culling。Java 只按规则包给出的 `ActionPlacement` 和稳定顺序选择通用槽位。按钮文字是仅授权玩家可见的客户端文字投影;普通动作使用青色,规则包标记的重点动作使用金色。
18+
19+
三种玩法共享同一套动作行和右侧固定槽,不存在日麻、MCR、四川三份按钮坐标代码。“看牌河”固定在动作行侧边,其命中区只接受对应座位玩家的 `(InteractionHandle, PlayerId)`。
20+
21+
## 俯视看牌
22+
23+
- 玩家必须仍坐在 CraftEngine 座椅内才能进入。
24+
- 点击“看牌河”后,客户端镜头从眼睛位置平滑移动到桌面中心上方 `4.5` 格;默认过渡 16 tick。
25+
- 俯视状态只读,座位动作标签会隐藏,任何牌局动作都被路由层拒绝。
26+
- 按 Shift 返回本人实体镜头并保持座位;传送、死亡、离桌、断线、桌面关闭也会强制恢复或清理镜头。
27+
- 镜头只使用客户端私有假实体和启动期预热、随后缓存的发包句柄,不生成 Bukkit 世界实体。
28+
29+
镜头动画由玩家实体调度器注册有限个单次任务,没有全服或全桌逐 tick 扫描。一个玩家的镜头失败只关闭该玩家的俯视功能,不修改规则状态,也不阻塞其他桌。
30+
31+
## 配置边界
32+
33+
可配置项位于 `presentation.geometry` 与 `presentation.overhead`。静态模型、桌椅、牌背、点棒、hitbox、座位和裁剪必须在 `craftengine/configuration/mahjong.yml` 中维护;只有随规则视图和玩家权限动态变化的坐标、私有牌面、文字与镜头由 Java 投影。
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package top.ellan.mahjong.application;
2+
3+
import java.util.Optional;
4+
import top.ellan.mahjong.domain.TableId;
5+
import top.ellan.mahjong.spi.PlayerId;
6+
import top.ellan.mahjong.spi.TileInstanceId;
7+
8+
/** Projects one player's ephemeral hand selection without touching rule state or persistence. */
9+
@FunctionalInterface
10+
public interface HandTileSelectionPort {
11+
HandTileSelectionPort NOOP = (tableId, playerId, selectedTile) -> {};
12+
13+
void showSelection(
14+
TableId tableId, PlayerId playerId, Optional<TileInstanceId> selectedTile);
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package top.ellan.mahjong.application;
2+
3+
/** How a routed scene interaction is interpreted by the platform-neutral input layer. */
4+
public enum InteractionPurpose {
5+
RULE_ACTION,
6+
HAND_TILE_ACTION,
7+
OVERHEAD_VIEW
8+
}

‎modules/mahjong-application/src/main/java/top/ellan/mahjong/application/InteractionRouteBinding.java‎

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,70 @@
33
import java.util.Objects;
44
import top.ellan.mahjong.spi.ActionToken;
55
import top.ellan.mahjong.spi.PlayerId;
6+
import top.ellan.mahjong.spi.TileInstanceId;
67

78
/** Per-player binding behind a shared public hit region. */
89
public record InteractionRouteBinding(
9-
InteractionHandle handle, PlayerId playerId, ActionToken actionToken) {
10+
InteractionHandle handle,
11+
PlayerId playerId,
12+
long revision,
13+
InteractionPurpose purpose,
14+
ActionToken actionToken,
15+
TileInstanceId targetTile) {
16+
public InteractionRouteBinding(
17+
InteractionHandle handle, PlayerId playerId, ActionToken actionToken) {
18+
this(
19+
handle,
20+
playerId,
21+
Objects.requireNonNull(actionToken, "actionToken").revision(),
22+
InteractionPurpose.RULE_ACTION,
23+
actionToken,
24+
null);
25+
}
26+
1027
public InteractionRouteBinding {
1128
Objects.requireNonNull(handle, "handle");
1229
Objects.requireNonNull(playerId, "playerId");
13-
Objects.requireNonNull(actionToken, "actionToken");
14-
if (!playerId.equals(actionToken.actor())) {
30+
Objects.requireNonNull(purpose, "purpose");
31+
if (revision < 0) {
32+
throw new IllegalArgumentException("Interaction revision must be non-negative");
33+
}
34+
if (purpose == InteractionPurpose.OVERHEAD_VIEW) {
35+
if (actionToken != null || targetTile != null) {
36+
throw new IllegalArgumentException("Overhead view routes cannot carry rule data");
37+
}
38+
} else if (actionToken == null
39+
|| actionToken.revision() != revision
40+
|| !playerId.equals(actionToken.actor())) {
1541
throw new IllegalArgumentException("Interaction route actor mismatch");
1642
}
43+
if ((purpose == InteractionPurpose.HAND_TILE_ACTION) != (targetTile != null)) {
44+
throw new IllegalArgumentException("Only hand-tile routes require a target tile");
45+
}
46+
}
47+
48+
public static InteractionRouteBinding handTile(
49+
InteractionHandle handle,
50+
PlayerId playerId,
51+
ActionToken token,
52+
TileInstanceId targetTile) {
53+
return new InteractionRouteBinding(
54+
handle,
55+
playerId,
56+
token.revision(),
57+
InteractionPurpose.HAND_TILE_ACTION,
58+
token,
59+
Objects.requireNonNull(targetTile, "targetTile"));
60+
}
61+
62+
public static InteractionRouteBinding overhead(
63+
InteractionHandle handle, PlayerId playerId, long revision) {
64+
return new InteractionRouteBinding(
65+
handle,
66+
playerId,
67+
revision,
68+
InteractionPurpose.OVERHEAD_VIEW,
69+
null,
70+
null);
1771
}
1872
}

0 commit comments

Comments
 (0)