Skip to main content

supreme_fs/
lib.rs

1pub use encoding_rs::WINDOWS_1252;
2
3pub use game_storage::DiscoverMode;
4pub use game_storage::GameStorage;
5pub use game_storage::OnlineProfileInfo;
6
7pub use errors::{HybridStorageError, OnlineStorageError};
8pub use events::SnapshotEvent;
9
10#[cfg(feature = "online")]
11pub use game_storage::{
12    AccountDto, AuthInfo, AuthPoll, RoomDto, RoomIdentity, RoomRecordDto, RoomSummaryDto,
13    RoomUploadResult, high_times_entries_from_records, http_get_bytes, http_get_bytes_opt,
14    http_post_bytes,
15};
16
17mod errors;
18mod events;
19/// Add mod declaration for `game_storage`
20mod game_storage;
21
22/// Wire DTOs for the Online Tournament rooms API.
23///
24/// The physical module is [`crate::game_storage`]'s `online::rooms`; this
25/// re-export provides the `supreme_fs::rooms` path, so consumers
26/// (launcher, hook proxy) can share the types while `supreme_fs` stays
27/// independent of `supreme_tournament` (and vice versa).
28#[cfg(feature = "online")]
29pub mod rooms {
30    pub use crate::game_storage::{
31        RoomDto, RoomIdentity, RoomRecordDto, RoomSummaryDto, RoomUploadResult,
32        high_times_entries_from_records, room_remove_payload,
33    };
34}
35
36/// Wire DTOs for the tournament account/auth API (the device-link flow).
37///
38/// The physical module is [`crate::game_storage`]'s `online::auth`; this
39/// re-export mirrors [`crate::rooms`] so consumers can share the types.
40#[cfg(feature = "online")]
41pub mod auth {
42    pub use crate::game_storage::{AccountDto, AuthInfo, AuthPoll};
43}
44
45#[derive(PartialEq, Clone, Copy, Debug)]
46pub enum AssetType {
47    Content,
48    Profile,
49}
50
51/// Get the supreme base path (.supreme directory)
52#[must_use]
53pub fn get_repository_path(root_path: &std::path::Path) -> std::path::PathBuf {
54    root_path.join(".supreme")
55}
56
57/// Get the contents directory path
58#[must_use]
59pub fn get_contents_path(root_path: &std::path::Path) -> std::path::PathBuf {
60    get_repository_path(root_path).join("contents")
61}
62
63/// Get the profiles directory path
64#[must_use]
65pub fn get_profiles_path(root_path: &std::path::Path) -> std::path::PathBuf {
66    get_repository_path(root_path).join("profiles")
67}
68
69#[cfg(test)]
70mod tests {
71    use super::*;
72    use std::path::Path;
73
74    #[test]
75    fn repository_path_is_dot_supreme_under_root() {
76        let root = Path::new("/games/my_game");
77        assert_eq!(
78            get_repository_path(root),
79            Path::new("/games/my_game/.supreme")
80        );
81    }
82
83    #[test]
84    fn contents_path_is_nested_under_repository_path() {
85        let root = Path::new("/games/my_game");
86        assert_eq!(
87            get_contents_path(root),
88            Path::new("/games/my_game/.supreme/contents")
89        );
90    }
91
92    #[test]
93    fn profiles_path_is_nested_under_repository_path() {
94        let root = Path::new("/games/my_game");
95        assert_eq!(
96            get_profiles_path(root),
97            Path::new("/games/my_game/.supreme/profiles")
98        );
99    }
100
101    #[test]
102    fn asset_type_supports_equality() {
103        assert_eq!(AssetType::Content, AssetType::Content);
104        assert_ne!(AssetType::Content, AssetType::Profile);
105    }
106}