Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(almanax): multi days Almanax #54

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-coats-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ganymede-app": minor
---

Vous pouvez désormais visualiser l'Almanax sur plusieurs jours. L'affichage de l'Almanax a légèrement changé.
5 changes: 5 additions & 0 deletions .changeset/chilly-snails-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ganymede-app": minor
---

Vous pouvez désormais choisir votre niveau lors du calcul des récompenses de l'Almanax.
5 changes: 5 additions & 0 deletions .changeset/sixty-buckets-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ganymede-app": minor
---

L'Almanax prend désormais en charge les différents fuseaux horaires. Les serveurs étant tous basés sur le fuseau horaire Europe/Paris, l'application prend donc également cette direction.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"clsx": "^2.1.1",
"cmdk": "^1.0.4",
"country-flag-icons": "^1.5.14",
"dayjs": "^1.11.13",
"html-react-parser": "^5.2.2",
"lucide-react": "^0.474.0",
"neverthrow": "^8.1.1",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tauri-plugin-log = "2.2.0"
log = "^0.4"
taurpc = { path = "./taurpc", version = "0.3.2" }
tauri-plugin-opener = "2.2.1"
chrono-tz = "0.10.1"

[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-window-state = "2.2.0"
Expand Down
48 changes: 11 additions & 37 deletions src-tauri/src/almanax.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::api::DOFUSDB_API;
use crate::item::Item;
use crate::quest::get_quest_data;
use chrono::Datelike;
use chrono::prelude::*;
use chrono_tz::Europe::Paris;
use serde::{Deserialize, Serialize};
use tauri::AppHandle;
use tauri_plugin_http::reqwest;
Expand All @@ -10,7 +11,6 @@ use crate::conf::{Conf, ConfLang};

const REWARD_REDUCED_SCALE: f32 = 0.7;
const REWARD_SCALE_CAP: f32 = 1.5;
const PLAYER_LEVEL: u32 = 200;

#[derive(Debug, Serialize, thiserror::Error)]
pub enum Error {
Expand All @@ -32,34 +32,6 @@ pub enum Error {
Quest(#[from] crate::quest::Error),
}

// impl Into<tauri::ipc::InvokeError> for Error {
// fn into(self) -> tauri::ipc::InvokeError {
// match self {
// Error::DofusDbAlmanaxMalformed(err) => tauri::ipc::InvokeError::from(format!(
// "DofusDbAlmanaxMalformed({})",
// err.to_string()
// )),
// Error::DofusDbItemMalformed(err) => {
// tauri::ipc::InvokeError::from(format!("DofusDbItemMalformed({})", err.to_string()))
// }
// Error::RequestAlmanax(err) => {
// tauri::ipc::InvokeError::from(format!("RequestAlmanax({})", err.to_string()))
// }
// Error::RequestAlmanaxContent(err) => {
// tauri::ipc::InvokeError::from(format!("RequestAlmanaxContent({})", err.to_string()))
// }
// Error::RequestItem(err) => {
// tauri::ipc::InvokeError::from(format!("RequestItem({})", err.to_string()))
// }
// Error::RequestItemContent(err) => {
// tauri::ipc::InvokeError::from(format!("RequestItemContent({})", err.to_string()))
// }
// Error::Conf(err) => err.into(),
// Error::Quest(err) => err.into(),
// }
// }
// }

#[derive(Serialize, Deserialize, Debug)]
pub struct AlmanaxName {
en: String,
Expand Down Expand Up @@ -160,8 +132,10 @@ pub fn get_experience_reward(
}
}

pub async fn get_almanax_data() -> Result<Almanax, Error> {
let date = chrono::offset::Local::now();
pub async fn get_almanax_data(date: String) -> Result<Almanax, Error> {
let date = DateTime::parse_from_rfc3339(date.as_str())
.unwrap()
.with_timezone(&Paris);
let day = date.day();
let month = date.month();
let year = date.year();
Expand Down Expand Up @@ -200,16 +174,16 @@ pub async fn get_item_data(item_id: u32) -> Result<Item, Error> {

#[taurpc::procedures(path = "almanax", export_to = "../src/ipc/bindings.ts")]
pub trait AlmanaxApi {
async fn get(app_handle: AppHandle) -> Result<AlmanaxReward, Error>;
async fn get(app_handle: AppHandle, level: u32, date: String) -> Result<AlmanaxReward, Error>;
}

#[derive(Clone)]
pub struct AlmanaxApiImpl;

#[taurpc::resolvers]
impl AlmanaxApi for AlmanaxApiImpl {
async fn get(self, app: AppHandle) -> Result<AlmanaxReward, Error> {
let almanax = get_almanax_data().await?;
async fn get(self, app: AppHandle, level: u32, date: String) -> Result<AlmanaxReward, Error> {
let almanax = get_almanax_data(date).await?;
let quest = get_quest_data(almanax.id).await.map_err(Error::Quest)?;
let item_id = quest.data[0].steps[0].objectives[0].need.generated.items[0];
let quantity = quest.data[0].steps[0].objectives[0]
Expand All @@ -227,14 +201,14 @@ impl AlmanaxApi for AlmanaxApiImpl {
};

let experience = get_experience_reward(
PLAYER_LEVEL,
level,
quest.optimal_level(),
quest.experience_ratio(),
quest.duration(),
);

let kamas = get_kamas_reward(
PLAYER_LEVEL,
level,
quest.level_max(),
quest.optimal_level(),
quest.kamas_ratio(),
Expand Down
28 changes: 9 additions & 19 deletions src-tauri/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ use std::collections::HashMap;
use std::fs;
use tauri::{AppHandle, Manager, Window, Wry};

const DEFAULT_LEVEL: u32 = 200;

const fn default_level() -> u32 {
DEFAULT_LEVEL
}

#[derive(Debug, Serialize, thiserror::Error)]
pub enum Error {
#[error("failed to get conf, file is malformed")]
Expand All @@ -26,29 +32,12 @@ pub enum Error {
ResetConf(Box<Error>),
}

// impl Into<InvokeError> for Error {
// fn into(self) -> InvokeError {
// use Error::*;

// let message = match self {
// Malformed(err) => format!("Malformed({})", err.to_string()),
// CreateConfDir(err) => format!("CreateConfDir({})", err.to_string()),
// ConfDir(err) => format!("ConfDir({})", err.to_string()),
// SerializeConf(err) => format!("SerializeConf({})", err.to_string()),
// UnhandledIo(err) => format!("UnhandledIo({})", err.to_string()),
// SaveConf(err) => format!("SaveConf({})", err.to_string()),
// GetProfileInUse => "GetProfileInUse".to_string(),
// ResetConf(err) => return (*err).into(),
// };

// InvokeError::from(message)
// }
// }

#[derive(Serialize, Deserialize, Debug, Clone, taurpc::specta::Type)]
pub struct Profile {
pub id: String,
pub name: String,
#[serde(default = "default_level")]
pub level: u32,
pub progresses: Vec<Progress>,
}

Expand Down Expand Up @@ -243,6 +232,7 @@ impl Default for Profile {
Profile {
id: uuid::Uuid::new_v4().to_string(),
name: "Player".to_string(),
level: 200,
progresses: vec![],
}
}
Expand Down
Loading