Fix web build and directory listing, and make sure huge_seattle is

treated separately in the updater. #326  [rebuild] [release]
This commit is contained in:
Dustin Carlino 2020-11-08 10:03:07 -08:00
parent 054561412d
commit 3d3cf9f3ea
2 changed files with 19 additions and 11 deletions

View File

@ -2,8 +2,6 @@ use std::collections::{BTreeMap, BTreeSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::Timer;
/// A list of all canonical data files for A/B Street that're uploaded somewhere. The file formats /// A list of all canonical data files for A/B Street that're uploaded somewhere. The file formats
/// are tied to the latest version of the git repo. Players use the updater crate to sync these /// are tied to the latest version of the git repo. Players use the updater crate to sync these
/// files with local copies. /// files with local copies.
@ -25,7 +23,8 @@ pub struct Entry {
impl Manifest { impl Manifest {
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub fn load() -> Manifest { pub fn load() -> Manifest {
crate::maybe_read_json(crate::path("MANIFEST.json"), &mut Timer::throwaway()).unwrap() crate::maybe_read_json(crate::path("MANIFEST.json"), &mut crate::Timer::throwaway())
.unwrap()
} }
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
@ -39,7 +38,8 @@ impl Manifest {
for path in self.entries.keys() { for path in self.entries.keys() {
// TODO Some hardcoded weird exceptions // TODO Some hardcoded weird exceptions
if !data_packs.runtime.contains("huge_seattle") if !data_packs.runtime.contains("huge_seattle")
&& path == "data/system/seattle/scenarios/montlake/everyone_weekday.bin" && (path == "data/system/seattle/maps/huge_seattle.bin"
|| path == "data/system/seattle/scenarios/huge_seattle/weekday.bin")
{ {
remove.push(path.clone()); remove.push(path.clone());
continue; continue;
@ -80,7 +80,7 @@ impl DataPacks {
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub fn load_or_create() -> DataPacks { pub fn load_or_create() -> DataPacks {
let path = crate::path("player/data.json"); let path = crate::path("player/data.json");
match crate::maybe_read_json::<DataPacks>(path.clone(), &mut Timer::throwaway()) { match crate::maybe_read_json::<DataPacks>(path.clone(), &mut crate::Timer::throwaway()) {
Ok(mut cfg) => { Ok(mut cfg) => {
// The game breaks without this required data pack. // The game breaks without this required data pack.
cfg.runtime.insert("seattle".to_string()); cfg.runtime.insert("seattle".to_string());

View File

@ -16,7 +16,7 @@ static SYSTEM_DATA: include_dir::Dir = include_dir::include_dir!(
"../data/system", "../data/system",
"assets/", "assets/",
"fonts/", "fonts/",
"proposals/" "proposals/",
"seattle/city.bin", "seattle/city.bin",
"seattle/maps/montlake.bin", "seattle/maps/montlake.bin",
// used by tutorial // used by tutorial
@ -38,19 +38,27 @@ pub fn file_exists<I: Into<String>>(path: I) -> bool {
pub fn list_dir(dir: String) -> Vec<String> { pub fn list_dir(dir: String) -> Vec<String> {
let mut results = BTreeSet::new(); let mut results = BTreeSet::new();
if let Some(dir) = SYSTEM_DATA.get_dir(dir.trim_start_matches("../data/system/")) { if dir == "../data/system" {
for f in SYSTEM_DATA.files() {
results.insert(format!("../data/system/{}", f.path().display()));
}
} else if let Some(dir) = SYSTEM_DATA.get_dir(dir.trim_start_matches("../data/system/")) {
for f in dir.files() { for f in dir.files() {
results.insert(format!("../data/system/{}", f.path().display())); results.insert(format!("../data/system/{}", f.path().display()));
} }
} else { } else {
error!("Can't list_dir({})", dir); warn!("list_dir({}): not in SYSTEM_DATA, maybe it's remote", dir);
} }
// Merge with remote files. Duplicates handled by BTreeSet. // Merge with remote files. Duplicates handled by BTreeSet.
let dir = dir.trim_start_matches("../"); let mut dir = dir.trim_start_matches("../").to_string();
if !dir.ends_with("/") {
dir = format!("{}/", dir);
}
for f in Manifest::load().entries.keys() { for f in Manifest::load().entries.keys() {
if f.starts_with(dir) { if let Some(path) = f.strip_prefix(&dir) {
results.insert(format!("../{}", f)); // Just list the things immediately in this directory; don't recurse arbitrarily
results.insert(format!("../{}/{}", dir, path.split("/").next().unwrap()));
} }
} }