Skip to content
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
13 changes: 11 additions & 2 deletions app/src-tauri/src/commands/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::atomic::Ordering;
use chrono::{DateTime, Utc};
use serde::Serialize;
use wf_core::{
ARBITRATION_FORECAST_TRUSTED, ArbitrationSchedule, CircuitRotation, Core, ItemTable,
WorldOfferOwnership, WorldRewardAlert,
ARBITRATION_FORECAST_TRUSTED, ArbitrationSchedule, BountyAlertOptions, CircuitRotation, Core,
ItemTable, WorldBountyBoard, WorldOfferOwnership, WorldRewardAlert,
};
use wf_data::store_item_to_type;
use wf_worldstate::{
Expand Down Expand Up @@ -32,6 +32,7 @@ pub struct WorldStateView {
pub prime_resurgence: Option<PrimeResurgence>,
pub nightwave: Option<NightwaveSeason>,
pub world_reward_alerts: Vec<WorldRewardAlert>,
pub bounty_boards: Vec<WorldBountyBoard>,
pub daily_reset: ResetWindow,
pub weekly_reset: ResetWindow,
pub fetched_at: Option<DateTime<Utc>>,
Expand Down Expand Up @@ -308,6 +309,7 @@ impl WorldStateView {
prime_resurgence: None,
nightwave: None,
world_reward_alerts: Vec::new(),
bounty_boards: Vec::new(),
daily_reset: daily_reset_window(now),
weekly_reset: weekly_reset_window(now),
fetched_at,
Expand All @@ -332,6 +334,7 @@ impl WorldStateView {
core.catalog().nightwave_act_text(challenge)
}),
world_reward_alerts: core.world_reward_alerts(now),
bounty_boards: core.bounty_boards(now),
daily_reset: daily_reset_window(now),
weekly_reset: weekly_reset_window(now),
fetched_at,
Expand All @@ -354,6 +357,12 @@ pub async fn invasion_weapon_parts(state: Shared<'_>) -> CommandResult<Vec<Invas
Ok(parts)
}

#[tauri::command]
pub async fn bounty_alert_options(state: Shared<'_>) -> CommandResult<BountyAlertOptions> {
let state = ready(&state).await?;
Ok(lock(&state.core).bounty_alert_options())
}

#[tauri::command]
pub async fn arbitrations(state: Shared<'_>) -> CommandResult<ArbitrationDashboard> {
let state = ready(&state).await?;
Expand Down
1 change: 1 addition & 0 deletions app/src-tauri/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn kind(event: &CoreEvent) -> &'static str {
CoreEvent::NewConversation { .. } => "new-conversation",
CoreEvent::FissureAlert { .. } => "fissure-alert",
CoreEvent::WorldRewardAlert { .. } => "world-reward-alert",
CoreEvent::WorldBountyAlert { .. } => "world-bounty-alert",
CoreEvent::ArbitrationAlert { .. } => "arbitration-alert",
CoreEvent::ArbitrationRunUpdated { .. } => "arbitration-run-updated",
CoreEvent::ArbitrationRunRecorded { .. } => "arbitration-run-recorded",
Expand Down
8 changes: 7 additions & 1 deletion app/src-tauri/src/event_feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tracing::{debug, info, warn};
use wf_core::{
ArbitrationAlert, ArbitrationRun, CoreEvent, FissureInfo, InventorySummary,
ResetChecklistGroup, ResetChecklistProgress, ResetChecklistRow, ResetChecklistRowId,
RewardScreen, Trade, WorldRewardAlert,
RewardScreen, Trade, WorldBountyAlert, WorldRewardAlert,
};

use crate::runtime::{AppEvent, MarketAutoClose, update_status};
Expand Down Expand Up @@ -120,6 +120,9 @@ pub enum FeedEvent {
WorldRewardAlert {
reward: WorldRewardAlert,
},
WorldBountyAlert {
alert: WorldBountyAlert,
},
ArbitrationAlert {
alert: ArbitrationAlert,
},
Expand Down Expand Up @@ -185,6 +188,9 @@ impl FeedEvent {
CoreEvent::WorldRewardAlert { reward } => Some(Self::WorldRewardAlert {
reward: reward.clone(),
}),
CoreEvent::WorldBountyAlert { alert } => Some(Self::WorldBountyAlert {
alert: alert.clone(),
}),
CoreEvent::ArbitrationAlert { alert } => Some(Self::ArbitrationAlert {
alert: alert.clone(),
}),
Expand Down
1 change: 1 addition & 0 deletions app/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ fn commands<R: Runtime>() -> impl Fn(tauri::ipc::Invoke<R>) -> bool {
commands::market::market_set_auctions_visibility,
commands::world::worldstate,
commands::world::invasion_weapon_parts,
commands::world::bounty_alert_options,
commands::world::arbitrations,
commands::arbitrations::arbitration_runs,
commands::arbitrations::arbitration_live_run,
Expand Down
52 changes: 50 additions & 2 deletions app/src-tauri/src/notice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::fmt::Write as _;

use serde::Serialize;
use wf_core::{
ArbitrationAlert, ArbitrationRun, CoreEvent, FissureInfo, InventorySummary, WorldRewardAlert,
counted, thousands,
ArbitrationAlert, ArbitrationRun, CoreEvent, FissureInfo, InventorySummary, WorldBountyAlert,
WorldRewardAlert, counted, thousands,
};
use wf_worldstate::{EARTH_AND_CETUS, WorldRewardSource};

Expand Down Expand Up @@ -40,6 +40,7 @@ impl Notice {
CoreEvent::NewConversation { player, .. } => Some(Self::conversation(player)),
CoreEvent::FissureAlert { fissure } => Some(Self::fissure(fissure)),
CoreEvent::WorldRewardAlert { reward } => Some(Self::reward(reward)),
CoreEvent::WorldBountyAlert { alert } => Some(Self::bounty(alert)),
CoreEvent::ArbitrationAlert { alert } => Some(Self::arbitration(alert)),
CoreEvent::ArbitrationRunRecorded { run } => Some(Self::arbitration_run(run)),
CoreEvent::TimerAlert {
Expand Down Expand Up @@ -138,6 +139,29 @@ impl Notice {
}
}

pub fn bounty(alert: &WorldBountyAlert) -> Self {
let (title, listed) = match alert.bounties.as_slice() {
[bounty] => (format!("{} bounty: {bounty}", alert.syndicate), None),
bounties => (
format!("{} {} bounties", bounties.len(), alert.syndicate),
Some(bounties.join(", ")),
),
};
let rewards = (!alert.rewards.is_empty()).then(|| alert.rewards.join(", "));
let left = format!("{} left", countdown(alert.remaining_secs));
Self {
title,
body: listed
.into_iter()
.chain(rewards)
.chain([left])
.collect::<Vec<String>>()
.join(". "),
tone: Tone::Warning,
in_game: Some(InGameToast::Bounty),
}
}

pub fn arbitration(alert: &ArbitrationAlert) -> Self {
let node = &alert.slot.node;
let mission = node.mission_type.unwrap_or("Unknown mission");
Expand Down Expand Up @@ -388,6 +412,30 @@ mod tests {
assert_eq!(countdown(2 * 86_400 + 5 * 3600), "2d 5h");
}

#[test]
fn bounty_notice() {
let alert = |bounties: &[&str], rewards: &[&str]| WorldBountyAlert {
syndicate: String::from("Ostrons"),
bounties: bounties.iter().map(|&name| name.to_owned()).collect(),
rewards: rewards.iter().map(|&name| name.to_owned()).collect(),
expiry: DateTime::from_timestamp(9000, 0).unwrap(),
remaining_secs: 8940,
};
let one = Notice::bounty(&alert(&["Spy Catcher (40-60)"], &["2 x Cetus Wisp"]));
let two = Notice::bounty(&alert(
&["Spy Catcher (40-60)", "Cull The Enemy (5-15)"],
&[],
));

assert_eq!(one.title, "Ostrons bounty: Spy Catcher (40-60)");
assert_eq!(one.body, "2 x Cetus Wisp. 2h 29m left");
assert_eq!(two.title, "2 Ostrons bounties");
assert_eq!(
two.body,
"Spy Catcher (40-60), Cull The Enemy (5-15). 2h 29m left"
);
}

#[test]
fn reward_notice() {
let invasion = WorldRewardAlert {
Expand Down
47 changes: 30 additions & 17 deletions app/src-tauri/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tauri_plugin_clipboard_manager::ClipboardExt;
#[cfg(not(target_os = "linux"))]
use tauri_plugin_notification::NotificationExt;
use tracing::{debug, error, info, warn};
use wf_core::{ArbitrationAlert, CoreEvent};
use wf_core::{ArbitrationAlert, CoreEvent, Trade};

use crate::envelope::CoreEventEnvelope;
use crate::event_feed::{self, EventFeed};
Expand Down Expand Up @@ -171,22 +171,7 @@ async fn deliver<R: Runtime>(app: &AppHandle<R>, state: &Arc<AppState>, event: &
}
}
CoreEvent::TradeCompleted { trade, .. } => {
info!(
offered = trade.offered.len(),
received = trade.received.len(),
plat = trade.plat,
"Trade completed"
);
debug!(
offered = ?trade.offered,
received = ?trade.received,
"Trade items"
);
count_trade(app, state);
emit(app, AppEvent::TradesUpdated);
if settings.market.market_auto_close {
auto_close(app, state, trade).await;
}
trade_completed(app, state, &settings, trade).await;
}
CoreEvent::FissureAlert { fissure } => {
let notice = Notice::fissure(fissure);
Expand All @@ -203,6 +188,10 @@ async fn deliver<R: Runtime>(app: &AppHandle<R>, state: &Arc<AppState>, event: &
let notice = Notice::reward(reward);
world_alert(app, state, &settings, &notice, DiscordMirroredAlert::Reward).await;
}
CoreEvent::WorldBountyAlert { alert } => {
let notice = Notice::bounty(alert);
world_alert(app, state, &settings, &notice, DiscordMirroredAlert::Bounty).await;
}
CoreEvent::ArbitrationAlert { alert } => {
arbitration_alert(app, state, &settings, alert).await;
}
Expand Down Expand Up @@ -234,6 +223,30 @@ async fn deliver<R: Runtime>(app: &AppHandle<R>, state: &Arc<AppState>, event: &
}
}

async fn trade_completed<R: Runtime>(
app: &AppHandle<R>,
state: &Arc<AppState>,
settings: &Settings,
trade: &Trade,
) {
info!(
offered = trade.offered.len(),
received = trade.received.len(),
plat = trade.plat,
"Trade completed"
);
debug!(
offered = ?trade.offered,
received = ?trade.received,
"Trade items"
);
count_trade(app, state);
emit(app, AppEvent::TradesUpdated);
if settings.market.market_auto_close {
auto_close(app, state, trade).await;
}
}

async fn world_alert<R: Runtime>(
app: &AppHandle<R>,
state: &Arc<AppState>,
Expand Down
2 changes: 2 additions & 0 deletions app/src-tauri/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ pub enum InGameToast {
Trade,
Fissure,
Reward,
Bounty,
Arbitration,
Timer,
MarketClose,
Expand Down Expand Up @@ -281,6 +282,7 @@ pub enum DiscordMirroredAlert {
Conversation,
Fissure,
Reward,
Bounty,
Arbitration,
Timer,
}
Expand Down
21 changes: 13 additions & 8 deletions app/src/components/item-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export function ItemSearch<T extends Searchable>({
items,
placeholder,
disabled,
listOnFocus = false,
onPick,
}: {
items: readonly T[];
placeholder: string;
disabled?: boolean;
listOnFocus?: boolean;
onPick: (item: T) => void;
}) {
const [query, setQuery] = useState("");
Expand All @@ -30,8 +32,9 @@ export function ItemSearch<T extends Searchable>({
const matches = useMemo(() => {
const search = query.trim().toLowerCase();
if (!search) {
return [];
return listOnFocus ? items : [];
}

return items
.filter((item) => item.name.toLowerCase().includes(search))
.sort(
Expand All @@ -40,7 +43,7 @@ export function ItemSearch<T extends Searchable>({
Number(a.name.toLowerCase() === search),
)
.slice(0, 20);
}, [items, query]);
}, [items, query, listOnFocus]);

const listed = open && matches.length > 0;
return (
Expand All @@ -57,7 +60,7 @@ export function ItemSearch<T extends Searchable>({
setQuery(next);
setOpen(true);
}}
onFocus={() => setOpen(query.trim().length > 0)}
onFocus={() => setOpen(listOnFocus || query.trim().length > 0)}
onBlur={() => setOpen(false)}
onKeyDown={(e) => {
if (e.key === "Escape") {
Expand Down Expand Up @@ -89,11 +92,13 @@ export function ItemSearch<T extends Searchable>({
onPick(item);
}}
>
<ItemImage
imageName={item.image_name}
size={24}
alt={item.name}
/>
{item.image_name && (
<ItemImage
imageName={item.image_name}
size={24}
alt={item.name}
/>
)}
<span className="truncate">{item.name}</span>
</CommandItem>
))}
Expand Down
18 changes: 17 additions & 1 deletion app/src/components/option-tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import type { ReactNode } from "react";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";

export interface OptionTab<T extends string> {
value: T;
label: string;
icon?: ReactNode;
mark?: string | false;
}

export function OptionTabs<T extends string>({
value,
options,
onChange,
}: {
value: T;
options: { value: T; label: string }[];
options: OptionTab<T>[];
onChange: (value: T) => void;
}) {
return (
Expand All @@ -18,7 +26,15 @@ export function OptionTabs<T extends string>({
<TabsList>
{options.map((option) => (
<TabsTrigger key={option.value} value={option.value}>
{option.icon}
{option.label}
{option.mark && (
<span
role="img"
aria-label={option.mark}
className="bg-warning size-2 rounded-full"
/>
)}
</TabsTrigger>
))}
</TabsList>
Expand Down
2 changes: 2 additions & 0 deletions app/src/lib/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
ArbitrationRun,
ArbitrationRunExportFormat,
Auction,
BountyAlertOptions,
CommandError,
ComparedStat,
CraftDetails,
Expand Down Expand Up @@ -258,6 +259,7 @@ export const api = {
call<string | null>("export_arbitration_run", { id, format }),
invasionWeaponParts: () =>
call<InvasionWeaponPart[]>("invasion_weapon_parts"),
bountyAlertOptions: () => call<BountyAlertOptions>("bounty_alert_options"),
appLogFile: () => call<string>("app_log_file"),
openDataFolder: () => call<void>("open_data_folder"),
openGameLogFolder: () => call<void>("open_game_log_folder"),
Expand Down
2 changes: 2 additions & 0 deletions app/src/pages/reset-checklist/checklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function progressText(progress: ResetChecklistProgress): string | null {
return countedText(progress.done, progress.total);
case "remaining":
return `${num(progress.left)} left of ${num(progress.cap)}`;
case "unlimited":
return "No limit";
case "manual":
case "yes_no":
return null;
Expand Down
Loading