summaryrefslogtreecommitdiff
path: root/systems/sheet
diff options
context:
space:
mode:
Diffstat (limited to 'systems/sheet')
-rw-r--r--systems/sheet/Cargo.toml2
-rw-r--r--systems/sheet/src/sheet.rs58
2 files changed, 58 insertions, 2 deletions
diff --git a/systems/sheet/Cargo.toml b/systems/sheet/Cargo.toml
index 5296bf8..7a20b47 100644
--- a/systems/sheet/Cargo.toml
+++ b/systems/sheet/Cargo.toml
@@ -6,9 +6,9 @@ version.workspace = true
[dependencies]
hex_display = { path = "../../utils/hex_display" }
+asset_system = { path = "../_asset" }
constants = { path = "../_constants" }
sheet_system_macros = { path = "macros" }
-asset_system = { path = "../_asset" }
serde.workspace = true
tokio.workspace = true
diff --git a/systems/sheet/src/sheet.rs b/systems/sheet/src/sheet.rs
index e7a130d..5ee2db7 100644
--- a/systems/sheet/src/sheet.rs
+++ b/systems/sheet/src/sheet.rs
@@ -5,6 +5,7 @@ use std::{
path::{Path, PathBuf},
};
+use asset_system::{RWDataTest, rw::RWData};
use memmap2::Mmap;
use serde::{Deserialize, Serialize};
use tokio::fs;
@@ -41,7 +42,7 @@ pub struct Sheet {
/// Full Sheet information
///
/// Used to wrap as a Sheet object for editing and persistence
-#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, RWDataTest)]
pub struct SheetData {
/// All local mappings
mappings: HashSet<LocalMapping>,
@@ -549,3 +550,58 @@ impl TryFrom<&[u8]> for SheetData {
read_sheet_data(value)
}
}
+
+impl RWData<SheetData> for SheetData {
+ type DataType = SheetData;
+
+ async fn read(path: &PathBuf) -> Result<Self::DataType, asset_system::error::DataReadError> {
+ let read_data = SheetData::full_read(&mut SheetData::empty(), path).await;
+ match read_data {
+ Ok(_) => {
+ let data = SheetData::full_read(&mut SheetData::empty(), path).await;
+ match data {
+ Ok(_) => Ok(SheetData::empty()),
+ Err(e) => Err(asset_system::error::DataReadError::IoError(
+ std::io::Error::new(std::io::ErrorKind::Other, e.to_string()),
+ )),
+ }
+ }
+ Err(e) => Err(asset_system::error::DataReadError::IoError(
+ std::io::Error::new(std::io::ErrorKind::Other, e.to_string()),
+ )),
+ }
+ }
+
+ async fn write(
+ data: Self::DataType,
+ path: &PathBuf,
+ ) -> Result<(), asset_system::error::DataWriteError> {
+ let write_data = tokio::fs::write(path, data.as_bytes()).await;
+ match write_data {
+ Ok(_) => Ok(()),
+ Err(e) => Err(asset_system::error::DataWriteError::IoError(
+ std::io::Error::new(std::io::ErrorKind::Other, e.to_string()),
+ )),
+ }
+ }
+
+ fn test_data() -> Self::DataType {
+ let sheet = SheetData::empty().pack("sheet");
+ let mut sheet = sheet;
+ sheet
+ .insert_mapping(
+ LocalMapping::new(
+ vec!["Test".to_string(), "File1.png".to_string()],
+ IndexSource::new(true, 1u32, 1u16),
+ LocalMappingForward::Version { version: 2u16 },
+ )
+ .unwrap(),
+ )
+ .unwrap();
+ sheet.unpack()
+ }
+
+ fn verify_data(data_a: Self::DataType, data_b: Self::DataType) -> bool {
+ data_a == data_b
+ }
+}