141 lines
4.2 KiB
Rust
141 lines
4.2 KiB
Rust
//! Example: Query world objects from the database
|
|
//!
|
|
//! Run with: cargo run --example verify_world_objects
|
|
|
|
use diesel::prelude::*;
|
|
use diesel::sqlite::SqliteConnection;
|
|
use std::env;
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
// Connect to database
|
|
let database_url = env::var("DATABASE_URL").unwrap_or_else(|_| "../cursebreaker.db".to_string());
|
|
let mut conn = SqliteConnection::establish(&database_url)?;
|
|
|
|
// Query teleporters
|
|
{
|
|
use cursebreaker_parser::schema::world_teleporters::dsl::*;
|
|
|
|
#[derive(Queryable, Debug)]
|
|
struct Teleporter {
|
|
pos_x: f32,
|
|
pos_y: f32,
|
|
tp_x: Option<f32>,
|
|
tp_y: Option<f32>,
|
|
}
|
|
|
|
let results = world_teleporters.load::<Teleporter>(&mut conn)?;
|
|
println!("=== World Teleporters ===");
|
|
println!("Found {} teleporters\n", results.len());
|
|
for tp in results {
|
|
print!(" At ({:.2}, {:.2})", tp.pos_x, tp.pos_y);
|
|
if let (Some(tx), Some(ty)) = (tp.tp_x, tp.tp_y) {
|
|
println!(" -> teleports to ({:.2}, {:.2})", tx, ty);
|
|
} else {
|
|
println!(" -> no destination");
|
|
}
|
|
}
|
|
println!();
|
|
}
|
|
|
|
// Query workbenches
|
|
{
|
|
use cursebreaker_parser::schema::world_workbenches::dsl::*;
|
|
|
|
#[derive(Queryable, Debug)]
|
|
struct Workbench {
|
|
pos_x: f32,
|
|
pos_y: f32,
|
|
workbench_id: i32,
|
|
}
|
|
|
|
let results = world_workbenches.load::<Workbench>(&mut conn)?;
|
|
println!("=== World Workbenches ===");
|
|
println!("Found {} workbenches\n", results.len());
|
|
for wb in results {
|
|
println!(" Workbench ID {} at ({:.2}, {:.2})", wb.workbench_id, wb.pos_x, wb.pos_y);
|
|
}
|
|
println!();
|
|
}
|
|
|
|
// Query loot spawners
|
|
{
|
|
use cursebreaker_parser::schema::world_loot::dsl::*;
|
|
|
|
#[derive(Queryable, Debug)]
|
|
struct Loot {
|
|
pos_x: f32,
|
|
pos_y: f32,
|
|
item_id: i32,
|
|
amount: i32,
|
|
respawn_time: i32,
|
|
visibility_checks: String,
|
|
}
|
|
|
|
let results = world_loot.load::<Loot>(&mut conn)?;
|
|
println!("=== World Loot ===");
|
|
println!("Found {} loot spawners\n", results.len());
|
|
for loot in results {
|
|
println!(" Item {} x{} (respawn: {}s) at ({:.2}, {:.2})",
|
|
loot.item_id, loot.amount, loot.respawn_time, loot.pos_x, loot.pos_y);
|
|
if !loot.visibility_checks.is_empty() {
|
|
println!(" Visibility checks: {}", loot.visibility_checks);
|
|
}
|
|
}
|
|
println!();
|
|
}
|
|
|
|
// Query map icons
|
|
{
|
|
use cursebreaker_parser::schema::world_map_icons::dsl::*;
|
|
|
|
#[derive(Queryable, Debug)]
|
|
struct MapIcon {
|
|
pos_x: f32,
|
|
pos_y: f32,
|
|
icon_type: i32,
|
|
icon_size: i32,
|
|
icon: String,
|
|
text: String,
|
|
font_size: i32,
|
|
hover_text: String,
|
|
}
|
|
|
|
let results = world_map_icons.load::<MapIcon>(&mut conn)?;
|
|
println!("=== World Map Icons ===");
|
|
println!("Found {} map icons\n", results.len());
|
|
for map_icon in results {
|
|
print!(" Type {} at ({:.2}, {:.2})", map_icon.icon_type, map_icon.pos_x, map_icon.pos_y);
|
|
if !map_icon.text.is_empty() {
|
|
print!(" - Text: \"{}\"", map_icon.text);
|
|
}
|
|
if !map_icon.hover_text.is_empty() {
|
|
print!(" - Hover: \"{}\"", map_icon.hover_text);
|
|
}
|
|
println!();
|
|
}
|
|
println!();
|
|
}
|
|
|
|
// Query map name changers
|
|
{
|
|
use cursebreaker_parser::schema::world_map_name_changers::dsl::*;
|
|
|
|
#[derive(Queryable, Debug)]
|
|
struct MapNameChanger {
|
|
pos_x: f32,
|
|
pos_y: f32,
|
|
map_name: String,
|
|
}
|
|
|
|
let results = world_map_name_changers.load::<MapNameChanger>(&mut conn)?;
|
|
println!("=== World Map Name Changers ===");
|
|
println!("Found {} map name changers\n", results.len());
|
|
for changer in results {
|
|
println!(" \"{}\" at ({:.2}, {:.2})", changer.map_name, changer.pos_x, changer.pos_y);
|
|
}
|
|
println!();
|
|
}
|
|
|
|
Ok(())
|
|
}
|