restructure

This commit is contained in:
2026-01-08 06:37:04 +00:00
parent db45105d90
commit d2bbd3e5f6
17 changed files with 179 additions and 43 deletions

View File

@@ -0,0 +1,121 @@
# 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
```rust
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
```rust
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
```bash
# 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](XML_PARSING.md).
Generate API documentation:
```bash
cargo doc --open
```

View File

@@ -0,0 +1,11 @@
mod item_database;
mod npc_database;
mod quest_database;
mod harvestable_database;
mod loot_database;
pub use item_database::ItemDatabase;
pub use npc_database::NpcDatabase;
pub use quest_database::QuestDatabase;
pub use harvestable_database::HarvestableDatabase;
pub use loot_database::LootDatabase;

View File

@@ -50,19 +50,17 @@
//! ``` //! ```
pub mod types; pub mod types;
pub mod databases;
mod xml_parser; mod xml_parser;
mod item_loader; mod item_loader;
mod item_database;
mod npc_database;
mod quest_database;
mod harvestable_database;
mod loot_database;
pub use item_database::ItemDatabase; pub use databases::{
pub use npc_database::NpcDatabase; ItemDatabase,
pub use quest_database::QuestDatabase; NpcDatabase,
pub use harvestable_database::HarvestableDatabase; QuestDatabase,
pub use loot_database::LootDatabase; HarvestableDatabase,
LootDatabase,
};
pub use types::{ pub use types::{
// Items // Items
Item, Item,

View File

@@ -0,0 +1,32 @@
mod item;
mod npc;
mod quest;
mod harvestable;
mod loot;
pub use item::{
// Main types
Item,
ItemStat,
CraftingRecipe,
CraftingRecipeItem,
AnimationSet,
GenerateRule,
// Enums
ItemType,
ItemCategory,
Tool,
SkillType,
StatType,
// Nested structs
Stat,
ItemXpBoost,
PermanentStatBoost,
CustomItemName,
// Constants
MAX_STACK,
};
pub use npc::{Npc, NpcStat, NpcLevel, RightClick, BarkGroup, Bark, QuestMarker, NpcAnimationSet};
pub use quest::{Quest, QuestPhase, QuestReward};
pub use harvestable::{Harvestable, HarvestableDrop};
pub use loot::{LootTable, LootDrop};

View File

@@ -1,34 +1,5 @@
mod interactable_resource; pub mod monobehaviours;
mod item; pub mod cursebreaker;
mod npc;
mod quest;
mod harvestable;
mod loot;
pub use interactable_resource::InteractableResource; pub use monobehaviours::*;
pub use item::{ pub use cursebreaker::*;
// Main types
Item,
ItemStat,
CraftingRecipe,
CraftingRecipeItem,
AnimationSet,
GenerateRule,
// Enums
ItemType,
ItemCategory,
Tool,
SkillType,
StatType,
// Nested structs
Stat,
ItemXpBoost,
PermanentStatBoost,
CustomItemName,
// Constants
MAX_STACK,
};
pub use npc::{Npc, NpcStat, NpcLevel, RightClick, BarkGroup, Bark, QuestMarker, NpcAnimationSet};
pub use quest::{Quest, QuestPhase, QuestReward};
pub use harvestable::{Harvestable, HarvestableDrop};
pub use loot::{LootTable, LootDrop};

View File

@@ -0,0 +1,3 @@
mod interactable_resource;
pub use interactable_resource::InteractableResource;