init
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/dist/
|
||||
/target/
|
||||
/Cargo.lock
|
||||
node_modules
|
||||
.vscode
|
||||
3
.taurignore
Normal file
@ -0,0 +1,3 @@
|
||||
/src
|
||||
/public
|
||||
/Cargo.toml
|
||||
21
Cargo.toml
Normal file
@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "poe2-loot-filter-tauri-ui"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[dependencies]
|
||||
leptos = { version = "0.7.1", features = ["csr"] }
|
||||
wasm-bindgen = "0.2"
|
||||
wasm-bindgen-futures = "0.4"
|
||||
js-sys = "0.3"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde-wasm-bindgen = "0.6"
|
||||
console_error_panic_hook = "0.1.7"
|
||||
reactive_stores = "0.1.1"
|
||||
strum = "0.26.3"
|
||||
strum_macros = "0.26.4"
|
||||
serde_json = "1.0.133"
|
||||
|
||||
[workspace]
|
||||
members = ["src-tauri"]
|
||||
7
README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Tauri + Leptos
|
||||
|
||||
This template should help get you started developing with Tauri and Leptos.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
[VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer).
|
||||
10
Trunk.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[build]
|
||||
target = "./index.html"
|
||||
|
||||
[watch]
|
||||
ignore = ["./src-tauri"]
|
||||
|
||||
[serve]
|
||||
port = 1420
|
||||
open = false
|
||||
ws_protocol = "ws"
|
||||
11
index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Tauri + Leptos App</title>
|
||||
<link data-trunk rel="tailwind-css" href="tailwind.css" />
|
||||
<link data-trunk rel="copy-dir" href="public" />
|
||||
<link data-trunk rel="rust" data-wasm-opt="z" />
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
11
package.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "poe2-loot-filter-tauri",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest",
|
||||
"daisyui": "^4.12.23"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
2
rust-analyzer.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[rustfmt]
|
||||
overrideCommand = ["leptosfmt", "--stdin", "--rustfmt"]
|
||||
2
rustfmt.toml
Normal file
@ -0,0 +1,2 @@
|
||||
edition = "2021"
|
||||
# (optional) other config...
|
||||
7
src-tauri/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
30
src-tauri/Cargo.toml
Normal file
@ -0,0 +1,30 @@
|
||||
[package]
|
||||
name = "poe2-loot-filter-tauri"
|
||||
version = "0.1.0"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
# The `_lib` suffix may seem redundant but it is necessary
|
||||
# to make the lib name unique and wouldn't conflict with the bin name.
|
||||
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
||||
name = "poe2_loot_filter_tauri_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
strum_macros = "0.26.4"
|
||||
strum = "0.26.3"
|
||||
reqwest = { version = "0.12.9", features = ["blocking"] }
|
||||
serde_json = "1.0.133"
|
||||
thiserror = "2.0.8"
|
||||
directories = "5.0.1"
|
||||
indoc = "2.0.5"
|
||||
3
src-tauri/build.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
10
src-tauri/capabilities/default.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"opener:default"
|
||||
]
|
||||
}
|
||||
1
src-tauri/config.json
Normal file
@ -0,0 +1 @@
|
||||
{"armours":[{"kind":"BodyArmours","armour":false,"evasion":false,"energy_shield":false,"armour_evasion":false,"armour_energy_shield":false,"evasion_energy_shield":false},{"kind":"Helmets","armour":false,"evasion":false,"energy_shield":false,"armour_evasion":false,"armour_energy_shield":false,"evasion_energy_shield":false},{"kind":"Boots","armour":false,"evasion":false,"energy_shield":false,"armour_evasion":false,"armour_energy_shield":false,"evasion_energy_shield":false},{"kind":"Gloves","armour":false,"evasion":false,"energy_shield":false,"armour_evasion":false,"armour_energy_shield":false,"evasion_energy_shield":false}],"weapons":[{"kind":"OneHandMaces","show":false},{"kind":"TwoHandMaces","show":false},{"kind":"Crossbows","show":false},{"kind":"Bows","show":false},{"kind":"Quivers","show":false},{"kind":"Sceptres","show":false},{"kind":"Wands","show":false},{"kind":"Staves","show":false},{"kind":"Quarterstaffs","show":false},{"kind":"Shields","show":false},{"kind":"Foci","show":false}],"accessories":[]}
|
||||
BIN
src-tauri/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 974 B |
BIN
src-tauri/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src-tauri/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
src-tauri/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
src-tauri/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
src-tauri/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 903 B |
BIN
src-tauri/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
src-tauri/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src-tauri/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src-tauri/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src-tauri/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src-tauri/icons/icon.icns
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
src-tauri/icons/icon.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
325
src-tauri/src/lib.rs
Normal file
@ -0,0 +1,325 @@
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{Read, Write},
|
||||
path::PathBuf,
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
use directories::{ProjectDirs, UserDirs};
|
||||
use indoc::{formatdoc, indoc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::IntoEnumIterator;
|
||||
use strum_macros::EnumIter;
|
||||
use tauri::{Manager, State};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
enum Error {
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
#[error(transparent)]
|
||||
Serde(#[from] serde_json::Error),
|
||||
}
|
||||
impl serde::Serialize for Error {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::ser::Serializer,
|
||||
{
|
||||
println!("{}", self.to_string());
|
||||
serializer.serialize_str(self.to_string().as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
#[tauri::command]
|
||||
fn update(state: State<'_, Mutex<AppState>>, config: POE2FilterConfig) {
|
||||
let mut state = state.lock().unwrap();
|
||||
write_config(state.config_dir.join(CONFIG_PATH), &config);
|
||||
let filter = generate_filter(&config);
|
||||
// write filter
|
||||
let mut config_file = File::create(state.config_dir.join(ADDON_FILTER_PATH)).unwrap();
|
||||
config_file.write_all(filter.as_bytes()).unwrap();
|
||||
|
||||
// write combined
|
||||
let combined = state.base_filter.clone()
|
||||
+ indoc! {"
|
||||
|
||||
#-------------------------------
|
||||
# Addons from Leon's config tool
|
||||
#-------------------------------
|
||||
|
||||
"} + &filter;
|
||||
let combined_bytes = combined.as_bytes();
|
||||
let mut config_file = File::create(state.config_dir.join(FINAL_FILTER_PATH)).unwrap();
|
||||
config_file.write_all(combined_bytes).unwrap();
|
||||
let user_dirs = UserDirs::new().unwrap();
|
||||
let documents_dir = user_dirs.document_dir().unwrap();
|
||||
let poe2_dir = documents_dir.join("My Games").join("Path of Exile 2");
|
||||
let mut config_file = File::create(poe2_dir.join(RELEASE_FILTER_PATH)).unwrap();
|
||||
config_file.write_all(combined_bytes).unwrap();
|
||||
|
||||
// update state
|
||||
state.config = config;
|
||||
}
|
||||
#[tauri::command]
|
||||
fn get_config(state: State<'_, Mutex<AppState>>) -> POE2FilterConfig {
|
||||
state.lock().unwrap().config.clone()
|
||||
}
|
||||
|
||||
fn generate_filter(config: &POE2FilterConfig) -> String {
|
||||
let mut rules: Vec<String> = vec![];
|
||||
let weapons_to_hide = config
|
||||
.weapons
|
||||
.iter()
|
||||
.filter(|filter| !filter.show)
|
||||
.map(|filter| format!(r#""{}""#, filter.kind.to_string()))
|
||||
.collect::<Vec<String>>()
|
||||
.join(" ");
|
||||
let max_level = config.settings.max_level;
|
||||
rules.push(with_leveling_setting(formatdoc! {"
|
||||
Hide
|
||||
Class {weapons_to_hide}"}, max_level));
|
||||
|
||||
config
|
||||
.armours
|
||||
.iter()
|
||||
.flat_map(|filter| {
|
||||
let mut armour_rules = Vec::new();
|
||||
if filter.armour {
|
||||
armour_rules.push(indoc! {"
|
||||
BaseArmour > 0
|
||||
BaseEvasion < 1
|
||||
BaseEnergyShield < 1"});
|
||||
}
|
||||
if filter.evasion {
|
||||
armour_rules.push(indoc! {"
|
||||
BaseArmour < 1
|
||||
BaseEvasion > 0
|
||||
BaseEnergyShield < 1"});
|
||||
}
|
||||
if filter.energy_shield {
|
||||
armour_rules.push(indoc! {"
|
||||
BaseArmour < 1
|
||||
BaseEvasion < 1
|
||||
BaseEnergyShield > 0"});
|
||||
}
|
||||
if filter.armour_evasion {
|
||||
armour_rules.push(indoc! {"
|
||||
BaseArmour > 0
|
||||
BaseEvasion > 0
|
||||
BaseEnergyShield < 1"});
|
||||
}
|
||||
if filter.armour_energy_shield {
|
||||
armour_rules.push(indoc! {"
|
||||
BaseArmour >
|
||||
BaseEvasion < 1
|
||||
BaseEnergyShield > 0"});
|
||||
}
|
||||
if filter.evasion_energy_shield {
|
||||
armour_rules.push(indoc! {"
|
||||
BaseArmour < 1
|
||||
BaseEvasion > 0
|
||||
BaseEnergyShield > 0"});
|
||||
}
|
||||
let kind = filter.kind.to_string();
|
||||
armour_rules
|
||||
.iter()
|
||||
.map(|rule| {
|
||||
with_leveling_setting(formatdoc! {"
|
||||
Show
|
||||
Class {kind}
|
||||
{rule}"}, max_level)
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
})
|
||||
.for_each(|rule| rules.push(rule));
|
||||
let all_armours = config
|
||||
.armours
|
||||
.iter()
|
||||
.map(|filter| format!(r#""{}""#, filter.kind.to_string()))
|
||||
.collect::<Vec<String>>()
|
||||
.join(" ");
|
||||
rules.push(with_leveling_setting(formatdoc! {"
|
||||
Hide
|
||||
Class {all_armours}"}, max_level));
|
||||
|
||||
(11..max_level)
|
||||
.map(|i| {
|
||||
let j = i - 10;
|
||||
formatdoc! {"
|
||||
Hide
|
||||
Rarity <= Magic
|
||||
AreaLevel >= {i}
|
||||
DropLevel < {j}"}
|
||||
})
|
||||
.for_each(|rule| rules.push(rule));
|
||||
|
||||
rules.join("\n\n")
|
||||
}
|
||||
|
||||
fn with_leveling_setting(str: String, max_level: u32) -> String {
|
||||
return formatdoc! {"
|
||||
{str}
|
||||
Rarity <= Magic
|
||||
AreaLevel < {max_level}
|
||||
DropLevel < {max_level}"};
|
||||
}
|
||||
|
||||
fn write_config(path: PathBuf, config: &POE2FilterConfig) {
|
||||
let serialized = serde_json::to_string_pretty(&config).unwrap();
|
||||
let mut config_file = File::create(path).unwrap();
|
||||
config_file.write_all(serialized.as_bytes()).unwrap();
|
||||
}
|
||||
|
||||
struct AppState {
|
||||
config_dir: PathBuf,
|
||||
base_filter: String,
|
||||
config: POE2FilterConfig,
|
||||
}
|
||||
|
||||
const CONFIG_PATH: &str = "config.json";
|
||||
const BASE_FILTER_PATH: &str = "base_filter.filter";
|
||||
const ADDON_FILTER_PATH: &str = "addon_filter.filter";
|
||||
const FINAL_FILTER_PATH: &str = "final_filter.filter";
|
||||
const RELEASE_FILTER_PATH: &str = "Leon.filter";
|
||||
|
||||
fn init() -> AppState {
|
||||
let config_dir = ProjectDirs::from("com", "LeonLiu", "POE2 Loot Filter")
|
||||
.map(|proj_dirs| {
|
||||
let config_dir = proj_dirs.config_dir().to_path_buf();
|
||||
if !config_dir.exists() {
|
||||
std::fs::create_dir_all(&config_dir).expect("Failed to create config directory");
|
||||
}
|
||||
config_dir
|
||||
})
|
||||
.unwrap();
|
||||
let config = File::open(config_dir.join(CONFIG_PATH))
|
||||
.map(|mut file| {
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents).unwrap();
|
||||
let deserialized: POE2FilterConfig = serde_json::from_str(&contents).unwrap();
|
||||
deserialized
|
||||
})
|
||||
.unwrap_or_else(|_| {
|
||||
let config = POE2FilterConfig {
|
||||
weapons: WeaponKind::iter()
|
||||
.map(|kind| WeaponFilter {
|
||||
kind: kind,
|
||||
show: false,
|
||||
})
|
||||
.collect(),
|
||||
armours: ArmourKind::iter()
|
||||
.map(|kind| ArmourFilter {
|
||||
kind: kind,
|
||||
armour: false,
|
||||
evasion: false,
|
||||
energy_shield: false,
|
||||
armour_evasion: false,
|
||||
armour_energy_shield: false,
|
||||
evasion_energy_shield: false,
|
||||
})
|
||||
.collect(),
|
||||
accessories: vec![],
|
||||
settings: FilterSettings {
|
||||
max_level: 80
|
||||
}
|
||||
};
|
||||
write_config(config_dir.join(CONFIG_PATH), &config);
|
||||
config
|
||||
});
|
||||
// let base_filter = File::open(config_dir.join(BASE_FILTER_PATH)).map(|mut file| {
|
||||
// let mut contents = String::new();
|
||||
// file.read_to_string(&mut contents).unwrap();
|
||||
// contents
|
||||
// }).unwrap_or_else(|_| {
|
||||
// let res = reqwest::blocking::get("https://raw.githubusercontent.com/NeverSinkDev/NeverSink-PoE2litefilter/refs/heads/main/NeverSinks%20Litefilter.filter").unwrap();
|
||||
// let content = res.text().unwrap();
|
||||
// let mut base_filter_file = File::create(config_dir.join(BASE_FILTER_PATH)).unwrap();
|
||||
// base_filter_file.write_all(content.as_bytes()).unwrap();
|
||||
// content
|
||||
// });
|
||||
let res = reqwest::blocking::get("https://raw.githubusercontent.com/NeverSinkDev/NeverSink-PoE2litefilter/refs/heads/main/NeverSinks%20Litefilter.filter").unwrap();
|
||||
let base_filter = res.text().unwrap();
|
||||
let mut base_filter_file = File::create(config_dir.join(BASE_FILTER_PATH)).unwrap();
|
||||
base_filter_file.write_all(base_filter.as_bytes()).unwrap();
|
||||
return AppState {
|
||||
config_dir: config_dir,
|
||||
base_filter: base_filter,
|
||||
config: config,
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
let state = init();
|
||||
app.manage(Mutex::new(state));
|
||||
Ok(())
|
||||
})
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.invoke_handler(tauri::generate_handler![update, get_config])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct POE2FilterConfig {
|
||||
armours: Vec<ArmourFilter>,
|
||||
weapons: Vec<WeaponFilter>,
|
||||
accessories: Vec<AccessoryFiler>,
|
||||
settings: FilterSettings,
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
struct FilterSettings {
|
||||
max_level: u32
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, strum_macros::Display, EnumIter, Serialize, Deserialize)]
|
||||
#[strum(serialize_all = "title_case")]
|
||||
enum ArmourKind {
|
||||
BodyArmours,
|
||||
Helmets,
|
||||
Boots,
|
||||
Gloves,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, strum_macros::Display, EnumIter, Serialize, Deserialize)]
|
||||
#[strum(serialize_all = "title_case")]
|
||||
enum WeaponKind {
|
||||
OneHandMaces,
|
||||
TwoHandMaces,
|
||||
Crossbows,
|
||||
Bows,
|
||||
Quivers,
|
||||
Sceptres,
|
||||
Wands,
|
||||
Staves,
|
||||
Quarterstaves,
|
||||
Shields,
|
||||
Foci,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, strum_macros::Display, EnumIter, Serialize, Deserialize)]
|
||||
#[strum(serialize_all = "title_case")]
|
||||
enum AccessoryKind {}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct ArmourFilter {
|
||||
kind: ArmourKind,
|
||||
armour: bool,
|
||||
evasion: bool,
|
||||
energy_shield: bool,
|
||||
armour_evasion: bool,
|
||||
armour_energy_shield: bool,
|
||||
evasion_energy_shield: bool,
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct WeaponFilter {
|
||||
kind: WeaponKind,
|
||||
show: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct AccessoryFiler {
|
||||
kind: AccessoryKind,
|
||||
}
|
||||
6
src-tauri/src/main.rs
Normal file
@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
poe2_loot_filter_tauri_lib::run()
|
||||
}
|
||||
35
src-tauri/tauri.conf.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "poe2-loot-filter-tauri",
|
||||
"version": "0.1.0",
|
||||
"identifier": "com.poe2-loot-filter-tauri.app",
|
||||
"build": {
|
||||
"beforeDevCommand": "trunk serve",
|
||||
"devUrl": "http://localhost:1420",
|
||||
"beforeBuildCommand": "trunk build",
|
||||
"frontendDist": "../dist"
|
||||
},
|
||||
"app": {
|
||||
"withGlobalTauri": true,
|
||||
"windows": [
|
||||
{
|
||||
"title": "poe2-loot-filter-tauri",
|
||||
"maximized": true
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||
327
src/app.rs
Normal file
@ -0,0 +1,327 @@
|
||||
use std::{fs::File, io::Read, sync::Arc};
|
||||
|
||||
use leptos::prelude::{Read as Reads, *};
|
||||
use reactive_stores::Store;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_wasm_bindgen::from_value;
|
||||
use strum_macros::EnumIter;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen_futures::spawn_local;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct Test {
|
||||
a: Arc<str>,
|
||||
}
|
||||
|
||||
impl Test {
|
||||
fn new() -> Self {
|
||||
let mut buf = String::new();
|
||||
let _ = File::open("").unwrap().read_to_string(&mut buf);
|
||||
serde_json::from_str(&buf).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
// invoke without arguments
|
||||
#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "core"], js_name = invoke)]
|
||||
async fn invoke_without_args(cmd: &str) -> JsValue;
|
||||
|
||||
// invoke with arguments (default)
|
||||
#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "core"])]
|
||||
async fn invoke(cmd: &str, args: JsValue) -> JsValue;
|
||||
|
||||
// They need to have different names!
|
||||
}
|
||||
#[derive(Store, Debug, Clone, Serialize, Deserialize)]
|
||||
struct POE2FilterConfig {
|
||||
#[store(key: String = |row| row.kind.to_string())]
|
||||
armours: Vec<ArmourFilter>,
|
||||
#[store(key: String = |row| row.kind.to_string())]
|
||||
weapons: Vec<WeaponFilter>,
|
||||
#[store(key: String = |row| row.kind.to_string())]
|
||||
accessories: Vec<AccessoryFiler>,
|
||||
settings: FilterSettings,
|
||||
}
|
||||
|
||||
#[derive(Store, Debug, Clone, Serialize, Deserialize, Default)]
|
||||
struct FilterSettings {
|
||||
max_level: u32,
|
||||
}
|
||||
|
||||
#[derive(Store, Debug, Clone, strum_macros::Display, EnumIter, Serialize, Deserialize)]
|
||||
#[strum(serialize_all = "title_case")]
|
||||
enum ArmourKind {
|
||||
BodyArmours,
|
||||
Helmets,
|
||||
Boots,
|
||||
Gloves,
|
||||
}
|
||||
|
||||
#[derive(Store, Debug, Clone, strum_macros::Display, EnumIter, Serialize, Deserialize)]
|
||||
#[strum(serialize_all = "title_case")]
|
||||
enum WeaponKind {
|
||||
OneHandMaces,
|
||||
TwoHandMaces,
|
||||
Crossbows,
|
||||
Bows,
|
||||
Quivers,
|
||||
Sceptres,
|
||||
Wands,
|
||||
Staves,
|
||||
Quarterstaves,
|
||||
Shields,
|
||||
Foci,
|
||||
}
|
||||
|
||||
#[derive(Store, Debug, Clone, strum_macros::Display, EnumIter, Serialize, Deserialize)]
|
||||
#[strum(serialize_all = "title_case")]
|
||||
enum AccessoryKind {}
|
||||
|
||||
#[derive(Store, Debug, Clone, Serialize, Deserialize)]
|
||||
struct ArmourFilter {
|
||||
kind: ArmourKind,
|
||||
armour: bool,
|
||||
evasion: bool,
|
||||
energy_shield: bool,
|
||||
armour_evasion: bool,
|
||||
armour_energy_shield: bool,
|
||||
evasion_energy_shield: bool,
|
||||
}
|
||||
#[derive(Store, Debug, Clone, Serialize, Deserialize)]
|
||||
struct WeaponFilter {
|
||||
kind: WeaponKind,
|
||||
show: bool,
|
||||
}
|
||||
|
||||
#[derive(Store, Debug, Clone, Serialize, Deserialize)]
|
||||
struct AccessoryFiler {
|
||||
kind: AccessoryKind,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct UpdateArgs {
|
||||
config: POE2FilterConfig,
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Main(config: POE2FilterConfig) -> impl IntoView {
|
||||
let store = Store::new(config);
|
||||
Effect::new(move |_| {
|
||||
let config = store.get();
|
||||
spawn_local(async move {
|
||||
let args = serde_wasm_bindgen::to_value(&UpdateArgs { config: config }).unwrap();
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
invoke("update", args).await;
|
||||
});
|
||||
});
|
||||
|
||||
let max_level = store.settings().max_level();
|
||||
view! {
|
||||
<main class="container p-4">
|
||||
<ul class="list-disc pl-4 pb-2">
|
||||
<li>"Config folder: %appdata%\\LeonLiu\\POE2 Loot Filter\\config"</li>
|
||||
<li>
|
||||
"Changes on the UI will immediately write the new filter file into POE2's config folder. Reload the filter in-game after changes on the UI."
|
||||
</li>
|
||||
<li>"The output filter is named " <strong>Leon</strong>.</li>
|
||||
<li>
|
||||
"Based on "
|
||||
<a
|
||||
class="text-blue-600 visited:text-purple-600"
|
||||
target="_blank"
|
||||
href="https://github.com/NeverSinkDev/NeverSink-PoE2litefilter"
|
||||
>
|
||||
NeverSink-PoE2litefilter
|
||||
</a>, will download on every app launch, saved as
|
||||
" base_filter.filter in the config folder".
|
||||
</li>
|
||||
<li>
|
||||
"From area level 11 to 69, hide normal or magic items of which the drop level is 10 level lower than the area level."
|
||||
</li>
|
||||
<li>
|
||||
"In areas lower than level"
|
||||
<input
|
||||
class="mx-1 h-8"
|
||||
type="number"
|
||||
min="60"
|
||||
max="100"
|
||||
prop:value=max_level.get()
|
||||
on:input:target=move |ev| {
|
||||
*max_level.write() = ev.target().value().parse::<u32>().unwrap_or(70);
|
||||
}
|
||||
/> ",hide normal or magic items, unless turned on in configurations below."
|
||||
</li>
|
||||
</ul>
|
||||
<h2 class="text-2xl font-bold">Weapons</h2>
|
||||
<p class="my-2">
|
||||
{format!(
|
||||
"In areas lower than level {}, only show normal or magic weapons selected.",
|
||||
max_level.get(),
|
||||
)}
|
||||
</p>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<For
|
||||
each=move || store.weapons()
|
||||
key=|row| row.read().kind.to_string()
|
||||
children=|child| {
|
||||
let kind = child.clone().kind().get().to_string();
|
||||
let show = child.show();
|
||||
view! {
|
||||
<label class="inline-flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
prop:checked=show.get()
|
||||
on:change:target=move |ev| {
|
||||
*show.write() = event_target_checked(&ev);
|
||||
}
|
||||
/>
|
||||
<span class="ml-2">{kind.clone()}</span>
|
||||
</label>
|
||||
}
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<h2 class="text-2xl font-bold">Armours</h2>
|
||||
<p class="my-2">
|
||||
{format!(
|
||||
"In areas lower than level {}, only show normal or magic armours with selected base defence types.",
|
||||
max_level.get(),
|
||||
)}
|
||||
</p>
|
||||
<div class="">
|
||||
<For
|
||||
each=move || store.armours()
|
||||
key=|row| row.read().kind.to_string()
|
||||
children=|child| {
|
||||
let kind = child.clone().kind().get().to_string();
|
||||
let armour = child.clone().armour();
|
||||
let evasion = child.clone().evasion();
|
||||
let energy_shield = child.clone().energy_shield();
|
||||
let armour_evasion = child.clone().armour_evasion();
|
||||
let armour_energy_shield = child.clone().armour_energy_shield();
|
||||
let evasion_energy_shield = child.clone().evasion_energy_shield();
|
||||
view! {
|
||||
<h2 class="text-xl">{kind.clone()}</h2>
|
||||
<div class="flex gap-2">
|
||||
<label class="inline-flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id=kind.clone() + "Armour"
|
||||
name=kind.clone() + "Armour"
|
||||
prop:checked=armour.get()
|
||||
on:change:target=move |ev| {
|
||||
*armour.write() = event_target_checked(&ev);
|
||||
}
|
||||
/>
|
||||
<span class="ml-2">"Armour"</span>
|
||||
</label>
|
||||
<label class="inline-flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id=kind.clone() + "Evasion"
|
||||
name=kind.clone() + "Evasion"
|
||||
prop:checked=evasion.get()
|
||||
on:change:target=move |ev| {
|
||||
*evasion.write() = event_target_checked(&ev);
|
||||
}
|
||||
/>
|
||||
<span class="ml-2">"Evasion"</span>
|
||||
</label>
|
||||
<label class="inline-flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id=kind.clone() + "EnergyShield"
|
||||
name=kind.clone() + "EnergyShield"
|
||||
prop:checked=energy_shield.get()
|
||||
on:change:target=move |ev| {
|
||||
*energy_shield.write() = event_target_checked(&ev);
|
||||
}
|
||||
/>
|
||||
<span class="ml-2">"Energy Shield"</span>
|
||||
</label>
|
||||
<label class="inline-flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id=kind.clone() + "ArmourEvasion"
|
||||
name=kind.clone() + "ArmourEvasion"
|
||||
prop:checked=armour_evasion.get()
|
||||
on:change:target=move |ev| {
|
||||
*armour_evasion.write() = event_target_checked(&ev);
|
||||
}
|
||||
/>
|
||||
<span class="ml-2">"Armour + Evasion"</span>
|
||||
</label>
|
||||
<label class="inline-flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id=kind.clone() + "ArmourEnergyShield"
|
||||
name=kind.clone() + "ArmourEnergyShield"
|
||||
prop:checked=armour_energy_shield.get()
|
||||
on:change:target=move |ev| {
|
||||
*armour_energy_shield.write() = event_target_checked(&ev);
|
||||
}
|
||||
/>
|
||||
<span class="ml-2">"Armour + Energy Shield"</span>
|
||||
</label>
|
||||
<label class="inline-flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id=kind.clone() + "EvasionEnergyShield"
|
||||
name=kind.clone() + "EvasionEnergyShield"
|
||||
prop:checked=evasion_energy_shield.get()
|
||||
on:change:target=move |ev| {
|
||||
*evasion_energy_shield.write() = event_target_checked(&ev);
|
||||
}
|
||||
/>
|
||||
<span class="ml-2">"Evasion + Energy Shield"</span>
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_data() -> POE2FilterConfig {
|
||||
from_value(invoke_without_args("get_config").await).unwrap()
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
let config = LocalResource::new(move || load_data());
|
||||
view! {
|
||||
<Suspense fallback=move || {
|
||||
view! {
|
||||
<main class="flex items-center justify-center h-screen">
|
||||
<div class="inline-flex items-center justify-start gap-1">
|
||||
<svg
|
||||
role="status"
|
||||
class="mr-2 h-8 w-8 animate-spin fill-green-600 text-gray-100 dark:text-gray-600"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
></path>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
></path>
|
||||
</svg>
|
||||
<span>Loading...</span>
|
||||
</div>
|
||||
</main>
|
||||
}
|
||||
}>
|
||||
{move || {
|
||||
config.get().as_deref().map(|config| view! { <Main config=config.clone() /> })
|
||||
}}
|
||||
</Suspense>
|
||||
}
|
||||
}
|
||||
13
src/main.rs
Normal file
@ -0,0 +1,13 @@
|
||||
mod app;
|
||||
|
||||
use app::*;
|
||||
use leptos::prelude::*;
|
||||
|
||||
fn main() {
|
||||
console_error_panic_hook::set_once();
|
||||
mount_to_body(|| {
|
||||
view! {
|
||||
<App/>
|
||||
}
|
||||
})
|
||||
}
|
||||
13
tailwind.config.js
Normal file
@ -0,0 +1,13 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: {
|
||||
files: ["*.html", "./src/**/*.rs"],
|
||||
transform: {
|
||||
rs: (content) => content.replace(/(?:^|\s)class:/g, ' '),
|
||||
},
|
||||
},
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [require('daisyui')],
|
||||
}
|
||||
3
tailwind.css
Normal file
@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||