feat: work on windows resizing

This commit is contained in:
2026-04-23 09:11:01 +02:00
parent 9d181f3676
commit 3fb8e23c07
15 changed files with 1286 additions and 114 deletions

View File

@ -60,6 +60,22 @@ pub fn migrate(conn: &Connection) -> Result<()> {
key TEXT PRIMARY KEY,
value TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS quest_step_progress (
profile_id TEXT NOT NULL,
quest_name TEXT NOT NULL,
step_index INTEGER NOT NULL,
PRIMARY KEY (profile_id, quest_name, step_index),
FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS resource_inventory (
profile_id TEXT NOT NULL,
resource_name TEXT NOT NULL,
quantity INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (profile_id, resource_name),
FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE
);
")?;
Ok(())
}
@ -145,6 +161,62 @@ pub fn get_guides(conn: &Connection) -> Result<Vec<GuideRow>> {
rows.collect()
}
pub fn get_completed_steps(conn: &Connection, profile_id: &str, quest_name: &str) -> Result<Vec<i64>> {
let mut stmt = conn.prepare(
"SELECT step_index FROM quest_step_progress WHERE profile_id = ?1 AND quest_name = ?2"
)?;
let rows = stmt.query_map(params![profile_id, quest_name], |row| row.get(0))?;
rows.collect()
}
pub fn toggle_quest_step(conn: &Connection, profile_id: &str, quest_name: &str, step_index: i64) -> Result<bool> {
let exists: bool = conn.query_row(
"SELECT COUNT(*) FROM quest_step_progress WHERE profile_id = ?1 AND quest_name = ?2 AND step_index = ?3",
params![profile_id, quest_name, step_index],
|row| row.get::<_, i64>(0),
).map(|c| c > 0)?;
if exists {
conn.execute(
"DELETE FROM quest_step_progress WHERE profile_id = ?1 AND quest_name = ?2 AND step_index = ?3",
params![profile_id, quest_name, step_index],
)?;
Ok(false)
} else {
conn.execute(
"INSERT INTO quest_step_progress (profile_id, quest_name, step_index) VALUES (?1, ?2, ?3)",
params![profile_id, quest_name, step_index],
)?;
Ok(true)
}
}
pub fn get_resource_inventory(conn: &Connection, profile_id: &str) -> Result<Vec<(String, i64)>> {
let mut stmt = conn.prepare(
"SELECT resource_name, quantity FROM resource_inventory WHERE profile_id = ?1"
)?;
let rows = stmt.query_map(params![profile_id], |row| {
Ok((row.get::<_, String>(0)?, row.get::<_, i64>(1)?))
})?;
rows.collect()
}
pub fn set_resource_quantity(conn: &Connection, profile_id: &str, resource_name: &str, quantity: i64) -> Result<()> {
if quantity <= 0 {
conn.execute(
"DELETE FROM resource_inventory WHERE profile_id = ?1 AND resource_name = ?2",
params![profile_id, resource_name],
)?;
} else {
conn.execute(
"INSERT INTO resource_inventory (profile_id, resource_name, quantity) VALUES (?1, ?2, ?3)
ON CONFLICT(profile_id, resource_name) DO UPDATE SET quantity=excluded.quantity",
params![profile_id, resource_name, quantity],
)?;
}
Ok(())
}
pub fn get_setting(conn: &Connection, key: &str) -> Option<String> {
conn.query_row(
"SELECT value FROM settings WHERE key = ?1",