mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
Bundle data/MANIFEST.json in wasm. Now loading all maps from HTTP works! #21
This commit is contained in:
parent
4d66e4e91d
commit
62b3af324b
@ -5,8 +5,6 @@ use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::Timer;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Manifest {
|
||||
// Keyed by path, starting with "data/"
|
||||
@ -23,13 +21,15 @@ pub struct Entry {
|
||||
}
|
||||
|
||||
impl Manifest {
|
||||
pub fn write(&self, path: String) {
|
||||
println!("- Wrote {}", path);
|
||||
crate::write_json(path, self);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn load() -> Manifest {
|
||||
crate::maybe_read_json(crate::path("MANIFEST.json"), &mut crate::Timer::throwaway())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn load(path: String) -> Result<Manifest, std::io::Error> {
|
||||
crate::maybe_read_json(path, &mut Timer::throwaway())
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn load() -> Manifest {
|
||||
crate::from_json(&include_bytes!("../../data/MANIFEST.json").to_vec()).unwrap()
|
||||
}
|
||||
|
||||
pub fn all_map_names(&self) -> BTreeSet<String> {
|
||||
|
@ -5,7 +5,7 @@ use widgetry::{
|
||||
};
|
||||
|
||||
use crate::app::App;
|
||||
use crate::game::{DrawBaselayer, PopupMsg, State, Transition};
|
||||
use crate::game::{DrawBaselayer, State, Transition};
|
||||
use crate::helpers::nice_map_name;
|
||||
use crate::render::DrawArea;
|
||||
|
||||
@ -59,10 +59,7 @@ impl CityPicker {
|
||||
|
||||
let mut other_cities = vec![Line("Other cities").draw(ctx)];
|
||||
let mut this_city = vec![];
|
||||
for name in abstutil::Manifest::load(abstutil::path("MANIFEST.json"))
|
||||
.unwrap()
|
||||
.all_map_names()
|
||||
{
|
||||
for name in abstutil::Manifest::load().all_map_names() {
|
||||
if let Some((_, color, _)) = regions.iter().find(|(n, _, _)| &name == n) {
|
||||
let btn = Btn::txt(&name, Text::from(Line(nice_map_name(&name)).fg(*color)))
|
||||
.tooltip(Text::new());
|
||||
@ -199,7 +196,7 @@ fn switch_map(
|
||||
})
|
||||
} else {
|
||||
// TODO Some kind of UI for running the updater from here!
|
||||
Transition::Replace(PopupMsg::new(
|
||||
Transition::Replace(crate::game::PopupMsg::new(
|
||||
ctx,
|
||||
"Missing data",
|
||||
vec![
|
||||
|
@ -181,8 +181,7 @@ impl State for MainMenu {
|
||||
}
|
||||
"Sandbox mode" => {
|
||||
// We might've left with a synthetic map loaded.
|
||||
let map_path = if abstutil::Manifest::load(abstutil::path("MANIFEST.json"))
|
||||
.unwrap()
|
||||
let map_path = if abstutil::Manifest::load()
|
||||
.all_map_names()
|
||||
.contains(app.primary.map.get_name())
|
||||
{
|
||||
|
@ -1,4 +1,3 @@
|
||||
use abstutil::{Entry, Manifest};
|
||||
use std::collections::BTreeMap;
|
||||
use std::error::Error;
|
||||
use std::fs::{create_dir_all, remove_file, set_permissions, File, Permissions};
|
||||
@ -7,6 +6,8 @@ use std::process::Command;
|
||||
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use abstutil::{Entry, Manifest, Timer};
|
||||
|
||||
const MD5_BUF_READ_SIZE: usize = 4096;
|
||||
const TMP_DOWNLOAD_NAME: &str = "tmp_download.zip";
|
||||
|
||||
@ -37,10 +38,7 @@ async fn main() {
|
||||
async fn download() {
|
||||
let cities = Cities::load_or_create();
|
||||
let local = generate_manifest();
|
||||
let truth = filter_manifest(
|
||||
Manifest::load("data/MANIFEST.json".to_string()).unwrap(),
|
||||
cities,
|
||||
);
|
||||
let truth = filter_manifest(Manifest::load(), cities);
|
||||
|
||||
// Anything local need deleting?
|
||||
for path in local.entries.keys() {
|
||||
@ -76,10 +74,7 @@ async fn download() {
|
||||
fn just_compare() {
|
||||
let cities = Cities::load_or_create();
|
||||
let local = generate_manifest();
|
||||
let truth = filter_manifest(
|
||||
Manifest::load("data/MANIFEST.json".to_string()).unwrap(),
|
||||
cities,
|
||||
);
|
||||
let truth = filter_manifest(Manifest::load(), cities);
|
||||
|
||||
// Anything local need deleting?
|
||||
for path in local.entries.keys() {
|
||||
@ -100,7 +95,11 @@ fn upload() {
|
||||
let remote_base = "/home/dabreegster/Dropbox/abstreet_data";
|
||||
|
||||
let mut local = generate_manifest();
|
||||
let remote = Manifest::load(format!("{}/MANIFEST.json", remote_base)).unwrap_or(Manifest {
|
||||
let remote: Manifest = abstutil::maybe_read_json(
|
||||
format!("{}/MANIFEST.json", remote_base),
|
||||
&mut Timer::throwaway(),
|
||||
)
|
||||
.unwrap_or(Manifest {
|
||||
entries: BTreeMap::new(),
|
||||
});
|
||||
|
||||
@ -147,17 +146,14 @@ fn upload() {
|
||||
}
|
||||
}
|
||||
|
||||
local.write(format!("{}/MANIFEST.json", remote_base));
|
||||
local.write("data/MANIFEST.json".to_string());
|
||||
abstutil::write_json(format!("{}/MANIFEST.json", remote_base), &local);
|
||||
abstutil::write_json("data/MANIFEST.json".to_string(), &local);
|
||||
}
|
||||
|
||||
async fn check_links() {
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
for (file, entry) in Manifest::load("data/MANIFEST.json".to_string())
|
||||
.unwrap()
|
||||
.entries
|
||||
{
|
||||
for (file, entry) in Manifest::load().entries {
|
||||
println!("> Check remote for {}", file);
|
||||
let url = entry.dropbox_url.unwrap();
|
||||
let url = format!("{}{}", &url[..url.len() - 1], "1");
|
||||
|
Loading…
Reference in New Issue
Block a user