Fix champ select review findings (#13)
- redraw the page on hover and lock-in changes, and reset the settings form when champ select takes the window away - keep the current pick when a client read fails; only a real answer that the draft is over ends it - read the client once per wake and share it between the follower and the live selection, reuse session event payloads, and touch only the cached champion list an event concerns - replay the captured raw client responses in the fake and cover the list cache, event updates and the anvil-champion read - name the five champions anvil champions and the set pickable, document them, and prepare redraw strings ahead of render
This commit is contained in:
1 parent
f4a9e5e7a8
commit
5ba3251875
12 files changed
+799
-271
No files matched your search
@@ -10,8 +10,9 @@ use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
use arena_tracker_core::{
|
||||
Account, Champion, ChampionCatalog, ChampionSource, ClientError, Date, GameClientSource,
|
||||
GamePhase, Gameflow, MatchHistorySource, Season, SourceError, Tracker,
|
||||
Account, ChampSelect, Champion, ChampionCatalog, ChampionSource, ClientError, ClientEvent,
|
||||
Date, GameClientSource, GamePhase, Gameflow, MatchHistorySource, Season, SourceError, Tracker,
|
||||
decode_gameflow,
|
||||
};
|
||||
use serde_json::Value;
|
||||
|
||||
@@ -569,7 +570,21 @@ struct ClientState {
|
||||
gameflow: Gameflow,
|
||||
tracks: HashMap<String, u32>,
|
||||
waits: Vec<Duration>,
|
||||
selection: Option<arena_tracker_core::ChampSelect>,
|
||||
/// The raw bodies the client answers for the current draft.
|
||||
champ_select: Option<RawChampSelect>,
|
||||
/// A raw gameflow body, replayed through the same parser as the live client.
|
||||
raw_gameflow: Option<String>,
|
||||
gameflow_error: Option<ClientError>,
|
||||
champ_select_error: Option<ClientError>,
|
||||
}
|
||||
|
||||
/// The raw client responses of a draft, replayed through the same parsing as the live client.
|
||||
#[derive(Clone)]
|
||||
pub struct RawChampSelect {
|
||||
pub pickable: String,
|
||||
pub disabled: String,
|
||||
pub anvil: String,
|
||||
pub session: String,
|
||||
}
|
||||
|
||||
impl FakeClient {
|
||||
@@ -622,6 +637,7 @@ impl FakeClient {
|
||||
/// `phase` is the client's own name for it, e.g. "InProgress".
|
||||
pub fn set_phase(&self, phase: &str, arena: bool) {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
state.raw_gameflow = None;
|
||||
state.gameflow = Gameflow {
|
||||
phase: GamePhase::from_client(phase),
|
||||
arena,
|
||||
@@ -629,13 +645,27 @@ impl FakeClient {
|
||||
};
|
||||
}
|
||||
|
||||
/// Replays a captured gameflow body through the live client's parser.
|
||||
pub fn set_gameflow(&self, body: &str) {
|
||||
self.state.lock().unwrap().raw_gameflow = Some(body.into());
|
||||
}
|
||||
|
||||
/// The client's id of the game being played (kept across phases until changed).
|
||||
pub fn set_game_id(&self, game_id: Option<u64>) {
|
||||
self.state.lock().unwrap().gameflow.game_id = game_id;
|
||||
}
|
||||
|
||||
pub fn set_selection(&self, value: arena_tracker_core::ChampSelect) {
|
||||
self.state.lock().unwrap().selection = Some(value);
|
||||
pub fn set_champ_select(&self, raw: RawChampSelect) {
|
||||
self.state.lock().unwrap().champ_select = Some(raw);
|
||||
}
|
||||
|
||||
/// The next gameflow or champ select read fails with this, until cleared.
|
||||
pub fn fail_gameflow(&self, error: Option<ClientError>) {
|
||||
self.state.lock().unwrap().gameflow_error = error;
|
||||
}
|
||||
|
||||
pub fn fail_champ_select(&self, error: Option<ClientError>) {
|
||||
self.state.lock().unwrap().champ_select_error = error;
|
||||
}
|
||||
|
||||
pub fn set_track(&self, name: &str, value: u32) {
|
||||
@@ -661,16 +691,27 @@ impl GameClientSource for FakeClient {
|
||||
fn gameflow(&self) -> Result<Gameflow, ClientError> {
|
||||
let state = self.state.lock().unwrap();
|
||||
state.signed_in.as_ref().ok_or(ClientError::Absent)?;
|
||||
Ok(state.gameflow.clone())
|
||||
if let Some(error) = &state.gameflow_error {
|
||||
return Err(error.clone());
|
||||
}
|
||||
match &state.raw_gameflow {
|
||||
Some(body) => decode_gameflow(200, body),
|
||||
None => Ok(state.gameflow.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
fn champ_select(&self) -> Result<arena_tracker_core::ChampSelect, ClientError> {
|
||||
self.state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.selection
|
||||
.clone()
|
||||
.ok_or(ClientError::Absent)
|
||||
fn champ_select(&self) -> Result<ChampSelect, ClientError> {
|
||||
let state = self.state.lock().unwrap();
|
||||
if let Some(error) = &state.champ_select_error {
|
||||
return Err(error.clone());
|
||||
}
|
||||
let raw = state.champ_select.as_ref().ok_or(ClientError::Absent)?;
|
||||
let session = serde_json::from_str(&raw.session)
|
||||
.map_err(|error| ClientError::Other(error.to_string()))?;
|
||||
let pickable = ChampSelect::pickable_champions(&raw.pickable, &raw.disabled)?;
|
||||
let anvil = serde_json::from_str(&raw.anvil)
|
||||
.map_err(|error| ClientError::Other(error.to_string()))?;
|
||||
ChampSelect::from_session(&session, pickable, anvil)
|
||||
}
|
||||
|
||||
fn official_progress(&self, track_name: &str) -> Result<Option<u32>, ClientError> {
|
||||
@@ -679,7 +720,8 @@ impl GameClientSource for FakeClient {
|
||||
Ok(state.tracks.get(track_name).copied())
|
||||
}
|
||||
|
||||
fn wait_for_change(&self, timeout: Duration) {
|
||||
fn wait_for_event(&self, timeout: Duration) -> ClientEvent {
|
||||
self.state.lock().unwrap().waits.push(timeout);
|
||||
ClientEvent::Other
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user