From cbebfa86e767e62d2ccf8b8d8eb639fe4c33fae4 Mon Sep 17 00:00:00 2001 From: Walidoux Date: Thu, 4 May 2023 16:16:15 +0100 Subject: [PATCH] chore: Add language dropdown for localization - Added a new language dropdown component for localization - Improved spacing and styling across multiple components - Removed unused code and commented out debug lines - Updated dependencies for flag icons and solid-js library. --- src-tauri/src/commands.rs | 18 ++++--- src-tauri/src/main.rs | 15 +++--- src-tauri/src/structs.rs | 37 ++++++++++++-- src-tauri/src/utils.rs | 51 +++++++++++++++---- src/App.tsx | 8 +-- .../layout/Downloaders/Downloaders.tsx | 9 +++- src/components/layout/Popup/Popup.tsx | 2 +- src/components/layout/index.ts | 2 + src/controllers/EffectMap.ts | 4 +- src/index.tsx | 2 + src/styles/styles.css | 2 +- 11 files changed, 114 insertions(+), 36 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index d7a124b..614f5e8 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use quickxml_to_serde::{xml_string_to_json, Config, NullValue}; use specta::specta; @@ -22,25 +24,27 @@ pub fn download_gamedata(data: &str, endpoint: GamedataEndpoints) { } } -/* #[specta] +#[specta] #[tauri::command] pub fn parse_data( - path: String, - file_name: String, - file_content: String, + path: &str, + file_name: &str, + file_content: &str, ) -> Result<(), Box> { let file_dir = PathBuf::from(&path).join(format!("{}.json", file_name)); + println!("{:?}", file_dir); + // By default, output files will be overwritten. I cannot recursively remove the entire output folder // and create it again because it just won't parse files' contents for some reason - if !exists(&Convertion::gamedata_dir()) { + /* if !exists(&Convertion::gamedata_dir()) { create_dir_all(&Convertion::gamedata_dir())?; } - write_file(&file_dir, file_content.as_bytes()); + write_file(&file_dir, file_content.as_bytes()); */ Ok(()) -} */ +} /* pub async fn convert_txt(path: &str, data: &str) -> Result<(), Box> { let mut badges: Vec = Vec::new(); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index a85b26f..195f75d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -12,13 +12,14 @@ fn main() { ts::export(collect_types![download_gamedata], "../src/tools/rusty.ts").unwrap(); // This is useful for custom eslint, prettier overrides at the top of the file. - // ts::export_with_cfg_with_header( - // collect_types![download_gamedata].unwrap(), - // Default::default(), - // "../src/tools/rusty.ts", - // "/* eslint-disable */\n".into(), - // ) - // .unwrap(); + /* ts::export_with_cfg_with_header( + collect_types![download_gamedata].unwrap(), + Default::default(), + "../src/tools/rusty.ts", + "/* eslint-disable */ + \n".into(), + ) + .unwrap(); */ tauri::Builder::default() .invoke_handler(tauri::generate_handler![download_gamedata]) diff --git a/src-tauri/src/structs.rs b/src-tauri/src/structs.rs index 70c44b0..acc323d 100644 --- a/src-tauri/src/structs.rs +++ b/src-tauri/src/structs.rs @@ -29,11 +29,42 @@ pub struct GamedataEndpoints { pub file_name: Converters, } -pub struct FigureData { +#[derive(Serialize, Deserialize, Type, Debug)] +pub struct FurniData { pub floor_items: Vec, pub wall_items: Vec, } -pub struct IFloorItem {} +#[derive(Serialize, Deserialize, Type, Debug)] +pub struct IFloorItem { + dimensions: IFloorItemDimensions, + permissions: IFloorItemPermissions, +} -pub struct IFurni {} +#[derive(Serialize, Deserialize, Type, Debug)] +pub struct IFloorItemDimensions { + x: i32, + y: i32, + default_direction: i32, +} + +#[derive(Serialize, Deserialize, Type, Debug)] +pub struct IFloorItemPermissions { + can_sit_on: bool, + can_lay_on: bool, + can_stand_on: bool, +} + +#[derive(Serialize, Deserialize, Type, Debug)] +pub struct IFurni { + id: i32, + classname: String, + description: Option, + name: Option, + furni_line: Option, + custom_params: Option, + adurl: Option, + offer_id: Option, + exclude_dynamic: bool, + special_type: i32, +} diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index 7123e40..e15d2ae 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -1,6 +1,6 @@ use serde_json::Value; -use crate::structs::Converters; +use crate::structs::{Converters, FurniData, IFloorItem, IFurni}; pub fn debug_typeof(_: &T) { println!("{}", std::any::type_name::()) @@ -9,17 +9,46 @@ pub fn debug_typeof(_: &T) { pub fn convert_json(data: &str, file_name: Converters) { let object: Value = serde_json::from_str(data).unwrap(); - println!("{}", object); - match file_name { - /* Converters::FurniData => { - for (key, value) in object["wallitemtypes"]["furnitype"].as_object().unwrap() { - println!("{} {}", key, value); + Converters::FurniData => { + let mut data = FurniData { + floor_items: Vec::new(), + wall_items: Vec::new(), + }; + + let floor_items_result: Result<_, Vec> = + Ok(serde_json::from_value::>( + object["wallitemtypes"]["furnitype"].clone(), + )); + + let wall_items_result: Result<_, Vec> = Ok( + serde_json::from_value::>(object["roomitemtypes"]["furnitype"].clone()), + ); + + // Handle the floor_items_result and wall_items_result appropriately + match (floor_items_result, wall_items_result) { + (Ok(floor_items), Ok(wall_items)) => { + while let Ok(ref value) = wall_items { + println!("{:?}", value); + } + while let Ok(ref value) = floor_items { + println!("{:?}", value); + } + } + (Err(e), _) => { + println!("Error deserializing floor items: {:?}", e); + } + (_, Err(e)) => { + println!("Error deserializing wall items: {:?}", e); + } } - } */ - Converters::FigureData => unimplemented!(), - Converters::FigureMap => todo!(), - Converters::EffectMap => todo!(), - Converters::FurniData => todo!(), + + // loop through each key value pairs (make sure your handle null exceptions) + // parse the data to the global variable above + // + } + Converters::FigureData => {} + Converters::FigureMap => {} + Converters::EffectMap => {} } } diff --git a/src/App.tsx b/src/App.tsx index 1bae45c..9edd4a6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,14 +1,16 @@ import type { Component } from 'solid-js' -import { Downloaders, TitleBar } from './components/layout' +import { Downloaders, TitleBar, LangDropdown } from './components/layout' const Main: Component = () => { return ( <> -
- I would like to: +
+ I would like to: + +
diff --git a/src/components/layout/Downloaders/Downloaders.tsx b/src/components/layout/Downloaders/Downloaders.tsx index d0788b3..9fa90f8 100644 --- a/src/components/layout/Downloaders/Downloaders.tsx +++ b/src/components/layout/Downloaders/Downloaders.tsx @@ -50,10 +50,17 @@ export const Downloaders: Component = () => { +