Skip to content

Commit

Permalink
Use crate instant to allow the lib works in wasm. (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
bladecoder authored Jan 3, 2024
1 parent 17ec39b commit 5a16feb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli-player/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
let json_string = get_json_string(&args.json_filename)?;

// REMOVE BOM if exits
// REMOVE BOM if exists
let json_string_without_bom = json_string.strip_prefix('\u{feff}').unwrap_or(&json_string);

let mut story = Story::new(json_string_without_bom)?;
Expand Down
5 changes: 5 additions & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ serde_json = "1.0.93"
strum = { version = "0.25.0", features = ["derive"] }
as-any = "0.3.0"
rand = "0.8.5"
instant = "0.1.12"

[features]
stdweb = [ "instant/stdweb" ]
wasm-bindgen = [ "instant/wasm-bindgen" ]
12 changes: 8 additions & 4 deletions lib/src/story/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
value::Value,
void::Void,
};
use std::{self, rc::Rc, time::Instant};
use std::{self, rc::Rc};

/// # Story Progress
/// Methods to move the story forwards.
Expand Down Expand Up @@ -93,8 +93,11 @@ impl Story {
}
}

// Start timing
let duration_stopwatch = Instant::now();
// Start timing (only when necessary)
let duration_stopwatch = match self.async_continue_active {
true => Some(instant::Instant::now()),
false => None,
};

let mut output_stream_ends_in_newline = false;
self.saw_lookahead_unsafe_function_after_new_line = false;
Expand All @@ -114,7 +117,8 @@ impl Story {

// Run out of async time?
if self.async_continue_active
&& duration_stopwatch.elapsed().as_millis() as f32 > millisecs_limit_async
&& duration_stopwatch.as_ref().unwrap().elapsed().as_millis() as f32
> millisecs_limit_async
{
break;
}
Expand Down

0 comments on commit 5a16feb

Please sign in to comment.