From 0ef4bfe45cb96dd67fe81e8d1dbc390b3844e87d Mon Sep 17 00:00:00 2001 From: Pistonight Date: Wed, 17 Jan 2024 20:15:56 -0800 Subject: [PATCH] make client build --- Taskfile.yml | 15 +++++++++++---- compiler-core/Cargo.toml | 1 + compiler-core/src/comp/comp_line.rs | 3 +-- compiler-wasm/build/src/build.rs | 14 ++++++++++---- web-client/src/ui/doc/utils.ts | 4 ++-- web-client/src/ui/map/MapLayerMgr.ts | 10 +++++----- web-client/src/ui/map/MapRoot.tsx | 6 +++++- web-client/src/ui/map/MapState.ts | 16 ++++++++++++++-- web-client/src/ui/toolbar/SwitchMapLayer.tsx | 6 +++++- 9 files changed, 54 insertions(+), 21 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index d7d28cc7..7e6ac503 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,6 +1,11 @@ version: '3' includes: + compiler-base: + taskfile: ./compiler-base + aliases: [base] + dir: ./compiler-base + compiler-core: taskfile: ./compiler-core aliases: [core] @@ -57,10 +62,12 @@ tasks: - task: themes:check check:rs: - deps: [core:grammar] + deps: [base:grammar] cmds: - cargo clippy --package compiler-macros --all-targets -- -D warnings -D clippy::todo - - cargo clippy --package compiler-core --features native,test --all-targets -- -D warnings -D clippy::todo + - cargo clippy --package compiler-base --features native --all-targets -- -D warnings -D clippy::todo + - cargo clippy --package compiler-base --features wasm --all-targets -- -D warnings -D clippy::todo + - cargo clippy --package compiler-core --features native --all-targets -- -D warnings -D clippy::todo - cargo clippy --package compiler-core --features wasm --all-targets -- -D warnings -D clippy::todo - cargo clippy --package compiler-wasm --all-targets -- -D warnings -D clippy::todo - cargo clippy --package web-server --all-targets -- -D warnings -D clippy::todo @@ -79,7 +86,7 @@ tasks: build:server: deps: - - core:grammar + - base:grammar dir: ./web-server cmds: - rustup default stable @@ -95,7 +102,7 @@ tasks: build:wasm: dir: ./compiler-wasm/build deps: - - core:grammar + - base:grammar cmds: - cargo run --bin buildwasm --release diff --git a/compiler-core/Cargo.toml b/compiler-core/Cargo.toml index a46c604e..ad378fc3 100644 --- a/compiler-core/Cargo.toml +++ b/compiler-core/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies.celerb] package = "compiler-base" path = "../compiler-base" +default-features = false [dependencies] derivative = "2.2.0" diff --git a/compiler-core/src/comp/comp_line.rs b/compiler-core/src/comp/comp_line.rs index 3e4d61b2..1f97faef 100644 --- a/compiler-core/src/comp/comp_line.rs +++ b/compiler-core/src/comp/comp_line.rs @@ -4,13 +4,12 @@ use serde_json::Value; use crate::json::RouteBlobRef; use crate::lang::{DocDiagnostic, DocRichText, DocRichTextBlock}; -use crate::macros::derive_wasm; use crate::pack::{Compiler, PackError}; use crate::util::StringMap; use super::{CompError, CompMarker, CompMovement, DocNote}; + #[derive(PartialEq, Default, Serialize, Deserialize, Debug, Clone)] -#[derive_wasm] pub struct CompLine { /// Primary text content of the line pub text: DocRichText, diff --git a/compiler-wasm/build/src/build.rs b/compiler-wasm/build/src/build.rs index 6967521b..21dd7aba 100644 --- a/compiler-wasm/build/src/build.rs +++ b/compiler-wasm/build/src/build.rs @@ -30,10 +30,16 @@ fn main_internal() -> io::Result<()> { println!("copying files"); fs::create_dir_all(OUTPUT_PUBLIC_DIR)?; - fs::copy( - Path::new(TEMP_OUTPUT_DIR).join(BINDING_TS), - Path::new(OUTPUT_LOW_DIR).join(BINDING_TS), - )?; + // there is some problem with wasm-bindgen (or tsify), where it doesn't generate + // the correct bindings in debug mode + if cfg!(debug_assertions) { + println!("not copying generated bindings in debug mode. Please run in release mode if bindings are updated!"); + } else { + fs::copy( + Path::new(TEMP_OUTPUT_DIR).join(BINDING_TS), + Path::new(OUTPUT_LOW_DIR).join(BINDING_TS), + )?; + } fs::copy( Path::new(TEMP_OUTPUT_DIR).join(WORKER_JS), diff --git a/web-client/src/ui/doc/utils.ts b/web-client/src/ui/doc/utils.ts index 06bcd3ce..bdede84c 100644 --- a/web-client/src/ui/doc/utils.ts +++ b/web-client/src/ui/doc/utils.ts @@ -1,6 +1,6 @@ //! Utilities -import { DocColor, DocTag } from "low/celerc"; +import { DocTagColor, DocTag } from "low/celerc"; import { DOMClass, DOMId, Logger } from "low/utils"; export const DocLog = new Logger("doc"); @@ -177,7 +177,7 @@ export const getInjectedStyleTag = (id: string): HTMLStyleElement => { return styleTag as HTMLStyleElement; }; -const createCssStringForColor = (color: DocColor, type: "fg" | "bg") => { +const createCssStringForColor = (color: DocTagColor, type: "fg" | "bg") => { if (typeof color === "string") { return `--rich-text-${type}-light:${color};--rich-text-${type}-dark:${color};`; } diff --git a/web-client/src/ui/map/MapLayerMgr.ts b/web-client/src/ui/map/MapLayerMgr.ts index f4e85b90..252bce6c 100644 --- a/web-client/src/ui/map/MapLayerMgr.ts +++ b/web-client/src/ui/map/MapLayerMgr.ts @@ -3,12 +3,12 @@ import L from "leaflet"; import "leaflet-rastercoords"; import { AppDispatcher, viewActions } from "core/store"; -import { MapLayerAttr, MapTilesetTransform, GameCoord } from "low/celerc"; +import { MapLayer, MapTilesetTransform, GameCoord } from "low/celerc"; import { MapLog, getAttributionHtml } from "./utils"; /// Tile layer wrapper -type MapLayer = { +type MapTileLayer = { /// The tile layer layer: L.TileLayer; /// The start Z value @@ -26,7 +26,7 @@ export class MapLayerMgr { /// Reference to the app store for dispatching actions private dispatcher: AppDispatcher; /// The tileset layers - private layers: MapLayer[] = []; + private layers: MapTileLayer[] = []; /// The active tileset layer private activeLayerIndex = -1; @@ -39,7 +39,7 @@ export class MapLayerMgr { /// This will also set the map to the initial coord public initLayers( map: L.Map, - mapLayers: MapLayerAttr[], + mapLayers: MapLayer[], initialCoord: GameCoord, ) { MapLog.info("initializing map layers"); @@ -69,7 +69,7 @@ export class MapLayerMgr { this.setActiveLayer(map, initialLayer); } - private getActiveLayer(): MapLayer | undefined { + private getActiveLayer(): MapTileLayer | undefined { return this.layers[this.activeLayerIndex]; } diff --git a/web-client/src/ui/map/MapRoot.tsx b/web-client/src/ui/map/MapRoot.tsx index 93deebdd..7d7e395b 100644 --- a/web-client/src/ui/map/MapRoot.tsx +++ b/web-client/src/ui/map/MapRoot.tsx @@ -40,7 +40,11 @@ export const MapRoot: React.FC = () => { return ; } - if (document.project.map.layers.length <= 0) { + const { map } = document.project; + if (!map) { + return This document has no map; + } + if (map.layers.length <= 0) { return This map has no layers; } diff --git a/web-client/src/ui/map/MapState.ts b/web-client/src/ui/map/MapState.ts index a39137fe..c3f45147 100644 --- a/web-client/src/ui/map/MapState.ts +++ b/web-client/src/ui/map/MapState.ts @@ -15,7 +15,7 @@ import { viewActions, viewSelector, } from "core/store"; -import { ExecDoc } from "low/celerc"; +import { ExecDoc, GameCoord, MapLayer } from "low/celerc"; import { Debouncer } from "low/utils"; import { MapLog, roughlyEquals } from "./utils"; @@ -206,7 +206,19 @@ export class MapState { newDoc.project.source !== oldDoc.project.source || newDoc.project.version !== oldDoc.project.version ) { - const { initialCoord, initialZoom, layers } = newDoc.project.map; + const newMap = newDoc.project.map; + let initialCoord: GameCoord; + let initialZoom; + let layers: MapLayer[]; + if (newMap) { + initialCoord = newMap.initialCoord; + initialZoom = newMap.initialZoom; + layers = newMap.layers; + } else { + initialCoord = [0, 0, 0]; + initialZoom = 0; + layers = []; + } this.layerMgr.initLayers(this.map, layers, initialCoord); const [center, _] = this.layerMgr.unproject(initialCoord); // initLayers above already sets the correct layer diff --git a/web-client/src/ui/toolbar/SwitchMapLayer.tsx b/web-client/src/ui/toolbar/SwitchMapLayer.tsx index d8a1fa97..d2de3b69 100644 --- a/web-client/src/ui/toolbar/SwitchMapLayer.tsx +++ b/web-client/src/ui/toolbar/SwitchMapLayer.tsx @@ -62,7 +62,11 @@ const useMapLayerNames = () => { if (!document) { return []; } - return document.project.map.layers.map( + const map = document.project.map; + if (!map) { + return []; + } + return map.layers.map( (layer) => layer.name || "(Unnamed layer)", ); };