Lint
This commit is contained in:
1 parent
8cf5110eb2
commit
6224a1b0a4
12 files changed
+54
-56
No files matched your search
+2
-2
@@ -156,11 +156,11 @@ pub fn build_render_job(
|
||||
batches.push(batch);
|
||||
}
|
||||
|
||||
return RenderJob {
|
||||
RenderJob {
|
||||
vertices,
|
||||
indices,
|
||||
batches,
|
||||
textures_delta,
|
||||
scale_factor,
|
||||
};
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -71,7 +71,7 @@ impl Installer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn frame(&mut self) -> anyhow::Result<StageFrameOutput> {
|
||||
pub fn frame(&self) -> anyhow::Result<StageFrameOutput> {
|
||||
let draw_commands = self.draw_current_progress();
|
||||
|
||||
Ok(StageFrameOutput {
|
||||
@@ -107,7 +107,9 @@ impl Installer {
|
||||
pub fn handle_event(&mut self, event: StageEvent) -> anyhow::Result<Option<StageTransition>> {
|
||||
match event {
|
||||
StageEvent::Resized(size) => self.window_state.size = size,
|
||||
StageEvent::ScaleFactorChanged(factor) => {
|
||||
StageEvent::ScaleFactorChanged(factor) =>
|
||||
{
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
self.window_state.set_scale_factor(factor as f32)
|
||||
}
|
||||
_ => {}
|
||||
|
||||
+6
-5
@@ -131,7 +131,7 @@ impl PathOfBuilding {
|
||||
Ok(lua)
|
||||
}
|
||||
|
||||
/// Adds "${script_dir}/lua" to package path
|
||||
/// Adds `${script_dir}/lua` to package path
|
||||
pub fn register_package_paths(lua: &Lua, script_dir: &Path) -> LuaResult<()> {
|
||||
let package: Table = lua.globals().get("package")?;
|
||||
let mut package_path: String = package.get("path")?;
|
||||
@@ -155,7 +155,7 @@ impl PathOfBuilding {
|
||||
fn restart(&mut self) -> LuaResult<()> {
|
||||
// move context out of current lua instance...
|
||||
let mut ctx = self.lua.remove_app_data::<Context>().unwrap();
|
||||
let script_dir = ctx.script_dir.to_owned();
|
||||
let script_dir = ctx.script_dir.clone();
|
||||
ctx.needs_restart = false;
|
||||
|
||||
// and move it into new instance
|
||||
@@ -166,7 +166,7 @@ impl PathOfBuilding {
|
||||
}
|
||||
|
||||
/// Handles events by updating context and forwarding them to PoB's event handlers.
|
||||
pub fn handle_event(&mut self, event: StageEvent) -> anyhow::Result<Option<StageTransition>> {
|
||||
pub fn handle_event(&self, event: StageEvent) -> anyhow::Result<Option<StageTransition>> {
|
||||
match event {
|
||||
StageEvent::KeyDown { key } => {
|
||||
self.ctx_mut().input_state.set_key_pressed(&key, true);
|
||||
@@ -238,6 +238,7 @@ impl PathOfBuilding {
|
||||
self.ctx_mut().window_state.size = size;
|
||||
}
|
||||
StageEvent::ScaleFactorChanged(scale_factor) => {
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
self.ctx_mut()
|
||||
.window_state
|
||||
.set_scale_factor(scale_factor as f32);
|
||||
@@ -358,7 +359,7 @@ impl PathOfBuilding {
|
||||
list_func.call::<Table>(())
|
||||
}
|
||||
|
||||
pub fn clear_pressed(&mut self) {
|
||||
pub fn clear_pressed(&self) {
|
||||
self.ctx_mut().input_state.clear_pressed();
|
||||
}
|
||||
|
||||
@@ -368,7 +369,7 @@ impl PathOfBuilding {
|
||||
}
|
||||
|
||||
/// Attaches the render-target window to the context
|
||||
pub fn set_window(&mut self, window: Arc<Window>) {
|
||||
pub fn set_window(&self, window: Arc<Window>) {
|
||||
self.ctx_mut().window_state.set_window(window);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -161,7 +161,7 @@ fn restart(l: &Lua, _: ()) -> LuaResult<()> {
|
||||
|
||||
fn open_url(l: &Lua, url: String) -> LuaResult<MultiValue> {
|
||||
match open::that(url) {
|
||||
Ok(_) => ().into_lua_multi(l),
|
||||
Ok(()) => ().into_lua_multi(l),
|
||||
Err(_) => "Unable to open url!".into_lua_multi(l),
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ pub fn protected_call(l: &Lua, (func, args): (Function, MultiValue)) -> LuaResul
|
||||
pub fn load_module(l: &Lua, (name, args): (String, MultiValue)) -> LuaResult<MultiValue> {
|
||||
let script_dir = {
|
||||
let ctx = l.app_data_ref::<Context>().unwrap();
|
||||
ctx.script_dir.to_owned()
|
||||
ctx.script_dir.clone()
|
||||
};
|
||||
let mut module_path = script_dir.join(name);
|
||||
if module_path.extension().is_none() {
|
||||
@@ -31,7 +31,7 @@ pub fn load_module(l: &Lua, (name, args): (String, MultiValue)) -> LuaResult<Mul
|
||||
pub fn protected_load_module(l: &Lua, (name, args): (String, MultiValue)) -> LuaResult<MultiValue> {
|
||||
let script_dir = {
|
||||
let ctx = l.app_data_ref::<Context>().unwrap();
|
||||
ctx.script_dir.to_owned()
|
||||
ctx.script_dir.clone()
|
||||
};
|
||||
let mut module_path = script_dir.join(name);
|
||||
if module_path.extension().is_none() {
|
||||
|
||||
@@ -42,7 +42,7 @@ pub fn set_work_dir(l: &Lua, path: String) -> LuaResult<()> {
|
||||
pub fn make_dir(l: &Lua, path: String) -> LuaResult<MultiValue> {
|
||||
match fs::create_dir_all(path) {
|
||||
// callers expect first return value to be true on success
|
||||
Ok(_) => (true).into_lua_multi(l),
|
||||
Ok(()) => (true).into_lua_multi(l),
|
||||
// otherwise it is set to Nil and second return value is set to error msg
|
||||
Err(err) => (Value::Nil, err.to_string()).into_lua_multi(l),
|
||||
}
|
||||
@@ -55,7 +55,7 @@ pub fn remove_dir(l: &Lua, (path, recursive): (String, Option<bool>)) -> LuaResu
|
||||
fs::remove_dir(&path)
|
||||
};
|
||||
match result {
|
||||
Ok(_) => (true).into_lua_multi(l),
|
||||
Ok(()) => (true).into_lua_multi(l),
|
||||
Err(err) => (Value::Nil, err.to_string()).into_lua_multi(l),
|
||||
}
|
||||
}
|
||||
+19
-20
@@ -168,7 +168,7 @@ unsafe extern "C-unwind" fn set_draw_layer(state: *mut ffi::lua_State) -> c_int
|
||||
let layer = i32_from_stack!(state, -nargs);
|
||||
Some(layer)
|
||||
}
|
||||
t => panic!("Expected Nil or Number, got {:?}", t),
|
||||
t => panic!("Expected Nil or Number, got {t:?}"),
|
||||
};
|
||||
let sublayer = i32_from_stack!(state, -nargs + 1);
|
||||
if let Some(layer) = layer {
|
||||
@@ -189,9 +189,10 @@ unsafe extern "C-unwind" fn draw_image(state: *mut ffi::lua_State) -> c_int {
|
||||
let mut ctx = lua_instance.app_data_mut::<Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
if !matches!(nargs, 5 | 6 | 7 | 9 | 10 | 11) {
|
||||
panic!("Unexpected number of arguments");
|
||||
}
|
||||
assert!(
|
||||
matches!(nargs, 5 | 6 | 7 | 9 | 10 | 11),
|
||||
"Unexpected number of arguments"
|
||||
);
|
||||
|
||||
#[allow(clippy::manual_range_patterns)]
|
||||
let parse_uv = matches!(nargs, 9 | 10 | 11);
|
||||
@@ -237,9 +238,10 @@ unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c_int
|
||||
let mut ctx = lua_instance.app_data_mut::<Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
if !matches!(nargs, 9 | 10 | 11 | 17 | 18 | 19) {
|
||||
panic!("Unexpected number of arguments");
|
||||
}
|
||||
assert!(
|
||||
matches!(nargs, 9 | 10 | 11 | 17 | 18 | 19),
|
||||
"Unexpected number of arguments"
|
||||
);
|
||||
|
||||
#[allow(clippy::manual_range_patterns)]
|
||||
let parse_uv = matches!(nargs, 17 | 18 | 19);
|
||||
@@ -560,17 +562,14 @@ impl<'a> Iterator for PoBStringSegmentIterator<'a> {
|
||||
let color = Some(Srgba::from_escape_code(escape_str));
|
||||
|
||||
let _ = self.captures.next(); // pop current code to peek the next one
|
||||
match self.captures.peek() {
|
||||
Some(next_code) => {
|
||||
// found another escape code. return text up the next code
|
||||
let next_code_start = next_code.get(0).unwrap().start();
|
||||
Some((color, &self.haystack[code_end..next_code_start]))
|
||||
}
|
||||
None => {
|
||||
// no additional escape codes found. return rest of string
|
||||
self.is_done = true;
|
||||
Some((color, &self.haystack[code_end..]))
|
||||
}
|
||||
if let Some(next_code) = self.captures.peek() {
|
||||
// found another escape code. return text up the next code
|
||||
let next_code_start = next_code.get(0).unwrap().start();
|
||||
Some((color, &self.haystack[code_end..next_code_start]))
|
||||
} else {
|
||||
// no additional escape codes found. return rest of string
|
||||
self.is_done = true;
|
||||
Some((color, &self.haystack[code_end..]))
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@@ -647,12 +646,12 @@ impl std::str::FromStr for PoBFontType {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
fn hex_byte(a: u8, b: u8) -> u8 {
|
||||
(hex_digit(a) << 4) | hex_digit(b)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
fn hex_digit(c: u8) -> u8 {
|
||||
match c {
|
||||
b'0'..=b'9' => c - b'0',
|
||||
|
||||
@@ -21,7 +21,7 @@ pub fn launch_subscript(
|
||||
let arguments = args.try_into()?;
|
||||
|
||||
let ctx = l.app_data_ref::<Context>().unwrap();
|
||||
let script_dir = ctx.script_dir.to_owned();
|
||||
let script_dir = ctx.script_dir.clone();
|
||||
let subscript_id = ctx.subscript_manager.borrow_mut().push(
|
||||
script_dir,
|
||||
script_text,
|
||||
|
||||
@@ -175,7 +175,7 @@ impl Subscript {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_calls(&mut self, lua: &Lua) {
|
||||
fn handle_calls(&self, lua: &Lua) {
|
||||
match self.receiver.try_recv() {
|
||||
Ok(SubscriptCall::Blocking {
|
||||
function_name,
|
||||
|
||||
@@ -61,7 +61,7 @@ impl ImageData {
|
||||
height,
|
||||
array_layers: 1,
|
||||
mipmap_count: NonZeroU32::new(1).expect("1 is non-zero"),
|
||||
data_order: Default::default(),
|
||||
data_order: DataOrder::default(),
|
||||
bytes: RgbaImage::from_pixel(width, height, color.0.into()).into_raw(),
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ impl From<DynamicImage> for ImageData {
|
||||
height: image.height(),
|
||||
array_layers: 1,
|
||||
mipmap_count: NonZeroU32::new(1).expect("1 is non-zero"),
|
||||
data_order: Default::default(),
|
||||
data_order: DataOrder::default(),
|
||||
bytes: image.to_rgba8().into_raw(),
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ impl From<RgbaImage> for ImageData {
|
||||
height: image.height(),
|
||||
array_layers: 1,
|
||||
mipmap_count: NonZeroU32::new(1).expect("1 is non-zero"),
|
||||
data_order: Default::default(),
|
||||
data_order: DataOrder::default(),
|
||||
bytes: image.into_raw(),
|
||||
}
|
||||
}
|
||||
@@ -138,12 +138,10 @@ fn resolve_path<P: AsRef<Path>>(path: P) -> std::path::PathBuf {
|
||||
|
||||
/// Checks if file is a compressed DDS file (.dds.zst)
|
||||
fn is_compressed_dds<P: AsRef<Path>>(path: P) -> bool {
|
||||
let path = path.as_ref();
|
||||
path.extension().and_then(|s| s.to_str()) == Some("zst")
|
||||
&& path
|
||||
.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
.is_some_and(|s| s.ends_with(".dds"))
|
||||
path.as_ref()
|
||||
.to_string_lossy()
|
||||
.to_ascii_lowercase()
|
||||
.ends_with(".dds.zst")
|
||||
}
|
||||
|
||||
fn dds_format_to_wgpu(format: dds::Format) -> anyhow::Result<wgpu::TextureFormat> {
|
||||
|
||||
+8
-8
@@ -66,29 +66,29 @@ pub enum ActiveStage {
|
||||
impl ActiveStage {
|
||||
pub fn update(&mut self) -> anyhow::Result<Option<StageTransition>> {
|
||||
match self {
|
||||
ActiveStage::Startup(s) => s.update(),
|
||||
ActiveStage::Main(s) => s.update(),
|
||||
Self::Startup(s) => s.update(),
|
||||
Self::Main(s) => s.update(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn frame(&mut self) -> anyhow::Result<StageFrameOutput> {
|
||||
match self {
|
||||
ActiveStage::Startup(s) => s.frame(),
|
||||
ActiveStage::Main(s) => s.frame(),
|
||||
Self::Startup(s) => s.frame(),
|
||||
Self::Main(s) => s.frame(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_event(&mut self, event: StageEvent) -> anyhow::Result<Option<StageTransition>> {
|
||||
match self {
|
||||
ActiveStage::Startup(s) => s.handle_event(event),
|
||||
ActiveStage::Main(s) => s.handle_event(event),
|
||||
Self::Startup(s) => s.handle_event(event),
|
||||
Self::Main(s) => s.handle_event(event),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_window(&mut self, window: Arc<Window>) {
|
||||
match self {
|
||||
ActiveStage::Startup(s) => s.set_window(window),
|
||||
ActiveStage::Main(s) => s.set_window(window),
|
||||
Self::Startup(s) => s.set_window(window),
|
||||
Self::Main(s) => s.set_window(window),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -81,8 +81,6 @@ impl WindowState {
|
||||
}
|
||||
|
||||
pub fn get_clipboard_text(&mut self) -> Option<String> {
|
||||
self.clipboard
|
||||
.as_mut()
|
||||
.and_then(|clipboard| clipboard.get_text())
|
||||
self.clipboard.as_mut().and_then(Clipboard::get_text)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user