From f5c9a102d575f9f61f30b926ac258393203fed64 Mon Sep 17 00:00:00 2001 From: Christopher Serr Date: Thu, 16 May 2019 01:05:07 +0200 Subject: [PATCH 1/3] Implement Custom Variables This Pull Request adds custom key value pairs to Runs. They can be created by the runner in the Run Editor and can store arbitrary string based values that the runner wishes to store with the splits. Components can then use these variables to visualize them. In particular, the text component can visualize these variables as key value pairs. Variables can also be provided by auto splitters, components or through other means. There is a distinction between permanent and temporary variables. Most automatically provided variables are temporary by default, but they can be turned into permanent ones. The permanent ones can be created by the runner in the run editor and will be stored in the splits files unlike the temporary ones. --- capi/bind_gen/src/typescript.ts | 19 ++- capi/src/lib.rs | 8 +- capi/src/run_editor.rs | 33 +++- capi/src/run_metadata.rs | 8 +- .../src/run_metadata_speedrun_com_variable.rs | 35 +++++ ...un_metadata_speedrun_com_variables_iter.rs | 38 +++++ capi/src/run_metadata_variable.rs | 31 ---- capi/src/run_metadata_variables_iter.rs | 34 ---- capi/src/text_component.rs | 13 +- capi/src/text_component_state.rs | 11 +- src/component/{text.rs => text/mod.rs} | 146 ++++++++++++++---- src/component/text/tests.rs | 75 +++++++++ src/layout/component.rs | 2 +- src/platform/no_std/indexmap.rs | 46 ++++++ src/rendering/component/text.rs | 6 +- src/run/editor/mod.rs | 51 +++++- src/run/editor/tests/custom_variables.rs | 45 ++++++ src/run/editor/tests/dissociate_run.rs | 33 +++- src/run/editor/tests/mark_as_modified.rs | 35 ++++- src/run/editor/tests/mod.rs | 1 + src/run/mod.rs | 2 +- src/run/parser/face_split.rs | 17 +- src/run/parser/livesplit.rs | 18 ++- src/run/parser/splits_io.rs | 36 +++++ src/run/parser/splitterz.rs | 24 ++- src/run/parser/worstrun.rs | 2 +- src/run/parser/wsplit.rs | 9 +- src/run/run_metadata.rs | 82 ++++++++-- src/run/saver/livesplit.rs | 20 ++- src/timing/timer/mod.rs | 12 ++ src/timing/timer/tests/mark_as_modified.rs | 24 ++- src/timing/timer/tests/mod.rs | 1 + src/timing/timer/tests/variables.rs | 115 ++++++++++++++ 33 files changed, 869 insertions(+), 163 deletions(-) create mode 100644 capi/src/run_metadata_speedrun_com_variable.rs create mode 100644 capi/src/run_metadata_speedrun_com_variables_iter.rs delete mode 100644 capi/src/run_metadata_variable.rs delete mode 100644 capi/src/run_metadata_variables_iter.rs rename src/component/{text.rs => text/mod.rs} (63%) create mode 100644 src/component/text/tests.rs create mode 100644 src/run/editor/tests/custom_variables.rs create mode 100644 src/timing/timer/tests/variables.rs diff --git a/capi/bind_gen/src/typescript.ts b/capi/bind_gen/src/typescript.ts index d2c9f77a..9f774f88 100644 --- a/capi/bind_gen/src/typescript.ts +++ b/capi/bind_gen/src/typescript.ts @@ -658,11 +658,22 @@ export interface RunMetadataJson { */ region_name: string, /** - * Stores all the variables. A variable is an arbitrary key value pair - * storing additional information about the category. An example of this - * may be whether Amiibos are used in this category. + * Stores all the speedrun.com variables. A variable is an arbitrary key + * value pair storing additional information about the category. An example + * of this may be whether Amiibos are used in this category. */ - variables: { [key: string]: string }, + speedrun_com_variables: { [key: string]: string | undefined }, + custom_variables: { [key: string]: CustomVariableJson | undefined }, +} + +export interface CustomVariableJson { + // TODO: + value: string, + /** + * States whether the variable is permanent. Temporary variables don't get + * stored in splits files. They also don't get shown in the run editor. + */ + is_permanent: boolean, } /** diff --git a/capi/src/lib.rs b/capi/src/lib.rs index 8d0e4d1d..879949e1 100644 --- a/capi/src/lib.rs +++ b/capi/src/lib.rs @@ -37,8 +37,8 @@ pub mod previous_segment_component; pub mod run; pub mod run_editor; pub mod run_metadata; -pub mod run_metadata_variable; -pub mod run_metadata_variables_iter; +pub mod run_metadata_speedrun_com_variable; +pub mod run_metadata_speedrun_com_variables_iter; pub mod segment; pub mod segment_history; pub mod segment_history_element; @@ -64,7 +64,7 @@ pub mod title_component; pub mod title_component_state; pub mod total_playtime_component; -use crate::run_metadata_variable::RunMetadataVariable; +use crate::run_metadata_speedrun_com_variable::RunMetadataSpeedrunComVariable; use crate::segment_history_element::SegmentHistoryElement; use livesplit_core::{Time, TimeSpan}; @@ -78,7 +78,7 @@ thread_local! { static TIME_SPAN: Cell = Cell::default(); static TIME: Cell