lazer pointer wao

feat: get server_url at compile time from env var cuz lazy

ptr.pet 651f0bad aad23617

verified
Changed files
+27 -4
src
+17 -1
build.nu
···
-
def main [feat: string, --run (-r)] {
+
$env.SERVER_URL = "ws://localhost:3111"
+
+
def build-web [run: bool] {
+
mut cmd = ["cargo" "run-wasm" "--package" "annoyance" "--features" "client" "--release"]
+
if not $run { $cmd = $cmd ++ ["--build-only"] }
+
run-external $cmd
+
}
+
+
def build-native [feat: string, run: bool] {
let dir = pwd | path join $"($feat)-build"
cargo b --release --features $feat --artifact-dir $dir -Z unstable-options
if $run {
exec ($dir | path join "annoyance.exe")
}
}
+
+
def main [feat: string = "server", --run (-r), --web (-w)] {
+
if $web {
+
build-web $run
+
} else {
+
build-native $feat $run
+
}
+
}
+10 -3
src/main.rs
···
if should_cleanup {
self.last_cleanup = self.clock.now();
-
for (_, points) in self.laser_points.iter_mut() {
+
let mut ids_to_remove = Vec::new();
+
for (id, points) in self.laser_points.iter_mut() {
let points_len = points.len();
if points_len == 0 {
continue;
···
}
*points = new_points;
-
if !points.is_empty() {
+
if points.is_empty() {
+
ids_to_remove.push(*id);
+
} else {
has_any_points = true;
}
+
}
+
+
for id in ids_to_remove {
+
self.laser_points.remove(&id);
}
} else {
has_any_points = self.laser_points.values().any(|points| !points.is_empty());
···
{
let client_id = app.client_id;
let fut = async move {
-
ws::client::connect("ws://localhost:3111", window, _rx, _tx, client_id)
+
ws::client::connect(env!("SERVER_URL"), window, _rx, _tx, client_id)
.await
.unwrap()
};