make emotions named instead, add drop prop

This commit is contained in:
Evan Carroll 2026-01-13 16:49:07 -06:00
parent 989e20757b
commit ea3b444d71
19 changed files with 1429 additions and 150 deletions

View file

@ -42,24 +42,26 @@ pub async fn get_scene_by_id<'e>(
let scene = sqlx::query_as::<_, Scene>(
r#"
SELECT
id,
realm_id,
name,
slug,
description,
background_image_path,
background_color,
ST_AsText(bounds) as bounds_wkt,
dimension_mode,
ambient_audio_id,
ambient_volume,
sort_order,
is_entry_point,
is_hidden,
created_at,
updated_at
FROM realm.scenes
WHERE id = $1
s.id,
s.realm_id,
s.name,
s.slug,
s.description,
s.background_image_path,
s.background_color,
ST_AsText(s.bounds) as bounds_wkt,
s.dimension_mode,
s.ambient_audio_id,
s.ambient_volume,
s.sort_order,
s.is_entry_point,
s.is_hidden,
s.created_at,
s.updated_at,
c.id as default_channel_id
FROM realm.scenes s
LEFT JOIN realm.channels c ON c.scene_id = s.id AND c.channel_type = 'public'
WHERE s.id = $1
"#,
)
.bind(scene_id)
@ -78,24 +80,26 @@ pub async fn get_scene_by_slug<'e>(
let scene = sqlx::query_as::<_, Scene>(
r#"
SELECT
id,
realm_id,
name,
slug,
description,
background_image_path,
background_color,
ST_AsText(bounds) as bounds_wkt,
dimension_mode,
ambient_audio_id,
ambient_volume,
sort_order,
is_entry_point,
is_hidden,
created_at,
updated_at
FROM realm.scenes
WHERE realm_id = $1 AND slug = $2
s.id,
s.realm_id,
s.name,
s.slug,
s.description,
s.background_image_path,
s.background_color,
ST_AsText(s.bounds) as bounds_wkt,
s.dimension_mode,
s.ambient_audio_id,
s.ambient_volume,
s.sort_order,
s.is_entry_point,
s.is_hidden,
s.created_at,
s.updated_at,
c.id as default_channel_id
FROM realm.scenes s
LEFT JOIN realm.channels c ON c.scene_id = s.id AND c.channel_type = 'public'
WHERE s.realm_id = $1 AND s.slug = $2
"#,
)
.bind(realm_id)
@ -167,7 +171,8 @@ pub async fn create_scene<'e>(
is_entry_point,
is_hidden,
created_at,
updated_at
updated_at,
NULL::uuid as default_channel_id
"#,
)
.bind(realm_id)
@ -236,7 +241,8 @@ pub async fn create_scene_with_id<'e>(
is_entry_point,
is_hidden,
created_at,
updated_at
updated_at,
NULL::uuid as default_channel_id
"#,
)
.bind(scene_id)
@ -305,20 +311,27 @@ pub async fn update_scene<'e>(
// If no updates, just return the current scene
let query = if set_clauses.is_empty() {
r#"SELECT id, realm_id, name, slug, description, background_image_path,
background_color, ST_AsText(bounds) as bounds_wkt, dimension_mode,
ambient_audio_id, ambient_volume, sort_order, is_entry_point,
is_hidden, created_at, updated_at
FROM realm.scenes WHERE id = $1"#.to_string()
r#"SELECT s.id, s.realm_id, s.name, s.slug, s.description, s.background_image_path,
s.background_color, ST_AsText(s.bounds) as bounds_wkt, s.dimension_mode,
s.ambient_audio_id, s.ambient_volume, s.sort_order, s.is_entry_point,
s.is_hidden, s.created_at, s.updated_at, c.id as default_channel_id
FROM realm.scenes s
LEFT JOIN realm.channels c ON c.scene_id = s.id AND c.channel_type = 'public'
WHERE s.id = $1"#.to_string()
} else {
set_clauses.push("updated_at = now()".to_string());
format!(
r#"UPDATE realm.scenes SET {}
WHERE id = $1
RETURNING id, realm_id, name, slug, description, background_image_path,
background_color, ST_AsText(bounds) as bounds_wkt, dimension_mode,
ambient_audio_id, ambient_volume, sort_order, is_entry_point,
is_hidden, created_at, updated_at"#,
r#"WITH updated AS (
UPDATE realm.scenes SET {}
WHERE id = $1
RETURNING id, realm_id, name, slug, description, background_image_path,
background_color, ST_AsText(bounds) as bounds_wkt, dimension_mode,
ambient_audio_id, ambient_volume, sort_order, is_entry_point,
is_hidden, created_at, updated_at
)
SELECT u.*, c.id as default_channel_id
FROM updated u
LEFT JOIN realm.channels c ON c.scene_id = u.id AND c.channel_type = 'public'"#,
set_clauses.join(", ")
)
};
@ -399,37 +412,42 @@ pub async fn get_next_sort_order<'e>(
/// 1. The scene specified by `default_scene_id` on the realm (if provided and exists)
/// 2. The first scene marked as `is_entry_point`
/// 3. The first scene by sort_order
///
/// Also includes the default public channel ID for the scene.
pub async fn get_entry_scene_for_realm<'e>(
executor: impl PgExecutor<'e>,
realm_id: Uuid,
default_scene_id: Option<Uuid>,
) -> Result<Option<Scene>, AppError> {
// Use a single query that handles the priority in SQL
// Joins with channels to get the default public channel for the scene
let scene = sqlx::query_as::<_, Scene>(
r#"
SELECT
id,
realm_id,
name,
slug,
description,
background_image_path,
background_color,
ST_AsText(bounds) as bounds_wkt,
dimension_mode,
ambient_audio_id,
ambient_volume,
sort_order,
is_entry_point,
is_hidden,
created_at,
updated_at
FROM realm.scenes
WHERE realm_id = $1 AND is_hidden = false
s.id,
s.realm_id,
s.name,
s.slug,
s.description,
s.background_image_path,
s.background_color,
ST_AsText(s.bounds) as bounds_wkt,
s.dimension_mode,
s.ambient_audio_id,
s.ambient_volume,
s.sort_order,
s.is_entry_point,
s.is_hidden,
s.created_at,
s.updated_at,
c.id as default_channel_id
FROM realm.scenes s
LEFT JOIN realm.channels c ON c.scene_id = s.id AND c.channel_type = 'public'
WHERE s.realm_id = $1 AND s.is_hidden = false
ORDER BY
CASE WHEN id = $2 THEN 0 ELSE 1 END,
is_entry_point DESC,
sort_order ASC
CASE WHEN s.id = $2 THEN 0 ELSE 1 END,
s.is_entry_point DESC,
s.sort_order ASC
LIMIT 1
"#,
)