1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-21 04:07:46 +00:00
physis/src/common.rs

77 lines
1.9 KiB
Rust
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
use std::fs;
use std::path::Path;
2022-07-21 19:58:07 -04:00
use binrw::binrw;
#[binrw]
#[brw(repr(u8))]
2022-07-21 20:08:14 -04:00
#[repr(u8)]
2023-04-09 15:33:43 -04:00
#[derive(Copy, Clone)]
2023-09-22 18:15:23 -04:00
/// The language the game data is written for. Some of these languages are supported in the Global region.
2022-07-19 19:29:41 -04:00
pub enum Language {
/// Used for data that is language-agnostic, such as item data.
2022-07-19 19:29:41 -04:00
None,
/// Japanese language.
2022-07-19 19:29:41 -04:00
Japanese,
/// English language.
2022-07-19 19:29:41 -04:00
English,
/// German language.
2022-07-19 19:29:41 -04:00
German,
/// French language.
2022-07-19 19:29:41 -04:00
French,
/// Chinese (Simplified) language.
2022-07-19 19:29:41 -04:00
ChineseSimplified,
/// Chinese (Traditional) language.
2022-07-19 19:29:41 -04:00
ChineseTraditional,
/// Korean language.
2022-07-19 19:29:41 -04:00
Korean,
}
/// Returns the shorthand language code for `language`. For example, English becomes "en".
2022-07-21 19:58:07 -04:00
pub fn get_language_code(lang: &Language) -> &'static str {
match &lang {
2022-07-19 19:29:41 -04:00
Language::None => "",
Language::Japanese => "ja",
Language::English => "en",
Language::German => "de",
Language::French => "fr",
Language::ChineseSimplified => "chs",
Language::ChineseTraditional => "cht",
2022-08-16 11:52:07 -04:00
Language::Korean => "ko",
2022-07-19 19:29:41 -04:00
}
}
2023-09-22 18:15:23 -04:00
/// The region of the game. Used to denote the region a patch is meant for.
#[binrw]
#[brw(repr = i16)]
2022-09-15 16:26:31 -04:00
#[derive(Debug, PartialEq, Eq)]
pub enum Region {
2023-09-22 18:15:23 -04:00
/// The global region.
2022-08-16 11:52:07 -04:00
Global = -1, // TODO: find patch codes for other regions :-)
}
/// Reads a version file.
pub fn read_version(p: &Path) -> Option<String> {
fs::read_to_string(p).ok()
}
#[binrw]
#[brw(repr = u8)]
#[derive(Clone, Debug, PartialEq)]
pub enum Platform {
Win32,
PS3,
PS4,
// TODO: confirm if there is a separate PS5, Xbox platform
}
pub fn get_platform_string(id: &Platform) -> &'static str {
match &id {
Platform::Win32 => "win32",
Platform::PS3 => "ps3",
Platform::PS4 => "ps4", // TODO: confirm if this "ps4" is correct
}
}