Files
cursebreaker-parser-rust/cursebreaker-parser/README.md
2026-01-08 06:37:04 +00:00

3.6 KiB

Cursebreaker Parser

A Rust library for parsing and managing game data from the Cursebreaker game. This crate provides tools to extract, load, and query game data from Unity scenes and XML files.

Overview

Cursebreaker Parser is designed to:

  • Parse Unity scenes and extract game objects using the unity-parser library
  • Load game data from XML files (Items, NPCs, Quests, Harvestables, Loot tables)
  • Provide in-memory databases for efficient querying of game data
  • Serialize game data to SQL format for database storage

Features

  • Item Database: Load and query items with support for filtering by ID, category, slot, and other attributes
  • NPC Database: Manage NPC data including stats, levels, animations, and quest markers
  • Quest Database: Handle quest definitions, phases, and rewards
  • Harvestable Database: Track harvestable resources and their drop tables
  • Loot Database: Manage loot tables and drop configurations
  • XML Parsing: Robust XML parsing with error handling
  • SQL Export: Prepare data for SQL database insertion

Usage

Loading Items from XML

use cursebreaker_parser::ItemDatabase;

// Load all items from XML
let item_db = ItemDatabase::load_from_xml("Data/XMLs/Items/Items.xml")?;
println!("Loaded {} items", item_db.len());

// Get item by ID
if let Some(item) = item_db.get_by_id(150) {
    println!("Found: {}", item.name);
}

// Query items by category
let weapons = item_db.get_by_category("bow");
println!("Found {} bows", weapons.len());

// Query items by slot
let consumables = item_db.get_by_slot("consumable");
for item in consumables {
    println!("Consumable: {}", item.name);
}

Preparing Data for SQL

use cursebreaker_parser::ItemDatabase;

let item_db = ItemDatabase::load_from_xml("Data/XMLs/Items/Items.xml")?;

// Prepare data for SQL insertion
// Returns Vec<(id, name, json_data)>
let sql_data = item_db.prepare_for_sql();

for (id, name, json) in sql_data.iter().take(5) {
    println!("INSERT INTO items VALUES ({}, '{}', '{}')", id, name, json);
}

Project Structure

cursebreaker-parser/
├── src/
│   ├── lib.rs              # Library entry point and public API
│   ├── main.rs             # Binary entry point
│   ├── xml_parser.rs       # XML parsing utilities
│   ├── item_loader.rs      # Item loading logic
│   ├── databases/          # Database implementations
│   │   ├── item_database.rs
│   │   ├── npc_database.rs
│   │   ├── quest_database.rs
│   │   ├── harvestable_database.rs
│   │   └── loot_database.rs
│   └── types/              # Type definitions
│       ├── cursebreaker/   # Game-specific types (Items, NPCs, Quests, etc.)
│       └── monobehaviours/ # Unity MonoBehaviour types
├── examples/               # Example usage
├── Cargo.toml             # Package configuration
└── XML_PARSING.md         # XML parsing documentation

Dependencies

  • unity-parser: For parsing Unity scene files
  • quick-xml: XML parsing
  • serde: Serialization/deserialization
  • serde_json: JSON support
  • serde_yaml: YAML support
  • sparsey: ECS (Entity Component System) support
  • diesel: Optional SQL database support
  • thiserror: Error handling

Building

# Build the library
cargo build

# Run tests
cargo test

# Build with SQL support
cargo build --features diesel

Documentation

For detailed XML parsing information, see XML_PARSING.md.

Generate API documentation:

cargo doc --open