Skip to main content

Crate wow_sharedmedia

Crate wow_sharedmedia 

Source
Expand description

§wow-sharedmedia

A Rust library for building World of Warcraft addons that register media assets — fonts, textures, sounds, borders, and statusbars — with LibSharedMedia-3.0.

§Overview

wow-sharedmedia provides stateless, one-shot operations for:

  • Importing media files (PNG, TGA, WebP, JPEG, BLP, TTF, OTF, OGG, MP3, WAV) with automatic format conversion to WoW-compatible formats.
  • Removing media entries and their associated files.
  • Updating entry metadata (display key, tags, locale masks).
  • Reading the addon’s data.lua file into a typed Rust struct.

Each operation is atomic: read data.lua → modify → write data.lua. No in-memory state, no dirty tracking, no separate save/generate/deploy steps.

§Installation

[dependencies]
wow-sharedmedia = "0.2"

§Quick Start

use wow_sharedmedia::{ensure_addon_dir, import_media, read_data, ImportOptions, MediaType, DEFAULT_MAX_BACKUPS};
use std::path::Path;

fn main() -> Result<(), wow_sharedmedia::Error> {

// Initialize addon directory (creates data.lua, loader.lua, .toc, media/ subdirs)
let addon_dir = Path::new("AddOns/MyMedia");
ensure_addon_dir(addon_dir, DEFAULT_MAX_BACKUPS)?;

// Import a statusbar texture
let source = Path::new("assets/my-statusbar.png");
let opts = ImportOptions::new(MediaType::Statusbar, "My Bar", &source);
let result = import_media(addon_dir, opts, DEFAULT_MAX_BACKUPS)?;
println!("Imported: {} (ID: {})", result.entry.key, result.entry.id);

// Read all entries
let data = read_data(addon_dir)?;
for entry in &data.entries {
    println!("  {} [{}] → {}", entry.key, entry.media_type, entry.file);
}

Ok(())
}

§Addon Directory Structure

After ensure_addon_dir, the directory layout is driven by the folder name. For a folder named MyMedia:

MyMedia/
├── MyMedia.toc       # WoW addon manifest (auto-generated)
├── data.lua           # Media registry (Lua table, single source of truth)
├── loader.lua         # LSM registration script (auto-generated)
├── libraries/         # Vendored LibSharedMedia-3.0 dependencies
└── media/
    ├── statusbar/    # TGA texture files
    ├── background/   # TGA texture files
    ├── border/       # TGA texture files
    ├── font/         # TTF/OTF font files
    └── sound/        # OGG audio files

If the folder name starts with ! (e.g. !!!MyMedia), the .toc file will be !!!MyMedia.toc but the in-addon title will strip the leading ! characters (e.g. MyMedia).

Modules§

converter
Format conversion modules.
template
Addon template management for loader.lua and .toc.

Structs§

AddonData
Top-level data structure persisted in data.lua.
EntryMetadata
Type-specific metadata extracted at import time.
ImportOptions
Options for importing a media file.
ImportResult
Result of an import operation.
ImportWarning
Non-fatal warning from import.
MediaEntry
A single media entry in the addon registry.
RemovedEntry
Result of a remove operation.
UpdateOptions
Options for updating an existing entry.

Enums§

Error
Core error type for the wow-sharedmedia library.
MediaType
Media type enumeration for LibSharedMedia categories.

Constants§

DEFAULT_MAX_BACKUPS
Default maximum number of backup files retained per write.
SCHEMA_VERSION
Current data.lua schema version.

Functions§

addon_name
Extract the addon name from its directory path.
addon_title
Derive the human-readable addon title from the addon name.
ensure_addon_dir
Initialize a LibSharedMedia-compatible addon directory.
import_media
Import a media file into the addon registry.
read_data
Read the current addon registry from data.lua.
remove_media
Remove a media entry: ensure addon exists → delete file → remove entry → write data.lua.
update_media
Update entry metadata: ensure addon exists → modify in memory → write data.lua.