'use client' import React, { SyntheticEvent } from "react"; import styles from "@/styles/dev-tools.module.css" import { Container, Select, Stack, Chip, MenuItem, InputLabel, Snackbar, IconButton, SnackbarCloseReason, Typography } from "@mui/material" import { RichTreeView } from '@mui/x-tree-view/RichTreeView'; import CloseIcon from '@mui/icons-material/Close'; import Draggable from 'react-draggable'; type EditorMode = "insert" | "update"; interface DBObject { record_num: number data_id: string; change_timestamp: string; } interface Unit extends DBObject { } interface Card extends DBObject { } interface EditorContextType { editorMode: "insert" | "update"; currentRecordNum: number | null; currentDataId: string | null; cards: Card[] | null; units: Unit[] | null; error: string | null, changeEditorMode?: (m: string) => void; changeCurrentRecordNum?: (n: number) => void; changeCurrentDataId?: (n: string) => void; changeError?: (e: string) => void; } const EditorContext = React.createContext({ currentRecordNum: null, currentDataId: null, editorMode: "insert", cards: null, units: null, error: null, }) function useEditor() { const ctx = React.useContext(EditorContext); if(!ctx){ throw new Error("Error: use Editor must be used within an EditorContext") } return ctx; } const unitTypes: string[] = ["minion", "enemy", "hero", "ally"]; const buildingTypes: string[] = ["enemy", "minion", "terrain", "support"]; export default function Page(){ const [currentRecordNum, setCurrentRecordNum] = React.useState(0); const [currentDataId, setCurrentDataId] = React.useState(""); const [editorMode, setEditorMode] = React.useState("insert"); const [cards, setCards] = React.useState(null); const [units, setUnits] = React.useState(null); const [error, setError] = React.useState(null); const [open, setOpen] = React.useState(false); const changeCurrentRecordNum = (n: number) => setCurrentRecordNum(n) const changeCurrentDataId = (id: string) => setCurrentDataId(id) const changeEditorMode = (m: string) =>{ if(m !== "insert" && m !== "update") return setEditorMode(m) } const changeError = (e: string) => setError(e); // get all of the cards, or units React.useEffect(() => { const getCards = async () => { try{ // fetch our db }catch (error) { } } const getUnits = async () => { try{ }catch (error) { } } getCards(); getUnits(); }, []) const handleClose = ( event: React.SyntheticEvent | Event, reason?: SnackbarCloseReason, ) => { if (reason === 'clickaway') { return; } setOpen(false); }; const action = ( {error} ); return (
{error && }
) } function DynamicCard() { // to add a new kind of data type "map", "string", "bool", etc. they add a prop for it. return ( <> ) } interface ThemeSelection { value: string; label: string; } const debugCard = [ { id: "terrain_forest", label: "Forest", children: [ { id: "terrain_haunted_forest", label: "Haunted Forest", children: [ { id: 'terrain_undead_candy_forest', label: "Undead Candy Forest" } ] } ] }, { id: "support_blacksmith", label: "Forest", children: [ { id: "support_terrain_haunted_forest", label: "Haunted Forest", children: [ { id: 'SUppror_terrain_undead_candy_forest', label: "Undead Candy Forest" } ] } ] }, { id: "enemy_graveyard", label: "Forest", children: [ { id: "enemy_terrain_haunted_forest", label: "Haunted Forest", children: [ { id: 'enemy_terrain_undead_candy_forest', label: "Undead Candy Forest" } ] } ] } ] function LeftMenu(){ const [themes, setThemes] = React.useState([]); // get from the database const [menuMode, setMenuMode] = React.useState<"unit" | "card">("card"); const { currentRecordNum, } = useEditor(); const handleSelectAsset = (e: React.MouseEvent) => { console.log("Got e:", e) } return ( Asset Type Theme Current {menuMode}s created ) } function Editor(){ const { editorMode } = useEditor(); const canvasWrapperRef = React.useRef(null); const canvasRef = React.useRef(null); const onMouseUp = (e: React.MouseEvent) => { console.log("event for mouse up", e) } const onMouseDown = (e: React.MouseEvent) => { console.log("event for mouse down", e) } const onDragOver = (e: React.DragEvent) => { e.preventDefault() //console.log("event for drag over:", e) } const onDrop = (e: React.DragEvent) => { e.preventDefault(); const raw = e.dataTransfer.getData("text/plain"); console.log("DROP canvas raw:", raw); // create a box? } return ( {editorMode === "insert" ? : null}
{ e.preventDefault(); e.dataTransfer.dropEffect = "copy"; }} onDrop={(e: React.DragEvent) => { e.preventDefault(); const raw = e.dataTransfer.getData("text/plain"); console.log("DROP wrapper raw:", raw); }} style={{ height: "100%", width: "100%", position: "relative" }} >
) } function CreateNewAsset({ type }: { type: string }) { return (
{type === "building" ? buildingTypes.map((buildingType, i) => { const label = buildingType[0].toUpperCase() + buildingType.slice(1); return (
{ console.log("DRAG START", buildingType); const payload = { kind: "building", type: buildingType, label, w: 160, h: 90 }; e.dataTransfer.setData("text/plain", JSON.stringify(payload)); e.dataTransfer.effectAllowed = "copy"; }} style={{ display: "inline-flex" }} >
); }) : unitTypes.map((unitType, i) => { const label = unitType[0].toUpperCase() + unitType.slice(1); return (
{ const payload = { kind: "unit", type: unitType, label, w: 140, h: 80 }; e.dataTransfer.setData("text/plain", JSON.stringify(payload)); e.dataTransfer.effectAllowed = "copy"; }} style={{ display: "inline-flex" }} >
); })}
); }