Skip to content

Commit ea302fe

Browse files
committed
Many bugfixes
1 parent 0e5389e commit ea302fe

File tree

5 files changed

+56
-32
lines changed

5 files changed

+56
-32
lines changed

client/PIXIBackend.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const PIXIBackend: (app: Application) => BackendFactory = (app: Application) =>
2626
}
2727

2828
function mouseDownListener(e: any) {
29-
if (currentObject == null) {
29+
if (currentObject == null && manager.getMonitor().canDragSource(sourceId)) {
3030
currentObject = reticle;
3131
initIndex = node.zIndex;
3232
initVisible = reticle.visible;
@@ -52,17 +52,17 @@ const PIXIBackend: (app: Application) => BackendFactory = (app: Application) =>
5252
const pos = reticle.parent.toLocal(e);
5353
if (manager.getMonitor().isDragging()) {
5454
reticle.position.copyFrom(pos);
55-
}
5655

57-
const matchingTargetIds = Object.keys(targetObjects)
58-
.filter((key) => targetObjects[key].getBounds().contains(e.x, e.y) && targetObjects[key].zIndex < 1000)
59-
.filter((key) => manager.getRegistry().getTargetType(key) == manager.getMonitor().getItemType());
56+
const matchingTargetIds = Object.keys(targetObjects)
57+
.filter((key) => targetObjects[key].getBounds().contains(e.x, e.y) && targetObjects[key].zIndex < 1000)
58+
.filter((key) => manager.getRegistry().getTargetType(key) == manager.getMonitor().getItemType());
6059

61-
if (matchingTargetIds.length > 0) {
62-
matchingTargetIds.sort((a, b) => targetObjects[b].zIndex - targetObjects[a].zIndex);
63-
manager.getActions().hover([matchingTargetIds[0]]);
64-
} else {
65-
manager.getActions().hover([]);
60+
if (matchingTargetIds.length > 0) {
61+
matchingTargetIds.sort((a, b) => targetObjects[b].zIndex - targetObjects[a].zIndex);
62+
manager.getActions().hover([matchingTargetIds[0]]);
63+
} else {
64+
manager.getActions().hover([]);
65+
}
6666
}
6767
}
6868
}

client/game/BoardCard.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ export default React.forwardRef(function BoardCard(props: GameCardProps, ref: Re
1515

1616
useImperativeHandle(ref, () => cardRef.current);
1717

18+
const canActivate =
19+
!props.state.exhausted &&
20+
props.info.hasActivate &&
21+
canPayPlan(cache, game, player, plan, { type: "activate", card: props.state });
22+
1823
const [{ isDragging }, drag, dragPreview] = useDrag(
1924
() => ({
2025
type: props.info.activateTargets ? "target" : "card",
2126
item: props.state,
2227
collect: (monitor) => ({
2328
isDragging: monitor.isDragging(),
2429
}),
30+
canDrag: () => canActivate
2531
}),
26-
[]
32+
[canActivate]
2733
);
2834

2935
useEffect(() => {
@@ -32,11 +38,6 @@ export default React.forwardRef(function BoardCard(props: GameCardProps, ref: Re
3238
}
3339
});
3440

35-
const canActivate =
36-
!props.state.exhausted &&
37-
props.info.hasActivate &&
38-
canPayPlan(cache, game, player, plan, { type: "activate", card: props.state });
39-
4041
function pointerdown(e: any) {
4142
if (props.state.exhausted || props.info.type != "agent") {
4243
return;

client/game/GameCard.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useDrop } from "react-dnd";
1212
import { CardColors, CardState } from "../../common/card.js";
1313
import { cardHeight, cardWidth, combineColors, isCardPropsEqual } from "../Card.js";
1414
import { CacheContext, CosmeticContext, HighlightContext, PlanContext } from "./Game.js";
15-
import { getCard } from "../../common/gameSlice.js";
15+
import { findCard, getCard } from "../../common/gameSlice.js";
1616
import { useClientSelector } from "../store.js";
1717
import { hex } from "../color.js";
1818
import util from "../../common/util.js";
@@ -58,20 +58,35 @@ export default React.memo(
5858
() => ({
5959
accept: "target",
6060
drop: (state: CardState) => {
61-
setPlan((plan) => [
62-
...plan,
63-
{
64-
type: "play",
65-
card: state,
66-
action: { id: state.id, target: { id: props.state.id } },
67-
},
68-
]);
61+
const found = findCard(game, state);
62+
if (!found) {
63+
return;
64+
}
65+
66+
const info = cache.getCardInfo(game, state);
67+
if (
68+
(found.zone == "deck" &&
69+
info.targets &&
70+
util.filter(cache, game, info.targets).some((c) => c.id == props.state.id)) ||
71+
(found.zone == "board" &&
72+
info.activateTargets &&
73+
util.filter(cache, game, info.activateTargets).some((c) => c.id == props.state.id))
74+
) {
75+
setPlan((plan) => [
76+
...plan,
77+
{
78+
type: found.zone == "deck" ? "play" : "activate",
79+
card: state,
80+
action: { id: state.id, target: { id: props.state.id } },
81+
},
82+
]);
83+
}
6984
},
7085
collect: (monitor) => ({
7186
isOver: monitor.isOver(),
7287
}),
7388
}),
74-
[]
89+
[game, props.state.id]
7590
);
7691

7792
useEffect(() => {

client/game/Plan.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useTimeShadowFilter } from "../time";
77
import { Container } from "@pixi/react";
88
import { useClientSelector } from "../store";
99
import { AnimatedCardProps } from "../AnimatedCard";
10-
import { CardState } from "../../common/card";
10+
import { CardState, CardStateInfo } from "../../common/card";
1111

1212
export default function Plan() {
1313
const { plan, setPlan } = useContext(PlanContext);
@@ -32,6 +32,13 @@ export default function Plan() {
3232
const x = 0;
3333
const y = (targetResolution.height - gameCardHeight) / 2 - cards.length * gameCardHeightDiff;
3434

35+
const listCards: CardStateInfo[] = [];
36+
for (let i = 0; i < cards.length; i++) {
37+
if (i >= plan.length) continue;
38+
const id = plan[i].type == "activate" ? `activate:${cards[i].state.id}-${turn}` : cards[i].state.id;
39+
listCards.push({ info: cards[i].info, state: { ...cards[i].state, id } });
40+
}
41+
3542
return (
3643
<Container filters={[timeShadowFilterRef.current]}>
3744
<CardList
@@ -42,11 +49,7 @@ export default function Plan() {
4249
cardWidth={gameCardWidth}
4350
cardHeight={gameCardHeight}
4451
card={planCard}
45-
cards={cards.flatMap((x, i) => {
46-
if (i >= plan.length) return [];
47-
const id = plan[i].type == "activate" ? `activate:${x.state.id}-${turn}` : x.state.id;
48-
return [{ info: x.info, state: { ...x.state, id } }];
49-
})}
52+
cards={listCards}
5053
hoverScale={gameCardZoom}
5154
/>
5255
</Container>

server/game.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ export async function createGame(players: [Player, Player], onEnd: OnGameEnd) {
236236

237237
for (const action of revealedActions) {
238238
if (action.payload.target) {
239+
if (action.type == "game/addCard") {
240+
const { player } = findCard(state, action.payload.target)!;
241+
revealed[player].add(action.payload.target.id);
242+
}
243+
239244
if (action.type == "game/revealCard" && !revealed[toPlayer].has(action.payload.target.id)) {
240245
const { player, zone, index } = findCard(state, action.payload.target)!;
241246
revealed[toPlayer].add(action.payload.target.id);

0 commit comments

Comments
 (0)