refactoring for wasm

This commit is contained in:
Michael Zhang 2023-12-31 21:38:14 -06:00
parent a59a320c85
commit edcb715de8
29 changed files with 18126 additions and 320 deletions

View file

@ -3,7 +3,5 @@
"singleQuote": false,
"trailingComma": "all",
"tabWidth": 2,
"printWidth": 80,
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
"printWidth": 80
}

184
Cargo.lock generated
View file

@ -120,12 +120,12 @@ dependencies = [
[[package]]
name = "anstyle-wincon"
version = "3.0.1"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
dependencies = [
"anstyle",
"windows-sys 0.48.0",
"windows-sys 0.52.0",
]
[[package]]
@ -169,20 +169,6 @@ dependencies = [
"syn 2.0.43",
]
[[package]]
name = "async-tungstenite"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e6acf7e4a267eecbb127ed696bb2d50572c22ba7f586a646321e1798d8336a1"
dependencies = [
"futures-io",
"futures-util",
"log",
"pin-project-lite",
"tokio",
"tungstenite",
]
[[package]]
name = "asynchronous-codec"
version = "0.6.2"
@ -233,44 +219,12 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "axum"
version = "0.6.20"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf"
checksum = "d09dbe0e490df5da9d69b36dca48a76635288a82f92eca90024883a56202026d"
dependencies = [
"async-trait",
"axum-core 0.3.4",
"bitflags 1.3.2",
"bytes",
"futures-util",
"http 0.2.11",
"http-body 0.4.6",
"hyper 0.14.28",
"itoa",
"matchit",
"memchr",
"mime",
"percent-encoding",
"pin-project-lite",
"rustversion",
"serde",
"serde_json",
"serde_path_to_error",
"serde_urlencoded",
"sync_wrapper",
"tokio",
"tower",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "202651474fe73c62d9e0a56c6133f7a0ff1dc1c8cf7a5b03381af2a26553ac9d"
dependencies = [
"async-trait",
"axum-core 0.4.1",
"axum-core",
"bytes",
"futures-util",
"http 1.0.0",
@ -294,30 +248,14 @@ dependencies = [
"tower",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
name = "axum-core"
version = "0.3.4"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c"
dependencies = [
"async-trait",
"bytes",
"futures-util",
"http 0.2.11",
"http-body 0.4.6",
"mime",
"rustversion",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum-core"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77cb22c689c44d4c07b0ab44ebc25d69d8ae601a2f28fb8d672d344178fa17aa"
checksum = "e87c8503f93e6d144ee5690907ba22db7ba79ab001a932ab99034f0fe836b3df"
dependencies = [
"async-trait",
"bytes",
@ -331,6 +269,7 @@ dependencies = [
"sync_wrapper",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
@ -338,20 +277,13 @@ name = "backend"
version = "0.1.0"
dependencies = [
"anyhow",
"axum 0.7.2",
"chrono",
"clap 4.4.11",
"colourado",
"names",
"petgraph 0.6.4",
"axum",
"clap 4.4.12",
"common",
"prisma-client-rust",
"rand 0.8.5",
"rand_chacha 0.3.1",
"rspc",
"serde",
"serde_json",
"tokio",
"triangle",
]
[[package]]
@ -397,12 +329,6 @@ version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]]
name = "base64"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5"
[[package]]
name = "base64"
version = "0.21.5"
@ -688,9 +614,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.4.11"
version = "4.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2"
checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d"
dependencies = [
"clap_builder",
"clap_derive 4.4.7",
@ -698,9 +624,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.4.11"
version = "4.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb"
checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9"
dependencies = [
"anstream",
"anstyle",
@ -804,6 +730,24 @@ dependencies = [
"unreachable",
]
[[package]]
name = "common"
version = "0.1.0"
dependencies = [
"anyhow",
"chrono",
"colourado",
"getrandom 0.2.11",
"names",
"petgraph 0.6.4",
"prisma-client-rust",
"rand 0.8.5",
"rand_chacha 0.3.1",
"serde",
"serde_json",
"triangle",
]
[[package]]
name = "connection-string"
version = "0.1.14"
@ -841,17 +785,6 @@ dependencies = [
"unicode-segmentation",
]
[[package]]
name = "cookie"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb"
dependencies = [
"percent-encoding",
"time",
"version_check",
]
[[package]]
name = "core-foundation"
version = "0.9.4"
@ -1662,8 +1595,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
"wasm-bindgen",
]
[[package]]
@ -1892,25 +1827,6 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "httpz"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6769d2cb10425c442c41a787d1a3719744770a188cfa7885cd4d8126fa13f37a"
dependencies = [
"async-tungstenite",
"axum 0.6.20",
"base64 0.20.0",
"cookie",
"form_urlencoded",
"futures",
"http 0.2.11",
"hyper 0.14.28",
"sha1",
"thiserror",
"tokio",
]
[[package]]
name = "hyper"
version = "0.14.28"
@ -4154,7 +4070,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c68477fb8c11280503aeab140c41b7a0eed57156a73185062ffb4782c18a918f"
dependencies = [
"futures",
"httpz",
"serde",
"serde_json",
"specta",
@ -5398,25 +5313,6 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "tungstenite"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30ee6ab729cd4cf0fd55218530c4522ed30b7b6081752839b68fcec8d0960788"
dependencies = [
"base64 0.13.1",
"byteorder",
"bytes",
"http 0.2.11",
"httparse",
"log",
"rand 0.8.5",
"sha1",
"thiserror",
"url",
"utf-8",
]
[[package]]
name = "twox-hash"
version = "1.6.3"
@ -5541,12 +5437,6 @@ dependencies = [
"user-facing-error-macros",
]
[[package]]
name = "utf-8"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "utf8parse"
version = "0.2.1"

View file

@ -1,3 +1,3 @@
workspace.members = ["backend", "prisma-cli", "triangle", "triangle-sys"]
workspace.members = ["backend", "common", "prisma-cli", "triangle", "triangle-sys"]
workspace.resolver = "2"
workspace.default-members = ["backend"]

View file

@ -3,4 +3,4 @@
## TODO Items
- [ ] Fog of war
- [ ]
- [ ]

View file

@ -4,21 +4,14 @@ version = "0.1.0"
edition = "2021"
[dependencies]
triangle = { path = "../triangle" }
common = { path = "../common", features = ["worldgen"] }
anyhow = "1.0.76"
axum = { version = "0.7.2", features = ["http2"] }
chrono = "0.4.31"
clap = { version = "4.4.11", features = ["derive"] }
serde = { version = "1.0.193", features = ["derive"] }
tokio = { version = "1.35.1", features = ["full"] }
serde_json = "1.0.108"
petgraph = "0.6.4"
names = "0.14.0"
rand = "0.8.5"
rspc = { version = "0.1.3", features = ["axum"] }
rand_chacha = "0.3.1"
colourado = "0.2.0"
tokio = { version = "1.35.1", features = ["full"] }
[dependencies.prisma-client-rust]
git = "https://github.com/Brendonovich/prisma-client-rust"

View file

@ -1,23 +1,18 @@
#[macro_use]
extern crate serde_json;
mod generate;
#[allow(unused_imports, dead_code, clippy::all)]
pub mod prisma;
mod routes;
pub mod state;
mod utils;
pub use common::prisma;
use std::sync::Arc;
use anyhow::Result;
use axum::{routing::get, Router};
use clap::{Parser, Subcommand};
use prisma::PrismaClient;
use common::{generate::generate_initial_game_state, prisma::PrismaClient};
use routes::{empire_list, universe_list, universe_map};
use crate::generate::generate_initial_game_state;
use crate::routes::{empire_list, universe_list, universe_map};
#[derive(Debug, Parser)]
struct Opt {
@ -33,7 +28,7 @@ enum Command {
#[derive(Clone)]
struct AppState {
prisma: Arc<PrismaClient>,
pub prisma: Arc<PrismaClient>,
}
#[tokio::main]

View file

@ -5,11 +5,9 @@ use axum::{
use prisma_client_rust::Direction;
use serde_json::Value;
use crate::{
prisma::{empire, planet, star_system, star_system_edges},
state::UniverseId,
AppState,
};
use common::prisma::{empire, planet, star_system, star_system_edges};
use crate::AppState;
pub async fn universe_list(state: State<AppState>) -> Json<Value> {
let universes = state
@ -51,7 +49,7 @@ pub async fn universe_map(
.star_system()
.find_many(vec![star_system::universe_id::equals(universe_id)])
.order_by(star_system::index::order(Direction::Asc))
.select(star_system::select!({ index coord_x coord_y owned_by_empire_id }))
.select(star_system::select!({ index coord_x coord_y owned_by_empire_id planets }))
.exec()
.await
.unwrap();

34
common/Cargo.toml Normal file
View file

@ -0,0 +1,34 @@
[package]
name = "common"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[features]
default = []
worldgen = ["db", "dep:triangle"]
db = ["dep:prisma-client-rust"]
[dependencies]
triangle = { path = "../triangle", optional = true }
anyhow = "1.0.76"
chrono = "0.4.31"
colourado = "0.2.0"
names = "0.14.0"
petgraph = "0.6.4"
rand = "0.8.5"
rand_chacha = "0.3.1"
# rspc = { version = "0.1.3", features = ["axum"] }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
# tokio = { version = "1.35.1", features = ["full"] }
getrandom = { version = "0.2.11", features = ["js"] }
[dependencies.prisma-client-rust]
git = "https://github.com/Brendonovich/prisma-client-rust"
tag = "0.6.10"
features = ["rspc"]
optional = true

View file

@ -31,7 +31,7 @@ pub fn generate_map() -> Result<Map> {
TrianglulateOpts::builder()
.point_list(point_list)
.voronoi(true)
.maximum_triangle_area(6_000.0)
.maximum_triangle_area(7_500.0)
.build()?,
)?
};

View file

@ -11,7 +11,7 @@ use rand::{seq::SliceRandom, thread_rng, RngCore, SeedableRng};
use rand_chacha::ChaCha12Rng;
use crate::{
prisma::{planet, star_system, universe, PrismaClient},
prisma::PrismaClient,
state::{
EmpireCoreState, EmpireId, GameCoreState, PlanetCoreState, PlanetId,
StarSystemId, UniverseId,

11
common/src/lib.rs Normal file
View file

@ -0,0 +1,11 @@
#[macro_use]
extern crate serde_json;
#[cfg(feature = "worldgen")]
pub mod generate;
#[allow(unused_imports, dead_code, clippy::all)]
#[cfg(feature = "db")]
pub mod prisma;
pub mod state;
pub mod utils;

17776
common/src/prisma.rs Normal file

File diff suppressed because one or more lines are too long

View file

@ -4,9 +4,11 @@ use anyhow::Result;
use chrono::{DateTime, Utc};
use petgraph::graphmap::UnGraphMap;
use crate::{
prisma::{empire, planet, star_system, star_system_edges, PrismaClient},
utils::format_color,
use crate::utils::format_color;
#[cfg(feature = "db")]
use crate::prisma::{
empire, planet, star_system, star_system_edges, PrismaClient,
};
use super::{EmpireCoreState, EmpireId, StarSystemCoreState, StarSystemId};
@ -29,6 +31,7 @@ pub struct GameDerivedState<'a> {
}
impl GameCoreState {
#[cfg(feature = "db")]
pub async fn save_to_database(&self, client: &PrismaClient) -> Result<()> {
// Save star systems to database
let mut owned_systems = HashMap::new();

View file

@ -2,17 +2,17 @@ module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
'react-refresh/only-export-components': [
'warn',
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
},
}
};

View file

@ -26,6 +26,7 @@
"leva": "^0.9.35",
"normalize.css": "^8.0.1",
"react": "^18.2.0",
"react-beautiful-dnd": "^13.1.1",
"react-dom": "^18.2.0",
"react-draggable": "^4.4.6",
"react-query": "^3.39.3",
@ -35,6 +36,7 @@
},
"devDependencies": {
"@types/react": "^18.2.43",
"@types/react-beautiful-dnd": "^13.1.8",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
@ -44,6 +46,8 @@
"eslint-plugin-react-refresh": "^0.4.5",
"sass": "^1.69.6",
"typescript": "^5.2.2",
"vite": "^5.0.8"
"vite": "^5.0.8",
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.3.0"
}
}

View file

@ -44,6 +44,9 @@ dependencies:
react:
specifier: ^18.2.0
version: 18.2.0
react-beautiful-dnd:
specifier: ^13.1.1
version: 13.1.1(react-dom@18.2.0)(react@18.2.0)
react-dom:
specifier: ^18.2.0
version: 18.2.0(react@18.2.0)
@ -67,6 +70,9 @@ devDependencies:
'@types/react':
specifier: ^18.2.43
version: 18.2.46
'@types/react-beautiful-dnd':
specifier: ^13.1.8
version: 13.1.8
'@types/react-dom':
specifier: ^18.2.17
version: 18.2.18
@ -97,6 +103,12 @@ devDependencies:
vite:
specifier: ^5.0.8
version: 5.0.10(sass@1.69.6)
vite-plugin-top-level-await:
specifier: ^1.4.1
version: 1.4.1(vite@5.0.10)
vite-plugin-wasm:
specifier: ^3.3.0
version: 3.3.0(vite@5.0.10)
packages:
@ -1047,6 +1059,16 @@ packages:
engines: {node: '>=14.0.0'}
dev: false
/@rollup/plugin-virtual@3.0.2:
resolution: {integrity: sha512-10monEYsBp3scM4/ND4LNH5Rxvh3e/cVeL3jWTgZ2SrQ+BmUoQcopVQvnaMcOnykb1VkxUFuDAN+0FnpTFRy2A==}
engines: {node: '>=14.0.0'}
peerDependencies:
rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0
peerDependenciesMeta:
rollup:
optional: true
dev: true
/@rollup/rollup-android-arm-eabi@4.9.1:
resolution: {integrity: sha512-6vMdBZqtq1dVQ4CWdhFwhKZL6E4L1dV6jUjuBvsavvNJSppzi6dLBbuV+3+IyUREaj9ZFvQefnQm28v4OCXlig==}
cpu: [arm]
@ -1286,6 +1308,13 @@ packages:
resolution: {integrity: sha512-4MMUjMQb4yA5fJ4osXx+QxGHt0/ZSy4spT6jL1HM7Tn8OJEC35siqdnpOo+HxPhYjqEFumKfGVF9hJfdyKBIBA==}
dev: false
/@types/hoist-non-react-statics@3.3.5:
resolution: {integrity: sha512-SbcrWzkKBw2cdwRTwQAswfpB9g9LJWfjtUeW/jvNwbhC8cpmmNYVePa+ncbUe0rGTQ7G3Ff6mYUN2VMfLVr+Sg==}
dependencies:
'@types/react': 18.2.46
hoist-non-react-statics: 3.3.2
dev: false
/@types/json-schema@7.0.15:
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
dev: true
@ -1297,6 +1326,12 @@ packages:
/@types/prop-types@15.7.11:
resolution: {integrity: sha512-ga8y9v9uyeiLdpKddhxYQkxNDrfvuPrlFb0N1qnZZByvcElJaXthF1UhvCh9TLWJBEHeNtdnbysW7Y6Uq8CVng==}
/@types/react-beautiful-dnd@13.1.8:
resolution: {integrity: sha512-E3TyFsro9pQuK4r8S/OL6G99eq7p8v29sX0PM7oT8Z+PJfZvSQTx4zTQbUJ+QZXioAF0e7TGBEcA1XhYhCweyQ==}
dependencies:
'@types/react': 18.2.46
dev: true
/@types/react-dom@18.2.18:
resolution: {integrity: sha512-TJxDm6OfAX2KJWJdMEVTwWke5Sc/E/RlnPGvGfS0W7+6ocy2xhDVQVh/KvC2Uf7kACs+gDytdusDSdWfWkaNzw==}
dependencies:
@ -1314,6 +1349,15 @@ packages:
'@types/react': 18.2.46
dev: false
/@types/react-redux@7.1.33:
resolution: {integrity: sha512-NF8m5AjWCkert+fosDsN3hAlHzpjSiXlVy9EgQEmLoBhaNXbmyeGs/aj5dQzKuF+/q+S7JQagorGDW8pJ28Hmg==}
dependencies:
'@types/hoist-non-react-statics': 3.3.5
'@types/react': 18.2.46
hoist-non-react-statics: 3.3.2
redux: 4.2.1
dev: false
/@types/react@18.2.46:
resolution: {integrity: sha512-nNCvVBcZlvX4NU1nRRNV/mFl1nNRuTuslAJglQsq+8ldXe5Xv0Wd2f7WTE3jOxhLH2BFfiZGC6GCp+kHQbgG+w==}
dependencies:
@ -1752,6 +1796,12 @@ packages:
shebang-command: 2.0.0
which: 2.0.2
/css-box-model@1.2.1:
resolution: {integrity: sha512-a7Vr4Q/kd/aw96bnJG332W9V9LkJO69JRcaCYDUqjp6/z0w6VcZjgAcTbgFxEPfBgdnAwlh3iwu+hLopa+flJw==}
dependencies:
tiny-invariant: 1.3.1
dev: false
/csstype@3.1.3:
resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==}
@ -2142,6 +2192,12 @@ packages:
tslib: 2.6.2
dev: false
/hoist-non-react-statics@3.3.2:
resolution: {integrity: sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==}
dependencies:
react-is: 16.13.1
dev: false
/ieee754@1.2.1:
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
dev: false
@ -2381,6 +2437,10 @@ packages:
remove-accents: 0.4.2
dev: false
/memoize-one@5.2.1:
resolution: {integrity: sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==}
dev: false
/merge-value@1.0.0:
resolution: {integrity: sha512-fJMmvat4NeKz63Uv9iHWcPDjCWcCkoiRoajRTEO8hlhUC6rwaHg0QCF9hBOTjZmm4JuglPckPSTtcuJL5kp0TQ==}
engines: {node: '>=0.10.0'}
@ -2625,6 +2685,29 @@ packages:
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
dev: true
/raf-schd@4.0.3:
resolution: {integrity: sha512-tQkJl2GRWh83ui2DiPTJz9wEiMN20syf+5oKfB03yYP7ioZcJwsIK8FjrtLwH1m7C7e+Tt2yYBlrOpdT+dyeIQ==}
dev: false
/react-beautiful-dnd@13.1.1(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-0Lvs4tq2VcrEjEgDXHjT98r+63drkKEgqyxdA7qD3mvKwga6a5SscbdLPO2IExotU1jW8L0Ksdl0Cj2AF67nPQ==}
peerDependencies:
react: ^16.8.5 || ^17.0.0 || ^18.0.0
react-dom: ^16.8.5 || ^17.0.0 || ^18.0.0
dependencies:
'@babel/runtime': 7.23.7
css-box-model: 1.2.1
memoize-one: 5.2.1
raf-schd: 4.0.3
react: 18.2.0
react-dom: 18.2.0(react@18.2.0)
react-redux: 7.2.9(react-dom@18.2.0)(react@18.2.0)
redux: 4.2.1
use-memo-one: 1.1.3(react@18.2.0)
transitivePeerDependencies:
- react-native
dev: false
/react-colorful@5.6.1(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-1exovf0uGTGyq5mXQT0zgQ80uvj2PCwvF8zY1RN9/vbJVSjSo3fsB/4L3ObbF7u70NduSiK4xu4Y6q1MHoUGEw==}
peerDependencies:
@ -2696,6 +2779,10 @@ packages:
resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==}
dev: false
/react-is@17.0.2:
resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==}
dev: false
/react-merge-refs@1.1.0:
resolution: {integrity: sha512-alTKsjEL0dKH/ru1Iyn7vliS2QRcBp9zZPGoWxUOvRGWPUYgjo+V01is7p04It6KhgrzhJGnIj9GgX8W4bZoCQ==}
dev: false
@ -2744,6 +2831,28 @@ packages:
scheduler: 0.21.0
dev: false
/react-redux@7.2.9(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-Gx4L3uM182jEEayZfRbI/G11ZpYdNAnBs70lFVMNdHJI76XYtR+7m0MN+eAs7UHBPhWXcnFPaS+9owSCJQHNpQ==}
peerDependencies:
react: ^16.8.3 || ^17 || ^18
react-dom: '*'
react-native: '*'
peerDependenciesMeta:
react-dom:
optional: true
react-native:
optional: true
dependencies:
'@babel/runtime': 7.23.7
'@types/react-redux': 7.1.33
hoist-non-react-statics: 3.3.2
loose-envify: 1.4.0
prop-types: 15.8.1
react: 18.2.0
react-dom: 18.2.0(react@18.2.0)
react-is: 17.0.2
dev: false
/react-redux@9.0.4(@types/react@18.2.46)(react@18.2.0)(redux@5.0.1):
resolution: {integrity: sha512-9J1xh8sWO0vYq2sCxK2My/QO7MzUMRi3rpiILP/+tDr8krBHixC6JMM17fMK88+Oh3e4Ae6/sHIhNBgkUivwFA==}
peerDependencies:
@ -2836,6 +2945,12 @@ packages:
redux: 5.0.1
dev: false
/redux@4.2.1:
resolution: {integrity: sha512-LAUYz4lc+Do8/g7aeRa8JkyDErK6ekstQaqWQrNRW//MY1TvCEpMtpTWvlQ+FPbWCx+Xixu/6SHt5N0HR+SB4w==}
dependencies:
'@babel/runtime': 7.23.7
dev: false
/redux@5.0.1:
resolution: {integrity: sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w==}
dev: false
@ -3051,6 +3166,10 @@ packages:
resolution: {integrity: sha512-DLU8lc0zNIPkM7rH5/e1Ks1Z8tWCGRq6g8mPowdDJpw1CFBJMU7UoJjC6PefXW7z//SSl0b2+GCw14LB+uDhng==}
dev: false
/tiny-invariant@1.3.1:
resolution: {integrity: sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw==}
dev: false
/to-regex-range@5.0.1:
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
engines: {node: '>=8.0'}
@ -3138,6 +3257,14 @@ packages:
punycode: 2.3.1
dev: true
/use-memo-one@1.1.3(react@18.2.0):
resolution: {integrity: sha512-g66/K7ZQGYrI6dy8GLpVcMsBp4s17xNkYJVSMvTEevGy3nDxHOfE6z8BVE22+5G5x7t3+bhzrlTDB7ObrEE0cQ==}
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0
dependencies:
react: 18.2.0
dev: false
/use-sync-external-store@1.2.0(react@18.2.0):
resolution: {integrity: sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==}
peerDependencies:
@ -3154,12 +3281,33 @@ packages:
/uuid@9.0.1:
resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==}
hasBin: true
dev: false
/v8n@1.5.1:
resolution: {integrity: sha512-LdabyT4OffkyXFCe9UT+uMkxNBs5rcTVuZClvxQr08D5TUgo1OFKkoT65qYRCsiKBl/usHjpXvP4hHMzzDRj3A==}
dev: false
/vite-plugin-top-level-await@1.4.1(vite@5.0.10):
resolution: {integrity: sha512-hogbZ6yT7+AqBaV6lK9JRNvJDn4/IJvHLu6ET06arNfo0t2IsyCaon7el9Xa8OumH+ESuq//SDf8xscZFE0rWw==}
peerDependencies:
vite: '>=2.8'
dependencies:
'@rollup/plugin-virtual': 3.0.2
'@swc/core': 1.3.101
uuid: 9.0.1
vite: 5.0.10(sass@1.69.6)
transitivePeerDependencies:
- '@swc/helpers'
- rollup
dev: true
/vite-plugin-wasm@3.3.0(vite@5.0.10):
resolution: {integrity: sha512-tVhz6w+W9MVsOCHzxo6SSMSswCeIw4HTrXEi6qL3IRzATl83jl09JVO1djBqPSwfjgnpVHNLYcaMbaDX5WB/pg==}
peerDependencies:
vite: ^2 || ^3 || ^4 || ^5
dependencies:
vite: 5.0.10(sass@1.69.6)
dev: true
/vite@5.0.10(sass@1.69.6):
resolution: {integrity: sha512-2P8J7WWgmc355HUMlFrwofacvr98DAjoE52BfdbwQtyLH06XKwaL/FMnmKM2crF0iX4MpmMKoDlNCB1ok7zHCw==}
engines: {node: ^18.0.0 || >=20.0.0}

View file

@ -1,15 +1,17 @@
html,body,#root {
width: 100%;
height: 100%;
html,
body,
#root {
width: 100%;
height: 100%;
}
#root {
display: flex;
flex-direction: column;
display: flex;
flex-direction: column;
}
#root > main {
min-height: 0;
flex-shrink: 1;
flex-grow: 1;
}
min-height: 0;
flex-shrink: 1;
flex-grow: 1;
}

View file

@ -6,9 +6,9 @@ import { useParams } from "react-router-dom";
import { MapControls, Text } from "@react-three/drei";
import { ColorRepresentation, DoubleSide, TextureLoader } from "three";
import { Bloom, EffectComposer } from "@react-three/postprocessing";
import Windows from "./Windows";
import { useAppDispatch } from "../store";
import { addWindow } from "../store/someShit";
import { DragDropContext } from "react-beautiful-dnd";
export default function MapView({}) {
const { universeId } = useParams();
@ -35,46 +35,60 @@ export default function MapView({}) {
return (
<main className={styles.main}>
<Canvas camera={{ position: [0, 20, 0] }}>
<ambientLight />
<MapControls makeDefault />
<DragDropContext
onDragEnd={(event) => {
console.log("evt", event);
}}
>
<Canvas camera={{ position: [0, 20, 0] }}>
<ambientLight />
<MapControls makeDefault />
<EffectComposer>
<Bloom />
</EffectComposer>
<EffectComposer>
<Bloom />
</EffectComposer>
<mesh>
<sphereGeometry args={[100.0, 32, 32]} />
<meshStandardMaterial map={outerSpace} side={DoubleSide} />
</mesh>
<mesh>
<sphereGeometry args={[100.0, 32, 32]} />
<meshStandardMaterial map={outerSpace} side={DoubleSide} />
</mesh>
{mapData.points.map((point) => {
return (
<StarSystem key={point.index} system={point} empires={empireMap} />
);
})}
{mapData.points.map((point) => {
return (
<StarSystem
key={point.index}
system={point}
empires={empireMap}
mapData={mapData}
/>
);
})}
{mapData.edges.map((edge) => {
return (
<Hyperlane
key={`${edge.fromSystemId}:${edge.toSystemId}`}
edge={edge}
points={mapData.points}
/>
);
})}
</Canvas>
<Windows />
{mapData.edges.map((edge) => {
return (
<Hyperlane
key={`${edge.fromSystemId}:${edge.toSystemId}`}
edge={edge}
points={mapData.points}
/>
);
})}
</Canvas>
</DragDropContext>
</main>
);
}
function StarSystem({ system, position, empires, ...props }: MeshProps) {
function StarSystem({
system,
position,
empires,
mapData,
...props
}: MeshProps) {
const dispatch = useAppDispatch();
const meshRef = useRef();
const [hovered, setHover] = useState(false);
const [active, setActive] = useState(false);
const active = false;
const x = system.coordX / 80;
const y = system.coordY / 80;
@ -88,18 +102,7 @@ function StarSystem({ system, position, empires, ...props }: MeshProps) {
return (
<>
<mesh
{...props}
position={[x, 0, y]}
ref={meshRef}
scale={active ? 1.5 : 1}
onClick={(_event) => {
setActive(!active);
dispatch(addWindow(["planet", { type: "planet" }]));
}}
onPointerOver={(_event) => setHover(true)}
onPointerOut={(_event) => setHover(false)}
>
<mesh {...props} position={[x, 0, y]} scale={active ? 1.5 : 1}>
<sphereGeometry args={[0.05]} />
<meshStandardMaterial
color={hovered ? "white" : color}
@ -108,13 +111,33 @@ function StarSystem({ system, position, empires, ...props }: MeshProps) {
/>
</mesh>
<mesh
{...props}
position={[x, 0, y]}
onClick={(event) => {
dispatch(addWindow(["planet", { type: "planet" }]));
event.stopPropagation();
}}
onPointerOver={(event) => {
setHover(true);
event.stopPropagation();
}}
onPointerOut={(event) => {
setHover(false);
event.stopPropagation();
}}
>
<sphereGeometry args={[0.2]} />
<meshStandardMaterial transparent opacity={0} />
</mesh>
{owner && (
<Text
color="white"
fontSize={0.48}
anchorX="center"
anchorY="middle"
position={[x, 0.2, y]}
position={[x, 0.6, y]}
>
{owner.name}
<meshStandardMaterial color={"pink"} />

View file

@ -1,3 +0,0 @@
.draggableHeader {
cursor: move;
}

View file

@ -1,68 +0,0 @@
import { createPlugin, Components } from "leva/plugin";
import { useControls } from "leva";
import { useAppDispatch, useAppSelector } from "../store";
import styles from "./Windows.module.scss";
import classNames from "classnames";
import Draggable from "react-draggable";
import { closeWindow } from "../store/someShit";
import { Tab, Tabs, TabsExpander } from "@blueprintjs/core";
const { Row, Label } = Components;
export default function Windows() {
const windowsRaw = useAppSelector((state) => state.someShit.windows);
const windows = Object.fromEntries(
Object.entries(windowsRaw).map(([name, windowDef]) => {
return [name, windowDef];
}),
);
return Object.entries(windows).map(([name, windowDef]) => {
return <Window key={name} name={name}></Window>;
});
}
function Window({ name }) {
const dispatch = useAppDispatch();
return (
<Draggable handle={`.${styles.draggableHeader}`}>
<div
className="bp5-dialog"
style={{ position: "absolute", bottom: "0", left: "0" }}
>
<div
className={classNames("bp5-dialog-header", styles.draggableHeader)}
>
<span className="bp5-icon-large bp5-icon-globe" />
<h5 className="bp5-heading">Planet</h5>
<button
type="button"
aria-label="Close"
className="bp5-dialog-close-button bp5-button bp5-minimal bp5-icon-cross"
onClick={() => dispatch(closeWindow(name))}
/>
</div>
<div className="bp5-dialog-body">
<Tabs vertical id="ouaic">
<input className="bp5-input" type="text" placeholder="Search..." />
<Tab title="Summary" panel={<>Helloge</>} />
<Tab title="Jobs" panel={<>Helloge</>} />
<Tab title="Armies" panel={<>Helloge</>} />
<TabsExpander />
</Tabs>
</div>
{/* <div className="bp5-dialog-footer">
<div className="bp5-dialog-footer-actions">
<button type="button" className="bp5-button">
Secondary button
</button>
<button type="submit" className="bp5-button bp5-intent-primary">
Primary button
</button>
</div>
</div> */}
</div>
</Draggable>
);
}

View file

@ -1,9 +1,11 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import reactPlugin from "@vitejs/plugin-react-swc";
import wasmPlugin from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [reactPlugin(), wasmPlugin(), topLevelAwait()],
server: {
proxy: {
"/api": {

View file

@ -1,6 +1,6 @@
generator client {
provider = "cargo prisma"
output = "../backend/src/prisma.rs"
output = "../common/src/prisma.rs"
}
datasource db {