change to double click and fix some issues
This commit is contained in:
parent
b07dff18ab
commit
5157720499
|
|
@ -9,6 +9,7 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column nowrap;
|
flex-flow: column nowrap;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
transition: 250ms;
|
||||||
|
|
||||||
&[data-cardcolor="black"] {
|
&[data-cardcolor="black"] {
|
||||||
background-color: black;
|
background-color: black;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import {createRef, CSSProperties, MouseEventHandler, TouchEventHandler, useEffect, useState} from "react";
|
import React, {createRef, CSSProperties, MouseEventHandler, TouchEventHandler, useEffect, useState} from "react";
|
||||||
import s from "./SizableCard.module.scss"
|
import s from "./SizableCard.module.scss"
|
||||||
|
|
||||||
export const CardSize = {
|
export const CardSize = {
|
||||||
|
|
@ -20,6 +20,8 @@ export type SizableCardProps = {
|
||||||
style?: CSSProperties,
|
style?: CSSProperties,
|
||||||
onMouseDown?: MouseEventHandler,
|
onMouseDown?: MouseEventHandler,
|
||||||
onMouseUp?: MouseEventHandler,
|
onMouseUp?: MouseEventHandler,
|
||||||
|
onDoubleClick?: MouseEventHandler,
|
||||||
|
doubleClickScale?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function SizableCard({
|
export default function SizableCard({
|
||||||
|
|
@ -33,11 +35,27 @@ export default function SizableCard({
|
||||||
style,
|
style,
|
||||||
onMouseDown,
|
onMouseDown,
|
||||||
onMouseUp,
|
onMouseUp,
|
||||||
|
onDoubleClick,
|
||||||
|
doubleClickScale
|
||||||
}: SizableCardProps) {
|
}: SizableCardProps) {
|
||||||
const [cardScale, setCardScale] = useState(1);
|
const [cardScale, setCardScale] = useState(1);
|
||||||
const [fontScale, setFontScale] = useState(1);
|
const [fontScale, setFontScale] = useState(1);
|
||||||
|
const [previouslyClicked, setPreviouslyClicked] = useState(false);
|
||||||
const cardRef = createRef<HTMLDivElement>();
|
const cardRef = createRef<HTMLDivElement>();
|
||||||
|
|
||||||
|
function internalMouseDown(ev: React.MouseEvent<HTMLDivElement>) {
|
||||||
|
onMouseDown?.(ev)
|
||||||
|
console.log("was clicked")
|
||||||
|
setPreviouslyClicked((prev) => {
|
||||||
|
if (prev) {
|
||||||
|
onDoubleClick?.(ev)
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
setCardScale(CardSize[size]);
|
setCardScale(CardSize[size]);
|
||||||
|
|
@ -48,8 +66,30 @@ export default function SizableCard({
|
||||||
setFontScale(Math.max((-1 / (Math.PI * 120) * (content.replace("{{fill}}", "_____").length - 40) + 1), 0.5) * CardSize[size]);
|
setFontScale(Math.max((-1 / (Math.PI * 120) * (content.replace("{{fill}}", "_____").length - 40) + 1), 0.5) * CardSize[size]);
|
||||||
}, [content, size]);
|
}, [content, size]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function windowClicked (ev: React.MouseEvent<HTMLElement>){
|
||||||
|
if (cardRef.current && !cardRef.current.contains(ev.target)) {
|
||||||
|
console.log("was not clicked")
|
||||||
|
setPreviouslyClicked(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.addEventListener("mousedown", windowClicked);
|
||||||
|
|
||||||
|
return () => document.removeEventListener("mousedown", windowClicked);
|
||||||
|
}, [cardRef]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (previouslyClicked && doubleClickScale) {
|
||||||
|
setCardScale(CardSize[size] + 0.1);
|
||||||
|
setFontScale(Math.max((-1 / (Math.PI * 120) * (content.replace("{{fill}}", "_____").length - 40) + 1), 0.5) * (CardSize[size] + 0.1));
|
||||||
|
} else {
|
||||||
|
setCardScale(CardSize[size]);
|
||||||
|
setFontScale(Math.max((-1 / (Math.PI * 120) * (content.replace("{{fill}}", "_____").length - 40) + 1), 0.5) * CardSize[size]);
|
||||||
|
}
|
||||||
|
}, [previouslyClicked, doubleClickScale]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div onClick={onClick} onMouseDown={onMouseDown} onMouseUp={onMouseUp} onTouchStart={onMouseDown as unknown as TouchEventHandler} onTouchEnd={onMouseUp as unknown as TouchEventHandler} ref={cardRef} className={[s["sizable-card"], className].join(" ")} data-cardcolor={color}
|
<div onClick={onClick} onMouseDown={internalMouseDown} onMouseUp={onMouseUp} onTouchStart={onMouseDown as unknown as TouchEventHandler} onTouchEnd={onMouseUp as unknown as TouchEventHandler} ref={cardRef} className={[s["sizable-card"], className].join(" ")} data-cardcolor={color}
|
||||||
style={{
|
style={{
|
||||||
["--sizable-card-scale" as string]: cardScale,
|
["--sizable-card-scale" as string]: cardScale,
|
||||||
["--sizable-card-font-scale" as string]: fontScale,
|
["--sizable-card-font-scale" as string]: fontScale,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import {useContext, useEffect, useState} from "react";
|
||||||
import {ConnectionScreen} from "../components/ConnectionScreen.tsx";
|
import {ConnectionScreen} from "../components/ConnectionScreen.tsx";
|
||||||
import s from "./ActionScreen.module.scss"
|
import s from "./ActionScreen.module.scss"
|
||||||
import SizableCard from "../components/cards/SizableCard.tsx";
|
import SizableCard from "../components/cards/SizableCard.tsx";
|
||||||
import {PressAndHold} from "../components/PressAndHold.tsx";
|
|
||||||
import {useNavigate} from "react-router";
|
import {useNavigate} from "react-router";
|
||||||
import {createPacket, handlePacket, handlers, Player} from "../sockets.ts";
|
import {createPacket, handlePacket, handlers, Player} from "../sockets.ts";
|
||||||
import useWebSocket, {ReadyState} from "react-use-websocket";
|
import useWebSocket, {ReadyState} from "react-use-websocket";
|
||||||
|
|
@ -33,7 +32,7 @@ export function ActionScreen () {
|
||||||
|
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const { sendMessage, lastMessage, readyState } = useWebSocket(`ws://localhost:8080/live/join-game/${gameContext.channel.current}`, {
|
const { sendMessage, lastMessage, readyState } = useWebSocket(`ws://192.168.0.99:8080/live/join-game/${gameContext.channel.current}`, {
|
||||||
reconnectAttempts: 5,
|
reconnectAttempts: 5,
|
||||||
retryOnError: true,
|
retryOnError: true,
|
||||||
reconnectInterval: (lastAttemptNumber) => lastAttemptNumber * 6000
|
reconnectInterval: (lastAttemptNumber) => lastAttemptNumber * 6000
|
||||||
|
|
@ -111,12 +110,12 @@ export function ActionScreen () {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.screen == "playing-card") {
|
if (data.screen == "playing-card") {
|
||||||
setInstruction("Press and hold a card of your choosing")
|
setInstruction("Double click a card of your choosing")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.screen == "picking-card") {
|
if (data.screen == "picking-card") {
|
||||||
setActionState("picking-card")
|
setActionState("picking-card")
|
||||||
setInstruction("Press and hold the funniest card.")
|
setInstruction("Double click the funniest card.")
|
||||||
setPlayedWhiteCards(new Map(Object.entries(data.cards!)))
|
setPlayedWhiteCards(new Map(Object.entries(data.cards!)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +157,9 @@ export function ActionScreen () {
|
||||||
}
|
}
|
||||||
}, [readyState])
|
}, [readyState])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
gameContext.isVip.current = false
|
gameContext.isVip.current = false
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={updateScreen} className={s["game-container"]}>
|
<div key={updateScreen} className={s["game-container"]}>
|
||||||
|
|
@ -194,31 +195,25 @@ export function ActionScreen () {
|
||||||
{actionState == "playing-card" && (
|
{actionState == "playing-card" && (
|
||||||
<div className={s["cards-list"]}>
|
<div className={s["cards-list"]}>
|
||||||
{gameContext.me.current?.availableCards.map((card) => (
|
{gameContext.me.current?.availableCards.map((card) => (
|
||||||
<PressAndHold key={card} onPressAndHold={() => {
|
<SizableCard doubleClickScale={true} key={card} onDoubleClick={() => {
|
||||||
console.log("Held for 500ms")
|
|
||||||
setActionState("default");
|
setActionState("default");
|
||||||
setInstruction(randomWaitingPrompts[Math.floor(Math.random() * randomWaitingPrompts.length)])
|
setInstruction(randomWaitingPrompts[Math.floor(Math.random() * randomWaitingPrompts.length)])
|
||||||
sendMessage(ser(createPacket("game.action.playCard", {
|
sendMessage(ser(createPacket("game.action.playCard", {
|
||||||
cardValue: card
|
cardValue: card
|
||||||
})))
|
})))
|
||||||
}} holdTime={1500} render={(onMouseDown, onMouseUp) => (
|
}} size={"lg"} content={card} color={"white"} />
|
||||||
<SizableCard onMouseDown={onMouseDown} onMouseUp={onMouseUp} size={"lg"} content={card} color={"white"} />
|
|
||||||
)} />
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{actionState == "picking-card" && (
|
{actionState == "picking-card" && (
|
||||||
<div className={s["cards-list"]}>
|
<div className={s["cards-list"]}>
|
||||||
{[...playedWhiteCards.entries()].map(([player, card]) => (
|
{[...playedWhiteCards.entries()].map(([player, card]) => (
|
||||||
<PressAndHold key={card} onPressAndHold={() => {
|
<SizableCard doubleClickScale={true} key={card} onDoubleClick={() => {
|
||||||
console.log("Held for 500ms")
|
|
||||||
sendMessage(ser(createPacket("game.action.pickCard", {
|
sendMessage(ser(createPacket("game.action.pickCard", {
|
||||||
uuid: player
|
uuid: player
|
||||||
})))
|
})))
|
||||||
}} holdTime={1500} render={(onMouseDown, onMouseUp) => (
|
}} size={"lg"}
|
||||||
<SizableCard onMouseDown={onMouseDown} onMouseUp={onMouseUp} size={"lg"}
|
|
||||||
content={card} color={"white"}/>
|
content={card} color={"white"}/>
|
||||||
)}/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user