-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe4617d
commit fa88d4e
Showing
44 changed files
with
1,008 additions
and
854 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,25 @@ | ||
use borsh::{BorshDeserialize, BorshSerialize}; | ||
|
||
use crate::{ | ||
error::{HandleError, HandleResult}, | ||
}; | ||
use crate::error::HandleError; | ||
|
||
/// A set of arguments for game handler initialization. | ||
#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, PartialEq, Eq)] | ||
pub struct InitAccount { | ||
pub max_players: u16, | ||
pub data: Vec<u8>, | ||
pub checkpoint: Option<Vec<u8>>, | ||
} | ||
|
||
impl InitAccount { | ||
pub fn data<S: BorshDeserialize>(&self) -> Result<S, HandleError> { | ||
S::try_from_slice(&self.data).or(Err(HandleError::MalformedGameAccountData)) | ||
} | ||
|
||
/// Get deserialized checkpoint, return None if not available. | ||
pub fn checkpoint<T: BorshDeserialize>(&self) -> HandleResult<Option<T>> { | ||
self.checkpoint | ||
.as_ref() | ||
.map(|c| T::try_from_slice(c).map_err(|_| HandleError::MalformedCheckpointData)) | ||
.transpose() | ||
} | ||
} | ||
|
||
impl Default for InitAccount { | ||
fn default() -> Self { | ||
Self { | ||
max_players: 0, | ||
data: Vec::new(), | ||
checkpoint: None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.