From 8ae882a56a2667987831d3628ccdade86c5a25e0 Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Fri, 7 Mar 2025 18:20:25 -0500 Subject: [PATCH] refactor(state): clean up client information tables --- src/lua/client/state.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/lua/client/state.rs b/src/lua/client/state.rs index 7c9a53a..3c2fb0b 100644 --- a/src/lua/client/state.rs +++ b/src/lua/client/state.rs @@ -31,26 +31,26 @@ pub fn score(_lua: &Lua, client: &Client) -> Result { pub async fn set_client_information( _lua: Lua, client: UserDataRef, - ci: Table, + info: Table, ) -> Result<()> { - let model_customization = if let Some(mc) = ci.get::>("model_customization")? { - ModelCustomization { - cape: mc.get("cape")?, - jacket: mc.get("jacket")?, - left_sleeve: mc.get("left_sleeve")?, - right_sleeve: mc.get("right_sleeve")?, - left_pants: mc.get("left_pants")?, - right_pants: mc.get("right_pants")?, - hat: mc.get("hat")?, - } - } else { - ModelCustomization::default() - }; + let get_bool = |table: &Table, name| table.get(name).unwrap_or(true); + if let Err(error) = client .set_client_information(ClientInformation { - allows_listing: ci.get("allows_listing")?, - model_customization, - view_distance: ci.get("view_distance").unwrap_or(8), + allows_listing: info.get("allows_listing")?, + model_customization: info + .get::("model_customization") + .map(|t| ModelCustomization { + cape: get_bool(&t, "cape"), + jacket: get_bool(&t, "jacket"), + left_sleeve: get_bool(&t, "left_sleeve"), + right_sleeve: get_bool(&t, "right_sleeve"), + left_pants: get_bool(&t, "left_pants"), + right_pants: get_bool(&t, "right_pants"), + hat: get_bool(&t, "hat"), + }) + .unwrap_or_default(), + view_distance: info.get("view_distance").unwrap_or(8), ..ClientInformation::default() }) .await