Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions crates/workshop-rs/src/gameplay/data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Embedded, provenance-pinned hero gameplay data.
//! Embedded gameplay data with a pinned source identity.
//!
//! The data file is a checked-in projection of the user-provided
//! `workshop-data` export. This module owns parsing, schema validation, and
Expand All @@ -12,7 +12,13 @@ use crate::gameplay::{GameplayCatalog, GameplayDataError, GameplayDatasetIdentit
/// The canonical gameplay dataset embedded in the crate.
pub const GAMEPLAY_DATA: &str = include_str!("gameplay.json");

const SCHEMA_VERSION: u32 = 1;
const SCHEMA_VERSION: u32 = 2;

#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct GameplaySchema {
schema_version: u32,
}

#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -24,9 +30,15 @@ struct GameplayFile {

/// Load and validate a gameplay dataset from its JSON representation.
pub fn load(json: &str) -> Result<GameplayCatalog, GameplayDataError> {
let schema: GameplaySchema = serde_json::from_str(json)
.map_err(|error| GameplayDataError::Malformed(error.to_string()))?;
if schema.schema_version != SCHEMA_VERSION {
return Err(GameplayDataError::UnsupportedSchema(schema.schema_version));
}

let file: GameplayFile = serde_json::from_str(json)
.map_err(|error| GameplayDataError::Malformed(error.to_string()))?;
if file.schema_version != SCHEMA_VERSION {
if file.schema_version != schema.schema_version {
return Err(GameplayDataError::UnsupportedSchema(file.schema_version));
}

Expand Down
Loading
Loading