feat: add puzzle clear template runtime
This commit is contained in:
88
server-rs/crates/spacetime-module/src/puzzle_clear/tables.rs
Normal file
88
server-rs/crates/spacetime-module/src/puzzle_clear/tables.rs
Normal file
@@ -0,0 +1,88 @@
|
||||
use crate::*;
|
||||
|
||||
const WORK_VISIBLE_DEFAULT: bool = true;
|
||||
|
||||
#[spacetimedb::table(
|
||||
accessor = puzzle_clear_agent_session,
|
||||
index(accessor = by_puzzle_clear_agent_session_owner_user_id, btree(columns = [owner_user_id]))
|
||||
)]
|
||||
pub struct PuzzleClearAgentSessionRow {
|
||||
#[primary_key]
|
||||
pub(crate) session_id: String,
|
||||
pub(crate) owner_user_id: String,
|
||||
pub(crate) status: String,
|
||||
pub(crate) draft_json: String,
|
||||
pub(crate) published_profile_id: String,
|
||||
pub(crate) created_at: Timestamp,
|
||||
pub(crate) updated_at: Timestamp,
|
||||
}
|
||||
|
||||
#[spacetimedb::table(
|
||||
accessor = puzzle_clear_work_profile,
|
||||
index(accessor = by_puzzle_clear_work_owner_user_id, btree(columns = [owner_user_id])),
|
||||
index(accessor = by_puzzle_clear_work_publication_status, btree(columns = [publication_status]))
|
||||
)]
|
||||
pub struct PuzzleClearWorkProfileRow {
|
||||
#[primary_key]
|
||||
pub(crate) profile_id: String,
|
||||
pub(crate) work_id: String,
|
||||
pub(crate) owner_user_id: String,
|
||||
pub(crate) source_session_id: String,
|
||||
pub(crate) author_display_name: String,
|
||||
pub(crate) work_title: String,
|
||||
pub(crate) work_description: String,
|
||||
pub(crate) theme_prompt: String,
|
||||
pub(crate) generate_board_background: bool,
|
||||
pub(crate) board_background_asset_json: String,
|
||||
#[default(None::<String>)]
|
||||
pub(crate) board_background_prompt: Option<String>,
|
||||
pub(crate) card_back_image_src: String,
|
||||
pub(crate) atlas_asset_json: String,
|
||||
pub(crate) pattern_groups_json: String,
|
||||
pub(crate) card_assets_json: String,
|
||||
pub(crate) cover_image_src: String,
|
||||
pub(crate) generation_status: String,
|
||||
pub(crate) publication_status: String,
|
||||
pub(crate) play_count: u32,
|
||||
pub(crate) updated_at: Timestamp,
|
||||
pub(crate) published_at: Option<Timestamp>,
|
||||
// 中文注释:后台可见性开关,隐藏后不进入公开列表。
|
||||
#[default(WORK_VISIBLE_DEFAULT)]
|
||||
pub(crate) visible: bool,
|
||||
}
|
||||
|
||||
#[spacetimedb::table(
|
||||
accessor = puzzle_clear_runtime_run,
|
||||
index(accessor = by_puzzle_clear_run_owner_user_id, btree(columns = [owner_user_id])),
|
||||
index(accessor = by_puzzle_clear_run_profile_id, btree(columns = [profile_id]))
|
||||
)]
|
||||
pub struct PuzzleClearRuntimeRunRow {
|
||||
#[primary_key]
|
||||
pub(crate) run_id: String,
|
||||
pub(crate) owner_user_id: String,
|
||||
pub(crate) profile_id: String,
|
||||
pub(crate) status: String,
|
||||
pub(crate) level_index: u32,
|
||||
pub(crate) clears_done: u32,
|
||||
pub(crate) snapshot_json: String,
|
||||
pub(crate) started_at_ms: i64,
|
||||
pub(crate) finished_at_ms: i64,
|
||||
pub(crate) created_at: Timestamp,
|
||||
pub(crate) updated_at: Timestamp,
|
||||
}
|
||||
|
||||
#[spacetimedb::table(
|
||||
accessor = puzzle_clear_event,
|
||||
index(accessor = by_puzzle_clear_event_profile_id, btree(columns = [profile_id])),
|
||||
index(accessor = by_puzzle_clear_event_run_id, btree(columns = [run_id]))
|
||||
)]
|
||||
pub struct PuzzleClearEventRow {
|
||||
#[primary_key]
|
||||
pub(crate) event_id: String,
|
||||
pub(crate) owner_user_id: String,
|
||||
pub(crate) profile_id: String,
|
||||
pub(crate) run_id: String,
|
||||
pub(crate) event_type: String,
|
||||
pub(crate) result: String,
|
||||
pub(crate) occurred_at: Timestamp,
|
||||
}
|
||||
304
server-rs/crates/spacetime-module/src/puzzle_clear/types.rs
Normal file
304
server-rs/crates/spacetime-module/src/puzzle_clear/types.rs
Normal file
@@ -0,0 +1,304 @@
|
||||
use crate::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const PUZZLE_CLEAR_TEMPLATE_ID: &str = "puzzle-clear";
|
||||
pub const PUZZLE_CLEAR_TEMPLATE_NAME: &str = "拼消消";
|
||||
pub const PUZZLE_CLEAR_PUBLICATION_DRAFT: &str = "draft";
|
||||
pub const PUZZLE_CLEAR_PUBLICATION_PUBLISHED: &str = "published";
|
||||
pub const PUZZLE_CLEAR_GENERATION_DRAFT: &str = "draft";
|
||||
pub const PUZZLE_CLEAR_GENERATION_READY: &str = "ready";
|
||||
pub const PUZZLE_CLEAR_GENERATION_FAILED: &str = "failed";
|
||||
pub const PUZZLE_CLEAR_CARD_BACK_IMAGE_SRC: &str = "/creation-type-references/puzzle.webp";
|
||||
pub const PUZZLE_CLEAR_EVENT_RUN_STARTED: &str = "run-started";
|
||||
pub const PUZZLE_CLEAR_EVENT_SWAP: &str = "swap";
|
||||
pub const PUZZLE_CLEAR_EVENT_RETRY_LEVEL: &str = "retry-level";
|
||||
pub const PUZZLE_CLEAR_EVENT_NEXT_LEVEL: &str = "next-level";
|
||||
pub const PUZZLE_CLEAR_EVENT_TIME_UP: &str = "time-up";
|
||||
pub const PUZZLE_CLEAR_EVENT_LEVEL_COMPLETED: &str = "level-completed";
|
||||
pub const PUZZLE_CLEAR_EVENT_RUN_FINISHED: &str = "run-finished";
|
||||
pub const PUZZLE_CLEAR_EVENT_LEVEL_FAILED: &str = "level-failed";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearAgentSessionCreateInput {
|
||||
pub session_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub work_title: String,
|
||||
pub work_description: String,
|
||||
pub theme_prompt: String,
|
||||
pub generate_board_background: bool,
|
||||
pub board_background_asset_json: Option<String>,
|
||||
pub board_background_prompt: String,
|
||||
pub created_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearAgentSessionGetInput {
|
||||
pub session_id: String,
|
||||
pub owner_user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearDraftCompileInput {
|
||||
pub session_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub profile_id: String,
|
||||
pub author_display_name: String,
|
||||
pub work_title: String,
|
||||
pub work_description: String,
|
||||
pub theme_prompt: String,
|
||||
pub generate_board_background: bool,
|
||||
pub board_background_asset_json: Option<String>,
|
||||
pub board_background_prompt: String,
|
||||
pub atlas_asset_json: Option<String>,
|
||||
pub pattern_groups_json: Option<String>,
|
||||
pub card_assets_json: Option<String>,
|
||||
pub generation_status: Option<String>,
|
||||
pub compiled_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearWorkUpdateInput {
|
||||
pub profile_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub work_title: String,
|
||||
pub work_description: String,
|
||||
pub theme_prompt: String,
|
||||
pub generate_board_background: bool,
|
||||
pub board_background_asset_json: Option<String>,
|
||||
pub board_background_prompt: String,
|
||||
pub updated_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearWorkPublishInput {
|
||||
pub profile_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub published_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearWorksListInput {
|
||||
pub owner_user_id: String,
|
||||
pub published_only: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearWorkGetInput {
|
||||
pub profile_id: String,
|
||||
pub owner_user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearRunStartInput {
|
||||
pub run_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub profile_id: String,
|
||||
pub client_event_id: String,
|
||||
pub started_at_ms: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearRunGetInput {
|
||||
pub run_id: String,
|
||||
pub owner_user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearRunSwapInput {
|
||||
pub run_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub from_row: u32,
|
||||
pub from_col: u32,
|
||||
pub to_row: u32,
|
||||
pub to_col: u32,
|
||||
pub client_action_id: String,
|
||||
pub swapped_at_ms: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearRunRetryLevelInput {
|
||||
pub run_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub client_action_id: String,
|
||||
pub restarted_at_ms: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearRunNextLevelInput {
|
||||
pub run_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub client_action_id: String,
|
||||
pub started_at_ms: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub struct PuzzleClearRunTimeUpInput {
|
||||
pub run_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub client_action_id: String,
|
||||
pub occurred_at_ms: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, SpacetimeType)]
|
||||
pub struct PuzzleClearAgentSessionProcedureResult {
|
||||
pub ok: bool,
|
||||
pub session: Option<PuzzleClearAgentSessionSnapshot>,
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, SpacetimeType)]
|
||||
pub struct PuzzleClearWorkProcedureResult {
|
||||
pub ok: bool,
|
||||
pub work: Option<PuzzleClearWorkSnapshot>,
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, SpacetimeType)]
|
||||
pub struct PuzzleClearWorksProcedureResult {
|
||||
pub ok: bool,
|
||||
pub items: Vec<PuzzleClearWorkSnapshot>,
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, SpacetimeType)]
|
||||
pub struct PuzzleClearRunProcedureResult {
|
||||
pub ok: bool,
|
||||
pub run: Option<PuzzleClearRuntimeSnapshot>,
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PuzzleClearImageAssetSnapshot {
|
||||
pub asset_id: String,
|
||||
pub image_src: String,
|
||||
pub image_object_key: String,
|
||||
pub asset_object_id: String,
|
||||
pub generation_provider: String,
|
||||
pub prompt: String,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PuzzleClearPatternGroupSnapshot {
|
||||
pub group_id: String,
|
||||
pub shape: String,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub atlas_x: u32,
|
||||
pub atlas_y: u32,
|
||||
pub atlas_width: u32,
|
||||
pub atlas_height: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PuzzleClearCardAssetSnapshot {
|
||||
pub card_id: String,
|
||||
pub group_id: String,
|
||||
pub shape: String,
|
||||
pub orientation: String,
|
||||
pub part_x: u32,
|
||||
pub part_y: u32,
|
||||
pub image_src: String,
|
||||
pub image_object_key: String,
|
||||
pub asset_object_id: String,
|
||||
pub source_atlas_cell: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PuzzleClearDraftSnapshot {
|
||||
pub template_id: String,
|
||||
pub template_name: String,
|
||||
pub profile_id: Option<String>,
|
||||
pub work_title: String,
|
||||
pub work_description: String,
|
||||
pub theme_prompt: String,
|
||||
pub generate_board_background: bool,
|
||||
pub board_background_asset: Option<PuzzleClearImageAssetSnapshot>,
|
||||
#[serde(default)]
|
||||
pub board_background_prompt: String,
|
||||
pub card_back_image_src: Option<String>,
|
||||
pub atlas_asset: Option<PuzzleClearImageAssetSnapshot>,
|
||||
pub pattern_groups: Vec<PuzzleClearPatternGroupSnapshot>,
|
||||
pub card_assets: Vec<PuzzleClearCardAssetSnapshot>,
|
||||
pub generation_status: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PuzzleClearAgentSessionSnapshot {
|
||||
pub session_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub status: String,
|
||||
pub draft: Option<PuzzleClearDraftSnapshot>,
|
||||
pub published_profile_id: Option<String>,
|
||||
pub created_at_micros: i64,
|
||||
pub updated_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PuzzleClearWorkSnapshot {
|
||||
pub work_id: String,
|
||||
pub profile_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub source_session_id: String,
|
||||
pub author_display_name: String,
|
||||
pub work_title: String,
|
||||
pub work_description: String,
|
||||
pub theme_prompt: String,
|
||||
pub generate_board_background: bool,
|
||||
pub board_background_asset: Option<PuzzleClearImageAssetSnapshot>,
|
||||
#[serde(default)]
|
||||
pub board_background_prompt: String,
|
||||
pub card_back_image_src: Option<String>,
|
||||
pub atlas_asset: PuzzleClearImageAssetSnapshot,
|
||||
pub pattern_groups: Vec<PuzzleClearPatternGroupSnapshot>,
|
||||
pub card_assets: Vec<PuzzleClearCardAssetSnapshot>,
|
||||
pub cover_image_src: Option<String>,
|
||||
pub publication_status: String,
|
||||
pub publish_ready: bool,
|
||||
pub play_count: u32,
|
||||
pub generation_status: String,
|
||||
pub updated_at_micros: i64,
|
||||
pub published_at_micros: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PuzzleClearBoardCellSnapshot {
|
||||
pub row: u32,
|
||||
pub col: u32,
|
||||
pub card: Option<PuzzleClearCardAssetSnapshot>,
|
||||
pub locked_group_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PuzzleClearBoardSnapshot {
|
||||
pub rows: u32,
|
||||
pub cols: u32,
|
||||
pub cells: Vec<PuzzleClearBoardCellSnapshot>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SpacetimeType)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PuzzleClearRuntimeSnapshot {
|
||||
pub run_id: String,
|
||||
pub profile_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub status: String,
|
||||
pub level_index: u32,
|
||||
pub clears_done: u32,
|
||||
pub target_clears: u32,
|
||||
pub level_duration_seconds: u32,
|
||||
pub level_started_at_ms: u64,
|
||||
pub board: PuzzleClearBoardSnapshot,
|
||||
pub ready_columns: Vec<Vec<PuzzleClearCardAssetSnapshot>>,
|
||||
pub started_at_ms: u64,
|
||||
pub finished_at_ms: Option<u64>,
|
||||
}
|
||||
Reference in New Issue
Block a user