Struct libxivdat::xiv_macro::MacroData [−][src]
pub struct MacroData<'a> { pub icon_key: &'a str, pub icon_id: &'a str, pub lines: Vec<&'a str>, pub title: &'a str, }
Expand description
Resource definition for a Final Fantasy XIV macro.
MacroData
is used to build sections with references to pre-allocated buffers.
To build a section that owns its own data, use Macro
.
Game client macro spec
Title: No more than 20 utf-8 characters.
Icon: Icon id and key are a matching pair corresponding to a valid MacroIcon
.
Lines: Exactly 15 lines of no more than 180 utf-8 characters.
Data Structure
The expected pattern of sections is “T” (Title), “I” (Icon), “K”, (Key), and repeating “L“s (Lines). Valid macros always contain exactly 15 lines, even if their contents are blank. This library does not strictly enforce this pattern, and will read lines until the next title.
Fields
icon_key: &'a str
The index of the icon in the GUI icon selection menu as 3 hexadecimal digits. This value must match
the icon_id
to be considered valid. Use change_icon()
to update both icon-related values at once.
icon_id: &'a str
The index of the icon in the game data files as 7 hexadecimal digits. This value must match
the icon_key
to be considered valid. Use change_icon()
to update both icon-related values at once.
lines: Vec<&'a str>
A vector of macro lines. Macros created by the game client are always 15 lines long, even if those lines are blank. Lines must be shorter than 180 utf-8 characters. This is a character limit, not a byte limit. This library does not enforce these standards, but attempting to write a macro of a different size and use it in the game client may produce undefined behavior. Macro lines may contain an extended, FFXIV-specific character set (including game icons such as the HQ icon and item link icon). These are likely to render improperly on other platforms.
title: &'a str
The title of the macro. Titles have a maximum length of 20 utf-8 characters in the game client. This is a character limit, not a byte limit. Longer titles may produce undefined behavior.
Implementations
Returns a Vec
of SectionData
representing the
MacroData
.
Errors
Returns a DATError::Overflow
if the content of a section would exceed
the maximum allowable length. (u16::MAX
- 1
)
Examples
use libxivdat::xiv_macro::MacroData; use libxivdat::xiv_macro::icon::MacroIcon; let a_macro = MacroData::new( "Title", vec!["Circle"], &MacroIcon::SymbolCircle ).unwrap(); let sections = a_macro.as_section_data().unwrap(); assert_eq!(sections[0].content, "Title");
Changes the icon_key
and icon_id
to a valid pair based on an input
MacroIcon
.
Examples
use libxivdat::xiv_macro::MacroData; use libxivdat::xiv_macro::icon::MacroIcon; let mut a_macro = MacroData::new( "Title", vec![""], &MacroIcon::NoIcon ).unwrap(); assert_eq!(a_macro.icon_id, "0000000"); assert_eq!(a_macro.icon_key, "000"); a_macro.change_icon(&MacroIcon::SymbolArrowUp); assert_eq!(a_macro.icon_id, "00102FF"); assert_eq!(a_macro.icon_key, "037");
Builds a MacroData
from a Vec
of SectionData
.
The expected pattern of section tags is “T” (Title), “I” (Icon), “K”, (Key), and repeating “L“s (Lines).
Valid macros always contain exactly 15 lines, even if their contents are blank. This function checks
the data for validity, unlick from_section_data_unsafe()
This is equivalent to calling from_section_data_unsafe()
followed by
validate()
on the resulting Macro
.
Macro spec
Title: No more than 20 utf-8 characters.
Icon: Icon id and key are a matching pair corresponding to a valid MacroIcon
.
Lines: Exactly 15 lines of no more than 180 utf-8 characters.
Errors
Returns DATError::InvalidInput
if the sections are not provided in the order described above or
the icon id and key specified are not a valid pair.
Returns DATError::Overflow
if the title or any line is too long, or if there are too many lines.
Returns DATError::Underflow
if there are too few lines.
Examples
use libxivdat::section::SectionData; use libxivdat::xiv_macro::MacroData; let mut sections = vec![ SectionData { content: "Title", content_size: 6, tag: "T" }, SectionData { content: "0000000", content_size: 8, tag: "I" }, SectionData { content: "000", content_size: 4, tag: "K" } ]; for line in std::iter::repeat("").take(15) { sections.push(SectionData { content: line, content_size: 1, tag: "L" }); } let result_macro = MacroData::from_section_data(sections).unwrap(); assert_eq!(result_macro.title, "Title");
pub fn from_section_data_unsafe(
sections: Vec<SectionData<'_>>
) -> Result<MacroData<'_>, DATError>
pub fn from_section_data_unsafe(
sections: Vec<SectionData<'_>>
) -> Result<MacroData<'_>, DATError>
Builds a MacroData
from a Vec
of SectionData
.
The expected pattern of section tags is “T” (Title), “I” (Icon), “K”, (Key), and repeating “L“s (Lines).
Valid macros always contain exactly 15 lines, even if their contents are blank. This library does not
strictly enforce this pattern, and will read lines until the next title.
This function does not check that the actual section content is valid. To perform validity checks,
use from_section_data()
.
Errors
Returns DATError::InvalidInput
if the sections are not provided in the order described above.
Examples
use libxivdat::section::SectionData; use libxivdat::xiv_macro::MacroData; let sections = vec![ SectionData { content: "Title", content_size: 6, tag: "T" }, SectionData { content: "0000000", content_size: 8, tag: "I" }, SectionData { content: "000", content_size: 4, tag: "K" }, SectionData { content: "A one line macro!?", content_size: 19, tag: "L" } ]; let result_macro = MacroData::from_section_data_unsafe(sections).unwrap(); assert_eq!(result_macro.title, "Title"); assert_eq!(result_macro.lines.len(), 1);
Gets the MacroIcon
correpsonding to the current icon_key
and icon_id
.
Returns None
if the id and key do not correspond to a known valid icon.
Examples
use libxivdat::xiv_macro::MacroData; use libxivdat::xiv_macro::icon::MacroIcon; let a_macro = MacroData::new( "Title", vec![""], &MacroIcon::SymbolArrowUp ).unwrap(); assert_eq!(a_macro.get_icon().unwrap(), MacroIcon::SymbolArrowUp);
Builds a new MacroData
with a given title, MacroIcon
, and content.
This ensures that the macro meets the spec described below, which is used
by the game client. If the provided line count is less than 15, the count
will be padded with blank lines.
To create an unvalidated MacroData
, you can directly
instantiate a struct literal.
Macro spec
Title: No more than 20 utf-8 characters.
Icon: Icon id and key are a matching pair corresponding to a valid MacroIcon
.
Lines: Exactly 15 lines of no more than 180 utf-8 characters.
Errors
Returns DATError::Overflow
if the title or content are too long, or if there
are too many lines.
Examples
use libxivdat::xiv_macro::MacroData; use libxivdat::xiv_macro::icon::MacroIcon; let a_macro = MacroData::new( "Title", vec!["Circle"], &MacroIcon::SymbolCircle ).unwrap(); assert_eq!(a_macro.title, "Title"); assert_eq!(a_macro.lines[0], "Circle"); assert_eq!(a_macro.get_icon().unwrap(), MacroIcon::SymbolCircle);
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for MacroData<'a>
impl<'a> UnwindSafe for MacroData<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more