Skip to content

Commit

Permalink
#18 show warning on UI about spt version
Browse files Browse the repository at this point in the history
  • Loading branch information
angel-git committed Aug 18, 2023
1 parent 053cd2b commit b7dec77
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ Simple stash editor with a simple UI. If you need more advanced features I recom

This is based out of another project of mine: [task-stash-console](https://github.com/angel-git/tarkov-stash-console):

> Some versions are not compatible, please check the terminal logs to see warnings
### Requirements

It is recommended to run this with [Windows terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701) and not the default command prompt, it supports emojis :-)

### Features

- Set *found in raid* to items
- Backup your profile
- Set _found in raid_ to items
- Increase currencies

### Demo
### Screenshots

TODO

Expand Down
24 changes: 13 additions & 11 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,18 @@ fn load_profile_file(state: State<TarkovStashState>) -> Result<UIProfile, String
let binding = b.as_ref();
match binding {
Some(file) => {
if !is_server_compatible(file) {
println!("🔥 Your current spt-server version might not be compatible! use with *more* caution")
}
create_backup(file);
let bsg_items = load_bsg_items(file);
let locale = load_locale(file);
let content = fs::read_to_string(file).unwrap();
let tarkov_profile = load_profile(content.as_str());
match tarkov_profile {
Ok(p) => Ok(convert_profile_to_ui(
p,
bsg_items.as_str(),
locale.as_str(),
)),
Ok(p) => {
let mut ui_profile =
convert_profile_to_ui(p, bsg_items.as_str(), locale.as_str());
ui_profile.spt_version = Some(get_server_version(file));
Ok(ui_profile)
}
Err(e) => Err(e.to_string()),
}
}
Expand Down Expand Up @@ -130,7 +128,7 @@ fn is_server_running() -> bool {
TcpStream::connect("127.0.0.1:6969").is_ok()
}

fn is_server_compatible(file: &String) -> bool {
fn get_server_version(file: &String) -> String {
let core = Path::new(file)
.ancestors()
.nth(3)
Expand All @@ -142,8 +140,12 @@ fn is_server_compatible(file: &String) -> bool {

let core_json: Value =
serde_json::from_str(fs::read_to_string(core).unwrap().as_str()).unwrap();
let version = core_json.get("akiVersion").unwrap().as_str().unwrap();
version.starts_with("3.6")
core_json
.get("akiVersion")
.unwrap()
.as_str()
.unwrap()
.to_string()
}

fn create_backup(profile_path: &str) {
Expand Down
7 changes: 5 additions & 2 deletions src-tauri/src/ui_profile/ui_profile_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct UIProfile {
pub items: Vec<Item>,
#[serde(rename = "bsgItems")]
pub bsg_items: HashMap<String, BsgItem>,
#[serde(rename = "sptVersion")]
pub spt_version: Option<String>,
}

#[derive(Deserialize, Serialize, Debug)]
Expand Down Expand Up @@ -131,11 +133,11 @@ pub fn convert_profile_to_ui(
let id = item.get("_id").unwrap().as_str().unwrap();
if let Some(props) = item.get("_props") {
if let Some(name) = props.get("ShortName") {
let locale_id = format!("{} Name", id.to_string());
let locale_id = format!("{} Name", id);
let maybe_name = locale_root.get(locale_id.as_str());
let name = maybe_name
.and_then(|v| v.as_str())
.unwrap_or(name.as_str().unwrap());
.unwrap_or_else(|| name.as_str().unwrap());
bsg_items.insert(
id.to_string(),
BsgItem {
Expand All @@ -153,6 +155,7 @@ pub fn convert_profile_to_ui(
size_y: stash_size_y,
items,
bsg_items,
spt_version: None,
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/routes/stash/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import Loading from '$lib/images/loading.gif';
import { invokeWithLoader } from '../../helper';
const supported_version = '3.6';
$: isLoading = $loading;
let selectedOption: Option | undefined;
let selectedItem: Item | undefined;
Expand Down Expand Up @@ -39,6 +41,11 @@

<div class="container container-center">
{#if $profile}
{#if !$profile.sptVersion.startsWith(supported_version)}
<h4 style="color: orangered">
{`Your SPT version ${$profile.sptVersion} might not be compatible with current supported version: ${supported_version}.x`}
</h4>
{/if}
<h3>
Editing <span class="highlight">{$profile.name}</span>'s stash
</h3>
Expand Down
5 changes: 1 addition & 4 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
export interface IProfile {
profile?: Profile;
}

export interface Profile {
name: string;
sizeX: number;
sizeY: number;
items: Array<Item>;
bsgItems: { [key: string]: BsgItem };
sptVersion: string;
}

export interface Item {
Expand Down

0 comments on commit b7dec77

Please sign in to comment.