Skip to content

Commit

Permalink
Fix some Clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed Apr 16, 2024
1 parent d7f8f03 commit 4d21f65
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 34 deletions.
4 changes: 2 additions & 2 deletions korangar/src/graphics/renderers/deferred/sprite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ impl SpriteRenderer {
smooth: bool,
) {
let half_screen = ScreenSize {
width: window_size.width as f32 / 2.0,
height: window_size.height as f32 / 2.0,
width: window_size.width / 2.0,
height: window_size.height / 2.0,
};
let screen_position = ScreenPosition {
left: screen_position.left / half_screen.width,
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/interface/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub struct InterfaceSettings {
}

impl InterfaceSettings {
pub fn new() -> Self {
pub fn load_or_default() -> Self {
let InterfaceSettingsStorage {
menu_theme,
main_theme,
Expand Down
12 changes: 6 additions & 6 deletions korangar/src/interface/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl korangar_interface::theme::ButtonTheme<InterfaceSettings> for ButtonTheme {
}

fn height_bound(&self) -> korangar_interface::layout::DimensionBound {
self.height_bound.clone()
self.height_bound
}
}

Expand Down Expand Up @@ -299,7 +299,7 @@ impl korangar_interface::theme::WindowTheme<InterfaceSettings> for WindowTheme {
}

fn title_height(&self) -> korangar_interface::layout::DimensionBound {
self.title_height.clone()
self.title_height
}
}

Expand Down Expand Up @@ -497,7 +497,7 @@ impl korangar_interface::theme::LabelTheme<InterfaceSettings> for LabelTheme {
}

fn size_bound(&self) -> korangar_interface::layout::SizeBound {
self.size_bound.clone()
self.size_bound
}
}

Expand Down Expand Up @@ -574,7 +574,7 @@ impl korangar_interface::theme::ValueTheme<InterfaceSettings> for ValueTheme {
}

fn size_bound(&self) -> korangar_interface::layout::SizeBound {
self.size_bound.clone()
self.size_bound
}
}

Expand Down Expand Up @@ -655,7 +655,7 @@ impl korangar_interface::theme::CloseButtonTheme<InterfaceSettings> for CloseBut
}

fn size_bound(&self) -> korangar_interface::layout::SizeBound {
self.size_bound.clone()
self.size_bound
}
}

Expand Down Expand Up @@ -840,7 +840,7 @@ impl korangar_interface::theme::InputTheme<InterfaceSettings> for InputTheme {
}

fn height_bound(&self) -> korangar_interface::layout::DimensionBound {
self.height_bound.clone()
self.height_bound
}
}

Expand Down
6 changes: 1 addition & 5 deletions korangar/src/loaders/archive/folder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ impl Archive for FolderArchive {
}

fn get_lua_files(&self, lua_files: &mut Vec<String>) {
let files = self
.file_mapping
.keys()
.filter(|file_name| file_name.ends_with(".lub"))
.map(|file_name| file_name.clone());
let files = self.file_mapping.keys().filter(|file_name| file_name.ends_with(".lub")).cloned();

lua_files.extend(files);
}
Expand Down
6 changes: 3 additions & 3 deletions korangar/src/loaders/gamefile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ impl GameFileLoader {
self.archives.iter().for_each(|archive| archive.get_lua_files(&mut lua_files));

let path = Path::new(LUA_GRF_FILE_NAME);
let mut lua_archive: Box<dyn Writable> = match GameFileLoader::get_archive_type_by_path(&path) {
ArchiveType::Folder => Box::new(FolderArchive::from_path(&path)),
ArchiveType::Native => Box::new(NativeArchiveBuilder::from_path(&path)),
let mut lua_archive: Box<dyn Writable> = match GameFileLoader::get_archive_type_by_path(path) {
ArchiveType::Folder => Box::new(FolderArchive::from_path(path)),
ArchiveType::Native => Box::new(NativeArchiveBuilder::from_path(path)),
};

let bytecode_format = Format::default();
Expand Down
20 changes: 9 additions & 11 deletions korangar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fn main() {
#[cfg(feature = "debug")]
let timer = Timer::new("initialize interface");

let mut application = InterfaceSettings::new();
let mut application = InterfaceSettings::load_or_default();
let mut interface = korangar_interface::Interface::new(swapchain_holder.window_screen_size());
let mut focus_state = FocusState::default();
let mut mouse_cursor = MouseCursor::new(&mut game_file_loader, &mut sprite_loader, &mut action_loader);
Expand Down Expand Up @@ -806,7 +806,7 @@ fn main() {
UserEvent::CameraRotate(factor) => player_camera.soft_rotate(factor),
UserEvent::OpenMenuWindow => {
if !entities.is_empty() {
interface.open_window(&application, &mut focus_state, &MenuWindow::default())
interface.open_window(&application, &mut focus_state, &MenuWindow)
}
}
UserEvent::OpenInventoryWindow => {
Expand Down Expand Up @@ -841,9 +841,7 @@ fn main() {
&mut focus_state,
&GraphicsSettingsWindow::new(present_mode_info, shadow_detail.clone_state(), framerate_limit.clone_state()),
),
UserEvent::OpenAudioSettingsWindow => {
interface.open_window(&application, &mut focus_state, &AudioSettingsWindow::default())
}
UserEvent::OpenAudioSettingsWindow => interface.open_window(&application, &mut focus_state, &AudioSettingsWindow),
UserEvent::OpenFriendsWindow => {
interface.open_window(&application, &mut focus_state, &networking_system.friends_window())
}
Expand Down Expand Up @@ -1054,11 +1052,11 @@ fn main() {
#[cfg(feature = "debug")]
UserEvent::OpenMapDataWindow => interface.open_window(&application, &mut focus_state, map.to_prototype_window()),
#[cfg(feature = "debug")]
UserEvent::OpenMapsWindow => interface.open_window(&application, &mut focus_state, &MapsWindow::default()),
UserEvent::OpenMapsWindow => interface.open_window(&application, &mut focus_state, &MapsWindow),
#[cfg(feature = "debug")]
UserEvent::OpenCommandsWindow => interface.open_window(&application, &mut focus_state, &CommandsWindow::default()),
UserEvent::OpenCommandsWindow => interface.open_window(&application, &mut focus_state, &CommandsWindow),
#[cfg(feature = "debug")]
UserEvent::OpenTimeWindow => interface.open_window(&application, &mut focus_state, &TimeWindow::default()),
UserEvent::OpenTimeWindow => interface.open_window(&application, &mut focus_state, &TimeWindow),
#[cfg(feature = "debug")]
UserEvent::SetDawn => game_timer.set_day_timer(0.0),
#[cfg(feature = "debug")]
Expand Down Expand Up @@ -1293,7 +1291,7 @@ fn main() {
picker_target,
&picker_renderer,
current_camera,
&render_settings,
render_settings,
entities,
hovered_marker_identifier,
);
Expand Down Expand Up @@ -1426,7 +1424,7 @@ fn main() {
screen_target,
&deferred_renderer,
current_camera,
&render_settings,
render_settings,
entities,
hovered_marker_identifier,
);
Expand Down Expand Up @@ -1484,7 +1482,7 @@ fn main() {
picker_target.image.clone(),
directional_shadow_image,
font_loader.borrow().get_font_atlas(),
&render_settings,
render_settings,
);
}

Expand Down
2 changes: 1 addition & 1 deletion korangar_interface/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ where
}

pub fn get_focused_window(&self) -> Option<usize> {
self.focused_window.clone()
self.focused_window
}

pub fn update_focused_element(&mut self, element: Option<ElementCell<App>>, window_index: usize) {
Expand Down
1 change: 1 addition & 0 deletions korangar_interface/src/elements/buttons/close/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::application::Application;
/// Type state [`CloseButton`] builder. This builder utilizes the type system to
/// prevent calling the same method multiple times and calling
/// [`build`](Self::build) before the mandatory methods have been called.
#[derive(Default)]
#[must_use = "`build` needs to be called"]
pub struct CloseButtonBuilder;

Expand Down
13 changes: 11 additions & 2 deletions korangar_interface/src/elements/miscellanious/input/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ where
marker: PhantomData<(App, Length, Hidden, Width)>,
}

impl<App> InputFieldBuilder<App, Unset, Unset, Unset, Unset, Unset, Unset>
impl<App> Default for InputFieldBuilder<App, Unset, Unset, Unset, Unset, Unset, Unset>
where
App: Application,
{
pub fn new() -> Self {
fn default() -> Self {
Self {
input_state: Unset,
ghost_text: Unset,
Expand All @@ -42,6 +42,15 @@ where
}
}

impl<App> InputFieldBuilder<App, Unset, Unset, Unset, Unset, Unset, Unset>
where
App: Application,
{
pub fn new() -> Self {
Self::default()
}
}

impl<App, Text, Action, Length, Hidden, Width> InputFieldBuilder<App, Unset, Text, Action, Length, Hidden, Width>
where
App: Application,
Expand Down
6 changes: 6 additions & 0 deletions korangar_interface/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ pub trait TrackedStateVec<Value> {
F: FnMut(&Value) -> bool;

fn len(&self) -> usize;

fn is_empty(&self) -> bool;
}

impl<T, Value> TrackedStateVec<Value> for T
Expand Down Expand Up @@ -359,6 +361,10 @@ where
fn len(&self) -> usize {
self.get().len()
}

fn is_empty(&self) -> bool {
self.get().is_empty()
}
}

pub trait TrackedStateBinary<Value>: TrackedState<Value> {
Expand Down
13 changes: 11 additions & 2 deletions korangar_interface/src/windows/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ where
marker: PhantomData<(Title, Closable, Class, Background, Theme)>,
}

impl<App> WindowBuilder<App, Unset, Unset, Unset, Unset, Unset, Unset, Unset>
impl<App> Default for WindowBuilder<App, Unset, Unset, Unset, Unset, Unset, Unset, Unset>
where
App: Application,
{
pub fn new() -> Self {
fn default() -> Self {
Self {
title: None,
closable: false,
Expand All @@ -46,6 +46,15 @@ where
}
}

impl<App> WindowBuilder<App, Unset, Unset, Unset, Unset, Unset, Unset, Unset>
where
App: Application,
{
pub fn new() -> Self {
Self::default()
}
}

impl<App, Class, Closable, Size, Elements, Background, Theme> WindowBuilder<App, Unset, Closable, Class, Size, Elements, Background, Theme>
where
App: Application,
Expand Down
2 changes: 1 addition & 1 deletion korangar_procedural/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn profile(name: InterfaceTokenStream, function: InterfaceTokenStream) -> In
let mut function: ItemFn = parse(function).expect("failed to parse token stream");
let name: LitStr = parse(name).unwrap_or_else(|_| {
let function_name = &function.sig.ident;
LitStr::new(function_name.to_string().replace("_", " ").as_str(), function_name.span())
LitStr::new(function_name.to_string().replace('_', " ").as_str(), function_name.span())
});

let code = quote! {
Expand Down

0 comments on commit 4d21f65

Please sign in to comment.