### ChoicePoint::has_start_content Source: https://docs.rs/bladeink/1.2.5/src/bladeink/choice_point.rs.html Checks if the choice point has starting content. ```APIDOC ## ChoicePoint::has_start_content ### Description Checks if the `ChoicePoint` has starting content. ### Method Signature `pub fn has_start_content(&self) -> bool` ### Returns `true` if the choice point has start content, `false` otherwise. ``` -------------------------------- ### Start Function Evaluation From Game Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Initiates a function evaluation context from the game, setting up the call stack and pointer. ```APIDOC ## start_function_evaluation_from_game ### Description Starts a new function evaluation from the game's perspective. This involves pushing a new context onto the call stack, setting the current pointer to the start of the function container, and preparing to pass arguments. ### Method `start_function_evaluation_from_game` ### Parameters - **func_container** (`Rc`): The container holding the function to be evaluated. - **arguments** (`Option<&Vec>`): An optional vector of values to be passed as arguments to the function. ### Response - `Result<(), StoryError>`: Ok if the function evaluation was started successfully, or an Err if an error occurred. ``` -------------------------------- ### Get the number of components in the path Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Returns the total number of components in the path. ```rust pub fn len(&self) -> usize { self.components.len() } ``` -------------------------------- ### Get Main Content Container Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/navigation.rs.html Retrieves the main content container, prioritizing a temporary one if available. ```rust pub(crate) fn get_main_content_container(&self) -> Rc { match self.temporary_evaluation_container.as_ref() { Some(c) => c.clone(), None => self.main_content_container.clone(), } } ``` -------------------------------- ### Start Function Evaluation from Game in Rust Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Initiates a function evaluation from the game, setting up the call stack and pointer. Requires a function container and optional arguments. ```rust pub fn start_function_evaluation_from_game( &mut self, func_container: Rc, arguments: Option<&Vec>, ) -> Result<(), StoryError> { self.get_callstack().borrow_mut().push( PushPopType::FunctionEvaluationFromGame, self.evaluation_stack.len(), 0, ); self.get_callstack() .borrow_mut() .get_current_element_mut() .current_pointer = Pointer::start_of(func_container); self.pass_arguments_to_evaluation_stack(arguments)?; Ok(()) } ``` -------------------------------- ### Creating a Pointer to the Start of a Container Source: https://docs.rs/bladeink/1.2.5/src/bladeink/pointer.rs.html The `start_of` function is a convenience constructor for creating a Pointer that references the beginning (index 0) of a given container. ```rust pub fn start_of(container: Rc) -> Pointer { Pointer { container: Some(container), index: 0, } } ``` -------------------------------- ### Navigate to Start of Content Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Sets the current pointer to the beginning of the main content container. This is used to reset the story's reading position. ```rust fn go_to_start(&self) { self.get_callstack() .as_ref() .borrow_mut() .get_current_element_mut() .current_pointer = Pointer::start_of(self.main_content_container.clone()) } ``` -------------------------------- ### Get the string representation of the path Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Generates and returns the string representation of the path. It caches the result for efficiency. ```rust pub fn get_components_string(&self) -> String { self.components_string .get_or_init(|| { let mut sb = String::new(); if let Some(first) = self.components.first() { sb.push_str(&first.to_string()); for i in 1..self.components.len() { sb.push('.'); sb.push_str(&self.components.get(i).unwrap().to_string()); } } if self.is_relative { return ".".to_owned() + &sb; } sb }) .to_string() } ``` -------------------------------- ### Get Path String on Choice Source: https://docs.rs/bladeink/1.2.5/src/bladeink/choice_point.rs.html Returns the path associated with the choice as a formatted string. ```rust pub fn get_path_string_on_choice(self: &Rc) -> String { Object::compact_path_string(self.clone(), &self.get_path_on_choice()) } ``` -------------------------------- ### Get Story Hierarchy String Source: https://docs.rs/bladeink/1.2.5/bladeink/story/struct.Story.html Generates a string that outlines the hierarchical structure of objects and containers within the story. ```rust pub fn build_string_of_hierarchy(&self) -> String ``` -------------------------------- ### Get Current Path Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/progress.rs.html Returns the string representation of the story's current location. Useful for debugging or tracking progress. ```rust pub fn get_current_path(&self) -> Option { self.get_state().current_path_string() } ``` -------------------------------- ### Start Variable Observation Batch Source: https://docs.rs/bladeink/1.2.5/src/bladeink/variables_state.rs.html Enables batch observation of variable changes. Sets `batch_observing_variable_changes` to true and initializes `changed_variables_for_batch_obs` to an empty HashSet. ```rust pub fn start_variable_observation(&mut self) { self.batch_observing_variable_changes = true; self.changed_variables_for_batch_obs = Some(HashSet::new()); } ``` -------------------------------- ### Initialize StoryState Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Creates a new StoryState instance with default values and initializes the story's starting point. Requires the main content container and list definitions. ```rust pub fn new( main_content_container: Rc, list_definitions: Rc, ) -> StoryState { let current_flow = Flow::new(DEFAULT_FLOW_NAME, main_content_container.clone()); let callstack = current_flow.callstack.clone(); let mut rng = rand::rng(); let story_seed = rng.random_range(0..100); let state = StoryState { current_flow, did_safe_exit: false, output_stream_text_dirty: true, output_stream_tags_dirty: true, variables_state: VariablesState::new(callstack, list_definitions.clone()), alive_flow_names_dirty: true, evaluation_stack: Vec::new(), main_content_container, current_errors: Vec::with_capacity(0), current_warnings: Vec::with_capacity(0), current_text: None, patch: None, named_flows: None, diverted_pointer: pointer::NULL.clone(), visit_counts: HashMap::new(), turn_indices: HashMap::new(), current_turn_index: -1, story_seed, previous_random: 0, current_tags: Vec::with_capacity(0), list_definitions, }; state.go_to_start(); state } ``` -------------------------------- ### get_current_text Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/progress.rs.html Gets the accumulated output text of the story up to the current point. ```APIDOC ## get_current_text ### Description Returns the accumulated string of output text generated by the story up to the current progression point. This method may return an error if called in an asynchronous context that is still in progress. ### Method `get_current_text()` ### Parameters None ### Response - **Result**: A `Result` containing the current text as a `String` on success, or a `StoryError` if called inappropriately in an async context. ``` -------------------------------- ### copy_and_start_patching Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Creates a copy of the current story state and prepares it for patching. ```APIDOC ## copy_and_start_patching ### Description Creates a deep copy of the current `StoryState` and initializes its `patch` field. This is useful for saving snapshots of the state or for applying modifications without altering the original state. ### Method `copy_and_start_patching(&self, for_background_save: bool) -> StoryState` ### Parameters - **for_background_save** (bool) - If `true`, choices are cloned to ensure thread safety during background saves. If `false`, choices are ref-copied. ### Returns - **StoryState** - A new `StoryState` instance that is a copy of the current state, ready for patching. ``` -------------------------------- ### Get Thread With Index Source: https://docs.rs/bladeink/1.2.5/src/bladeink/callstack.rs.html Retrieves a thread from the thread list by its index. ```APIDOC ## get_thread_with_index ### Description Retrieves an immutable reference to a specific thread from the list of threads based on its index. ### Method `get_thread_with_index(&self, index: usize) -> Option<&Thread>` ### Parameters - `index` (usize): The index of the thread to retrieve. ### Returns - `Option<&Thread>`: An `Option` containing an immutable reference to the `Thread` if found at the given index, otherwise `None`. ``` -------------------------------- ### Play an Ink Story with Bladeink Source: https://docs.rs/bladeink/1.2.5/bladeink/index.html This example demonstrates the basic workflow for playing an Ink story using the `bladeink` crate. It involves initializing the story, iterating through narrative lines, handling user choices, and continuing the story until completion. Ensure you implement a `read_input` function to capture user selections. ```rust let mut story = Story::new(json_string)?; loop { while story.can_continue() { let line = story.cont()?; println!("{}", line); } let choices = story.get_current_choices(); if !choices.is_empty() { // read_input is a method that you should implement // to get the choice selected by the user. let choice_idx:usize = read_input(&choices); // set the option selected by the user story.choose_choice_index(choice_idx)?; } else { break; } } ``` -------------------------------- ### Get Current Thread Source: https://docs.rs/bladeink/1.2.5/src/bladeink/callstack.rs.html Retrieves an immutable reference to the current thread. ```APIDOC ## get_current_thread ### Description Returns an immutable reference to the currently active thread. ### Method `get_current_thread()` ### Returns - `&Thread`: An immutable reference to the current `Thread` object. ``` -------------------------------- ### Get Callstack Source: https://docs.rs/bladeink/1.2.5/src/bladeink/callstack.rs.html Provides immutable access to the vector of elements in the callstack. ```APIDOC ## get_callstack ### Description Returns an immutable reference to the vector of `Element` objects representing the current callstack. ### Method `get_callstack()` ### Returns - `&Vec`: An immutable reference to the callstack's element vector. ``` -------------------------------- ### Pointer::start_of Source: https://docs.rs/bladeink/1.2.5/src/bladeink/pointer.rs.html Creates a Pointer that points to the beginning (index 0) of the given container. ```APIDOC pub fn start_of(container: Rc) -> Pointer ``` -------------------------------- ### Play Ink Story with Bladeink Source: https://docs.rs/bladeink/1.2.5/index.html This example demonstrates basic story playback using the `Story::new` function and handling narrative flow with `cont` and `get_current_choices`. You will need to implement `read_input` to handle user choice selection. ```rust // story is the entry point of the `bladeink` lib. // json_string is a string with all the contents of the .ink.json file. let mut story = Story::new(json_string)?; loop { while story.can_continue() { let line = story.cont()?; println!("{}", line); } let choices = story.get_current_choices(); if !choices.is_empty() { // read_input is a method that you should implement // to get the choice selected by the user. let choice_idx:usize = read_input(&choices); // set the option selected by the user story.choose_choice_index(choice_idx)?; } else { break; } } ``` -------------------------------- ### Get Current Errors Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Returns a slice of strings representing the current errors. ```rust pub fn get_current_errors(&self) -> &[String] { &self.current_errors } ``` -------------------------------- ### Get Variable Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/state.rs.html Retrieves the current value of a named global ink variable. ```APIDOC ## get_variable ### Description Get the value of a named global ink variable. The types available are the standard ink types. ### Method ```rust pub fn get_variable(&self, variable_name: &str) -> Option ``` ### Parameters #### Path Parameters - **variable_name** (str) - Description: The name of the variable to retrieve. ### Returns - Option - The value of the variable if it exists, otherwise None. ``` -------------------------------- ### Get Mutable Current Thread Source: https://docs.rs/bladeink/1.2.5/src/bladeink/callstack.rs.html Retrieves a mutable reference to the current thread. ```APIDOC ## get_current_thread_mut ### Description Returns a mutable reference to the currently active thread. ### Method `get_current_thread_mut()` ### Returns - `&mut Thread`: A mutable reference to the current `Thread` object. ``` -------------------------------- ### Choice::new Source: https://docs.rs/bladeink/1.2.5/src/bladeink/choice.rs.html Creates a new Choice instance. This is an internal constructor. ```APIDOC pub(crate) fn new( target_path: Path, source_path: String, is_invisible_default: bool, tags: Vec, thread_at_generation: Thread, text: String, ) -> Choice ``` -------------------------------- ### Initialize CallStack Source: https://docs.rs/bladeink/1.2.5/src/bladeink/callstack.rs.html Creates a new CallStack instance, initializing it with a root element and clearing any existing threads. This is typically called at the start of a story or game. ```rust pub fn new(main_content_container: Rc) -> CallStack { let mut cs = CallStack { thread_counter: 0, start_of_root: Pointer::start_of(main_content_container), threads: Vec::new(), }; cs.reset(); cs } ``` -------------------------------- ### StatePatch::new Source: https://docs.rs/bladeink/1.2.5/src/bladeink/state_patch.rs.html Creates a new, empty StatePatch instance. ```APIDOC ## StatePatch::new ### Description Creates a new, empty StatePatch instance with initialized HashMaps and HashSet. ### Signature `pub fn new() -> StatePatch` ``` -------------------------------- ### Get Mutable Callstack Source: https://docs.rs/bladeink/1.2.5/src/bladeink/callstack.rs.html Provides mutable access to the vector of elements in the callstack. ```APIDOC ## get_callstack_mut ### Description Returns a mutable reference to the vector of `Element` objects representing the current callstack. ### Method `get_callstack_mut()` ### Returns - `&mut Vec`: A mutable reference to the callstack's element vector. ``` -------------------------------- ### Get Mutable Elements Source: https://docs.rs/bladeink/1.2.5/src/bladeink/callstack.rs.html Provides mutable access to the vector of elements in the callstack. ```APIDOC ## get_elements_mut ### Description Returns a mutable reference to the vector of `Element` objects representing the current callstack. ### Method `get_elements_mut()` ### Returns - `&mut Vec`: A mutable reference to the callstack's element vector. ``` -------------------------------- ### Object Creation and Basic Properties Source: https://docs.rs/bladeink/1.2.5/src/bladeink/object.rs.html Provides methods for creating a new Object instance and checking if it represents the root element. ```APIDOC ## Object::new() ### Description Creates a new `Object` with default initial values. ### Method `new()` ### Returns - `Object`: A new instance of the `Object` struct. ## Object::is_root() ### Description Checks if the current `Object` is the root object in the hierarchy (i.e., has no parent). ### Method `is_root(&self) -> bool` ### Returns - `bool`: `true` if the object is the root, `false` otherwise. ``` -------------------------------- ### Path Resolution Source: https://docs.rs/bladeink/1.2.5/src/bladeink/object.rs.html Utilities for getting, resolving, and converting paths associated with objects. ```APIDOC ## Object::get_path() ### Description Retrieves the `Path` associated with a given `RTObject`. If the path is not cached, it computes and caches it. ### Method `get_path(rtobject: &dyn RTObject) -> Path` ### Parameters - `rtobject` (`&dyn RTObject`): A reference to the `RTObject` for which to get the path. ### Returns - `Path`: The computed or cached `Path` of the `RTObject`. ## Object::resolve_path() ### Description Resolves a given `Path` relative to a starting `RTObject`. ### Method `resolve_path(rtobject: Rc, path: &Path) -> SearchResult` ### Parameters - `rtobject` (`Rc`): The starting `RTObject` for path resolution. - `path` (`&Path`): The `Path` to resolve. ### Returns - `SearchResult`: The result of the path resolution. ## Object::convert_path_to_relative() ### Description Converts a global path into a relative path from the perspective of a given `RTObject`. ### Method `convert_path_to_relative(rtobject: &Rc, global_path: &Path) -> Path` ### Parameters - `rtobject` (`&Rc`): The reference `RTObject` from which the path should be relative. - `global_path` (`&Path`): The global path to convert. ### Returns - `Path`: The converted relative path. ``` -------------------------------- ### Implement Display for Container Source: https://docs.rs/bladeink/1.2.5/src/bladeink/container.rs.html Formats the Container for display, showing its name or a placeholder if no name is set. ```rust impl fmt::Display for Container { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "Container ({})", self.name.as_ref().unwrap_or(&"".to_owned()) ) } } ``` -------------------------------- ### Path::new Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Creates a new Path instance with the given components and relative flag. ```APIDOC ## Path::new ### Description Creates a new Path instance with the given components and relative flag. ### Signature pub fn new(components: &[Component], relative: bool) -> Path ### Parameters * `components` - A slice of `Component` structs representing the path components. * `relative` - A boolean indicating whether the path is relative. ``` -------------------------------- ### Basic Ink Story Playback in Rust Source: https://docs.rs/bladeink/1.2.5/src/bladeink/lib.rs.html Demonstrates how to initialize and play an Ink story using the bladeink crate. Requires a JSON string representing the Ink story and a user input function to handle choices. ```rust use bladeink::{story::Story, story_error::StoryError}; fn main() -> Result<(), StoryError> { let json_string = r##"{"inkVersion":21, "root":["done",null],"listDefs":{}}"##; let read_input = |_:&_| 0; // story is the entry point of the `bladeink` lib. // json_string is a string with all the contents of the .ink.json file. let mut story = Story::new(json_string)?; loop { while story.can_continue() { let line = story.cont()?; println!("{}", line); } let choices = story.get_current_choices(); if !choices.is_empty() { // read_input is a method that you should implement // to get the choice selected by the user. let choice_idx:usize = read_input(&choices); // set the option selected by the user story.choose_choice_index(choice_idx)?; } else { break; } } Ok(()) } ``` -------------------------------- ### Get Output Stream Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Provides immutable access to the story's output stream. ```rust pub fn get_output_stream(&self) -> &Vec> { &self.current_flow.output_stream } ``` -------------------------------- ### Implement RTObject Trait Source: https://docs.rs/bladeink/1.2.5/src/bladeink/variable_reference.rs.html Provides the necessary method to get the underlying Object for the VariableReference. ```rust impl RTObject for VariableReference { fn get_object(&self) -> &Object { &self.obj } } ``` -------------------------------- ### Create a new Path with components and relative flag Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Initializes a new Path instance with a given slice of components and a boolean indicating if it's a relative path. ```rust pub fn new(components: &[Component], relative: bool) -> Path { let mut comp: Vec = Vec::new(); comp.extend_from_slice(components); Path { components: comp, is_relative: relative, ..Default::default() } } ``` -------------------------------- ### Get Mutable Output Stream Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Provides mutable access to the story's output stream. ```rust fn get_output_stream_mut(&mut self) -> &mut Vec> { &mut self.current_flow.output_stream } ``` -------------------------------- ### Get Immutable Choices Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Provides immutable access to the current choices within the story state. ```rust pub fn get_generated_choices(&self) -> &Vec> { &self.current_flow.current_choices } ``` -------------------------------- ### From Implementation Source: https://docs.rs/bladeink/1.2.5/bladeink/value_type/enum.ValueType.html Enables creating a ValueType from an i32. ```APIDOC ### impl From for ValueType #### fn from(value: i32) -> ValueType Converts to this type from the input type. ``` -------------------------------- ### Get Mutable Choices Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Provides mutable access to the current choices within the story state. ```rust pub fn get_generated_choices_mut(&mut self) -> &mut Vec> { &mut self.current_flow.current_choices } ``` -------------------------------- ### Create a new Path with default values Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Initializes a new Path instance using default values, typically representing an empty or root path. ```rust pub fn new_with_defaults() -> Path { Path { ..Default::default() } } ``` -------------------------------- ### Get All Items from List Operation Source: https://docs.rs/bladeink/1.2.5/src/bladeink/native_function_call.rs.html Retrieves all items from a list. This function is used for list-specific operations. ```rust Ok(Rc::new(Value::new::(op1.get_all()))) ``` -------------------------------- ### Pointer::new Source: https://docs.rs/bladeink/1.2.5/src/bladeink/pointer.rs.html Creates a new Pointer instance with a given container and index. ```APIDOC pub const fn new(container: Option>, index: i32) -> Pointer ``` -------------------------------- ### Get Temporary Variable With Name Source: https://docs.rs/bladeink/1.2.5/src/bladeink/callstack.rs.html Retrieves the value of a temporary variable by name from a specific context. ```APIDOC ## get_temporary_variable_with_name ### Description Retrieves the value of a temporary variable by its name from a specified callstack context. If `context_index` is -1, it defaults to the current element's context. ### Method `get_temporary_variable_with_name(&self, name: &str, context_index: i32) -> Option>` ### Parameters - `name` (&str): The name of the temporary variable to retrieve. - `context_index` (i32): The 1-based index of the callstack element (context) to search within. If -1, the current element's context is used. ### Returns - `Option>`: An `Option` containing the `Rc` of the variable if found, otherwise `None`. ``` -------------------------------- ### Get ChoicePoint Flags Source: https://docs.rs/bladeink/1.2.5/src/bladeink/choice_point.rs.html Reconstructs and returns the integer flags representing the ChoicePoint's properties. ```rust pub fn get_flags(&self) -> i32 { let mut flags = 0; if self.has_condition() { flags |= 1; } if self.has_start_content() { flags |= 2; } if self.has_choice_only_content() { flags |= 4; } if self.is_invisible_default() { flags |= 8; } if self.once_only() { flags |= 16; } flags } ``` -------------------------------- ### ChoicePoint::new Source: https://docs.rs/bladeink/1.2.5/src/bladeink/choice_point.rs.html Constructs a new ChoicePoint instance. The flags parameter is a bitmask representing various properties of the choice point. ```APIDOC ## ChoicePoint::new ### Description Constructs a new `ChoicePoint` instance. ### Method Signature `pub fn new(flags: i32, path_string_on_choice: &str) -> Self` ### Parameters * `flags` (i32) - A bitmask where: * `1`: `has_condition` * `2`: `has_start_content` * `4`: `has_choice_only_content` * `8`: `is_invisible_default` * `16`: `once_only` * `path_string_on_choice` (&str) - The string representation of the path to navigate to upon choice. ### Returns A new `ChoicePoint` instance. ``` -------------------------------- ### From Implementation Source: https://docs.rs/bladeink/1.2.5/bladeink/value_type/enum.ValueType.html Enables creating a ValueType from a f32. ```APIDOC ### impl From for ValueType #### fn from(value: f32) -> ValueType Converts to this type from the input type. ``` -------------------------------- ### Get Path String for Count Source: https://docs.rs/bladeink/1.2.5/src/bladeink/variable_reference.rs.html Returns the compact string representation of the path used for counting, if it exists. ```rust pub fn get_path_string_for_count(self: &Rc) -> Option { self.path_for_count .as_ref() .map(|path_for_count| Object::compact_path_string(self.clone(), path_for_count)) } ``` -------------------------------- ### Get Container for Count Source: https://docs.rs/bladeink/1.2.5/src/bladeink/variable_reference.rs.html Retrieves the container associated with the path for count. Returns an error if the path is not set. ```rust pub fn get_container_for_count(self: &Rc) -> Result, String> { if let Some(path) = &self.path_for_count { Ok(Object::resolve_path(self.clone(), path) .container() .unwrap()) } else { Err("Path for count is not set.".to_owned()) } } ``` -------------------------------- ### Path::new_with_components_string Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Creates a new Path instance from a string representation of components. ```APIDOC ## Path::new_with_components_string ### Description Creates a new Path instance from a string representation of components. Handles relative paths indicated by a leading dot. ### Signature pub fn new_with_components_string(components_string: Option<&str>) -> Path ### Parameters * `components_string` - An optional string slice representing the path components. ``` -------------------------------- ### Create a new Component with an index Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Constructor for `Component` that takes a `usize` and creates a component with an `index`. ```rust pub fn new_i(index: usize) -> Component { Component { name: None, index: Some(index), } } ``` -------------------------------- ### Compact Path String Source: https://docs.rs/bladeink/1.2.5/src/bladeink/divert.rs.html Compares and returns the shorter string representation of a path, either relative or global. ```rust fn compact_path_string(&self, other_path: &Path) -> String { let global_path_str; let relative_path_str; if other_path.is_relative() { relative_path_str = other_path.get_components_string(); global_path_str = Object::get_path(self) .path_by_appending_path(other_path) .get_components_string(); } else { let relative_path = self.convert_path_to_relative(other_path); relative_path_str = relative_path.get_components_string(); global_path_str = other_path.get_components_string(); } if relative_path_str.len() < global_path_str.len() { relative_path_str.clone() } else { global_path_str.clone() } } ``` -------------------------------- ### Get a self-referential path Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Returns a Path instance that represents the current context, typically marked as relative. ```rust pub fn get_self() -> Path { Path { is_relative: true, ..Default::default() } } ``` -------------------------------- ### TryFrom<&ValueType> for i32 Source: https://docs.rs/bladeink/1.2.5/bladeink/value_type/enum.ValueType.html Enables attempting to convert a ValueType reference to an i32. ```APIDOC ### impl TryFrom<&ValueType> for i32 #### type Error = () #### fn try_from(value: &ValueType) -> Result Performs the conversion. ``` -------------------------------- ### Get Ordered Items Source: https://docs.rs/bladeink/1.2.5/src/bladeink/ink_list.rs.html Retrieves all items from the InkList, sorted first by their integer value, then by their origin name. ```rust fn get_ordered_items(&self) -> Vec<(&InkListItem, &i32)> { let mut ordered: Vec<_> = self.items.iter().collect(); ordered.sort_by(|a, b| { if a.1 == b.1 { a.0.get_origin_name().cmp(&b.0.get_origin_name()) } else { a.1.cmp(b.1) } }); ordered } ``` -------------------------------- ### Path::get_components_string Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Generates and returns the string representation of the path. ```APIDOC ## Path::get_components_string ### Description Generates and returns the string representation of the path. If the path is relative, it will be prefixed with a dot. ### Signature pub fn get_components_string(&self) -> String ### Returns A `String` representing the path. ``` -------------------------------- ### Create a new Component with a name Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Constructor for `Component` that takes a string slice and creates a component with a `name`. ```rust pub fn new(name: &str) -> Component { Component { name: Some(name.to_string()), index: None, } } ``` -------------------------------- ### Get Current Warnings Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/errors.rs.html Retrieves a slice of strings containing all warnings generated during the story's evaluation. ```rust pub fn get_current_warnings(&self) -> &[String] { self.get_state().get_current_warnings() } ``` -------------------------------- ### Get Global Story Tags with get_global_tags Source: https://docs.rs/bladeink/1.2.5/bladeink/story/struct.Story.html Retrieve all tags defined at the very top of the Ink story file. ```rust let global_tags = story.get_global_tags()?; ``` -------------------------------- ### InkList::new Source: https://docs.rs/bladeink/1.2.5/src/bladeink/ink_list.rs.html Creates a new, empty InkList. ```APIDOC ## InkList::new ### Description Creates a new, empty InkList with no items or origins. ### Signature ```rust pub fn new() -> Self ``` ### Returns A new `InkList` instance. ``` -------------------------------- ### Get Current Story Warnings Source: https://docs.rs/bladeink/1.2.5/bladeink/story/struct.Story.html Retrieves a slice containing any warnings generated during the story's evaluation. ```rust pub fn get_current_warnings(&self) -> &[String] ``` -------------------------------- ### Initialize ListDefinitionsOrigin Source: https://docs.rs/bladeink/1.2.5/src/bladeink/list_definitions_origin.rs.html Creates a new ListDefinitionsOrigin by processing a vector of ListDefinition objects. It populates internal hashmaps for quick lookups and caches all unambiguous list values. ```rust use std::{collections::HashMap, rc::Rc}; use crate::{ink_list::InkList, list_definition::ListDefinition, value::Value}; #[derive(Clone)] pub struct ListDefinitionsOrigin { lists: HashMap, all_unambiguous_list_value_cache: HashMap>, } impl ListDefinitionsOrigin { pub fn new(lists: &mut Vec) -> Self { let mut list_definitions_origin = ListDefinitionsOrigin { lists: HashMap::new(), all_unambiguous_list_value_cache: HashMap::new(), }; for list in lists { list_definitions_origin .lists .insert(list.get_name().to_string(), list.clone()); for (key, val) in list.get_items() { let mut l = InkList::new(); l.items.insert(key.clone(), *val); let list_value = Rc::new(Value::new::(l)); list_definitions_origin .all_unambiguous_list_value_cache .insert(key.get_item_name().to_string(), list_value.clone()); list_definitions_origin .all_unambiguous_list_value_cache .insert(key.get_full_name().to_string(), list_value.clone()); } } list_definitions_origin } pub fn get_list_definition(&self, name: &str) -> Option<&ListDefinition> { self.lists.get(name) } pub fn find_single_item_list_with_name(&self, name: &str) -> Option<&Rc> { if name.trim().is_empty() { return None; } self.all_unambiguous_list_value_cache.get(name) } } ``` -------------------------------- ### Get Target Pointer Source: https://docs.rs/bladeink/1.2.5/src/bladeink/divert.rs.html Resolves and returns the target pointer for the divert. It caches the pointer after the first resolution. ```rust pub fn get_target_pointer(self: &Rc) -> Pointer { let target_pointer_null = self.target_pointer.borrow().is_null(); if target_pointer_null { let target_obj = Object::resolve_path(self.clone(), self.target_path.borrow().as_ref().unwrap()) .obj .clone(); if self .target_path .borrow() .as_ref() .unwrap() .get_last_component() .unwrap() .is_index() { self.target_pointer.borrow_mut().container = target_obj.get_object().get_parent(); self.target_pointer.borrow_mut().index = self .target_path .borrow() .as_ref() .unwrap() .get_last_component() .unwrap() .index .unwrap() as i32; } else { let c = target_obj.into_any().downcast::(); self.target_pointer.replace(Pointer::start_of(c.unwrap())); } } self.target_pointer.borrow().clone() } ``` -------------------------------- ### Story::new Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/mod.rs.html Constructs a new `Story` instance from a JSON string compiled by `inklecate`. It handles version compatibility checks and initializes the story state. ```APIDOC ## Story::new ### Description Constructs a `Story` out of a JSON string that was compiled with `inklecate`. ### Method `pub fn new(json_string: &str) -> Result` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let story = Story::new("{\"inkVersion\": 21, \"root\": [\"Hello world!\"]}"); ``` ### Response #### Success Response (Ok(Story)) - Returns a `Story` instance on success. #### Response Example ```rust // On success, a Story instance is returned. ``` ### Errors - `StoryError`: If there is an issue loading or parsing the JSON string, or if the story version is incompatible. ``` -------------------------------- ### ListDefinition::new Source: https://docs.rs/bladeink/1.2.5/src/bladeink/list_definition.rs.html Constructs a new ListDefinition. Initializes with a name and a map of item names to their integer values. The internal items map is initially empty and will be populated on first access. ```APIDOC pub fn new(name: String, items: HashMap) -> Self ``` -------------------------------- ### Get Choice Target Container Source: https://docs.rs/bladeink/1.2.5/src/bladeink/choice_point.rs.html Resolves the path associated with a choice and returns the target container if found. ```rust pub fn get_choice_target(self: &Rc) -> Option> { Object::resolve_path(self.clone(), &self.path_on_choice.borrow()).container() } ``` -------------------------------- ### CloneToUninit Trait Implementation (Nightly) Source: https://docs.rs/bladeink/1.2.5/bladeink/choice/struct.Choice.html An experimental nightly-only API for copying Choice data to uninitialized memory. Use with caution. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Get Global Tags Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/tags.rs.html Retrieves any global tags defined at the very top of the story. These are typically marked with hash tags. ```APIDOC ## get_global_tags ### Description Get any global tags associated with the story. These are defined as hash tags defined at the very top of the story. ### Method Signature `pub fn get_global_tags(&self) -> Result, StoryError>` ### Returns - `Result, StoryError>`: A vector of strings representing the global tags, or a `StoryError` if an issue occurs. ``` -------------------------------- ### TryFrom<&ValueType> for f32 Source: https://docs.rs/bladeink/1.2.5/bladeink/value_type/enum.ValueType.html Enables attempting to convert a ValueType reference to a f32. ```APIDOC ### impl TryFrom<&ValueType> for f32 #### type Error = () #### fn try_from(value: &ValueType) -> Result Performs the conversion. ``` -------------------------------- ### Get Current Story Errors Source: https://docs.rs/bladeink/1.2.5/bladeink/story/struct.Story.html Retrieves a slice containing any critical errors that occurred during the story's evaluation. ```rust pub fn get_current_errors(&self) -> &[String] ``` -------------------------------- ### Initialize Story from JSON Source: https://docs.rs/bladeink/1.2.5/bladeink/story/struct.Story.html Constructs a new Story instance from a JSON string compiled by inklecate. Ensure the JSON is valid. ```rust pub fn new(json_string: &str) -> Result ``` -------------------------------- ### Path::len Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Returns the number of components in the path. ```APIDOC ## Path::len ### Description Returns the number of components in the path. ### Signature pub fn len(&self) -> usize ### Returns The number of components in the path. ``` -------------------------------- ### Get Path on Choice Source: https://docs.rs/bladeink/1.2.5/src/bladeink/choice_point.rs.html Retrieves the path associated with the choice. It resolves relative paths to global ones if possible. ```rust pub fn get_path_on_choice(self: &Rc) -> Path { // Resolve any relative paths to global ones as we come across them if self.path_on_choice.borrow().is_relative() && let Some(choice_target_obj) = self.get_choice_target() { self.path_on_choice.replace(choice_target_obj.get_path()); } self.path_on_choice.borrow().clone() } ``` -------------------------------- ### Get Previous Pointer from Callstack Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story_state.rs.html Retrieves the previous pointer for the current thread from the callstack. This allows for restoring the execution context. ```rust pub fn get_previous_pointer(&self) -> Pointer { self.get_callstack() .as_ref() .borrow_mut() .get_current_thread_mut() .previous_pointer .clone() } ``` -------------------------------- ### Helper Methods for ValueType Source: https://docs.rs/bladeink/1.2.5/src/bladeink/value_type.rs.html Provides utility methods for creating and retrieving values from ValueType. `new` creates a ValueType from any convertible type, and `get` attempts to retrieve a value of a specific type. ```rust impl ValueType { pub fn new>(v: T) -> Self { v.into() } pub fn get<'val, T>(&'val self) -> Option where &'val Self: TryInto, { self.try_into().ok() } /// Tries to convert the internal value of this `ValueType` to `i32` pub fn coerce_to_int(&self) -> Result { match self { ValueType::Bool(v) => { if *v { Ok(1) } else { Ok(0) } } ValueType::Int(v) => Ok(*v), ValueType::Float(v) => Ok(*v as i32), _ => Err(StoryError::BadArgument("Failed to cast to int".to_owned())), } } /// Tries to convert the internal value of this `ValueType` to `f32` pub fn coerce_to_float(&self) -> Result { match self { ValueType::Bool(v) => { if *v { Ok(1.0) } else { Ok(0.0) } } ValueType::Int(v) => Ok(*v as f32), ValueType::Float(v) => Ok(*v), _ => Err(StoryError::BadArgument( "Failed to cast to float".to_owned(), )), } } /// Tries to convert the internal value of this `ValueType` to `bool` pub fn coerce_to_bool(&self) -> Result { match self { ValueType::Bool(v) => Ok(*v), ValueType::Int(v) => { if *v == 1 { Ok(true) } else { Ok(false) } } _ => Err(StoryError::BadArgument( "Failed to cast to boolean".to_owned(), )), } } /// Tries to convert the internal value of this `ValueType` to `String` pub fn coerce_to_string(&self) -> Result { match self { ``` -------------------------------- ### Path::new_with_defaults Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Creates a new Path instance with default values. ```APIDOC ## Path::new_with_defaults ### Description Creates a new Path instance with default values. ### Signature pub fn new_with_defaults() -> Path ``` -------------------------------- ### Get Current Choices Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/progress.rs.html Retrieves a vector of available choices, excluding invisible ones. Use this to present options to the user. ```rust pub fn get_current_choices(&self) -> Vec> { // Don't include invisible choices for external usage. let mut choices = Vec::new(); if let Some(current_choices) = self.get_state().get_current_choices() { for c in current_choices { if !c.is_invisible_default { c.index.replace(choices.len()); choices.push(c.clone()); } } } choices } ``` -------------------------------- ### Create a parent Component Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Factory method to create a `Component` representing the parent directory, using the `PARENT_ID` constant. ```rust pub fn to_parent() -> Component { Component::new(PARENT_ID) } ``` -------------------------------- ### Get Current Tags Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/tags.rs.html Retrieves a list of tags that were seen during the most recent `cont` call. This feature is noted as a work in progress. ```APIDOC ## get_current_tags ### Description Gets a list of tags defined with '#' in the ink source that were seen during the most recent [`cont`](Story::cont) call. This functionality is currently a work in progress. ### Method Signature `pub fn get_current_tags(&mut self) -> Result, StoryError>` ### Returns - `Result, StoryError>`: A vector of strings representing the tags seen during the last `cont` call, or a `StoryError` if an issue occurs. Note: This method may return an error if called in an asynchronous context due to its work-in-progress status. ``` -------------------------------- ### Initialize VariablesState Source: https://docs.rs/bladeink/1.2.5/src/bladeink/variables_state.rs.html Creates a new instance of `VariablesState` with provided callstack and list definitions origin. Initializes global and default global variables as empty HashMaps. ```rust pub fn new( callstack: Rc>, list_defs_origin: Rc, ) -> VariablesState { VariablesState { global_variables: HashMap::new(), default_global_variables: HashMap::new(), batch_observing_variable_changes: false, callstack, changed_variables_for_batch_obs: None, patch: None, list_defs_origin, } } ``` -------------------------------- ### Get the last component of the path Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Returns an Option containing a reference to the last Component in the path, or None if the path is empty. ```rust pub fn get_last_component(&self) -> Option<&Component> { if !self.components.is_empty() { return self.components.last(); } None } ``` -------------------------------- ### Navigate Story Path with choose_path_string Source: https://docs.rs/bladeink/1.2.5/bladeink/story/struct.Story.html Change the current position in the story using a dot-separated path. Optionally reset the call stack to discard previous context. ```rust story.choose_path_string("myKnot", true, None)?; ``` ```rust story.choose_path_string("myKnot.myStitch", true, None)?; ``` -------------------------------- ### Get Min Item Source: https://docs.rs/bladeink/1.2.5/src/bladeink/ink_list.rs.html Finds and returns the item with the lowest integer value in the InkList. Returns None if the list is empty. ```rust pub fn get_min_item(&self) -> Option<(&InkListItem, i32)> { let mut min: Option<(&InkListItem, i32)> = None; for (k, v) in &self.items { if min.is_none() || *v < min.as_ref().unwrap().1 { min = Some((k, *v)); } } min } ``` -------------------------------- ### Implement Display for Path Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Implements the `fmt::Display` trait for the `Path` struct, allowing it to be formatted as a string using its components. ```rust impl fmt::Display for Path { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.get_components_string()) } } ``` -------------------------------- ### Get Max Item Source: https://docs.rs/bladeink/1.2.5/src/bladeink/ink_list.rs.html Finds and returns the item with the highest integer value in the InkList. Returns None if the list is empty. ```rust pub fn get_max_item(&self) -> Option<(&InkListItem, i32)> { let mut max: Option<(&InkListItem, i32)> = None; for (k, v) in &self.items { if max.is_none() || *v > max.as_ref().unwrap().1 { max = Some((k, *v)); } } max } ``` -------------------------------- ### Get a specific component by index Source: https://docs.rs/bladeink/1.2.5/src/bladeink/path.rs.html Retrieves a reference to a Component at a given index within the path's components, if it exists. ```rust pub fn get_component(&self, index: usize) -> Option<&Component> { self.components.get(index) } ``` -------------------------------- ### Load JSON from String - BladeInk Source: https://docs.rs/bladeink/1.2.5/src/bladeink/json/json_read_stream.rs.html Initializes a JSON tokenizer from a string and calls the main parse function. This is the entry point for parsing JSON data. ```rust pub fn load_from_string( s: &str, ) -> Result<(i32, Rc, Rc), StoryError> { let mut tok = JsonTokenizer::new_from_str(s); parse(&mut tok) } ``` -------------------------------- ### Get Current Critical Errors Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/errors.rs.html Retrieves a slice of strings containing all critical errors generated during the story's evaluation. ```rust pub fn get_current_errors(&self) -> &[String] { self.get_state().get_current_errors() } ``` -------------------------------- ### Continue Story Immediately Source: https://docs.rs/bladeink/1.2.5/src/bladeink/story/progress.rs.html Executes the story until the next user input is required or an error occurs. Returns any text generated during this continuation. Ensure `can_continue` is true before calling. ```rust pub fn cont(&mut self) -> Result { self.continue_async(0.0)?; self.get_current_text() } ``` -------------------------------- ### Get Tags for Content Path with tags_for_content_at_path Source: https://docs.rs/bladeink/1.2.5/bladeink/story/struct.Story.html Fetch tags associated with a specific knot or stitch within the Ink story. ```rust let knot_tags = story.tags_for_content_at_path("myKnot.myStitch")?; ``` -------------------------------- ### JsonTokenizer Initialization Source: https://docs.rs/bladeink/1.2.5/src/bladeink/json/json_tokenizer.rs.html Creates a new `JsonTokenizer` instance from a string slice. The tokenizer is configured to skip whitespaces by default. ```rust pub(super) struct JsonTokenizer<'a> { json: &'a [u8], lookahead: Option, skip_whitespaces: bool, } impl<'a> JsonTokenizer<'a> { pub(super) fn new_from_str(s: &'a str) -> JsonTokenizer<'a> { JsonTokenizer { json: s.as_bytes(), lookahead: None, skip_whitespaces: true, } } // ... ``` -------------------------------- ### Get Current Story Path with get_current_path Source: https://docs.rs/bladeink/1.2.5/bladeink/story/struct.Story.html Obtain a string representation of the story's current location, such as a knot or stitch. ```rust if let Some(path) = story.get_current_path() { println!("Current path: {}", path); } ``` -------------------------------- ### Get Target Path String Source: https://docs.rs/bladeink/1.2.5/src/bladeink/divert.rs.html Retrieves the target path of the divert as a formatted string. This method resolves relative paths. ```rust pub fn get_target_path_string(self: &Rc) -> Option { self.get_target_path() .as_ref() .map(|p| self.compact_path_string(p)) } ``` -------------------------------- ### Continue Story Flow with cont Source: https://docs.rs/bladeink/1.2.5/bladeink/story/struct.Story.html Advance the story by one step, returning any text produced. This is typically used when `can_continue` is true. ```rust let text = story.cont()?; ``` -------------------------------- ### Tag Display Implementation Source: https://docs.rs/bladeink/1.2.5/src/bladeink/tag.rs.html Shows how the `Tag` struct implements the `fmt::Display` trait for formatted output, typically as a markdown-style tag. ```APIDOC ## `impl fmt::Display for Tag` ### Description Implements the `Display` trait for the `Tag` struct, enabling formatted string representation. ### Method #### `fmt` ##### Description Formats the tag for display, prepending it with a '#' symbol. ##### Signature `fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result` ##### Parameters - `f` (`&mut fmt::Formatter<'_>`) - The formatter to write to. ##### Returns A `fmt::Result` indicating success or failure of the formatting operation. ### Example Output `# tag_text` ```