|
|
@ -1,31 +1,36 @@
|
|
|
|
|
|
|
|
mod datapaths;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use crate::data::datapaths::Datapaths;
|
|
|
|
use crate::models::version::Version;
|
|
|
|
use crate::models::version::Version;
|
|
|
|
use crate::{DataError, DataResult};
|
|
|
|
use crate::{DataError, DataResult};
|
|
|
|
use include_dir::Dir;
|
|
|
|
use include_dir::Dir;
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
|
|
pub static MINECRAFT_DATA: Dir = include_dir::include_dir!("minecraft-data/data/pc");
|
|
|
|
pub static MINECRAFT_DATA: Dir = include_dir::include_dir!("minecraft-data/data");
|
|
|
|
|
|
|
|
|
|
|
|
pub static BIOMES_FILE: &str = "biomes.json";
|
|
|
|
pub static BIOMES_FILE: &str = "biomes";
|
|
|
|
pub static BLOCK_LOOT_FILE: &str = "blockLoot.json";
|
|
|
|
pub static BLOCK_LOOT_FILE: &str = "blockLoot";
|
|
|
|
pub static BLOCKS_FILE: &str = "blocks.json";
|
|
|
|
pub static BLOCKS_FILE: &str = "blocks";
|
|
|
|
pub static COMMANDS_FILE: &str = "commands.json";
|
|
|
|
pub static COMMANDS_FILE: &str = "commands";
|
|
|
|
pub static ENTITIES_FILE: &str = "entities.json";
|
|
|
|
pub static ENTITIES_FILE: &str = "entities";
|
|
|
|
pub static ENTITY_LOOT_FILE: &str = "entityLoot.json";
|
|
|
|
pub static ENTITY_LOOT_FILE: &str = "entityLoot";
|
|
|
|
pub static ITEMS_FILE: &str = "items.json";
|
|
|
|
pub static ITEMS_FILE: &str = "items";
|
|
|
|
pub static LOGIN_PACKET_FILE: &str = "loginPacket.json";
|
|
|
|
pub static LOGIN_PACKET_FILE: &str = "loginPacket";
|
|
|
|
pub static MATERIALS_FILE: &str = "materials.json";
|
|
|
|
pub static MATERIALS_FILE: &str = "materials";
|
|
|
|
pub static PROTOCOL_FILE: &str = "protocol.json";
|
|
|
|
pub static PROTOCOL_FILE: &str = "protocol";
|
|
|
|
pub static RECIPES_FILE: &str = "recipes.json";
|
|
|
|
pub static RECIPES_FILE: &str = "recipes";
|
|
|
|
pub static TINTS_FILE: &str = "tints.json";
|
|
|
|
pub static TINTS_FILE: &str = "tints";
|
|
|
|
|
|
|
|
pub static ENCHANTMENTS_FILE: &str = "enchantments";
|
|
|
|
// pub static VERSION_FILE: &str = "version.json";
|
|
|
|
// pub static VERSION_FILE: &str = "version.json";
|
|
|
|
pub static MAP_ICONS_FILE: &str = "mapIcons.json";
|
|
|
|
pub static MAP_ICONS_FILE: &str = "mapIcons";
|
|
|
|
pub static PARTICLES_FILE: &str = "particles.json";
|
|
|
|
pub static PARTICLES_FILE: &str = "particles";
|
|
|
|
pub static PROTOCOL_VERSIONS_FILE: &str = "protocolVersions.json";
|
|
|
|
pub static PROTOCOL_VERSIONS_FILE: &str = "protocolVersions";
|
|
|
|
pub static VERSIONS_FILE: &str = "versions.json";
|
|
|
|
pub static VERSIONS_FILE: &str = "versions";
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the string encoded content of the common file
|
|
|
|
/// Returns the string encoded content of the common file
|
|
|
|
pub fn get_common_file(filename: &str) -> DataResult<String> {
|
|
|
|
pub fn get_common_file(filename: &str) -> DataResult<String> {
|
|
|
|
MINECRAFT_DATA
|
|
|
|
MINECRAFT_DATA
|
|
|
|
.get_file(format!("common/{}", filename))
|
|
|
|
.get_file(format!("pc/common/{}.json", filename))
|
|
|
|
.ok_or(DataError::NotFoundError(filename.to_string()))?
|
|
|
|
.ok_or(DataError::NotFoundError(filename.to_string()))?
|
|
|
|
.contents_utf8()
|
|
|
|
.contents_utf8()
|
|
|
|
.ok_or(DataError::InvalidEncodingError(filename.to_string()))
|
|
|
|
.ok_or(DataError::InvalidEncodingError(filename.to_string()))
|
|
|
@ -34,23 +39,10 @@ pub fn get_common_file(filename: &str) -> DataResult<String> {
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the string encoded content of the version specific file
|
|
|
|
/// Returns the string encoded content of the version specific file
|
|
|
|
pub fn get_version_specific_file(version: &Version, filename: &str) -> DataResult<String> {
|
|
|
|
pub fn get_version_specific_file(version: &Version, filename: &str) -> DataResult<String> {
|
|
|
|
let search_folders = vec![
|
|
|
|
let path = get_path(version, filename)?;
|
|
|
|
version.minecraft_version.clone(),
|
|
|
|
MINECRAFT_DATA
|
|
|
|
version.major_version.clone(),
|
|
|
|
.get_file(format!("{}/{}.json", path, filename))
|
|
|
|
version.major_first(),
|
|
|
|
.ok_or(DataError::NotFoundError(format!(
|
|
|
|
version.previous_major(),
|
|
|
|
|
|
|
|
version.previous_major_first(),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
let mut data = None;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for folder in search_folders {
|
|
|
|
|
|
|
|
data = MINECRAFT_DATA.get_file(format!("{}/{}", folder, filename));
|
|
|
|
|
|
|
|
if data.is_some() {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.ok_or(DataError::NotFoundError(format!(
|
|
|
|
|
|
|
|
"{}/{}",
|
|
|
|
"{}/{}",
|
|
|
|
version.minecraft_version, filename
|
|
|
|
version.minecraft_version, filename
|
|
|
|
)))?
|
|
|
|
)))?
|
|
|
@ -58,3 +50,29 @@ pub fn get_version_specific_file(version: &Version, filename: &str) -> DataResul
|
|
|
|
.ok_or(DataError::InvalidEncodingError(filename.to_string()))
|
|
|
|
.ok_or(DataError::InvalidEncodingError(filename.to_string()))
|
|
|
|
.map(|d| d.to_string())
|
|
|
|
.map(|d| d.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the data path for a given file
|
|
|
|
|
|
|
|
pub fn get_path(version: &Version, filename: &str) -> DataResult<String> {
|
|
|
|
|
|
|
|
lazy_static::lazy_static! {
|
|
|
|
|
|
|
|
static ref PATHS: Datapaths = getDatapaths().unwrap();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
PATHS
|
|
|
|
|
|
|
|
.pc
|
|
|
|
|
|
|
|
.get(&version.minecraft_version)
|
|
|
|
|
|
|
|
.ok_or(DataError::NotFoundError(version.minecraft_version.clone()))?
|
|
|
|
|
|
|
|
.get(filename)
|
|
|
|
|
|
|
|
.cloned()
|
|
|
|
|
|
|
|
.ok_or(DataError::NotFoundError(filename.to_string()))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the parsed data paths
|
|
|
|
|
|
|
|
fn getDatapaths() -> DataResult<Datapaths> {
|
|
|
|
|
|
|
|
let content = MINECRAFT_DATA
|
|
|
|
|
|
|
|
.get_file("dataPaths.json")
|
|
|
|
|
|
|
|
.ok_or(DataError::NotFoundError("dataPaths.json".to_string()))?
|
|
|
|
|
|
|
|
.contents_utf8()
|
|
|
|
|
|
|
|
.ok_or(DataError::InvalidEncodingError(
|
|
|
|
|
|
|
|
"dataPaths.json".to_string(),
|
|
|
|
|
|
|
|
))?;
|
|
|
|
|
|
|
|
serde_json::from_str::<Datapaths>(content).map_err(DataError::from)
|
|
|
|
|
|
|
|
}
|
|
|
|