Skip to content

Commit

Permalink
fix: use f32 point struct for airports, split routes
Browse files Browse the repository at this point in the history
  • Loading branch information
cathaypacific8747 committed Jun 7, 2024
1 parent 1f9f7de commit e1aba8e
Show file tree
Hide file tree
Showing 23 changed files with 184 additions and 123 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ members = ["am4", "am4-app", "am4-web", "misc/scripts/prepare_data"]
debug = true
lto = true

[profile.wasm-release]
inherits = "release"
opt-level = 's'
lto = true
codegen-units = 1

[patch.crates-io]
indexed_db_futures = { git = "https://github.com/Twey/rust-indexed-db", branch = "no-uuid-wasm-bindgen" } # for am4-web
8 changes: 1 addition & 7 deletions am4-web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "am4-web"
version = "0.2.0-alpha.0"
version = "0.2.0-alpha.2"
edition = "2021"

[dependencies]
Expand All @@ -12,11 +12,5 @@ indexed_db_futures = "0.4.1"
serde = "1.0.203"
wasm-bindgen-futures = "0.4.42"

[profile.wasm-release]
inherits = "release"
opt-level = 'z'
lto = true
codegen-units = 1

[package.metadata.leptos]
lib-profile-release = "wasm-release"
1 change: 1 addition & 0 deletions am4-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
rustup target add wasm32-unknown-unknown
cargo install trunk
trunk serve --open
trunk build -M --release
```

dev
Expand Down
7 changes: 5 additions & 2 deletions am4-web/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<!DOCTYPE html>
<html>
<html lang="en">

<head>
<title>AM4Help</title>
<link data-trunk rel="rust" data-wasm-opt="z" />
<meta charset="UTF-8">
<meta name="description" content="Tools and utilities for the game Airline Manager 4.">
<link data-trunk rel="rust" data-wasm-opt="s" data-reference-types="true" />
<link data-trunk rel="scss" href="src/app.module.scss" />
<link data-trunk rel="copy-dir" href="../am4/data" />
<link data-trunk rel="copy-dir" href="assets" />
<link rel="icon" href="assets/img/logo-32.webp" sizes="32x32" />
<link rel="icon" href="assets/img/logo-128.webp" sizes="128x128" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>0</script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion am4-web/src/app.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ body {

span#version,
>#db-progress {
color: #6a6a6a;
color: #aaa;
}

span#version {
Expand Down
17 changes: 9 additions & 8 deletions am4-web/src/components/aircraft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn ACSearch() -> impl IntoView {
on:input=move |event| {
let target = event.target().unwrap();
let value = target.unchecked_into::<web_sys::HtmlInputElement>().value();
set_search_term.set(value.into());
set_search_term.set(value);
}
/>

Expand All @@ -47,8 +47,9 @@ fn ACErr(e: AircraftSearchError) -> impl IntoView {

if let AircraftSearchError::AircraftNotFound(ctx) = &e {
return database.with_value(|db| {
let suggs = db.as_ref().unwrap().aircrafts.suggest_by_ctx(&ctx);
return view! {
let suggs = db.as_ref().unwrap().aircrafts.suggest_by_ctx(ctx);

view! {
<div>
<p class="err">"Aircraft not found. Did you mean: "</p>
<ul>
Expand All @@ -65,7 +66,7 @@ fn ACErr(e: AircraftSearchError) -> impl IntoView {

</ul>
</div>
};
}
});
} else if let AircraftSearchError::EmptyQuery = &e {
return view! { <div></div> };
Expand Down Expand Up @@ -115,7 +116,7 @@ fn Ac(aircraft: Aircraft) -> impl IntoView {
</tr>
<tr>
<th>{"Cost"}</th>
<td>" $" {aircraft.cost}</td>
<td>"$ " {aircraft.cost}</td>
</tr>
<tr>
<th>{"Capacity"}</th>
Expand All @@ -131,11 +132,11 @@ fn Ac(aircraft: Aircraft) -> impl IntoView {
</tr>
<tr>
<th>{"Maintenance"}</th>
<td>{aircraft.maint} "hr"</td>
<td>{aircraft.maint} " hr"</td>
</tr>
<tr>
<th>{"Ceiling"}</th>
<td>{aircraft.ceil} "ft"</td>
<td>{aircraft.ceil} " ft"</td>
</tr>
<tr>
<th>{"Personnel"}</th>
Expand All @@ -152,7 +153,7 @@ fn Ac(aircraft: Aircraft) -> impl IntoView {
</tr>
<tr>
<th>{"Dimensions"}</th>
<td>{format!("{} m x {} m", aircraft.length, aircraft.wingspan)}</td>
<td>{format!("{} m × {} m", aircraft.length, aircraft.wingspan)}</td>
</tr>
</table>
</div>
Expand Down
11 changes: 6 additions & 5 deletions am4-web/src/components/airport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn APSearch() -> impl IntoView {
on:input=move |event| {
let target = event.target().unwrap();
let value = target.unchecked_into::<web_sys::HtmlInputElement>().value();
set_search_term.set(value.into());
set_search_term.set(value);
}
/>

Expand All @@ -47,8 +47,9 @@ fn APErr(e: AirportSearchError) -> impl IntoView {

if let AirportSearchError::AirportNotFound(ctx) = &e {
return database.with_value(|db| {
let suggs = db.as_ref().unwrap().airports.suggest_by_ctx(&ctx);
return view! {
let suggs = db.as_ref().unwrap().airports.suggest_by_ctx(ctx);

view! {
<div>
<p>"Airport not found. Did you mean: "</p>
<ul>
Expand All @@ -68,7 +69,7 @@ fn APErr(e: AirportSearchError) -> impl IntoView {

</ul>
</div>
};
}
});
} else if let AirportSearchError::EmptyQuery = &e {
return view! { <div></div> };
Expand Down Expand Up @@ -100,7 +101,7 @@ fn Ap(airport: Airport) -> impl IntoView {
</tr>
<tr>
<th>"Location"</th>
<td>{format!("{}, {}", &airport.lat, &airport.lng)}</td>
<td>{format!("{}, {}", &airport.location.lat, &airport.location.lng)}</td>
</tr>
<tr>
<th>"Runway"</th>
Expand Down
28 changes: 12 additions & 16 deletions am4-web/src/components/nav.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
use crate::db::{LoadDbProgress, Idb};
use leptos::{*, logging::log};
use leptos::*;

static VERSION: &'static str = env!("CARGO_PKG_VERSION");
static VERSION: &str = env!("CARGO_PKG_VERSION");

impl std::fmt::Display for LoadDbProgress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LoadDbProgress::Starting => write!(f, "starting"),
LoadDbProgress::IDBConnect => write!(f, "idb(connect)"),
LoadDbProgress::IDBRead(key) => write!(f, "idb(read): {}", key),
LoadDbProgress::IDBCheck(key) => write!(f, "idb(check): {}", key),
LoadDbProgress::IDBWrite(key) => write!(f, "idb(write): {}", key),
LoadDbProgress::Fetching(key) => write!(f, "fetch: {}", key),
LoadDbProgress::Parsing(key) => write!(f, "parse: {}", key),
LoadDbProgress::Loaded => write!(f, ""),
LoadDbProgress::Err(e) => write!(f, "error: {}", e.to_string()),
LoadDbProgress::Err(e) => write!(f, "error: {}", e),
}
}
}
Expand All @@ -25,7 +24,6 @@ pub fn Header(progress: ReadSignal<LoadDbProgress>) -> impl IntoView {
let prog_str = move || progress.get().to_string();

let clear_db = create_action(|_e| {
log!("clear cache");
async move {
Idb::connect().await.unwrap().clear().await.unwrap();
}
Expand All @@ -34,7 +32,7 @@ pub fn Header(progress: ReadSignal<LoadDbProgress>) -> impl IntoView {
view! {
<header role="banner">
<div id="global-nav">
<a href="https://github.com/cathaypacific8747/am4" target="_blank">
<a href="https://cathaypacific8747.github.io/am4/" target="_blank">
<img src="/assets/img/logo-64.webp" alt="logo" height="32" width="32"/>
</a>
<div>
Expand All @@ -56,17 +54,15 @@ pub fn Header(progress: ReadSignal<LoadDbProgress>) -> impl IntoView {
"Formulae"
</a>
</li>
<Show when=move || progress.get() == LoadDbProgress::Loaded>
<li
id="clear-cache"
on:click=move |ev| {
clear_db.dispatch(ev);
}
>
<li
id="clear-cache"
on:click=move |ev| {
clear_db.dispatch(ev);
}
>

"Clear Cache"
</li>
</Show>
"Clear Cache"
</li>
</ul>
</nav>
</div>
Expand Down
Loading

0 comments on commit e1aba8e

Please sign in to comment.