diff --git a/service/src/main.rs b/service/src/main.rs index 02e886d..9799f30 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -112,9 +112,6 @@ async fn main() -> std::io::Result<()> { let host = env::var("SERVICE_HOST").unwrap_or("localhost".to_string()); let port = env::var("SERVICE_PORT").unwrap_or("5000".to_string()); - crate::storage::upload_file("test.txt", b"Test").await.unwrap(); - crate::storage::delete_file("test.txt").await.unwrap(); - let server = match HttpServer::new(move || { let cors = Cors::default() .allow_any_origin() diff --git a/service/src/storage/mod.rs b/service/src/storage/mod.rs index 83763bf..21e5b5d 100644 --- a/service/src/storage/mod.rs +++ b/service/src/storage/mod.rs @@ -4,7 +4,7 @@ use s3::{Region, creds::Credentials, Bucket, BucketConfiguration, request::Respo use siren::ServiceError; use crate::diesel_migrations::MigrationHarness; use lazy_static::lazy_static; -use log::{error, info, warn}; +use log::{error, info}; use r2d2; use std::env; @@ -35,7 +35,7 @@ lazy_static! { RedisClient::open(url).expect("Failed to create redis client") }; static ref BUCKET: Bucket = { - let url = env::var("MINIO_URL").unwrap_or("localhost".to_string()); + let url = env::var("MINIO_HOST").unwrap_or("localhost".to_string()); let port = env::var("MINIO_PORT").unwrap_or("9000".to_string()); let user = env::var("MINIO_ROOT_USER").expect("MINIO_ROOT_USER is not set"); let password = env::var("MINIO_ROOT_PASSWORD").expect("MINIO_ROOT_PASSWORD is not set"); diff --git a/ui/src/components/TileGrid/TileControls.tsx b/ui/src/components/TileGrid/TileControls.tsx index 516b572..49104bd 100644 --- a/ui/src/components/TileGrid/TileControls.tsx +++ b/ui/src/components/TileGrid/TileControls.tsx @@ -131,7 +131,7 @@ export default function TileControls({ {colors.map((color, index) => ( - + (EditTool.SQUARE); const [colors, setColors] = useState(defaultColors); const [selectedColor, setSelectedColor] = useState(0); + const [edits, setEdits] = useState([]); useEffect(() => { if (window) { @@ -31,54 +38,105 @@ export default function TileGrid() { }, { passive: false } ); + // Disable right click context menu + window.addEventListener( + 'contextmenu', + (event) => { + event.preventDefault(); + }, + { passive: false } + ); } }, []); - const draw = useCallback((g: PixiGraphics) => { - g.clear(); - // Draw dot in the corner of each tile - for (let x = 0; x < gridSize.width; x += 32 * scale) { - for (let y = 0; y < gridSize.height; y += 32 * scale) { - g.beginFill(0xffffff, 0.5); - g.drawCircle(x, y, 1); - g.endFill(); + const drawGrid = useCallback( + (g: PixiGraphics) => { + g.clear(); + // Draw dot in the corner of each tile + for (let x = 0; x < gridSize.width; x += 32 * zoom) { + for (let y = 0; y < gridSize.height; y += 32 * zoom) { + g.beginFill(0xffffff, 0.5); + g.drawCircle(x, y, 1); + g.endFill(); + } } - } - }, []); + }, + [gridSize, zoom] + ); + + const drawEdits = useCallback( + (g: PixiGraphics) => { + g.clear(); + edits.forEach((edit) => { + g.beginFill(parseInt(edit.color.replace('#', ''), 16)); + g.drawRect(edit.x * 32 * zoom, edit.y * 32 * zoom, 32 * zoom, 32 * zoom); + g.endFill(); + }); + }, + [edits] + ); function clickEvent(e: MouseEvent) { - if (tool === Tool.HAND) { - setMouseDown(true); - setLastPosition({ x: e.clientX, y: e.clientY }); + setMouseDown(true); + setLastPosition({ x: e.clientX, y: e.clientY }); + if (tool == Tool.ZOOM) { + handleZoom(e.button === 0 ? -100 : 100); } } function moveEvent(e: MouseEvent) { if (mouseDown) { - let dx = position.x + e.clientX - lastPosition.x; - let dy = position.y + e.clientY - lastPosition.y; - // Prevent coordinates from going out of bounds - dx = Math.min(dx, 0); - dx = Math.max(dx, -gridSize.width * scale + width); - dy = Math.min(dy, 0); - dy = Math.max(dy, -gridSize.height * scale + height); - setPosition({ x: dx, y: dy }); - setLastPosition({ x: e.clientX, y: e.clientY }); + if (tool == Tool.HAND) { + let dx = position.x + e.clientX - lastPosition.x; + let dy = position.y + e.clientY - lastPosition.y; + // Prevent coordinates from going out of bounds + dx = Math.min(dx, 0); + dx = Math.max(dx, -gridSize.width * zoom + width); + dy = Math.min(dy, 0); + dy = Math.max(dy, -gridSize.height * zoom + height); + setPosition({ x: dx, y: dy }); + setLastPosition({ x: e.clientX, y: e.clientY }); + } else if (tool === Tool.EDIT) { + if (editTool === EditTool.SQUARE) { + // Calculate tile coordinates + const x = Math.floor((e.clientX - position.x) / (32 * zoom)); + const y = Math.floor((e.clientY - position.y - 64) / (32 * zoom)); + // Check if tile is already edited, and remove it + const index = edits.findIndex((edit) => edit.x === x && edit.y === y); + if (index !== -1) { + setEdits([...edits.slice(0, index), ...edits.slice(index + 1)]); + } + // Add new edit if left mouse button is pressed + if (e.buttons === 1) { + setEdits([...edits, { x, y, color: colors[selectedColor] }]); + } + } else if (editTool === EditTool.CIRCLE) { + // handle circle + } + } else if (tool === Tool.TOKEN) { + // handle token + } } } function zoomEvent(e: WheelEvent) { - const delta = e.deltaY; + handleZoom(e.deltaY); + } + + function handleZoom(delta: number) { + let newZoom = zoom; if (delta > 0) { - setZoom(zoom / 1.1); + newZoom = zoom / 1.1; } else { - setZoom(zoom * 1.1); + newZoom = zoom * 1.1; } - setScale(scale * zoom); + newZoom = Math.min(newZoom, 3); + newZoom = Math.max(newZoom, 0.6); + setZoom(newZoom); } return ( - + moveEvent(e)} onWheel={(e) => zoomEvent(e)} > - - + + - + ); }