parent
a9a8865d6b
commit
de8fbdb3a2
Before Width: | Height: | Size: 427 B After Width: | Height: | Size: 405 B |
@ -0,0 +1,52 @@
|
|||||||
|
import "../../style/actions/arrow_action.css"
|
||||||
|
import Draggable from "react-draggable"
|
||||||
|
import {RefObject, useRef} from "react"
|
||||||
|
import Xarrow, {useXarrow, Xwrapper} from "react-xarrows"
|
||||||
|
|
||||||
|
export interface ArrowActionProps {
|
||||||
|
originRef: RefObject<HTMLDivElement>
|
||||||
|
onArrowDropped: (arrowHead: DOMRect) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ArrowAction({
|
||||||
|
originRef,
|
||||||
|
onArrowDropped,
|
||||||
|
}: ArrowActionProps) {
|
||||||
|
const arrowHeadRef = useRef<HTMLDivElement>(null)
|
||||||
|
const updateXarrow = useXarrow()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="arrow-action">
|
||||||
|
<div className="arrow-action-pin"/>
|
||||||
|
|
||||||
|
<Xwrapper>
|
||||||
|
<Draggable
|
||||||
|
nodeRef={arrowHeadRef}
|
||||||
|
onDrag={updateXarrow}
|
||||||
|
onStop={() => {
|
||||||
|
const headBounds =
|
||||||
|
arrowHeadRef.current!.getBoundingClientRect()
|
||||||
|
updateXarrow()
|
||||||
|
onArrowDropped(headBounds)
|
||||||
|
}}
|
||||||
|
position={{x: 0, y: 0}}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
}}
|
||||||
|
ref={arrowHeadRef}
|
||||||
|
className="arrow-head-pick"
|
||||||
|
onMouseDown={updateXarrow}/>
|
||||||
|
</Draggable>
|
||||||
|
|
||||||
|
<div className={"arrow-head-xarrow"}>
|
||||||
|
<Xarrow
|
||||||
|
start={originRef}
|
||||||
|
end={arrowHeadRef}
|
||||||
|
startAnchor={"auto"}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Xwrapper>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
import {BallPiece} from "../editor/BallPiece";
|
||||||
|
|
||||||
|
|
||||||
|
export interface BallActionProps {
|
||||||
|
onDrop: (el: HTMLElement) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function BallAction({onDrop}: BallActionProps) {
|
||||||
|
return (
|
||||||
|
<BallPiece onDrop={onDrop} />
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
import RemoveIcon from "../../assets/icon/remove.svg?react"
|
||||||
|
import "../../style/actions/remove_action.css"
|
||||||
|
|
||||||
|
export interface RemoveActionProps {
|
||||||
|
onRemove: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function RemoveAction({ onRemove }: RemoveActionProps) {
|
||||||
|
return (
|
||||||
|
<RemoveIcon
|
||||||
|
className="remove-action"
|
||||||
|
onClick={onRemove}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
|
||||||
|
.arrow-action {
|
||||||
|
height: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-action-pin, .arrow-head-pick {
|
||||||
|
position: absolute;
|
||||||
|
min-width: 10px;
|
||||||
|
min-height: 10px;
|
||||||
|
border-radius: 100px;
|
||||||
|
background-color: red;
|
||||||
|
cursor: grab;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-head-pick {
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-head-xarrow {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-action:active .arrow-head-xarrow {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-action:active .arrow-head-pick {
|
||||||
|
min-height: unset;
|
||||||
|
min-width: unset;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
.remove-action {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.remove-action * {
|
||||||
|
stroke: red;
|
||||||
|
fill: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.remove-action:hover * {
|
||||||
|
fill: #f1dbdb;
|
||||||
|
stroke: #ff331a;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
import { PlayerId } from "./Player"
|
||||||
|
|
||||||
|
export enum MovementActionKind {
|
||||||
|
SCREEN = "SCREEN",
|
||||||
|
DRIBBLE = "DRIBBLE",
|
||||||
|
MOVE = "MOVE",
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Action = {type: MovementActionKind } & MovementAction
|
||||||
|
|
||||||
|
export interface MovementAction {
|
||||||
|
moveFrom: PlayerId
|
||||||
|
moveTo: PlayerId
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
import { Action, MovementActionKind } from "../../tactic/Action"
|
||||||
|
import Xarrow, { Xwrapper } from "react-xarrows"
|
||||||
|
import { xarrowPropsType } from "react-xarrows/lib/types"
|
||||||
|
|
||||||
|
|
||||||
|
export function renderAction(action: Action) {
|
||||||
|
|
||||||
|
const from = action.moveFrom;
|
||||||
|
const to = action.moveTo;
|
||||||
|
|
||||||
|
let arrowStyle: xarrowPropsType = {start: from, end: to, color: "var(--arrows-color)"}
|
||||||
|
|
||||||
|
switch (action.type) {
|
||||||
|
case MovementActionKind.DRIBBLE:
|
||||||
|
arrowStyle.dashness = {
|
||||||
|
animation: true,
|
||||||
|
strokeLen: 5,
|
||||||
|
nonStrokeLen: 5
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case MovementActionKind.SCREEN:
|
||||||
|
arrowStyle.headShape = "circle"
|
||||||
|
arrowStyle.headSize = 2.5
|
||||||
|
break
|
||||||
|
case MovementActionKind.MOVE:
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Xwrapper key={`${action.type}-${from}-${to}`}>
|
||||||
|
<Xarrow {...arrowStyle}/>
|
||||||
|
</Xwrapper>
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in new issue