This commit is contained in:
2026-04-27 22:50:18 +08:00
parent ded6f6ee2a
commit b6c6640548
77 changed files with 5240 additions and 833 deletions

View File

@@ -31,7 +31,8 @@ pub use mapper::{
PuzzleAgentSuggestedActionRecord, PuzzleAnchorItemRecord, PuzzleAnchorPackRecord,
PuzzleBoardRecord, PuzzleCellPositionRecord, PuzzleCreatorIntentRecord,
PuzzleGeneratedImageCandidateRecord, PuzzleGeneratedImagesSaveRecordInput,
PuzzleMergedGroupRecord, PuzzlePieceStateRecord, PuzzlePublishRecordInput,
PuzzleLeaderboardEntryRecord, PuzzleLeaderboardSubmitRecordInput, PuzzleMergedGroupRecord,
PuzzlePieceStateRecord, PuzzlePublishRecordInput,
PuzzleResultDraftRecord, PuzzleResultPreviewBlockerRecord, PuzzleResultPreviewFindingRecord,
PuzzleResultPreviewRecord, PuzzleRunDragRecordInput, PuzzleRunNextLevelRecordInput,
PuzzleRunRecord, PuzzleRunStartRecordInput, PuzzleRunSwapRecordInput, PuzzleRuntimeLevelRecord,

View File

@@ -2272,6 +2272,11 @@ pub(crate) fn map_puzzle_run_snapshot(snapshot: DomainPuzzleRunSnapshot) -> Puzz
.current_level
.map(map_puzzle_runtime_level_snapshot),
recommended_next_profile_id: snapshot.recommended_next_profile_id,
leaderboard_entries: snapshot
.leaderboard_entries
.into_iter()
.map(map_puzzle_leaderboard_entry)
.collect(),
}
}
@@ -2289,6 +2294,25 @@ pub(crate) fn map_puzzle_runtime_level_snapshot(
cover_image_src: snapshot.cover_image_src,
board: map_puzzle_board_snapshot(snapshot.board),
status: snapshot.status.as_str().to_string(),
started_at_ms: snapshot.started_at_ms,
cleared_at_ms: snapshot.cleared_at_ms,
elapsed_ms: snapshot.elapsed_ms,
leaderboard_entries: snapshot
.leaderboard_entries
.into_iter()
.map(map_puzzle_leaderboard_entry)
.collect(),
}
}
pub(crate) fn map_puzzle_leaderboard_entry(
snapshot: module_puzzle::PuzzleLeaderboardEntry,
) -> PuzzleLeaderboardEntryRecord {
PuzzleLeaderboardEntryRecord {
rank: snapshot.rank,
nickname: snapshot.nickname,
elapsed_ms: snapshot.elapsed_ms,
is_current_player: snapshot.is_current_player,
}
}
@@ -4374,6 +4398,14 @@ pub struct PuzzleMergedGroupRecord {
pub occupied_cells: Vec<PuzzleCellPositionRecord>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PuzzleLeaderboardEntryRecord {
pub rank: u32,
pub nickname: String,
pub elapsed_ms: u64,
pub is_current_player: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PuzzleBoardRecord {
pub rows: u32,
@@ -4396,6 +4428,10 @@ pub struct PuzzleRuntimeLevelRecord {
pub cover_image_src: Option<String>,
pub board: PuzzleBoardRecord,
pub status: String,
pub started_at_ms: u64,
pub cleared_at_ms: Option<u64>,
pub elapsed_ms: Option<u64>,
pub leaderboard_entries: Vec<PuzzleLeaderboardEntryRecord>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -4409,6 +4445,18 @@ pub struct PuzzleRunRecord {
pub previous_level_tags: Vec<String>,
pub current_level: Option<PuzzleRuntimeLevelRecord>,
pub recommended_next_profile_id: Option<String>,
pub leaderboard_entries: Vec<PuzzleLeaderboardEntryRecord>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PuzzleLeaderboardSubmitRecordInput {
pub run_id: String,
pub owner_user_id: String,
pub profile_id: String,
pub grid_size: u32,
pub elapsed_ms: u64,
pub nickname: String,
pub submitted_at_micros: i64,
}
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@@ -294,6 +294,8 @@ pub mod puzzle_agent_session_row_type;
pub mod puzzle_agent_stage_type;
pub mod puzzle_draft_compile_input_type;
pub mod puzzle_generated_images_save_input_type;
pub mod puzzle_leaderboard_entry_row_type;
pub mod puzzle_leaderboard_submit_input_type;
pub mod puzzle_publication_status_type;
pub mod puzzle_publish_input_type;
pub mod puzzle_run_drag_input_type;
@@ -442,6 +444,7 @@ pub mod submit_big_fish_input_procedure;
pub mod submit_big_fish_message_procedure;
pub mod submit_custom_world_agent_message_procedure;
pub mod submit_puzzle_agent_message_procedure;
pub mod submit_puzzle_leaderboard_entry_procedure;
pub mod swap_puzzle_pieces_procedure;
pub mod treasure_interaction_action_type;
pub mod treasure_record_procedure_result_type;
@@ -755,6 +758,8 @@ pub use puzzle_agent_session_row_type::PuzzleAgentSessionRow;
pub use puzzle_agent_stage_type::PuzzleAgentStage;
pub use puzzle_draft_compile_input_type::PuzzleDraftCompileInput;
pub use puzzle_generated_images_save_input_type::PuzzleGeneratedImagesSaveInput;
pub use puzzle_leaderboard_entry_row_type::PuzzleLeaderboardEntryRow;
pub use puzzle_leaderboard_submit_input_type::PuzzleLeaderboardSubmitInput;
pub use puzzle_publication_status_type::PuzzlePublicationStatus;
pub use puzzle_publish_input_type::PuzzlePublishInput;
pub use puzzle_run_drag_input_type::PuzzleRunDragInput;
@@ -903,6 +908,7 @@ pub use submit_big_fish_input_procedure::submit_big_fish_input;
pub use submit_big_fish_message_procedure::submit_big_fish_message;
pub use submit_custom_world_agent_message_procedure::submit_custom_world_agent_message;
pub use submit_puzzle_agent_message_procedure::submit_puzzle_agent_message;
pub use submit_puzzle_leaderboard_entry_procedure::submit_puzzle_leaderboard_entry;
pub use swap_puzzle_pieces_procedure::swap_puzzle_pieces;
pub use treasure_interaction_action_type::TreasureInteractionAction;
pub use treasure_record_procedure_result_type::TreasureRecordProcedureResult;

View File

@@ -0,0 +1,70 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
#![allow(unused, clippy::all)]
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct PuzzleLeaderboardEntryRow {
pub entry_id: String,
pub profile_id: String,
pub grid_size: u32,
pub user_id: String,
pub nickname: String,
pub best_elapsed_ms: u64,
pub last_run_id: String,
pub updated_at: __sdk::Timestamp,
}
impl __sdk::InModule for PuzzleLeaderboardEntryRow {
type Module = super::RemoteModule;
}
/// Column accessor struct for the table `PuzzleLeaderboardEntryRow`.
///
/// Provides typed access to columns for query building.
pub struct PuzzleLeaderboardEntryRowCols {
pub entry_id: __sdk::__query_builder::Col<PuzzleLeaderboardEntryRow, String>,
pub profile_id: __sdk::__query_builder::Col<PuzzleLeaderboardEntryRow, String>,
pub grid_size: __sdk::__query_builder::Col<PuzzleLeaderboardEntryRow, u32>,
pub user_id: __sdk::__query_builder::Col<PuzzleLeaderboardEntryRow, String>,
pub nickname: __sdk::__query_builder::Col<PuzzleLeaderboardEntryRow, String>,
pub best_elapsed_ms: __sdk::__query_builder::Col<PuzzleLeaderboardEntryRow, u64>,
pub last_run_id: __sdk::__query_builder::Col<PuzzleLeaderboardEntryRow, String>,
pub updated_at: __sdk::__query_builder::Col<PuzzleLeaderboardEntryRow, __sdk::Timestamp>,
}
impl __sdk::__query_builder::HasCols for PuzzleLeaderboardEntryRow {
type Cols = PuzzleLeaderboardEntryRowCols;
fn cols(table_name: &'static str) -> Self::Cols {
PuzzleLeaderboardEntryRowCols {
entry_id: __sdk::__query_builder::Col::new(table_name, "entry_id"),
profile_id: __sdk::__query_builder::Col::new(table_name, "profile_id"),
grid_size: __sdk::__query_builder::Col::new(table_name, "grid_size"),
user_id: __sdk::__query_builder::Col::new(table_name, "user_id"),
nickname: __sdk::__query_builder::Col::new(table_name, "nickname"),
best_elapsed_ms: __sdk::__query_builder::Col::new(table_name, "best_elapsed_ms"),
last_run_id: __sdk::__query_builder::Col::new(table_name, "last_run_id"),
updated_at: __sdk::__query_builder::Col::new(table_name, "updated_at"),
}
}
}
/// Indexed column accessor struct for the table `PuzzleLeaderboardEntryRow`.
///
/// Provides typed access to indexed columns for query building.
pub struct PuzzleLeaderboardEntryRowIxCols {
pub entry_id: __sdk::__query_builder::IxCol<PuzzleLeaderboardEntryRow, String>,
}
impl __sdk::__query_builder::HasIxCols for PuzzleLeaderboardEntryRow {
type IxCols = PuzzleLeaderboardEntryRowIxCols;
fn ix_cols(table_name: &'static str) -> Self::IxCols {
PuzzleLeaderboardEntryRowIxCols {
entry_id: __sdk::__query_builder::IxCol::new(table_name, "entry_id"),
}
}
}
impl __sdk::__query_builder::CanBeLookupTable for PuzzleLeaderboardEntryRow {}

View File

@@ -0,0 +1,21 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
#![allow(unused, clippy::all)]
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct PuzzleLeaderboardSubmitInput {
pub run_id: String,
pub owner_user_id: String,
pub profile_id: String,
pub grid_size: u32,
pub elapsed_ms: u64,
pub nickname: String,
pub submitted_at_micros: i64,
}
impl __sdk::InModule for PuzzleLeaderboardSubmitInput {
type Module = super::RemoteModule;
}

View File

@@ -0,0 +1,59 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
#![allow(unused, clippy::all)]
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
use super::puzzle_leaderboard_submit_input_type::PuzzleLeaderboardSubmitInput;
use super::puzzle_run_procedure_result_type::PuzzleRunProcedureResult;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
struct SubmitPuzzleLeaderboardEntryArgs {
pub input: PuzzleLeaderboardSubmitInput,
}
impl __sdk::InModule for SubmitPuzzleLeaderboardEntryArgs {
type Module = super::RemoteModule;
}
#[allow(non_camel_case_types)]
/// Extension trait for access to the procedure `submit_puzzle_leaderboard_entry`.
///
/// Implemented for [`super::RemoteProcedures`].
pub trait submit_puzzle_leaderboard_entry {
fn submit_puzzle_leaderboard_entry(&self, input: PuzzleLeaderboardSubmitInput) {
self.submit_puzzle_leaderboard_entry_then(input, |_, _| {});
}
fn submit_puzzle_leaderboard_entry_then(
&self,
input: PuzzleLeaderboardSubmitInput,
__callback: impl FnOnce(
&super::ProcedureEventContext,
Result<PuzzleRunProcedureResult, __sdk::InternalError>,
) + Send
+ 'static,
);
}
impl submit_puzzle_leaderboard_entry for super::RemoteProcedures {
fn submit_puzzle_leaderboard_entry_then(
&self,
input: PuzzleLeaderboardSubmitInput,
__callback: impl FnOnce(
&super::ProcedureEventContext,
Result<PuzzleRunProcedureResult, __sdk::InternalError>,
) + Send
+ 'static,
) {
self.imp
.invoke_procedure_with_callback::<_, PuzzleRunProcedureResult>(
"submit_puzzle_leaderboard_entry",
SubmitPuzzleLeaderboardEntryArgs { input },
__callback,
);
}
}

View File

@@ -462,4 +462,32 @@ impl SpacetimeClient {
})
.await
}
pub async fn submit_puzzle_leaderboard_entry(
&self,
input: PuzzleLeaderboardSubmitRecordInput,
) -> Result<PuzzleRunRecord, SpacetimeClientError> {
let procedure_input = PuzzleLeaderboardSubmitInput {
run_id: input.run_id,
owner_user_id: input.owner_user_id,
profile_id: input.profile_id,
grid_size: input.grid_size,
elapsed_ms: input.elapsed_ms,
nickname: input.nickname,
submitted_at_micros: input.submitted_at_micros,
};
self.call_after_connect(move |connection, sender| {
connection.procedures().submit_puzzle_leaderboard_entry_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
.and_then(map_puzzle_run_procedure_result);
send_once(&sender, mapped);
},
);
})
.await
}
}