feat: add global & server leveling, quests, achievements, guilds land-claiming, social & toggleable configs
This commit is contained in:
1 parent
4b79f69c20
commit
b4cef85b1f
40 files changed
+10261
-27
No files matched your search
@@ -6,7 +6,11 @@ use crate::settings::Settings;
|
||||
use crate::state::{build, AppState};
|
||||
use crate::updater;
|
||||
use scopenet_core::ping::ServerStatus;
|
||||
use scopenet_shared::{LauncherManifest, PlayerProfile, SkinProfile};
|
||||
use scopenet_shared::{
|
||||
Achievement, DirectMessage, FriendInfo, GameInvite, Guild, GuildClaim, GuildMember, GuildPost,
|
||||
LauncherManifest, PlayerProfile, SkinProfile, UserLevelInfo, UserPost, UserProfileView,
|
||||
UserQuest,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use tauri::{AppHandle, Manager, State};
|
||||
use tauri_plugin_opener::OpenerExt;
|
||||
@@ -520,3 +524,382 @@ pub async fn get_public_servers(state: State<'_, AppState>) -> Res<serde_json::V
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Leveling & Quests
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_my_level(state: State<'_, AppState>) -> Res<UserLevelInfo> {
|
||||
let req = account_api(&state, reqwest::Method::GET, "/levels/me").await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load user level".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_my_quests(state: State<'_, AppState>) -> Res<Vec<UserQuest>> {
|
||||
let req = account_api(&state, reqwest::Method::GET, "/quests/my").await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load quests".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn claim_quest(state: State<'_, AppState>, quest_id: String) -> Res<UserQuest> {
|
||||
let req = account_api(&state, reqwest::Method::POST, &format!("/quests/{quest_id}/claim")).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to claim quest").to_string());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Achievements
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_my_achievements(state: State<'_, AppState>) -> Res<Vec<Achievement>> {
|
||||
let req = account_api(&state, reqwest::Method::GET, "/achievements/my").await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load achievements".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Guilds & Land Claims
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_guilds(state: State<'_, AppState>, instance_id: Option<String>) -> Res<Vec<Guild>> {
|
||||
let panel = state.panel_url().ok_or("no panel configured")?;
|
||||
let q = instance_id.map(|i| format!("?instance_id={i}")).unwrap_or_default();
|
||||
let resp = state.http.get(format!("{panel}/api/v1/guilds{q}")).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load guilds".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_my_guild(state: State<'_, AppState>, instance_id: Option<String>) -> Res<Option<Guild>> {
|
||||
let q = instance_id.map(|i| format!("?instance_id={i}")).unwrap_or_default();
|
||||
let req = account_api(&state, reqwest::Method::GET, &format!("/guilds/my{q}")).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Ok(None);
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn create_guild(
|
||||
state: State<'_, AppState>,
|
||||
instance_id: String,
|
||||
name: String,
|
||||
tag: String,
|
||||
description: String,
|
||||
) -> Res<Guild> {
|
||||
let req = account_api(&state, reqwest::Method::POST, "/guilds").await?;
|
||||
let resp = req.json(&serde_json::json!({
|
||||
"instance_id": instance_id,
|
||||
"name": name,
|
||||
"tag": tag,
|
||||
"description": description,
|
||||
})).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to create guild").to_string());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_guild_claims(
|
||||
state: State<'_, AppState>,
|
||||
instance_id: String,
|
||||
dimension: Option<String>,
|
||||
) -> Res<Vec<GuildClaim>> {
|
||||
let panel = state.panel_url().ok_or("no panel configured")?;
|
||||
let dim = dimension.unwrap_or_else(|| "minecraft:overworld".into());
|
||||
let resp = state.http.get(format!("{panel}/api/v1/guilds/claims/grid?instance_id={instance_id}&dimension={dim}"))
|
||||
.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load claims".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn claim_guild_chunk(
|
||||
state: State<'_, AppState>,
|
||||
guild_id: String,
|
||||
instance_id: String,
|
||||
dimension: String,
|
||||
chunk_x: i32,
|
||||
chunk_z: i32,
|
||||
) -> Res<GuildClaim> {
|
||||
let req = account_api(&state, reqwest::Method::POST, &format!("/guilds/{guild_id}/claim")).await?;
|
||||
let resp = req.json(&serde_json::json!({
|
||||
"instance_id": instance_id,
|
||||
"dimension": dimension,
|
||||
"chunk_x": chunk_x,
|
||||
"chunk_z": chunk_z,
|
||||
})).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to claim chunk").to_string());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn unclaim_guild_chunk(
|
||||
state: State<'_, AppState>,
|
||||
guild_id: String,
|
||||
instance_id: String,
|
||||
dimension: String,
|
||||
chunk_x: i32,
|
||||
chunk_z: i32,
|
||||
) -> Res<()> {
|
||||
let req = account_api(&state, reqwest::Method::POST, &format!("/guilds/{guild_id}/unclaim")).await?;
|
||||
let resp = req.json(&serde_json::json!({
|
||||
"instance_id": instance_id,
|
||||
"dimension": dimension,
|
||||
"chunk_x": chunk_x,
|
||||
"chunk_z": chunk_z,
|
||||
})).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to unclaim chunk").to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_guild_posts(state: State<'_, AppState>, guild_id: String) -> Res<Vec<GuildPost>> {
|
||||
let req = account_api(&state, reqwest::Method::GET, &format!("/guilds/{guild_id}/posts")).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load guild posts".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn create_guild_post(
|
||||
state: State<'_, AppState>,
|
||||
guild_id: String,
|
||||
title: String,
|
||||
content: String,
|
||||
) -> Res<GuildPost> {
|
||||
let req = account_api(&state, reqwest::Method::POST, &format!("/guilds/{guild_id}/posts")).await?;
|
||||
let resp = req.json(&serde_json::json!({
|
||||
"title": title,
|
||||
"content": content,
|
||||
})).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to post announcement").to_string());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_guild_members(state: State<'_, AppState>, guild_id: String) -> Res<Vec<GuildMember>> {
|
||||
let req = account_api(&state, reqwest::Method::GET, &format!("/guilds/{guild_id}/members")).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load members".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Social: Friends, DMs, Invites, Profiles & Feed
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_friends(state: State<'_, AppState>) -> Res<Vec<FriendInfo>> {
|
||||
let req = account_api(&state, reqwest::Method::GET, "/friends").await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load friends".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn send_friend_request(state: State<'_, AppState>, username: String) -> Res<()> {
|
||||
let req = account_api(&state, reqwest::Method::POST, "/friends/request").await?;
|
||||
let resp = req.json(&serde_json::json!({ "username": username })).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to send friend request").to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn respond_friend_request(state: State<'_, AppState>, target_uuid: String, accept: bool) -> Res<()> {
|
||||
let req = account_api(&state, reqwest::Method::POST, "/friends/respond").await?;
|
||||
let resp = req.json(&serde_json::json!({ "target_uuid": target_uuid, "accept": accept })).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to respond to friend request").to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn remove_friend(state: State<'_, AppState>, target_uuid: String) -> Res<()> {
|
||||
let req = account_api(&state, reqwest::Method::DELETE, &format!("/friends/{target_uuid}")).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to remove friend").to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_direct_messages(state: State<'_, AppState>, friend_uuid: String) -> Res<Vec<DirectMessage>> {
|
||||
let req = account_api(&state, reqwest::Method::GET, &format!("/messages/{friend_uuid}")).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load messages".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn send_direct_message(state: State<'_, AppState>, friend_uuid: String, content: String) -> Res<DirectMessage> {
|
||||
let req = account_api(&state, reqwest::Method::POST, &format!("/messages/{friend_uuid}")).await?;
|
||||
let resp = req.json(&serde_json::json!({ "content": content })).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to send message").to_string());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_game_invites(state: State<'_, AppState>) -> Res<Vec<GameInvite>> {
|
||||
let req = account_api(&state, reqwest::Method::GET, "/invites").await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load invites".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn send_game_invite(
|
||||
state: State<'_, AppState>,
|
||||
recipient_uuid: String,
|
||||
instance_id: String,
|
||||
server_id: Option<i64>,
|
||||
) -> Res<GameInvite> {
|
||||
let req = account_api(&state, reqwest::Method::POST, "/invites").await?;
|
||||
let resp = req.json(&serde_json::json!({
|
||||
"recipient_uuid": recipient_uuid,
|
||||
"instance_id": instance_id,
|
||||
"server_id": server_id,
|
||||
})).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to send invite").to_string());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn respond_game_invite(state: State<'_, AppState>, invite_id: String, accept: bool) -> Res<()> {
|
||||
let req = account_api(&state, reqwest::Method::POST, &format!("/invites/{invite_id}/respond")).await?;
|
||||
let resp = req.json(&serde_json::json!({ "accept": accept })).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to respond to invite").to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_user_profile(state: State<'_, AppState>, uuid: String) -> Res<UserProfileView> {
|
||||
let req = account_api(&state, reqwest::Method::GET, &format!("/profiles/{uuid}")).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load user profile".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn update_my_profile(
|
||||
state: State<'_, AppState>,
|
||||
bio: String,
|
||||
banner_url: Option<String>,
|
||||
custom_badge: Option<String>,
|
||||
featured_achievement_id: Option<String>,
|
||||
) -> Res<UserProfileView> {
|
||||
let req = account_api(&state, reqwest::Method::PUT, "/profiles/me").await?;
|
||||
let resp = req.json(&serde_json::json!({
|
||||
"bio": bio,
|
||||
"banner_url": banner_url,
|
||||
"custom_badge": custom_badge,
|
||||
"featured_achievement_id": featured_achievement_id,
|
||||
})).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to update profile").to_string());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_user_posts(state: State<'_, AppState>, user_uuid: Option<String>) -> Res<Vec<UserPost>> {
|
||||
let path = user_uuid.map(|u| format!("/posts?uuid={u}")).unwrap_or_else(|| "/posts".into());
|
||||
let req = account_api(&state, reqwest::Method::GET, &path).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load posts".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn create_user_post(
|
||||
state: State<'_, AppState>,
|
||||
content: String,
|
||||
image_url: Option<String>,
|
||||
) -> Res<UserPost> {
|
||||
let req = account_api(&state, reqwest::Method::POST, "/posts").await?;
|
||||
let resp = req.json(&serde_json::json!({
|
||||
"content": content,
|
||||
"image_url": image_url,
|
||||
})).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
return Err(body["error"].as_str().unwrap_or("unable to publish post").to_string());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn like_user_post(state: State<'_, AppState>, post_id: i64) -> Res<()> {
|
||||
let req = account_api(&state, reqwest::Method::POST, &format!("/posts/{post_id}/like")).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to like post".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -84,6 +84,33 @@ pub fn run() {
|
||||
commands::get_player_stats,
|
||||
commands::get_leaderboard,
|
||||
commands::get_public_servers,
|
||||
commands::get_my_level,
|
||||
commands::get_my_quests,
|
||||
commands::claim_quest,
|
||||
commands::get_my_achievements,
|
||||
commands::get_guilds,
|
||||
commands::get_my_guild,
|
||||
commands::create_guild,
|
||||
commands::get_guild_claims,
|
||||
commands::claim_guild_chunk,
|
||||
commands::unclaim_guild_chunk,
|
||||
commands::get_guild_posts,
|
||||
commands::create_guild_post,
|
||||
commands::get_guild_members,
|
||||
commands::get_friends,
|
||||
commands::send_friend_request,
|
||||
commands::respond_friend_request,
|
||||
commands::remove_friend,
|
||||
commands::get_direct_messages,
|
||||
commands::send_direct_message,
|
||||
commands::get_game_invites,
|
||||
commands::send_game_invite,
|
||||
commands::respond_game_invite,
|
||||
commands::get_user_profile,
|
||||
commands::update_my_profile,
|
||||
commands::get_user_posts,
|
||||
commands::create_user_post,
|
||||
commands::like_user_post,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running the launcher");
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
import Home from './pages/Home.svelte';
|
||||
import Settings from './pages/Settings.svelte';
|
||||
import Stats from './pages/Stats.svelte';
|
||||
import Quests from './pages/Quests.svelte';
|
||||
import Guilds from './pages/Guilds.svelte';
|
||||
import Social from './pages/Social.svelte';
|
||||
import PlayerProfileModal from './components/PlayerProfileModal.svelte';
|
||||
import { app, init } from './lib/store.svelte';
|
||||
import { errorText } from './lib/tauri';
|
||||
|
||||
@@ -45,6 +49,12 @@
|
||||
<Settings />
|
||||
{:else if app.view === 'stats'}
|
||||
<Stats />
|
||||
{:else if app.view === 'quests'}
|
||||
<Quests />
|
||||
{:else if app.view === 'guilds'}
|
||||
<Guilds />
|
||||
{:else if app.view === 'social'}
|
||||
<Social />
|
||||
{:else}
|
||||
<Home />
|
||||
{/if}
|
||||
@@ -66,6 +76,9 @@
|
||||
<SignIn />
|
||||
</Modal>
|
||||
<InstanceSettings />
|
||||
{#if app.viewProfileUuid}
|
||||
<PlayerProfileModal uuid={app.viewProfileUuid} onclose={() => (app.viewProfileUuid = null)} />
|
||||
{/if}
|
||||
<CrashDialog />
|
||||
<Toasts />
|
||||
|
||||
|
||||
@@ -0,0 +1,492 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import {
|
||||
Shield, Lock, Plus, Trash2, Compass, ArrowUp, ArrowDown, ArrowLeft, ArrowRight,
|
||||
MapPin, Globe, LoaderCircle, CheckCircle2, AlertTriangle, RefreshCw
|
||||
} from '@lucide/svelte';
|
||||
import { invoke } from '../lib/tauri';
|
||||
import { toast } from '../lib/store.svelte';
|
||||
import type { GuildClaim } from '../lib/types';
|
||||
|
||||
let {
|
||||
instanceId,
|
||||
myGuildId = null,
|
||||
myGuildTag = '',
|
||||
onclaim,
|
||||
onunclaim
|
||||
}: {
|
||||
instanceId: string;
|
||||
myGuildId?: string | null;
|
||||
myGuildTag?: string;
|
||||
onclaim?: (claim: GuildClaim) => void;
|
||||
onunclaim?: (claimId: number) => void;
|
||||
} = $props();
|
||||
|
||||
let dimension = $state<'minecraft:overworld' | 'minecraft:the_nether' | 'minecraft:the_end'>('minecraft:overworld');
|
||||
let centerX = $state(0);
|
||||
let centerZ = $state(0);
|
||||
let radius = $state(5); // 11x11 grid
|
||||
let claims = $state<GuildClaim[]>([]);
|
||||
let loading = $state(false);
|
||||
let claiming = $state(false);
|
||||
let hoveredChunk = $state<{ x: number; z: number } | null>(null);
|
||||
let selectedChunk = $state<{ x: number; z: number } | null>(null);
|
||||
|
||||
const dimensions = [
|
||||
{ id: 'minecraft:overworld', label: 'Overworld', icon: Globe },
|
||||
{ id: 'minecraft:the_nether', label: 'The Nether', icon: Compass },
|
||||
{ id: 'minecraft:the_end', label: 'The End', icon: Compass }
|
||||
] as const;
|
||||
|
||||
async function loadClaims() {
|
||||
if (!instanceId) return;
|
||||
loading = true;
|
||||
try {
|
||||
claims = await invoke<GuildClaim[]>('get_guild_claims', {
|
||||
instanceId,
|
||||
dimension
|
||||
});
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to load territory claims', 'error');
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function getClaimAt(x: number, z: number): GuildClaim | undefined {
|
||||
return claims.find((c) => c.chunk_x === x && c.chunk_z === z && c.dimension === dimension);
|
||||
}
|
||||
|
||||
const selectedClaim = $derived(
|
||||
selectedChunk ? getClaimAt(selectedChunk.x, selectedChunk.z) : null
|
||||
);
|
||||
|
||||
const myClaimsCount = $derived(
|
||||
myGuildId ? claims.filter((c) => c.guild_id === myGuildId).length : 0
|
||||
);
|
||||
|
||||
async function handleClaim() {
|
||||
if (!selectedChunk || !myGuildId) return;
|
||||
claiming = true;
|
||||
try {
|
||||
const claim = await invoke<GuildClaim>('claim_guild_chunk', {
|
||||
instanceId,
|
||||
dimension,
|
||||
chunkX: selectedChunk.x,
|
||||
chunkZ: selectedChunk.z
|
||||
});
|
||||
claims = [...claims, claim];
|
||||
toast(`Successfully claimed chunk [${selectedChunk.x}, ${selectedChunk.z}]!`, 'ok');
|
||||
onclaim?.(claim);
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to claim chunk', 'error');
|
||||
} finally {
|
||||
claiming = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleUnclaim() {
|
||||
if (!selectedClaim) return;
|
||||
claiming = true;
|
||||
try {
|
||||
await invoke('unclaim_guild_chunk', { claimId: selectedClaim.id });
|
||||
claims = claims.filter((c) => c.id !== selectedClaim.id);
|
||||
toast(`Unclaimed chunk [${selectedClaim.chunk_x}, ${selectedClaim.chunk_z}]`, 'ok');
|
||||
onunclaim?.(selectedClaim.id);
|
||||
selectedChunk = null;
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to unclaim chunk', 'error');
|
||||
} finally {
|
||||
claiming = false;
|
||||
}
|
||||
}
|
||||
|
||||
function pan(dx: number, dz: number) {
|
||||
centerX += dx;
|
||||
centerZ += dz;
|
||||
}
|
||||
|
||||
function resetCenter() {
|
||||
centerX = 0;
|
||||
centerZ = 0;
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (instanceId && dimension) {
|
||||
loadClaims();
|
||||
}
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
loadClaims();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="chunk-map-container glass">
|
||||
<!-- Controls Bar -->
|
||||
<div class="map-controls">
|
||||
<div class="dim-selector">
|
||||
{#each dimensions as dim}
|
||||
{@const DimIcon = dim.icon}
|
||||
<button
|
||||
class="dim-btn"
|
||||
class:active={dimension === dim.id}
|
||||
onclick={() => { dimension = dim.id; selectedChunk = null; }}
|
||||
>
|
||||
<DimIcon size={14} />
|
||||
<span>{dim.label}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div class="nav-controls">
|
||||
<span class="coord-label">Center: [{centerX}, {centerZ}]</span>
|
||||
<div class="nav-buttons">
|
||||
<button class="ghost icon sm" onclick={() => pan(0, -2)} title="Pan North"><ArrowUp size={14} /></button>
|
||||
<div class="nav-row">
|
||||
<button class="ghost icon sm" onclick={() => pan(-2, 0)} title="Pan West"><ArrowLeft size={14} /></button>
|
||||
<button class="ghost icon sm" onclick={resetCenter} title="Center at (0,0)"><MapPin size={14} /></button>
|
||||
<button class="ghost icon sm" onclick={() => pan(2, 0)} title="Pan East"><ArrowRight size={14} /></button>
|
||||
</div>
|
||||
<button class="ghost icon sm" onclick={() => pan(0, 2)} title="Pan South"><ArrowDown size={14} /></button>
|
||||
</div>
|
||||
<button class="ghost icon sm refresh-btn" onclick={loadClaims} title="Refresh Claims">
|
||||
<RefreshCw size={14} class={loading ? 'spin' : ''} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main Chunk Map Canvas / Grid -->
|
||||
<div class="grid-wrapper">
|
||||
<div
|
||||
class="chunk-grid"
|
||||
style:grid-template-columns="repeat({radius * 2 + 1}, minmax(36px, 1fr))"
|
||||
style:grid-template-rows="repeat({radius * 2 + 1}, minmax(36px, 1fr))"
|
||||
>
|
||||
{#each Array.from({ length: radius * 2 + 1 }, (_, r) => centerZ - radius + r) as cz}
|
||||
{#each Array.from({ length: radius * 2 + 1 }, (_, c) => centerX - radius + c) as cx}
|
||||
{@const claim = getClaimAt(cx, cz)}
|
||||
{@const isMyClaim = claim && myGuildId && claim.guild_id === myGuildId}
|
||||
{@const isOtherClaim = claim && (!myGuildId || claim.guild_id !== myGuildId)}
|
||||
{@const isSelected = selectedChunk && selectedChunk.x === cx && selectedChunk.z === cz}
|
||||
{@const isCenter = cx === 0 && cz === 0}
|
||||
|
||||
<button
|
||||
class="chunk-cell"
|
||||
class:my-claim={isMyClaim}
|
||||
class:other-claim={isOtherClaim}
|
||||
class:selected={isSelected}
|
||||
class:is-center={isCenter}
|
||||
onmouseenter={() => (hoveredChunk = { x: cx, z: cz })}
|
||||
onmouseleave={() => (hoveredChunk = null)}
|
||||
onclick={() => (selectedChunk = { x: cx, z: cz })}
|
||||
title="Chunk [{cx}, {cz}] (Blocks {cx * 16}..{(cx + 1) * 16 - 1}, {cz * 16}..{(cz + 1) * 16 - 1})"
|
||||
>
|
||||
{#if isMyClaim}
|
||||
<Shield size={16} class="claim-icon mine" />
|
||||
<span class="cell-tag">{claim.guild_tag || myGuildTag || 'YOU'}</span>
|
||||
{:else if isOtherClaim}
|
||||
<Lock size={15} class="claim-icon rival" />
|
||||
<span class="cell-tag">{claim.guild_tag || 'GUILD'}</span>
|
||||
{:else if isCenter}
|
||||
<span class="spawn-dot" title="World Origin"></span>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Legend & Action Bar -->
|
||||
<div class="map-footer">
|
||||
<div class="info-block">
|
||||
{#if selectedChunk}
|
||||
<div class="selected-details">
|
||||
<span class="chunk-title">Selected: Chunk <strong>[{selectedChunk.x}, {selectedChunk.z}]</strong></span>
|
||||
<span class="block-range muted tiny">
|
||||
X: {selectedChunk.x * 16}..{(selectedChunk.x + 1) * 16 - 1}, Z: {selectedChunk.z * 16}..{(selectedChunk.z + 1) * 16 - 1}
|
||||
</span>
|
||||
{#if selectedClaim}
|
||||
<div class="claim-status">
|
||||
{#if myGuildId && selectedClaim.guild_id === myGuildId}
|
||||
<span class="badge mine"><Shield size={12} /> Claimed by Your Guild</span>
|
||||
<button
|
||||
class="danger sm action-btn"
|
||||
onclick={handleUnclaim}
|
||||
disabled={claiming}
|
||||
>
|
||||
<Trash2 size={13} /> Unclaim
|
||||
</button>
|
||||
{:else}
|
||||
<span class="badge rival"><Lock size={12} /> Claimed by {selectedClaim.guild_name || 'Rival Guild'} [{selectedClaim.guild_tag || '?'}]</span>
|
||||
<span class="tiny muted protected-note">Grief Protection Active</span>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="unclaimed-status">
|
||||
<span class="badge unclaimed">Wilderness (Unclaimed)</span>
|
||||
{#if myGuildId}
|
||||
<button
|
||||
class="primary sm action-btn"
|
||||
onclick={handleClaim}
|
||||
disabled={claiming}
|
||||
>
|
||||
{#if claiming}<LoaderCircle size={13} class="spin" />{:else}<Plus size={13} />{/if}
|
||||
Claim Chunk
|
||||
</button>
|
||||
{:else}
|
||||
<span class="tiny muted">Join or create a guild to claim land</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if hoveredChunk}
|
||||
<div class="hover-info">
|
||||
<span>Chunk: <strong>[{hoveredChunk.x}, {hoveredChunk.z}]</strong></span>
|
||||
<span class="muted tiny">Click to view details or claim</span>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="hint-info muted tiny">
|
||||
<span>Click any grid square to inspect or claim chunks. Claimed chunks are protected in-game against block edits by other players.</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="legend">
|
||||
<div class="legend-item"><span class="legend-box mine"></span><span>My Guild ({myClaimsCount})</span></div>
|
||||
<div class="legend-item"><span class="legend-box rival"></span><span>Rival Guild</span></div>
|
||||
<div class="legend-item"><span class="legend-box wild"></span><span>Wilderness</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.chunk-map-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.8rem;
|
||||
padding: 1rem;
|
||||
border-radius: var(--radius);
|
||||
background: color-mix(in srgb, var(--surface) 80%, transparent);
|
||||
border: 1px solid var(--line);
|
||||
user-select: none;
|
||||
}
|
||||
.map-controls {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
.dim-selector {
|
||||
display: flex;
|
||||
background: color-mix(in srgb, var(--bg) 60%, transparent);
|
||||
padding: 0.2rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.dim-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0.35rem 0.75rem;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 560;
|
||||
color: var(--muted);
|
||||
border-radius: calc(var(--radius-sm) - 2px);
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.dim-btn.active {
|
||||
background: color-mix(in srgb, var(--accent) 15%, transparent);
|
||||
color: var(--text);
|
||||
}
|
||||
.nav-controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
.coord-label {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
color: var(--muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.nav-buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.1rem;
|
||||
}
|
||||
.nav-row {
|
||||
display: flex;
|
||||
gap: 0.1rem;
|
||||
}
|
||||
.refresh-btn {
|
||||
margin-left: 0.3rem;
|
||||
}
|
||||
.grid-wrapper {
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 0.5rem;
|
||||
background: color-mix(in srgb, var(--bg) 80%, black);
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
|
||||
max-height: 24rem;
|
||||
}
|
||||
.chunk-grid {
|
||||
display: grid;
|
||||
gap: 2px;
|
||||
}
|
||||
.chunk-cell {
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
padding: 0;
|
||||
border-radius: 4px;
|
||||
background: color-mix(in srgb, var(--surface) 60%, transparent);
|
||||
border: 1px solid color-mix(in srgb, var(--line) 40%, transparent);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
transition: transform 0.1s, border-color 0.15s, background 0.15s;
|
||||
}
|
||||
.chunk-cell:hover {
|
||||
transform: scale(1.08);
|
||||
z-index: 10;
|
||||
border-color: var(--text);
|
||||
background: color-mix(in srgb, var(--text) 12%, transparent);
|
||||
}
|
||||
.chunk-cell.selected {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 8px var(--accent);
|
||||
z-index: 15;
|
||||
}
|
||||
.chunk-cell.is-center::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
border-radius: 50%;
|
||||
background: #f59e0b;
|
||||
}
|
||||
.chunk-cell.my-claim {
|
||||
background: color-mix(in srgb, var(--success) 22%, transparent);
|
||||
border-color: color-mix(in srgb, var(--success) 70%, transparent);
|
||||
}
|
||||
.chunk-cell.other-claim {
|
||||
background: color-mix(in srgb, var(--danger) 22%, transparent);
|
||||
border-color: color-mix(in srgb, var(--danger) 70%, transparent);
|
||||
}
|
||||
:global(.claim-icon.mine) {
|
||||
color: var(--success);
|
||||
}
|
||||
:global(.claim-icon.rival) {
|
||||
color: var(--danger);
|
||||
}
|
||||
.cell-tag {
|
||||
font-size: 0.55rem;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
margin-top: 1px;
|
||||
max-width: 34px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.map-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.8rem;
|
||||
padding-top: 0.5rem;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
.info-block {
|
||||
flex: 1;
|
||||
min-width: 14rem;
|
||||
}
|
||||
.selected-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
.chunk-title {
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
.claim-status, .unclaimed-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 0.2rem;
|
||||
}
|
||||
.action-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
font-size: 0.8rem;
|
||||
padding: 0.35rem 0.75rem;
|
||||
}
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
padding: 0.18rem 0.55rem;
|
||||
border-radius: 99rem;
|
||||
}
|
||||
.badge.mine {
|
||||
background: color-mix(in srgb, var(--success) 18%, transparent);
|
||||
color: var(--success);
|
||||
}
|
||||
.badge.rival {
|
||||
background: color-mix(in srgb, var(--danger) 18%, transparent);
|
||||
color: var(--danger);
|
||||
}
|
||||
.badge.unclaimed {
|
||||
background: color-mix(in srgb, var(--text) 10%, transparent);
|
||||
color: var(--muted);
|
||||
}
|
||||
.protected-note {
|
||||
font-style: italic;
|
||||
}
|
||||
.legend {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
font-size: 0.76rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
.legend-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
.legend-box {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 3px;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
.legend-box.mine {
|
||||
background: color-mix(in srgb, var(--success) 35%, transparent);
|
||||
border-color: var(--success);
|
||||
}
|
||||
.legend-box.rival {
|
||||
background: color-mix(in srgb, var(--danger) 35%, transparent);
|
||||
border-color: var(--danger);
|
||||
}
|
||||
.legend-box.wild {
|
||||
background: color-mix(in srgb, var(--surface) 80%, transparent);
|
||||
border-color: var(--line);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,824 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import {
|
||||
X, Trophy, Shield, Heart, Image as ImageIcon, Send, Edit3, Check,
|
||||
Clock, Swords, Flame, Pickaxe, Box, LoaderCircle, Award, Star, MessageSquare
|
||||
} from '@lucide/svelte';
|
||||
import Avatar from './Avatar.svelte';
|
||||
import Modal from './Modal.svelte';
|
||||
import { activeAccount, app, toast } from '../lib/store.svelte';
|
||||
import { invoke } from '../lib/tauri';
|
||||
import type { UserProfileView, UserPost } from '../lib/types';
|
||||
|
||||
let {
|
||||
uuid,
|
||||
onclose
|
||||
}: {
|
||||
uuid: string;
|
||||
onclose: () => void;
|
||||
} = $props();
|
||||
|
||||
let profile = $state<UserProfileView | null>(null);
|
||||
let loading = $state(true);
|
||||
let activeTab = $state<'feed' | 'progression' | 'achievements' | 'stats'>('feed');
|
||||
|
||||
// Edit Profile State
|
||||
let editing = $state(false);
|
||||
let editBio = $state('');
|
||||
let editBanner = $state('');
|
||||
let savingProfile = $state(false);
|
||||
|
||||
// New Post State
|
||||
let newPostContent = $state('');
|
||||
let newPostImageUrl = $state('');
|
||||
let posting = $state(false);
|
||||
|
||||
const isMe = $derived(activeAccount()?.uuid === uuid);
|
||||
|
||||
async function loadProfile() {
|
||||
loading = true;
|
||||
try {
|
||||
profile = await invoke<UserProfileView>('get_user_profile', { uuid });
|
||||
if (profile) {
|
||||
editBio = profile.bio || '';
|
||||
editBanner = profile.banner_url || '';
|
||||
}
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to load player profile', 'error');
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSaveProfile() {
|
||||
savingProfile = true;
|
||||
try {
|
||||
profile = await invoke<UserProfileView>('update_my_profile', {
|
||||
bio: editBio.trim() || null,
|
||||
bannerUrl: editBanner.trim() || null
|
||||
});
|
||||
editing = false;
|
||||
toast('Profile updated successfully!', 'ok');
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to save profile', 'error');
|
||||
} finally {
|
||||
savingProfile = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCreatePost() {
|
||||
if (!newPostContent.trim()) return;
|
||||
posting = true;
|
||||
try {
|
||||
const post = await invoke<UserPost>('create_user_post', {
|
||||
content: newPostContent.trim(),
|
||||
imageUrl: newPostImageUrl.trim() || null
|
||||
});
|
||||
if (profile) {
|
||||
profile.posts = [post, ...profile.posts];
|
||||
}
|
||||
newPostContent = '';
|
||||
newPostImageUrl = '';
|
||||
toast('Post published!', 'ok');
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to create post', 'error');
|
||||
} finally {
|
||||
posting = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLikePost(post: UserPost) {
|
||||
try {
|
||||
const liked = await invoke<boolean>('like_user_post', { postId: post.id });
|
||||
post.liked_by_me = liked;
|
||||
post.likes_count = liked ? post.likes_count + 1 : Math.max(0, post.likes_count - 1);
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to update like', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function formatPlaytime(secs: number): string {
|
||||
if (!secs || secs < 60) return `${secs || 0}s`;
|
||||
const hours = Math.floor(secs / 3600);
|
||||
const mins = Math.floor((secs % 3600) / 60);
|
||||
return hours > 0 ? `${hours}h ${mins}m` : `${mins}m`;
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
loadProfile();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="profile-backdrop" role="presentation" onclick={(e) => e.target === e.currentTarget && onclose()}>
|
||||
<div class="profile-modal glass" role="dialog" aria-modal="true" aria-label="Player Profile">
|
||||
<button class="ghost icon close-btn" onclick={onclose} aria-label="Close Profile">
|
||||
<X size={18} />
|
||||
</button>
|
||||
|
||||
{#if loading || !profile}
|
||||
<div class="center-state"><LoaderCircle class="spin" size={32} /></div>
|
||||
{:else}
|
||||
<!-- Banner & Profile Header -->
|
||||
<div
|
||||
class="profile-banner"
|
||||
style:background-image={profile.banner_url ? `linear-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0.8)), url(${profile.banner_url})` : undefined}
|
||||
>
|
||||
<div class="header-overlay">
|
||||
<div class="user-main">
|
||||
<div class="avatar-ring">
|
||||
<Avatar uuid={profile.uuid} name={profile.username} size={4.2} />
|
||||
</div>
|
||||
<div class="user-titles">
|
||||
<div class="user-row">
|
||||
<h2>{profile.username}</h2>
|
||||
{#if profile.global_level?.title}
|
||||
<span class="badge title-badge"><Award size={12} /> {profile.global_level.title}</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="meta-row tiny muted">
|
||||
<span>Joined {new Date(profile.created_at).toLocaleDateString()}</span>
|
||||
<span>•</span>
|
||||
<span>{profile.friends_count} Friends</span>
|
||||
<span>•</span>
|
||||
<span class="global-lvl-tag">Level {profile.global_level?.level ?? 1}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if isMe}
|
||||
<button class="ghost sm edit-btn" onclick={() => (editing = !editing)}>
|
||||
<Edit3 size={14} /> {editing ? 'Cancel' : 'Edit Profile'}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bio / Edit Form -->
|
||||
<div class="bio-section">
|
||||
{#if editing}
|
||||
<div class="edit-profile-box glass">
|
||||
<label>
|
||||
<span class="tiny bold">Bio</span>
|
||||
<textarea bind:value={editBio} placeholder="Tell other players about yourself..." rows="2"></textarea>
|
||||
</label>
|
||||
<label>
|
||||
<span class="tiny bold">Banner Image URL</span>
|
||||
<input type="url" bind:value={editBanner} placeholder="https://example.com/banner.jpg" />
|
||||
</label>
|
||||
<div class="edit-actions">
|
||||
<button class="ghost sm" onclick={() => (editing = false)}>Cancel</button>
|
||||
<button class="primary sm" onclick={handleSaveProfile} disabled={savingProfile}>
|
||||
{#if savingProfile}<LoaderCircle size={13} class="spin" />{:else}<Check size={13} />{/if}
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{:else if profile.bio}
|
||||
<p class="bio-text">{profile.bio}</p>
|
||||
{/if}
|
||||
|
||||
{#if profile.badges && profile.badges.length > 0}
|
||||
<div class="badges-list">
|
||||
{#each profile.badges as badge}
|
||||
<span class="badge custom-badge"><Star size={11} /> {badge}</span>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Segmented Profile Tabs -->
|
||||
<div class="profile-tabs">
|
||||
<button class:active={activeTab === 'feed'} onclick={() => (activeTab = 'feed')}>
|
||||
<MessageSquare size={14} /> Posts & Feed
|
||||
</button>
|
||||
<button class:active={activeTab === 'progression'} onclick={() => (activeTab = 'progression')}>
|
||||
<Award size={14} /> Levels & Ranks
|
||||
</button>
|
||||
<button class:active={activeTab === 'achievements'} onclick={() => (activeTab = 'achievements')}>
|
||||
<Trophy size={14} /> Achievements ({profile.achievements.length})
|
||||
</button>
|
||||
<button class:active={activeTab === 'stats'} onclick={() => (activeTab = 'stats')}>
|
||||
<Swords size={14} /> Stats
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Tab Content Area -->
|
||||
<div class="modal-tab-content">
|
||||
{#if activeTab === 'feed'}
|
||||
<div class="feed-container">
|
||||
<!-- Create Post (if viewing self) -->
|
||||
{#if isMe}
|
||||
<div class="create-post-box glass">
|
||||
<textarea
|
||||
bind:value={newPostContent}
|
||||
placeholder="Share a milestone, screenshot, or status update..."
|
||||
rows="2"
|
||||
class="post-input"
|
||||
></textarea>
|
||||
<div class="post-controls">
|
||||
<div class="image-input-wrap">
|
||||
<ImageIcon size={14} class="muted" />
|
||||
<input
|
||||
type="url"
|
||||
placeholder="Photo URL (optional)"
|
||||
bind:value={newPostImageUrl}
|
||||
class="img-url-input"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
class="primary sm"
|
||||
onclick={handleCreatePost}
|
||||
disabled={posting || !newPostContent.trim()}
|
||||
>
|
||||
{#if posting}<LoaderCircle size={13} class="spin" />{:else}<Send size={13} />{/if}
|
||||
Post
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- User Posts List -->
|
||||
{#if profile.posts.length === 0}
|
||||
<div class="empty-state">
|
||||
<p class="muted">No posts yet from {profile.username}.</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="posts-stream">
|
||||
{#each profile.posts as post (post.id)}
|
||||
<div class="post-card glass">
|
||||
<div class="post-top">
|
||||
<Avatar uuid={profile.uuid} name={profile.username} size={2} />
|
||||
<div class="post-author-meta">
|
||||
<span class="author-name">{profile.username}</span>
|
||||
<span class="post-time tiny muted">{new Date(post.created_at).toLocaleString()}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="post-body">{post.content}</p>
|
||||
{#if post.image_url}
|
||||
<div class="post-photo-wrap">
|
||||
<img src={post.image_url} alt="Post Attachment" class="post-photo" />
|
||||
</div>
|
||||
{/if}
|
||||
<div class="post-footer">
|
||||
<button
|
||||
class="ghost sm like-btn"
|
||||
class:liked={post.liked_by_me}
|
||||
onclick={() => handleLikePost(post)}
|
||||
>
|
||||
<Heart size={14} fill={post.liked_by_me ? 'currentColor' : 'none'} />
|
||||
<span>{post.likes_count}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if activeTab === 'progression'}
|
||||
<!-- Progression Tab -->
|
||||
<div class="progression-view">
|
||||
<!-- Global Level Card -->
|
||||
<div class="prog-card glass">
|
||||
<div class="prog-header">
|
||||
<div>
|
||||
<span class="tiny bold uppercase muted">Account Progression</span>
|
||||
<h3>SCOPENET Global Level</h3>
|
||||
</div>
|
||||
<div class="level-pill">
|
||||
Level {profile.global_level.level}
|
||||
</div>
|
||||
</div>
|
||||
<div class="xp-bar-wrap">
|
||||
<div class="xp-numbers tiny">
|
||||
<span>{profile.global_level.current_xp.toLocaleString()} XP</span>
|
||||
<span>{profile.global_level.next_level_xp.toLocaleString()} XP</span>
|
||||
</div>
|
||||
<div class="xp-bar">
|
||||
<div class="xp-fill" style:width="{profile.global_level.progress_pct}%"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Server Levels List -->
|
||||
{#if profile.server_levels && profile.server_levels.length > 0}
|
||||
<h4 class="subhead">Server Specific Levels</h4>
|
||||
<div class="servers-levels-grid">
|
||||
{#each profile.server_levels as sl}
|
||||
<div class="server-lvl-card glass">
|
||||
<div class="sl-top">
|
||||
<div>
|
||||
<strong>{sl.server_name}</strong>
|
||||
{#if sl.rank_title}
|
||||
<span class="badge rank-badge">{sl.rank_title}</span>
|
||||
{/if}
|
||||
</div>
|
||||
<span class="lvl-badge">Lv. {sl.level}</span>
|
||||
</div>
|
||||
<div class="xp-bar">
|
||||
<div class="xp-fill" style:width="{sl.progress_pct}%"></div>
|
||||
</div>
|
||||
<span class="tiny muted">{sl.current_xp} / {sl.next_level_xp} XP</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="muted tiny">No server levels recorded yet.</p>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if activeTab === 'achievements'}
|
||||
<!-- Achievements Tab -->
|
||||
<div class="achievements-view">
|
||||
{#if profile.achievements.length === 0}
|
||||
<div class="empty-state">
|
||||
<Trophy size={32} class="muted" />
|
||||
<p class="muted">No achievements unlocked yet.</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="ach-grid">
|
||||
{#each profile.achievements as ach (ach.id)}
|
||||
<div class="ach-item glass" class:frame-challenge={ach.frame_type === 'challenge'}>
|
||||
<div class="ach-icon-box" style:background={ach.icon_bg || 'rgba(0,0,0,0.5)'}>
|
||||
<span>{ach.icon_item || '🏆'}</span>
|
||||
</div>
|
||||
<div class="ach-meta">
|
||||
<span class="ach-name">{ach.title}</span>
|
||||
<p class="ach-sub tiny muted">{ach.description}</p>
|
||||
<span class="tiny xp-label">+{ach.xp_reward} XP</span>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if activeTab === 'stats'}
|
||||
<!-- Stats Tab -->
|
||||
<div class="stats-view">
|
||||
{#if profile.stats}
|
||||
<div class="stats-cards-grid">
|
||||
<div class="stat-mini-card glass">
|
||||
<Clock size={16} class="muted" />
|
||||
<span class="tiny muted">Playtime</span>
|
||||
<strong>{formatPlaytime(profile.stats.playtime_secs)}</strong>
|
||||
</div>
|
||||
<div class="stat-mini-card glass">
|
||||
<Swords size={16} class="accent" />
|
||||
<span class="tiny muted">Player Kills</span>
|
||||
<strong>{profile.stats.player_kills.toLocaleString()}</strong>
|
||||
</div>
|
||||
<div class="stat-mini-card glass">
|
||||
<Flame size={16} class="warn" />
|
||||
<span class="tiny muted">Mob Kills</span>
|
||||
<strong>{profile.stats.mob_kills.toLocaleString()}</strong>
|
||||
</div>
|
||||
<div class="stat-mini-card glass">
|
||||
<Pickaxe size={16} class="success" />
|
||||
<span class="tiny muted">Blocks Mined</span>
|
||||
<strong>{profile.stats.blocks_broken.toLocaleString()}</strong>
|
||||
</div>
|
||||
<div class="stat-mini-card glass">
|
||||
<Box size={16} class="muted" />
|
||||
<span class="tiny muted">Blocks Placed</span>
|
||||
<strong>{profile.stats.blocks_placed.toLocaleString()}</strong>
|
||||
</div>
|
||||
<div class="stat-mini-card glass">
|
||||
<Award size={16} class="accent" />
|
||||
<span class="tiny muted">Server Joins</span>
|
||||
<strong>{profile.stats.joins.toLocaleString()}</strong>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="empty-state">
|
||||
<p class="muted">No statistics recorded yet for this player.</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.profile-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 85;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 1.5rem;
|
||||
background: color-mix(in srgb, var(--bg) 75%, transparent);
|
||||
animation: fade 0.15s ease;
|
||||
}
|
||||
.profile-modal {
|
||||
width: 100%;
|
||||
max-width: 36rem;
|
||||
max-height: calc(100vh - 4rem);
|
||||
overflow-y: auto;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line-strong);
|
||||
border-radius: var(--radius);
|
||||
position: relative;
|
||||
box-shadow: 0 1rem 3rem -1rem rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
top: 0.8rem;
|
||||
right: 0.8rem;
|
||||
z-index: 10;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
border-radius: 50%;
|
||||
}
|
||||
.profile-banner {
|
||||
height: 9rem;
|
||||
background-color: color-mix(in srgb, var(--accent) 25%, black);
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
}
|
||||
.header-overlay {
|
||||
width: 100%;
|
||||
padding: 1rem 1.4rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, transparent 100%);
|
||||
}
|
||||
.user-main {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 1rem;
|
||||
}
|
||||
.avatar-ring {
|
||||
border: 3px solid var(--surface);
|
||||
border-radius: 28%;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
|
||||
background: var(--surface);
|
||||
}
|
||||
.user-titles {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.user-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
.user-row h2 {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 750;
|
||||
margin: 0;
|
||||
}
|
||||
.title-badge {
|
||||
background: color-mix(in srgb, #f59e0b 25%, transparent);
|
||||
color: #f59e0b;
|
||||
}
|
||||
.meta-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.global-lvl-tag {
|
||||
color: var(--accent);
|
||||
font-weight: 650;
|
||||
}
|
||||
.edit-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.bio-section {
|
||||
padding: 0.9rem 1.4rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.bio-text {
|
||||
font-size: 0.88rem;
|
||||
color: color-mix(in srgb, var(--text) 90%, transparent);
|
||||
line-height: 1.4;
|
||||
margin: 0;
|
||||
}
|
||||
.edit-profile-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
padding: 0.9rem;
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
.edit-profile-box textarea, .edit-profile-box input {
|
||||
background: color-mix(in srgb, var(--bg) 60%, transparent);
|
||||
border: 1px solid var(--line);
|
||||
color: var(--text);
|
||||
padding: 0.4rem 0.6rem;
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
.edit-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.badges-list {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.custom-badge {
|
||||
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
.profile-tabs {
|
||||
display: flex;
|
||||
border-bottom: 1px solid var(--line);
|
||||
background: color-mix(in srgb, var(--surface) 90%, black);
|
||||
padding: 0 1rem;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
.profile-tabs button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-bottom: 2px solid transparent;
|
||||
padding: 0.65rem 0.9rem;
|
||||
font-size: 0.82rem;
|
||||
font-weight: 560;
|
||||
color: var(--muted);
|
||||
border-radius: 0;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.profile-tabs button.active {
|
||||
color: var(--text);
|
||||
border-bottom-color: var(--accent);
|
||||
}
|
||||
.modal-tab-content {
|
||||
padding: 1.2rem 1.4rem;
|
||||
}
|
||||
/* Feed Tab */
|
||||
.feed-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
.create-post-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
padding: 0.9rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.post-input {
|
||||
background: color-mix(in srgb, var(--bg) 50%, transparent);
|
||||
border: 1px solid var(--line);
|
||||
color: var(--text);
|
||||
padding: 0.5rem 0.7rem;
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.85rem;
|
||||
resize: vertical;
|
||||
}
|
||||
.post-controls {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
.image-input-wrap {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
background: color-mix(in srgb, var(--bg) 50%, transparent);
|
||||
border: 1px solid var(--line);
|
||||
padding: 0.25rem 0.6rem;
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
.img-url-input {
|
||||
flex: 1;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text);
|
||||
font-size: 0.8rem;
|
||||
outline: none;
|
||||
}
|
||||
.posts-stream {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.9rem;
|
||||
}
|
||||
.post-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
padding: 1rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.post-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
.author-name {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 650;
|
||||
display: block;
|
||||
}
|
||||
.post-body {
|
||||
font-size: 0.86rem;
|
||||
line-height: 1.4;
|
||||
margin: 0;
|
||||
}
|
||||
.post-photo-wrap {
|
||||
border-radius: var(--radius-sm);
|
||||
overflow: hidden;
|
||||
max-height: 16rem;
|
||||
}
|
||||
.post-photo {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.post-footer {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.like-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
.like-btn.liked {
|
||||
color: #e11d48;
|
||||
}
|
||||
/* Progression */
|
||||
.progression-view {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
.prog-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
padding: 1.1rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.prog-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.prog-header h3 {
|
||||
margin: 0.1rem 0 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
.level-pill {
|
||||
padding: 0.3rem 0.7rem;
|
||||
border-radius: 99rem;
|
||||
background: color-mix(in srgb, var(--accent) 20%, transparent);
|
||||
color: var(--accent);
|
||||
font-weight: 700;
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
.xp-bar-wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
.xp-numbers {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
color: var(--muted);
|
||||
}
|
||||
.xp-bar {
|
||||
width: 100%;
|
||||
height: 0.45rem;
|
||||
background: color-mix(in srgb, var(--text) 10%, transparent);
|
||||
border-radius: 99rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
.xp-fill {
|
||||
height: 100%;
|
||||
background: var(--accent);
|
||||
border-radius: 99rem;
|
||||
}
|
||||
.subhead {
|
||||
font-size: 0.88rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.servers-levels-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
|
||||
gap: 0.8rem;
|
||||
}
|
||||
.server-lvl-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
padding: 0.8rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.sl-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.lvl-badge {
|
||||
font-weight: 700;
|
||||
color: var(--accent);
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
.rank-badge {
|
||||
background: color-mix(in srgb, #f59e0b 20%, transparent);
|
||||
color: #f59e0b;
|
||||
font-size: 0.65rem;
|
||||
}
|
||||
/* Achievements */
|
||||
.ach-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
|
||||
gap: 0.8rem;
|
||||
}
|
||||
.ach-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.7rem;
|
||||
padding: 0.75rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.ach-icon-box {
|
||||
width: 2.2rem;
|
||||
height: 2.2rem;
|
||||
border-radius: 4px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-size: 1.1rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ach-meta {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
.ach-name {
|
||||
font-size: 0.84rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.ach-sub {
|
||||
margin: 0.1rem 0;
|
||||
line-height: 1.25;
|
||||
}
|
||||
.xp-label {
|
||||
color: var(--accent);
|
||||
font-weight: 700;
|
||||
}
|
||||
/* Stats Grid */
|
||||
.stats-cards-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
|
||||
gap: 0.8rem;
|
||||
}
|
||||
.stat-mini-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
padding: 0.8rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.stat-mini-card strong {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 600;
|
||||
padding: 0.16rem 0.5rem;
|
||||
border-radius: 99rem;
|
||||
}
|
||||
.center-state, .empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.8rem;
|
||||
padding: 2.5rem 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { Settings, Plus, Check, LogOut, Home, Trophy } from '@lucide/svelte';
|
||||
import { Settings, Plus, Check, LogOut, Home, Trophy, Target, Shield, Users } from '@lucide/svelte';
|
||||
import Avatar from './Avatar.svelte';
|
||||
import { abs, activeAccount, app, instances, removeAccount, selectInstance, switchAccount } from '../lib/store.svelte';
|
||||
|
||||
@@ -27,9 +27,18 @@
|
||||
</div>
|
||||
|
||||
<div class="bottom">
|
||||
{#if app.view === 'settings' || app.view === 'stats'}
|
||||
{#if app.view !== 'home'}
|
||||
<button class="ghost icon big" onclick={() => (app.view = 'home')} aria-label="Home" title="Home"><Home size={20} /></button>
|
||||
{/if}
|
||||
<button class="ghost icon big" class:on={app.view === 'quests'} onclick={() => (app.view = 'quests')} aria-label="Quests & Objectives" title="Quests & Objectives">
|
||||
<Target size={19} />
|
||||
</button>
|
||||
<button class="ghost icon big" class:on={app.view === 'guilds'} onclick={() => (app.view = 'guilds')} aria-label="Guilds & Claims" title="Guilds & Claims">
|
||||
<Shield size={19} />
|
||||
</button>
|
||||
<button class="ghost icon big" class:on={app.view === 'social'} onclick={() => (app.view = 'social')} aria-label="Friends & Social" title="Friends & Social">
|
||||
<Users size={19} />
|
||||
</button>
|
||||
<button class="ghost icon big" class:on={app.view === 'stats'} onclick={() => (app.view = 'stats')} aria-label="Stats & Leaderboards" title="Stats & Leaderboards">
|
||||
<Trophy size={19} />
|
||||
</button>
|
||||
|
||||
@@ -181,6 +181,123 @@ export async function mockInvoke(cmd: string, args: Record<string, any>): Promis
|
||||
return null;
|
||||
case 'detect_java':
|
||||
return 21;
|
||||
case 'get_my_level':
|
||||
return { uuid: 'mock-user-1', level: 14, current_xp: 3450, next_level_xp: 5000, progress_pct: 69, title: 'Veteran Adventurer', badges: ['Beta Pioneer', 'Dragon Slayer'], rewards: [] };
|
||||
case 'get_my_quests':
|
||||
return [
|
||||
{ quest: { id: 'q1', title: 'Deepslate Quarry', description: 'Mine 50 deepslate blocks in the caverns.', quest_type: 'daily', category: 'mining', xp_reward: 120, stat_type: 'mine_deepslate', target_count: 50, icon: 'pickaxe', active: true }, current_count: 35, completed: false, claimed: false, expires_at: '2026-10-01T00:00:00Z' },
|
||||
{ quest: { id: 'q2', title: 'Night Patrol', description: 'Defeat 15 hostile monsters.', quest_type: 'daily', category: 'combat', xp_reward: 150, stat_type: 'kill_monsters', target_count: 15, icon: 'sword', active: true }, current_count: 15, completed: true, claimed: false, expires_at: '2026-10-01T00:00:00Z' },
|
||||
{ quest: { id: 'q3', title: 'Territorial Fortress', description: 'Place 250 building blocks within claimed territory.', quest_type: 'weekly', category: 'building', xp_reward: 500, stat_type: 'place_blocks', target_count: 250, icon: 'hammer', active: true }, current_count: 180, completed: false, claimed: false, expires_at: '2026-10-05T00:00:00Z' },
|
||||
];
|
||||
case 'claim_quest':
|
||||
return { uuid: 'mock-user-1', level: 14, current_xp: 3600, next_level_xp: 5000, progress_pct: 72, title: 'Veteran Adventurer', badges: ['Beta Pioneer'], rewards: [] };
|
||||
case 'get_my_achievements':
|
||||
return [
|
||||
{ id: 'ach1', title: 'Stone Age', description: 'Mine your first piece of cobblestone.', category: 'mining', xp_reward: 50, frame_type: 'task', icon_item: '🪨', icon_bg: '#334155', icon_border: '#64748b', unlocked: true, unlocked_at: '2026-09-20T12:00:00Z' },
|
||||
{ id: 'ach2', title: 'Acquire Hardware', description: 'Smelt an iron ingot in a furnace.', category: 'mining', xp_reward: 100, frame_type: 'task', icon_item: '⛓️', icon_bg: '#475569', icon_border: '#94a3b8', unlocked: true, unlocked_at: '2026-09-21T14:30:00Z' },
|
||||
{ id: 'ach3', title: 'Diamonds!', description: 'Acquire diamonds from deep underground.', category: 'mining', xp_reward: 350, frame_type: 'goal', icon_item: '💎', icon_bg: '#0284c7', icon_border: '#38bdf8', unlocked: true, unlocked_at: '2026-09-24T18:15:00Z' },
|
||||
{ id: 'ach4', title: 'Free the End', description: 'Defeat the Ender Dragon in the End dimension.', category: 'combat', xp_reward: 1000, frame_type: 'challenge', icon_item: '🐉', icon_bg: '#581c87', icon_border: '#f59e0b', unlocked: false, unlocked_at: null },
|
||||
];
|
||||
case 'get_guilds':
|
||||
return [
|
||||
{ id: 'g1', instance_id: args?.instanceId ?? 'survival-smp', name: 'Iron Fortress', tag: 'IRON', description: 'Defenders of the realm and builders of grand monuments.', icon_url: null, banner_url: null, leader_uuid: 'mock-user-1', member_count: 5, max_members: 20, claims_count: 8, created_at: '2026-09-01T00:00:00Z' },
|
||||
{ id: 'g2', instance_id: args?.instanceId ?? 'survival-smp', name: 'Void Walkers', tag: 'VOID', description: 'Exploring the farthest reaches of every dimension.', icon_url: null, banner_url: null, leader_uuid: 'other-user', member_count: 8, max_members: 20, claims_count: 12, created_at: '2026-09-05T00:00:00Z' }
|
||||
];
|
||||
case 'get_my_guild':
|
||||
return { id: 'g1', instance_id: args?.instanceId ?? 'survival-smp', name: 'Iron Fortress', tag: 'IRON', description: 'Defenders of the realm and builders of grand monuments.', icon_url: null, banner_url: null, leader_uuid: 'mock-user-1', member_count: 5, max_members: 20, claims_count: 8, created_at: '2026-09-01T00:00:00Z' };
|
||||
case 'get_guild_claims':
|
||||
return [
|
||||
{ id: 101, guild_id: 'g1', instance_id: args?.instanceId ?? 'survival-smp', dimension: args?.dimension ?? 'minecraft:overworld', chunk_x: 0, chunk_z: 0, claimed_by_uuid: 'mock-user-1', claimed_at: '2026-09-10T00:00:00Z', guild_name: 'Iron Fortress', guild_tag: 'IRON' },
|
||||
{ id: 102, guild_id: 'g1', instance_id: args?.instanceId ?? 'survival-smp', dimension: args?.dimension ?? 'minecraft:overworld', chunk_x: 1, chunk_z: 0, claimed_by_uuid: 'mock-user-1', claimed_at: '2026-09-10T00:00:00Z', guild_name: 'Iron Fortress', guild_tag: 'IRON' },
|
||||
{ id: 103, guild_id: 'g2', instance_id: args?.instanceId ?? 'survival-smp', dimension: args?.dimension ?? 'minecraft:overworld', chunk_x: -2, chunk_z: 1, claimed_by_uuid: 'other-user', claimed_at: '2026-09-11T00:00:00Z', guild_name: 'Void Walkers', guild_tag: 'VOID' }
|
||||
];
|
||||
case 'claim_guild_chunk':
|
||||
return { id: Math.floor(Math.random() * 10000), guild_id: 'g1', instance_id: args?.instanceId, dimension: args?.dimension, chunk_x: args?.chunkX, chunk_z: args?.chunkZ, claimed_by_uuid: 'mock-user-1', claimed_at: new Date().toISOString(), guild_name: 'Iron Fortress', guild_tag: 'IRON' };
|
||||
case 'unclaim_guild_chunk':
|
||||
return null;
|
||||
case 'get_guild_members':
|
||||
return [
|
||||
{ guild_id: 'g1', user_uuid: 'mock-user-1', username: 'Alyssa', role: 'leader', joined_at: '2026-09-01T00:00:00Z', is_online: true },
|
||||
{ guild_id: 'g1', user_uuid: 'friend-1', username: 'Alex', role: 'officer', joined_at: '2026-09-02T00:00:00Z', is_online: true },
|
||||
{ guild_id: 'g1', user_uuid: 'friend-2', username: 'Steve', role: 'member', joined_at: '2026-09-05T00:00:00Z', is_online: false }
|
||||
];
|
||||
case 'get_guild_posts':
|
||||
return [
|
||||
{ id: 'gp1', guild_id: 'g1', author_uuid: 'mock-user-1', author_name: 'Alyssa', title: 'Community Farm Completed!', content: 'The automatic wheat and pumpkin farm at chunk [2, 1] is open to all guild members. Please replenish seeds after harvesting.', pinned: true, created_at: '2026-09-25T16:00:00Z' }
|
||||
];
|
||||
case 'create_guild_post':
|
||||
return { id: 'gp' + Date.now(), guild_id: args?.guildId, author_uuid: 'mock-user-1', author_name: 'Alyssa', title: args?.title, content: args?.content, pinned: args?.pinned ?? false, created_at: new Date().toISOString() };
|
||||
case 'get_friends':
|
||||
return [
|
||||
{ uuid: 'friend-1', username: 'Alex', status: 'accepted', is_online: true, playing_on: 'Survival SMP', avatar_url: null },
|
||||
{ uuid: 'friend-2', username: 'Steve', status: 'accepted', is_online: false, playing_on: null, avatar_url: null },
|
||||
{ uuid: 'friend-3', username: 'Notch', status: 'pending_received', is_online: true, playing_on: null, avatar_url: null }
|
||||
];
|
||||
case 'send_friend_request':
|
||||
case 'respond_friend_request':
|
||||
case 'remove_friend':
|
||||
return null;
|
||||
case 'get_direct_messages':
|
||||
return [
|
||||
{ id: 1, from_uuid: args?.friendUuid, to_uuid: 'mock-user-1', content: 'Hey! Want to team up and explore the trial chambers?', created_at: '2026-09-28T18:20:00Z', is_read: true },
|
||||
{ id: 2, from_uuid: 'mock-user-1', to_uuid: args?.friendUuid, content: 'Definitely! Let me grab some potions from base first.', created_at: '2026-09-28T18:22:00Z', is_read: true }
|
||||
];
|
||||
case 'send_direct_message':
|
||||
return { id: Date.now(), from_uuid: 'mock-user-1', to_uuid: args?.toUuid, content: args?.content, created_at: new Date().toISOString(), is_read: true };
|
||||
case 'get_game_invites':
|
||||
return [
|
||||
{ id: 'inv-1', from_uuid: 'friend-1', from_username: 'Alex', to_uuid: 'mock-user-1', instance_id: 'survival-smp', server_address: 'smp.scopenet.gg', server_name: 'Survival SMP', status: 'pending', created_at: '2026-09-28T19:00:00Z' }
|
||||
];
|
||||
case 'send_game_invite':
|
||||
return { id: 'inv-' + Date.now(), from_uuid: 'mock-user-1', from_username: 'Alyssa', to_uuid: args?.toUuid, instance_id: args?.instanceId, server_address: args?.serverAddress, server_name: args?.serverName, status: 'pending', created_at: new Date().toISOString() };
|
||||
case 'respond_game_invite':
|
||||
return null;
|
||||
case 'get_user_profile':
|
||||
return {
|
||||
uuid: args?.uuid,
|
||||
username: args?.uuid === 'mock-user-1' ? 'Alyssa' : (args?.uuid === 'friend-1' ? 'Alex' : 'Steve'),
|
||||
bio: 'Explorer, redstone engineer, and proud founder of the Iron Fortress guild!',
|
||||
banner_url: null,
|
||||
skin_url: null,
|
||||
skin_model: 'classic',
|
||||
cape_url: null,
|
||||
global_level: { uuid: args?.uuid, level: 14, current_xp: 3450, next_level_xp: 5000, progress_pct: 69, title: 'Veteran Adventurer', badges: ['Beta Pioneer', 'Dragon Slayer'], rewards: [] },
|
||||
server_levels: [
|
||||
{ server_id: 1, server_name: 'Survival SMP', uuid: args?.uuid, level: 9, current_xp: 1200, next_level_xp: 2200, progress_pct: 54, rank_title: 'Knight' }
|
||||
],
|
||||
badges: ['Beta Pioneer', 'Dragon Slayer'],
|
||||
achievements: [
|
||||
{ id: 'ach1', title: 'Diamonds!', description: 'Acquire diamonds.', category: 'mining', xp_reward: 350, frame_type: 'goal', icon_item: '💎', icon_bg: '#0284c7', icon_border: '#38bdf8', unlocked: true, unlocked_at: '2026-09-24T18:15:00Z' }
|
||||
],
|
||||
posts: [
|
||||
{ id: 'post-1', user_uuid: args?.uuid, username: 'Alyssa', content: 'Just finished our mountain watchtower! What do you guys think?', image_url: null, likes_count: 7, liked_by_me: true, created_at: '2026-09-27T20:10:00Z' }
|
||||
],
|
||||
friends_count: 12,
|
||||
stats: { playtime_secs: 74200, joins: 48, deaths: 12, player_kills: 19, mob_kills: 480, blocks_broken: 15400, blocks_placed: 9800, messages: 320, first_seen: '2026-08-01T00:00:00Z', last_seen: '2026-09-28T22:00:00Z' },
|
||||
created_at: '2026-08-01T00:00:00Z'
|
||||
};
|
||||
case 'update_my_profile':
|
||||
return {
|
||||
uuid: 'mock-user-1',
|
||||
username: 'Alyssa',
|
||||
bio: args?.bio ?? '',
|
||||
banner_url: args?.bannerUrl ?? null,
|
||||
skin_url: null,
|
||||
skin_model: 'classic',
|
||||
cape_url: null,
|
||||
global_level: { uuid: 'mock-user-1', level: 14, current_xp: 3450, next_level_xp: 5000, progress_pct: 69, title: 'Veteran Adventurer', badges: ['Beta Pioneer'], rewards: [] },
|
||||
server_levels: [],
|
||||
badges: ['Beta Pioneer'],
|
||||
achievements: [],
|
||||
posts: [],
|
||||
friends_count: 12,
|
||||
stats: null,
|
||||
created_at: '2026-08-01T00:00:00Z'
|
||||
};
|
||||
case 'create_user_post':
|
||||
return { id: 'post-' + Date.now(), user_uuid: 'mock-user-1', username: 'Alyssa', content: args?.content, image_url: args?.imageUrl ?? null, likes_count: 0, liked_by_me: false, created_at: new Date().toISOString() };
|
||||
case 'like_user_post':
|
||||
return true;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -27,8 +27,9 @@ export const app = $state({
|
||||
active: null as string | null,
|
||||
panelUrl: null as string | null,
|
||||
offline: false,
|
||||
view: 'home' as 'home' | 'settings' | 'stats',
|
||||
view: 'home' as 'home' | 'settings' | 'stats' | 'quests' | 'guilds' | 'social',
|
||||
settingsTab: 'account',
|
||||
viewProfileUuid: null as string | null,
|
||||
selected: null as string | null,
|
||||
launch: idle(),
|
||||
launchingId: null as string | null,
|
||||
|
||||
@@ -122,3 +122,197 @@ export interface SkinProfile {
|
||||
created_at: string;
|
||||
}
|
||||
export interface UpdateInfo { version: string; notes: string; url: string; size: number }
|
||||
|
||||
export interface PlayerStats {
|
||||
server_id: number;
|
||||
uuid: string;
|
||||
name: string;
|
||||
playtime_secs: number;
|
||||
joins: number;
|
||||
deaths: number;
|
||||
player_kills: number;
|
||||
mob_kills: number;
|
||||
blocks_broken: number;
|
||||
blocks_placed: number;
|
||||
messages: number;
|
||||
first_seen: string;
|
||||
last_seen: string;
|
||||
server_name?: string;
|
||||
}
|
||||
|
||||
export interface LevelReward {
|
||||
id: number;
|
||||
level: number;
|
||||
reward_type: 'title' | 'item' | 'cosmetic' | 'profile_badge';
|
||||
reward_value: string;
|
||||
description: string;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
export interface UserLevelInfo {
|
||||
uuid: string;
|
||||
level: number;
|
||||
current_xp: number;
|
||||
next_level_xp: number;
|
||||
progress_pct: number;
|
||||
title: string | null;
|
||||
badges: string[];
|
||||
rewards: LevelReward[];
|
||||
}
|
||||
|
||||
export interface ServerLevelInfo {
|
||||
server_id: number;
|
||||
server_name: string;
|
||||
uuid: string;
|
||||
level: number;
|
||||
current_xp: number;
|
||||
next_level_xp: number;
|
||||
progress_pct: number;
|
||||
rank_title: string | null;
|
||||
}
|
||||
|
||||
export interface Quest {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
quest_type: 'daily' | 'weekly';
|
||||
category: 'mining' | 'combat' | 'building' | 'farming' | 'social' | 'exploration';
|
||||
xp_reward: number;
|
||||
stat_type: string;
|
||||
target_count: number;
|
||||
icon: string;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export interface UserQuest {
|
||||
quest: Quest;
|
||||
current_count: number;
|
||||
completed: boolean;
|
||||
claimed: boolean;
|
||||
expires_at: string;
|
||||
}
|
||||
|
||||
export interface Achievement {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
category: string;
|
||||
xp_reward: number;
|
||||
frame_type: 'task' | 'goal' | 'challenge';
|
||||
icon_item: string;
|
||||
icon_bg: string;
|
||||
icon_border: string;
|
||||
stat_type?: string | null;
|
||||
target_count?: number | null;
|
||||
event_type?: string | null;
|
||||
unlocked?: boolean;
|
||||
unlocked_at?: string | null;
|
||||
}
|
||||
|
||||
export interface Guild {
|
||||
id: string;
|
||||
instance_id: string;
|
||||
name: string;
|
||||
tag: string;
|
||||
description: string;
|
||||
icon_url: string | null;
|
||||
banner_url: string | null;
|
||||
leader_uuid: string;
|
||||
member_count: number;
|
||||
max_members: number;
|
||||
claims_count: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface GuildMember {
|
||||
guild_id: string;
|
||||
user_uuid: string;
|
||||
username: string;
|
||||
role: 'leader' | 'officer' | 'member';
|
||||
joined_at: string;
|
||||
is_online?: boolean;
|
||||
}
|
||||
|
||||
export interface GuildPost {
|
||||
id: string;
|
||||
guild_id: string;
|
||||
author_uuid: string;
|
||||
author_name: string;
|
||||
title: string;
|
||||
content: string;
|
||||
pinned: boolean;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface GuildClaim {
|
||||
id: number;
|
||||
guild_id: string;
|
||||
instance_id: string;
|
||||
dimension: string;
|
||||
chunk_x: number;
|
||||
chunk_z: number;
|
||||
claimed_by_uuid: string;
|
||||
claimed_at: string;
|
||||
guild_name?: string;
|
||||
guild_tag?: string;
|
||||
}
|
||||
|
||||
export interface FriendInfo {
|
||||
uuid: string;
|
||||
username: string;
|
||||
status: 'pending_sent' | 'pending_received' | 'accepted';
|
||||
is_online: boolean;
|
||||
playing_on: string | null;
|
||||
avatar_url?: string | null;
|
||||
}
|
||||
|
||||
export interface DirectMessage {
|
||||
id: number;
|
||||
from_uuid: string;
|
||||
to_uuid: string;
|
||||
content: string;
|
||||
created_at: string;
|
||||
is_read: boolean;
|
||||
}
|
||||
|
||||
export interface GameInvite {
|
||||
id: string;
|
||||
from_uuid: string;
|
||||
from_username: string;
|
||||
to_uuid: string;
|
||||
instance_id: string;
|
||||
server_address: string;
|
||||
server_name: string;
|
||||
status: 'pending' | 'accepted' | 'declined' | 'expired';
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface UserPost {
|
||||
id: string;
|
||||
user_uuid: string;
|
||||
username: string;
|
||||
content: string;
|
||||
image_url: string | null;
|
||||
likes_count: number;
|
||||
liked_by_me: boolean;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface UserProfileView {
|
||||
uuid: string;
|
||||
username: string;
|
||||
bio: string;
|
||||
banner_url: string | null;
|
||||
skin_url: string | null;
|
||||
skin_model: string;
|
||||
cape_url: string | null;
|
||||
global_level: UserLevelInfo;
|
||||
server_levels: ServerLevelInfo[];
|
||||
badges: string[];
|
||||
achievements: Achievement[];
|
||||
posts: UserPost[];
|
||||
friends_count: number;
|
||||
stats: PlayerStats | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,850 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import {
|
||||
Shield, Map, Users, MessageSquare, Plus, Crown, UserCheck, Trash2,
|
||||
Pin, LoaderCircle, RefreshCw, ChevronDown, Check, AlertCircle, Sparkles, Send
|
||||
} from '@lucide/svelte';
|
||||
import Avatar from '../components/Avatar.svelte';
|
||||
import ChunkMap from '../components/ChunkMap.svelte';
|
||||
import Modal from '../components/Modal.svelte';
|
||||
import { app, instances, selectedInstance, toast } from '../lib/store.svelte';
|
||||
import { invoke } from '../lib/tauri';
|
||||
import type { Guild, GuildMember, GuildPost } from '../lib/types';
|
||||
|
||||
let selectedInstId = $state<string>(selectedInstance()?.id || (instances()[0]?.id ?? ''));
|
||||
let myGuild = $state<Guild | null>(null);
|
||||
let allGuilds = $state<Guild[]>([]);
|
||||
let members = $state<GuildMember[]>([]);
|
||||
let posts = $state<GuildPost[]>([]);
|
||||
let activeTab = $state<'territory' | 'members' | 'feed'>('territory');
|
||||
let loading = $state(false);
|
||||
|
||||
// Create Guild Modal
|
||||
let createModalOpen = $state(false);
|
||||
let newGuildName = $state('');
|
||||
let newGuildTag = $state('');
|
||||
let newGuildDesc = $state('');
|
||||
let newGuildIcon = $state('');
|
||||
let newGuildBanner = $state('');
|
||||
let creating = $state(false);
|
||||
|
||||
// New Post Form
|
||||
let postTitle = $state('');
|
||||
let postContent = $state('');
|
||||
let postPinned = $state(false);
|
||||
let posting = $state(false);
|
||||
|
||||
const currentInstance = $derived(
|
||||
instances().find((i) => i.id === selectedInstId) ?? instances()[0] ?? null
|
||||
);
|
||||
|
||||
async function loadInstanceGuildData() {
|
||||
if (!selectedInstId) return;
|
||||
loading = true;
|
||||
try {
|
||||
const [mine, list] = await Promise.all([
|
||||
invoke<Guild | null>('get_my_guild', { instanceId: selectedInstId }).catch(() => null),
|
||||
invoke<Guild[]>('get_guilds', { instanceId: selectedInstId }).catch(() => [])
|
||||
]);
|
||||
myGuild = mine;
|
||||
allGuilds = list;
|
||||
|
||||
if (mine) {
|
||||
const [mList, pList] = await Promise.all([
|
||||
invoke<GuildMember[]>('get_guild_members', { guildId: mine.id }).catch(() => []),
|
||||
invoke<GuildPost[]>('get_guild_posts', { guildId: mine.id }).catch(() => [])
|
||||
]);
|
||||
members = mList;
|
||||
posts = pList;
|
||||
} else {
|
||||
members = [];
|
||||
posts = [];
|
||||
}
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to load guild data', 'error');
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCreateGuild() {
|
||||
if (!newGuildName.trim() || !newGuildTag.trim()) {
|
||||
toast('Please enter both guild name and tag', 'error');
|
||||
return;
|
||||
}
|
||||
creating = true;
|
||||
try {
|
||||
const guild = await invoke<Guild>('create_guild', {
|
||||
instanceId: selectedInstId,
|
||||
name: newGuildName.trim(),
|
||||
tag: newGuildTag.trim().toUpperCase(),
|
||||
description: newGuildDesc.trim(),
|
||||
iconUrl: newGuildIcon.trim() || null,
|
||||
bannerUrl: newGuildBanner.trim() || null
|
||||
});
|
||||
toast(`Guild [${guild.tag}] ${guild.name} founded!`, 'ok');
|
||||
createModalOpen = false;
|
||||
newGuildName = '';
|
||||
newGuildTag = '';
|
||||
newGuildDesc = '';
|
||||
newGuildIcon = '';
|
||||
newGuildBanner = '';
|
||||
await loadInstanceGuildData();
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to create guild', 'error');
|
||||
} finally {
|
||||
creating = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCreatePost() {
|
||||
if (!myGuild || !postTitle.trim() || !postContent.trim()) {
|
||||
toast('Please provide a title and announcement content', 'error');
|
||||
return;
|
||||
}
|
||||
posting = true;
|
||||
try {
|
||||
const post = await invoke<GuildPost>('create_guild_post', {
|
||||
guildId: myGuild.id,
|
||||
title: postTitle.trim(),
|
||||
content: postContent.trim(),
|
||||
pinned: postPinned
|
||||
});
|
||||
posts = [post, ...posts];
|
||||
postTitle = '';
|
||||
postContent = '';
|
||||
postPinned = false;
|
||||
toast('Announcement posted to guild wall', 'ok');
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to create post', 'error');
|
||||
} finally {
|
||||
posting = false;
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (selectedInstId) {
|
||||
loadInstanceGuildData();
|
||||
}
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
if (selectedInstance()?.id) {
|
||||
selectedInstId = selectedInstance()!.id;
|
||||
}
|
||||
loadInstanceGuildData();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="guilds-page">
|
||||
<!-- Page Header & Instance Picker -->
|
||||
<div class="page-header">
|
||||
<div class="title-wrap">
|
||||
<h1><Shield class="guild-icon" size={26} /> Guilds & Territories</h1>
|
||||
<p class="lead">Form factions, claim land chunks protected from griefing, and collaborate with your party.</p>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<div class="instance-select-wrap">
|
||||
<label for="instance-select" class="tiny muted uppercase">Instance</label>
|
||||
<select
|
||||
id="instance-select"
|
||||
class="inst-select"
|
||||
bind:value={selectedInstId}
|
||||
>
|
||||
{#each instances() as inst}
|
||||
<option value={inst.id}>{inst.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<button class="ghost icon" onclick={loadInstanceGuildData} title="Refresh" aria-label="Refresh">
|
||||
<RefreshCw size={17} class={loading ? 'spin' : ''} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if loading && !myGuild && !allGuilds.length}
|
||||
<div class="center-state"><LoaderCircle class="spin" size={32} /></div>
|
||||
{:else if myGuild}
|
||||
<!-- User is in a Guild -->
|
||||
<div class="guild-hub">
|
||||
<!-- Guild Banner & Meta Header -->
|
||||
<div
|
||||
class="guild-hero glass"
|
||||
style:background-image={myGuild.banner_url ? `linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.85)), url(${myGuild.banner_url})` : undefined}
|
||||
>
|
||||
<div class="guild-hero-content">
|
||||
<div class="guild-tag-badge">
|
||||
<span class="tag-text">[{myGuild.tag}]</span>
|
||||
</div>
|
||||
<div class="guild-info">
|
||||
<div class="guild-title-line">
|
||||
<h2>{myGuild.name}</h2>
|
||||
<span class="badge member-badge"><Users size={12} /> {myGuild.member_count} / {myGuild.max_members} Members</span>
|
||||
<span class="badge claim-badge"><Shield size={12} /> {myGuild.claims_count} Claims</span>
|
||||
</div>
|
||||
{#if myGuild.description}
|
||||
<p class="guild-desc">{myGuild.description}</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Segmented Navigation Tabs -->
|
||||
<div class="guild-tabs-row">
|
||||
<div class="tabs-segmented">
|
||||
<button class:active={activeTab === 'territory'} onclick={() => (activeTab = 'territory')}>
|
||||
<Map size={15} /> Territory & Land Claims
|
||||
</button>
|
||||
<button class:active={activeTab === 'members'} onclick={() => (activeTab = 'members')}>
|
||||
<Users size={15} /> Roster ({members.length})
|
||||
</button>
|
||||
<button class:active={activeTab === 'feed'} onclick={() => (activeTab = 'feed')}>
|
||||
<MessageSquare size={15} /> Guild Feed ({posts.length})
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tab Content -->
|
||||
{#if activeTab === 'territory'}
|
||||
<div class="territory-tab">
|
||||
<div class="protection-callout glass">
|
||||
<Shield size={18} class="callout-icon" />
|
||||
<div class="callout-text">
|
||||
<strong>Grief Protection Relay Active</strong>
|
||||
<p class="tiny muted">
|
||||
Chunks claimed by your guild are synchronized with the SCOPENET mod/plugin on the server. Non-members cannot break or place blocks within your claims.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ChunkMap
|
||||
instanceId={selectedInstId}
|
||||
myGuildId={myGuild.id}
|
||||
myGuildTag={myGuild.tag}
|
||||
onclaim={() => { if (myGuild) myGuild.claims_count += 1; }}
|
||||
onunclaim={() => { if (myGuild) myGuild.claims_count = Math.max(0, myGuild.claims_count - 1); }}
|
||||
/>
|
||||
</div>
|
||||
{:else if activeTab === 'members'}
|
||||
<div class="members-tab">
|
||||
<div class="members-grid">
|
||||
{#each members as m (m.user_uuid)}
|
||||
<div
|
||||
class="member-card glass"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onclick={() => (app.viewProfileUuid = m.user_uuid)}
|
||||
onkeydown={(e) => e.key === 'Enter' && (app.viewProfileUuid = m.user_uuid)}
|
||||
>
|
||||
<div class="member-avatar-wrap">
|
||||
<Avatar uuid={m.user_uuid} name={m.username} size={2.5} />
|
||||
{#if m.is_online}
|
||||
<span class="online-indicator" title="Online"></span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="member-details">
|
||||
<div class="member-name-row">
|
||||
<span class="member-name">{m.username}</span>
|
||||
{#if m.role === 'leader'}
|
||||
<span class="badge leader-badge"><Crown size={11} /> Leader</span>
|
||||
{:else if m.role === 'officer'}
|
||||
<span class="badge officer-badge"><UserCheck size={11} /> Officer</span>
|
||||
{:else}
|
||||
<span class="badge member-role-badge">Member</span>
|
||||
{/if}
|
||||
</div>
|
||||
<span class="tiny muted">Joined {new Date(m.joined_at).toLocaleDateString()}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{:else if activeTab === 'feed'}
|
||||
<div class="feed-tab">
|
||||
<!-- Post Announcement Form -->
|
||||
<div class="post-creator glass">
|
||||
<span class="creator-title">Post Guild Announcement</span>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Announcement Title"
|
||||
bind:value={postTitle}
|
||||
class="post-title-input"
|
||||
/>
|
||||
<textarea
|
||||
placeholder="Share news, raid plans, or updates with your guild..."
|
||||
bind:value={postContent}
|
||||
rows="3"
|
||||
class="post-textarea"
|
||||
></textarea>
|
||||
<div class="post-creator-footer">
|
||||
<label class="pin-checkbox tiny">
|
||||
<input type="checkbox" bind:checked={postPinned} />
|
||||
<span>Pin to top</span>
|
||||
</label>
|
||||
<button
|
||||
class="primary sm"
|
||||
onclick={handleCreatePost}
|
||||
disabled={posting}
|
||||
>
|
||||
{#if posting}<LoaderCircle size={13} class="spin" />{:else}<Send size={13} />{/if}
|
||||
Publish
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Posts Feed -->
|
||||
<div class="posts-list">
|
||||
{#if posts.length === 0}
|
||||
<div class="empty-state glass">
|
||||
<MessageSquare size={32} class="muted" />
|
||||
<p>No guild announcements posted yet.</p>
|
||||
</div>
|
||||
{:else}
|
||||
{#each posts as p (p.id)}
|
||||
<div class="post-card glass" class:pinned={p.pinned}>
|
||||
<div class="post-header">
|
||||
<div class="author-meta">
|
||||
<Avatar uuid={p.author_uuid} name={p.author_name} size={1.8} />
|
||||
<div class="author-info">
|
||||
<span class="author-name">{p.author_name}</span>
|
||||
<span class="post-date tiny muted">{new Date(p.created_at).toLocaleString()}</span>
|
||||
</div>
|
||||
</div>
|
||||
{#if p.pinned}
|
||||
<span class="badge pinned-badge"><Pin size={11} /> Pinned</span>
|
||||
{/if}
|
||||
</div>
|
||||
<h4 class="post-headline">{p.title}</h4>
|
||||
<p class="post-text">{p.content}</p>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<!-- User is NOT in a Guild on this instance -->
|
||||
<div class="no-guild-container">
|
||||
<div class="hero-prompt glass">
|
||||
<div class="prompt-icon-box">
|
||||
<Shield size={38} class="guild-icon" />
|
||||
</div>
|
||||
<div class="prompt-text">
|
||||
<h2>No Guild on {currentInstance?.name || 'this Instance'}</h2>
|
||||
<p class="lead">
|
||||
Guilds are tied to instances. Start your own guild to claim land chunks, invite members, and build a faction base, or browse existing factions below.
|
||||
</p>
|
||||
<button class="primary create-guild-btn" onclick={() => (createModalOpen = true)}>
|
||||
<Plus size={16} /> Create a Guild
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Browse Guilds Section -->
|
||||
<div class="browse-section">
|
||||
<div class="browse-header">
|
||||
<h3>Active Guilds ({allGuilds.length})</h3>
|
||||
</div>
|
||||
{#if allGuilds.length === 0}
|
||||
<div class="empty-state glass">
|
||||
<p>No guilds have been created on this instance yet. Be the first to establish territory!</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="guilds-directory-grid">
|
||||
{#each allGuilds as g (g.id)}
|
||||
<div class="guild-dir-card glass">
|
||||
<div class="dir-top">
|
||||
<div class="dir-tag">[{g.tag}]</div>
|
||||
<div class="dir-meta">
|
||||
<h4>{g.name}</h4>
|
||||
<span class="tiny muted">{g.member_count} / {g.max_members} Members • {g.claims_count} Chunks Claimed</span>
|
||||
</div>
|
||||
</div>
|
||||
{#if g.description}
|
||||
<p class="dir-desc">{g.description}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Create Guild Modal -->
|
||||
<Modal bind:open={createModalOpen} title="Found a New Guild" width={28}>
|
||||
<div class="modal-form">
|
||||
<label>
|
||||
<span class="field-label">Guild Name</span>
|
||||
<input type="text" placeholder="e.g. Iron Fortress" bind:value={newGuildName} maxlength="32" />
|
||||
</label>
|
||||
<label>
|
||||
<span class="field-label">Guild Tag (3 - 5 characters)</span>
|
||||
<input type="text" placeholder="e.g. IRON" bind:value={newGuildTag} maxlength="5" class="tag-input" />
|
||||
<span class="tiny muted">Appears in brackets on claimed chunks and chat tags.</span>
|
||||
</label>
|
||||
<label>
|
||||
<span class="field-label">Description / Moto</span>
|
||||
<textarea placeholder="Describe your guild's playstyle, goals, or rules..." bind:value={newGuildDesc} rows="3"></textarea>
|
||||
</label>
|
||||
<label>
|
||||
<span class="field-label">Banner Image URL (Optional)</span>
|
||||
<input type="url" placeholder="https://example.com/banner.png" bind:value={newGuildBanner} />
|
||||
</label>
|
||||
</div>
|
||||
{#snippet footer()}
|
||||
<button class="ghost" onclick={() => (createModalOpen = false)}>Cancel</button>
|
||||
<button class="primary" onclick={handleCreateGuild} disabled={creating}>
|
||||
{#if creating}<LoaderCircle size={14} class="spin" />{:else}<Sparkles size={14} />{/if}
|
||||
Found Guild
|
||||
</button>
|
||||
{/snippet}
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
.guilds-page {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: auto;
|
||||
padding: 1.6rem 2.2rem 2.5rem;
|
||||
gap: 1.2rem;
|
||||
}
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
border-bottom: 1px solid var(--line);
|
||||
padding-bottom: 1rem;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
}
|
||||
.title-wrap h1 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
:global(.guild-icon) {
|
||||
color: var(--accent);
|
||||
}
|
||||
.lead {
|
||||
color: var(--muted);
|
||||
font-size: 0.88rem;
|
||||
margin-top: 0.2rem;
|
||||
}
|
||||
.header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
.instance-select-wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.inst-select {
|
||||
background: color-mix(in srgb, var(--bg) 70%, transparent);
|
||||
border: 1px solid var(--line);
|
||||
color: var(--text);
|
||||
padding: 0.35rem 0.75rem;
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.guild-hub {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
.guild-hero {
|
||||
display: flex;
|
||||
padding: 1.5rem 1.8rem;
|
||||
border-radius: var(--radius);
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.guild-hero-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.2rem;
|
||||
}
|
||||
.guild-tag-badge {
|
||||
padding: 0.6rem 1rem;
|
||||
border-radius: var(--radius-sm);
|
||||
background: color-mix(in srgb, var(--accent) 25%, transparent);
|
||||
border: 2px solid var(--accent);
|
||||
box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 30%, transparent);
|
||||
}
|
||||
.tag-text {
|
||||
font-size: 1.4rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--accent);
|
||||
}
|
||||
.guild-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
.guild-title-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.guild-title-line h2 {
|
||||
font-size: 1.4rem;
|
||||
font-weight: 750;
|
||||
}
|
||||
.guild-desc {
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
max-width: 42rem;
|
||||
}
|
||||
.guild-tabs-row {
|
||||
display: flex;
|
||||
}
|
||||
.tabs-segmented {
|
||||
display: flex;
|
||||
background: color-mix(in srgb, var(--surface) 80%, transparent);
|
||||
padding: 0.25rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.tabs-segmented button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0.45rem 1rem;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 560;
|
||||
color: var(--muted);
|
||||
border-radius: calc(var(--radius-sm) - 2px);
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.tabs-segmented button.active {
|
||||
background: color-mix(in srgb, var(--text) 10%, transparent);
|
||||
color: var(--text);
|
||||
}
|
||||
.territory-tab {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.9rem;
|
||||
}
|
||||
.protection-callout {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: var(--radius-sm);
|
||||
background: color-mix(in srgb, var(--success) 10%, transparent);
|
||||
border: 1px solid color-mix(in srgb, var(--success) 35%, transparent);
|
||||
}
|
||||
:global(.callout-icon) {
|
||||
color: var(--success);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.callout-text p {
|
||||
margin: 0;
|
||||
}
|
||||
.members-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
|
||||
gap: 0.9rem;
|
||||
}
|
||||
.member-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
padding: 0.8rem 1rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
background: var(--surface);
|
||||
cursor: pointer;
|
||||
transition: transform 0.12s, border-color 0.15s;
|
||||
}
|
||||
.member-card:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: var(--line-strong);
|
||||
}
|
||||
.member-avatar-wrap {
|
||||
position: relative;
|
||||
}
|
||||
.online-indicator {
|
||||
position: absolute;
|
||||
bottom: -1px;
|
||||
right: -1px;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border-radius: 50%;
|
||||
background: var(--success);
|
||||
border: 2px solid var(--surface);
|
||||
}
|
||||
.member-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.member-name-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
.member-name {
|
||||
font-weight: 650;
|
||||
font-size: 0.88rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.leader-badge {
|
||||
background: color-mix(in srgb, #f59e0b 20%, transparent);
|
||||
color: #f59e0b;
|
||||
}
|
||||
.officer-badge {
|
||||
background: color-mix(in srgb, var(--accent) 20%, transparent);
|
||||
color: var(--accent);
|
||||
}
|
||||
.member-role-badge {
|
||||
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||
color: var(--muted);
|
||||
}
|
||||
.feed-tab {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.2rem;
|
||||
}
|
||||
.post-creator {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
padding: 1rem 1.2rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.creator-title {
|
||||
font-size: 0.88rem;
|
||||
font-weight: 650;
|
||||
}
|
||||
.post-title-input {
|
||||
background: color-mix(in srgb, var(--bg) 60%, transparent);
|
||||
border: 1px solid var(--line);
|
||||
color: var(--text);
|
||||
padding: 0.4rem 0.75rem;
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
.post-textarea {
|
||||
background: color-mix(in srgb, var(--bg) 60%, transparent);
|
||||
border: 1px solid var(--line);
|
||||
color: var(--text);
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.85rem;
|
||||
resize: vertical;
|
||||
}
|
||||
.post-creator-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.pin-checkbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
.posts-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.9rem;
|
||||
}
|
||||
.post-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
padding: 1.1rem 1.3rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.post-card.pinned {
|
||||
border-color: color-mix(in srgb, #f59e0b 40%, transparent);
|
||||
background: linear-gradient(135deg, color-mix(in srgb, #f59e0b 6%, var(--surface)) 0%, var(--surface) 100%);
|
||||
}
|
||||
.post-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.author-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
.author-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.author-name {
|
||||
font-size: 0.84rem;
|
||||
font-weight: 650;
|
||||
}
|
||||
.pinned-badge {
|
||||
background: color-mix(in srgb, #f59e0b 20%, transparent);
|
||||
color: #f59e0b;
|
||||
}
|
||||
.post-headline {
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.post-text {
|
||||
font-size: 0.85rem;
|
||||
color: color-mix(in srgb, var(--text) 85%, transparent);
|
||||
line-height: 1.4;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
/* No Guild View */
|
||||
.no-guild-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
.hero-prompt {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.8rem;
|
||||
padding: 2rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.prompt-icon-box {
|
||||
width: 4.5rem;
|
||||
height: 4.5rem;
|
||||
border-radius: var(--radius);
|
||||
background: color-mix(in srgb, var(--accent) 15%, transparent);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.prompt-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.prompt-text h2 {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.create-guild-btn {
|
||||
align-self: flex-start;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
.browse-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.9rem;
|
||||
}
|
||||
.browse-header h3 {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.guilds-directory-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
.guild-dir-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
padding: 1.1rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.dir-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
.dir-tag {
|
||||
font-size: 1rem;
|
||||
font-weight: 800;
|
||||
color: var(--accent);
|
||||
padding: 0.3rem 0.6rem;
|
||||
border-radius: var(--radius-sm);
|
||||
background: color-mix(in srgb, var(--accent) 15%, transparent);
|
||||
}
|
||||
.dir-meta h4 {
|
||||
font-size: 0.95rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.dir-desc {
|
||||
font-size: 0.82rem;
|
||||
color: var(--muted);
|
||||
line-height: 1.35;
|
||||
}
|
||||
.modal-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.9rem;
|
||||
}
|
||||
.modal-form label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
.field-label {
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.tag-input {
|
||||
text-transform: uppercase;
|
||||
font-family: monospace;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 600;
|
||||
padding: 0.16rem 0.5rem;
|
||||
border-radius: 99rem;
|
||||
}
|
||||
.member-badge {
|
||||
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||
}
|
||||
.claim-badge {
|
||||
background: color-mix(in srgb, var(--success) 16%, transparent);
|
||||
color: var(--success);
|
||||
}
|
||||
.center-state, .empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.8rem;
|
||||
padding: 3rem 1.5rem;
|
||||
text-align: center;
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,723 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import {
|
||||
Target, Trophy, Clock, Sparkles, Check, Gift, Pickaxe, Swords, Hammer,
|
||||
Wheat, Users, Compass, RefreshCw, LoaderCircle, Flame, Star, Award, Shield
|
||||
} from '@lucide/svelte';
|
||||
import { invoke } from '../lib/tauri';
|
||||
import { toast } from '../lib/store.svelte';
|
||||
import type { UserLevelInfo, ServerLevelInfo, UserQuest, Achievement } from '../lib/types';
|
||||
|
||||
let activeTab = $state<'daily' | 'weekly' | 'achievements'>('daily');
|
||||
let selectedCategory = $state<string>('all');
|
||||
let loading = $state(false);
|
||||
let claimingQuestId = $state<string | null>(null);
|
||||
|
||||
let levelInfo = $state<UserLevelInfo | null>(null);
|
||||
let userQuests = $state<UserQuest[]>([]);
|
||||
let achievements = $state<Achievement[]>([]);
|
||||
|
||||
const categoryIcons: Record<string, any> = {
|
||||
mining: Pickaxe,
|
||||
combat: Swords,
|
||||
building: Hammer,
|
||||
farming: Wheat,
|
||||
social: Users,
|
||||
exploration: Compass
|
||||
};
|
||||
|
||||
async function loadData() {
|
||||
loading = true;
|
||||
try {
|
||||
const [lvl, quests, achs] = await Promise.all([
|
||||
invoke<UserLevelInfo>('get_my_level').catch(() => null),
|
||||
invoke<UserQuest[]>('get_my_quests').catch(() => []),
|
||||
invoke<Achievement[]>('get_my_achievements').catch(() => [])
|
||||
]);
|
||||
if (lvl) levelInfo = lvl;
|
||||
userQuests = quests;
|
||||
achievements = achs;
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to load quests data', 'error');
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClaimQuest(questId: string) {
|
||||
claimingQuestId = questId;
|
||||
try {
|
||||
const updatedLevel = await invoke<UserLevelInfo>('claim_quest', { questId });
|
||||
levelInfo = updatedLevel;
|
||||
// Mark as claimed locally
|
||||
userQuests = userQuests.map((uq) => {
|
||||
if (uq.quest.id === questId) {
|
||||
return { ...uq, claimed: true };
|
||||
}
|
||||
return uq;
|
||||
});
|
||||
toast('Quest reward claimed! XP awarded to your Global Level.', 'ok');
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to claim reward', 'error');
|
||||
} finally {
|
||||
claimingQuestId = null;
|
||||
}
|
||||
}
|
||||
|
||||
const filteredQuests = $derived(
|
||||
userQuests.filter((uq) => {
|
||||
if (uq.quest.quest_type !== activeTab) return false;
|
||||
if (selectedCategory !== 'all' && uq.quest.category !== selectedCategory) return false;
|
||||
return true;
|
||||
})
|
||||
);
|
||||
|
||||
const completedCount = $derived(
|
||||
userQuests.filter((uq) => uq.quest.quest_type === activeTab && uq.completed).length
|
||||
);
|
||||
|
||||
const totalTabQuests = $derived(
|
||||
userQuests.filter((uq) => uq.quest.quest_type === activeTab).length
|
||||
);
|
||||
|
||||
const unlockedAchievementsCount = $derived(
|
||||
achievements.filter((a) => a.unlocked).length
|
||||
);
|
||||
|
||||
function getTimeUntilReset(type: 'daily' | 'weekly'): string {
|
||||
const now = new Date();
|
||||
if (type === 'daily') {
|
||||
const tomorrow = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + 1));
|
||||
const diffMs = tomorrow.getTime() - now.getTime();
|
||||
const hours = Math.floor(diffMs / (1000 * 60 * 60));
|
||||
const mins = Math.floor((diffMs % (1000 * 60 * 60)) / (1000 * 60));
|
||||
return `${hours}h ${mins}m`;
|
||||
} else {
|
||||
const day = now.getUTCDay();
|
||||
const daysUntilSunday = (7 - day) % 7 || 7;
|
||||
const nextSunday = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + daysUntilSunday));
|
||||
const diffMs = nextSunday.getTime() - now.getTime();
|
||||
const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
||||
const hours = Math.floor((diffMs % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
||||
return `${days}d ${hours}h`;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
loadData();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="quests-page">
|
||||
<!-- Page Header -->
|
||||
<div class="page-header">
|
||||
<div class="title-wrap">
|
||||
<h1><Target class="target-icon" size={26} /> Quests & Progression</h1>
|
||||
<p class="lead">Complete daily and weekly quests across servers to level up your SCOPENET account.</p>
|
||||
</div>
|
||||
<button class="ghost icon" onclick={loadData} title="Refresh" aria-label="Refresh">
|
||||
<RefreshCw size={17} class={loading ? 'spin' : ''} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Global Level Summary Hero Card -->
|
||||
{#if levelInfo}
|
||||
<div class="hero-level glass">
|
||||
<div class="level-badge-wrap">
|
||||
<div class="level-circle">
|
||||
<span class="lvl-label">LVL</span>
|
||||
<span class="lvl-number">{levelInfo.level}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-details">
|
||||
<div class="level-title-row">
|
||||
<div class="title-meta">
|
||||
<span class="level-name">SCOPENET Global Level</span>
|
||||
{#if levelInfo.title}
|
||||
<span class="badge title-badge"><Award size={12} /> {levelInfo.title}</span>
|
||||
{/if}
|
||||
</div>
|
||||
<span class="xp-ratio">
|
||||
<strong>{levelInfo.current_xp.toLocaleString()}</strong> / {levelInfo.next_level_xp.toLocaleString()} XP
|
||||
</span>
|
||||
</div>
|
||||
<div class="progress-bar-bg">
|
||||
<div class="progress-fill" style:width="{Math.min(100, Math.max(0, levelInfo.progress_pct))}%"></div>
|
||||
</div>
|
||||
<div class="level-footer">
|
||||
<span class="muted tiny">
|
||||
Playing on any SCOPENET server earns Global XP. Unlocks exclusive titles, badges, and cosmetic items.
|
||||
</span>
|
||||
{#if levelInfo.badges && levelInfo.badges.length > 0}
|
||||
<div class="badges-row">
|
||||
{#each levelInfo.badges as badge}
|
||||
<span class="badge icon-badge" title={badge}><Star size={11} /> {badge}</span>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Segmented Tabs Navigation -->
|
||||
<div class="nav-bar">
|
||||
<div class="tabs-segmented">
|
||||
<button class:active={activeTab === 'daily'} onclick={() => (activeTab = 'daily')}>
|
||||
<Clock size={15} /> Daily Quests
|
||||
</button>
|
||||
<button class:active={activeTab === 'weekly'} onclick={() => (activeTab = 'weekly')}>
|
||||
<Flame size={15} /> Weekly Quests
|
||||
</button>
|
||||
<button class:active={activeTab === 'achievements'} onclick={() => (activeTab = 'achievements')}>
|
||||
<Trophy size={15} /> Achievements ({unlockedAchievementsCount}/{achievements.length})
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if activeTab !== 'achievements'}
|
||||
<div class="reset-countdown muted tiny">
|
||||
<Clock size={13} />
|
||||
<span>Resets in: <strong>{getTimeUntilReset(activeTab)}</strong></span>
|
||||
<span class="divider">•</span>
|
||||
<span>Completed: <strong>{completedCount} / {totalTabQuests}</strong></span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Content Section -->
|
||||
{#if loading && !userQuests.length}
|
||||
<div class="center-state"><LoaderCircle class="spin" size={32} /></div>
|
||||
{:else if activeTab === 'achievements'}
|
||||
<!-- Achievements List with Minecraft Frame Styling -->
|
||||
<div class="achievements-section">
|
||||
<div class="achievements-grid">
|
||||
{#each achievements as ach (ach.id)}
|
||||
<div class="achievement-card glass" class:unlocked={ach.unlocked} class:frame-task={ach.frame_type === 'task'} class:frame-goal={ach.frame_type === 'goal'} class:frame-challenge={ach.frame_type === 'challenge'}>
|
||||
<div class="achievement-icon-frame" style:background={ach.icon_bg || 'rgba(0,0,0,0.5)'} style:border-color={ach.icon_border || 'var(--line)'}>
|
||||
<span class="sprite-icon">{ach.icon_item || '💎'}</span>
|
||||
</div>
|
||||
<div class="achievement-body">
|
||||
<div class="achievement-header">
|
||||
<span class="ach-title">{ach.title}</span>
|
||||
<span class="badge frame-badge {ach.frame_type}">{ach.frame_type.toUpperCase()}</span>
|
||||
</div>
|
||||
<p class="ach-desc">{ach.description}</p>
|
||||
<div class="ach-footer">
|
||||
<span class="xp-tag">+{ach.xp_reward} XP</span>
|
||||
{#if ach.unlocked}
|
||||
<span class="badge unlocked-tag"><Check size={11} /> Unlocked</span>
|
||||
{:else}
|
||||
<span class="badge locked-tag">Locked</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Quests List -->
|
||||
<div class="quests-content">
|
||||
<!-- Category Filter Pills -->
|
||||
<div class="category-filters">
|
||||
{#each ['all', 'mining', 'combat', 'building', 'farming', 'social', 'exploration'] as cat}
|
||||
{@const CatIcon = categoryIcons[cat]}
|
||||
<button
|
||||
class="pill-btn"
|
||||
class:active={selectedCategory === cat}
|
||||
onclick={() => (selectedCategory = cat)}
|
||||
>
|
||||
{#if cat !== 'all' && CatIcon}
|
||||
<CatIcon size={13} />
|
||||
{/if}
|
||||
<span class="cap">{cat}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
{#if filteredQuests.length === 0}
|
||||
<div class="empty-state glass">
|
||||
<Target size={36} class="muted" />
|
||||
<p>No {activeTab} quests found in this category.</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="quests-grid">
|
||||
{#each filteredQuests as uq (uq.quest.id)}
|
||||
{@const pct = Math.min(100, Math.round((uq.current_count / Math.max(1, uq.quest.target_count)) * 100))}
|
||||
{@const IconComponent = categoryIcons[uq.quest.category] || Target}
|
||||
|
||||
<div class="quest-card glass" class:completed={uq.completed} class:claimed={uq.claimed}>
|
||||
<div class="quest-top">
|
||||
<div class="quest-icon-wrapper">
|
||||
<IconComponent size={20} class="cat-icon" />
|
||||
</div>
|
||||
<div class="quest-meta">
|
||||
<div class="quest-title-row">
|
||||
<span class="quest-title">{uq.quest.title}</span>
|
||||
<span class="badge cat-badge">{uq.quest.category}</span>
|
||||
</div>
|
||||
<p class="quest-desc">{uq.quest.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="quest-progress-wrap">
|
||||
<div class="progress-labels">
|
||||
<span class="progress-ratio">
|
||||
<strong>{uq.current_count}</strong> / {uq.quest.target_count} ({pct}%)
|
||||
</span>
|
||||
<span class="xp-badge">+{uq.quest.xp_reward} XP</span>
|
||||
</div>
|
||||
<div class="progress-bar-bg">
|
||||
<div class="progress-fill" style:width="{pct}%"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="quest-action-row">
|
||||
{#if uq.claimed}
|
||||
<span class="badge claimed-badge"><Check size={13} /> Reward Claimed</span>
|
||||
{:else if uq.completed}
|
||||
<button
|
||||
class="primary claim-btn"
|
||||
onclick={() => handleClaimQuest(uq.quest.id)}
|
||||
disabled={claimingQuestId === uq.quest.id}
|
||||
>
|
||||
{#if claimingQuestId === uq.quest.id}
|
||||
<LoaderCircle size={14} class="spin" />
|
||||
{:else}
|
||||
<Gift size={14} />
|
||||
{/if}
|
||||
Claim +{uq.quest.xp_reward} XP
|
||||
</button>
|
||||
{:else}
|
||||
<span class="badge in-progress-badge">In Progress</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.quests-page {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: auto;
|
||||
padding: 1.6rem 2.2rem 2.5rem;
|
||||
gap: 1.2rem;
|
||||
}
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
border-bottom: 1px solid var(--line);
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
.title-wrap h1 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
:global(.target-icon) {
|
||||
color: var(--accent);
|
||||
}
|
||||
.lead {
|
||||
color: var(--muted);
|
||||
font-size: 0.88rem;
|
||||
margin-top: 0.2rem;
|
||||
}
|
||||
.hero-level {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.5rem;
|
||||
padding: 1.2rem 1.6rem;
|
||||
border-radius: var(--radius);
|
||||
background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 15%, var(--surface)) 0%, var(--surface) 100%);
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
|
||||
}
|
||||
.level-badge-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.level-circle {
|
||||
width: 4.5rem;
|
||||
height: 4.5rem;
|
||||
border-radius: 50%;
|
||||
background: color-mix(in srgb, var(--accent) 25%, transparent);
|
||||
border: 3px solid var(--accent);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 40%, transparent);
|
||||
}
|
||||
.lvl-label {
|
||||
font-size: 0.65rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--accent);
|
||||
}
|
||||
.lvl-number {
|
||||
font-size: 1.6rem;
|
||||
font-weight: 800;
|
||||
line-height: 1;
|
||||
color: var(--text);
|
||||
}
|
||||
.level-details {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.45rem;
|
||||
}
|
||||
.level-title-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.title-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
.level-name {
|
||||
font-size: 1.15rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.title-badge {
|
||||
background: color-mix(in srgb, #f59e0b 20%, transparent);
|
||||
color: #f59e0b;
|
||||
border: 1px solid color-mix(in srgb, #f59e0b 40%, transparent);
|
||||
}
|
||||
.xp-ratio {
|
||||
font-size: 0.88rem;
|
||||
color: var(--muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.xp-ratio strong {
|
||||
color: var(--text);
|
||||
}
|
||||
.progress-bar-bg {
|
||||
width: 100%;
|
||||
height: 0.55rem;
|
||||
border-radius: 99rem;
|
||||
background: color-mix(in srgb, var(--text) 10%, transparent);
|
||||
overflow: hidden;
|
||||
}
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
border-radius: 99rem;
|
||||
background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, white));
|
||||
transition: width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
|
||||
}
|
||||
.level-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
.badges-row {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.icon-badge {
|
||||
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
.nav-bar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
.tabs-segmented {
|
||||
display: flex;
|
||||
background: color-mix(in srgb, var(--surface) 80%, transparent);
|
||||
padding: 0.25rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.tabs-segmented button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0.45rem 1rem;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 560;
|
||||
color: var(--muted);
|
||||
border-radius: calc(var(--radius-sm) - 2px);
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.tabs-segmented button.active {
|
||||
background: color-mix(in srgb, var(--text) 10%, transparent);
|
||||
color: var(--text);
|
||||
}
|
||||
.reset-countdown {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.divider {
|
||||
color: var(--line-strong);
|
||||
}
|
||||
.quests-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
.category-filters {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
overflow-x: auto;
|
||||
padding-bottom: 0.2rem;
|
||||
}
|
||||
.pill-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
padding: 0.35rem 0.75rem;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 560;
|
||||
border-radius: 99rem;
|
||||
background: color-mix(in srgb, var(--text) 6%, transparent);
|
||||
border: 1px solid transparent;
|
||||
color: var(--muted);
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.pill-btn.active {
|
||||
background: color-mix(in srgb, var(--accent) 18%, transparent);
|
||||
border-color: color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
color: var(--text);
|
||||
}
|
||||
.cap {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
.quests-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
.quest-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
padding: 1.1rem 1.25rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
gap: 0.9rem;
|
||||
transition: transform 0.15s, border-color 0.15s;
|
||||
}
|
||||
.quest-card:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: var(--line-strong);
|
||||
}
|
||||
.quest-card.completed {
|
||||
border-color: color-mix(in srgb, var(--success) 45%, transparent);
|
||||
}
|
||||
.quest-card.claimed {
|
||||
opacity: 0.75;
|
||||
}
|
||||
.quest-top {
|
||||
display: flex;
|
||||
gap: 0.8rem;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.quest-icon-wrapper {
|
||||
width: 2.2rem;
|
||||
height: 2.2rem;
|
||||
border-radius: var(--radius-sm);
|
||||
background: color-mix(in srgb, var(--accent) 14%, transparent);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
flex-shrink: 0;
|
||||
color: var(--accent);
|
||||
}
|
||||
.quest-meta {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
.quest-title-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.quest-title {
|
||||
font-size: 0.92rem;
|
||||
font-weight: 650;
|
||||
line-height: 1.2;
|
||||
}
|
||||
.cat-badge {
|
||||
text-transform: uppercase;
|
||||
font-size: 0.65rem;
|
||||
letter-spacing: 0.05em;
|
||||
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||
color: var(--muted);
|
||||
}
|
||||
.quest-desc {
|
||||
font-size: 0.82rem;
|
||||
color: var(--muted);
|
||||
line-height: 1.35;
|
||||
}
|
||||
.quest-progress-wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
.progress-labels {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.xp-badge {
|
||||
color: var(--accent);
|
||||
font-weight: 700;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.quest-action-row {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
border-top: 1px solid color-mix(in srgb, var(--line) 40%, transparent);
|
||||
padding-top: 0.6rem;
|
||||
}
|
||||
.claim-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
font-size: 0.82rem;
|
||||
padding: 0.4rem 0.9rem;
|
||||
background: var(--success);
|
||||
border-color: var(--success);
|
||||
animation: pulse 2s infinite ease-in-out;
|
||||
}
|
||||
@keyframes pulse {
|
||||
0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 50%, transparent); }
|
||||
50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--success) 0%, transparent); }
|
||||
}
|
||||
.claimed-badge {
|
||||
background: color-mix(in srgb, var(--success) 15%, transparent);
|
||||
color: var(--success);
|
||||
}
|
||||
.in-progress-badge {
|
||||
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||
color: var(--muted);
|
||||
}
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 600;
|
||||
padding: 0.16rem 0.5rem;
|
||||
border-radius: 99rem;
|
||||
}
|
||||
.center-state, .empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.8rem;
|
||||
padding: 3rem 1.5rem;
|
||||
text-align: center;
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
/* Achievements Section */
|
||||
.achievements-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
.achievement-card {
|
||||
display: flex;
|
||||
gap: 0.9rem;
|
||||
padding: 1.1rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
position: relative;
|
||||
opacity: 0.65;
|
||||
transition: opacity 0.15s, border-color 0.15s;
|
||||
}
|
||||
.achievement-card.unlocked {
|
||||
opacity: 1;
|
||||
border-color: color-mix(in srgb, var(--accent) 40%, transparent);
|
||||
}
|
||||
.achievement-card.frame-challenge.unlocked {
|
||||
border-color: #f59e0b88;
|
||||
background: linear-gradient(135deg, color-mix(in srgb, #f59e0b 8%, var(--surface)) 0%, var(--surface) 100%);
|
||||
}
|
||||
.achievement-icon-frame {
|
||||
width: 2.8rem;
|
||||
height: 2.8rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 2px solid var(--line);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
flex-shrink: 0;
|
||||
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
.sprite-icon {
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
.achievement-body {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
.achievement-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.ach-title {
|
||||
font-size: 0.92rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.frame-badge {
|
||||
font-size: 0.62rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
.frame-badge.task { background: #64748b33; color: #94a3b8; }
|
||||
.frame-badge.goal { background: #3b82f633; color: #60a5fa; }
|
||||
.frame-badge.challenge { background: #f59e0b33; color: #fbbf24; }
|
||||
.ach-desc {
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted);
|
||||
line-height: 1.35;
|
||||
}
|
||||
.ach-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 0.2rem;
|
||||
}
|
||||
.xp-tag {
|
||||
font-size: 0.78rem;
|
||||
font-weight: 700;
|
||||
color: var(--accent);
|
||||
}
|
||||
.unlocked-tag {
|
||||
background: color-mix(in srgb, var(--success) 20%, transparent);
|
||||
color: var(--success);
|
||||
}
|
||||
.locked-tag {
|
||||
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||
color: var(--muted);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,913 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import {
|
||||
Users, UserPlus, MessageSquare, Gamepad2, Send, Check, X, Trash2,
|
||||
Clock, ExternalLink, LoaderCircle, RefreshCw, Circle, UserX, Sparkles
|
||||
} from '@lucide/svelte';
|
||||
import Avatar from '../components/Avatar.svelte';
|
||||
import Modal from '../components/Modal.svelte';
|
||||
import { activeAccount, app, instances, toast } from '../lib/store.svelte';
|
||||
import { invoke } from '../lib/tauri';
|
||||
import type { FriendInfo, DirectMessage, GameInvite } from '../lib/types';
|
||||
|
||||
let activeSection = $state<'friends' | 'messages' | 'invites'>('friends');
|
||||
let friendsFilter = $state<'all' | 'online' | 'pending'>('all');
|
||||
let loading = $state(false);
|
||||
|
||||
let friends = $state<FriendInfo[]>([]);
|
||||
let invites = $state<GameInvite[]>([]);
|
||||
let activeChatFriend = $state<FriendInfo | null>(null);
|
||||
let messages = $state<DirectMessage[]>([]);
|
||||
let messageInput = $state('');
|
||||
let sendingMessage = $state(false);
|
||||
|
||||
// Add Friend Modal / Input
|
||||
let addFriendUsername = $state('');
|
||||
let sendingFriendReq = $state(false);
|
||||
|
||||
// Send Game Invite Modal
|
||||
let inviteModalOpen = $state(false);
|
||||
let inviteTargetFriend = $state<FriendInfo | null>(null);
|
||||
let inviteInstanceId = $state(instances()[0]?.id ?? '');
|
||||
let sendingInvite = $state(false);
|
||||
|
||||
async function loadData() {
|
||||
loading = true;
|
||||
try {
|
||||
const [fList, iList] = await Promise.all([
|
||||
invoke<FriendInfo[]>('get_friends').catch(() => []),
|
||||
invoke<GameInvite[]>('get_game_invites').catch(() => [])
|
||||
]);
|
||||
friends = fList;
|
||||
invites = iList;
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to load social data', 'error');
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSendFriendRequest() {
|
||||
if (!addFriendUsername.trim()) return;
|
||||
sendingFriendReq = true;
|
||||
try {
|
||||
await invoke('send_friend_request', { friendUsername: addFriendUsername.trim() });
|
||||
toast(`Friend request sent to ${addFriendUsername.trim()}!`, 'ok');
|
||||
addFriendUsername = '';
|
||||
await loadData();
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to send friend request', 'error');
|
||||
} finally {
|
||||
sendingFriendReq = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRespondRequest(friendUuid: string, accept: boolean) {
|
||||
try {
|
||||
await invoke('respond_friend_request', { friendUuid, accept });
|
||||
toast(accept ? 'Friend request accepted!' : 'Request declined.', 'ok');
|
||||
await loadData();
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Action failed', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRemoveFriend(friendUuid: string) {
|
||||
try {
|
||||
await invoke('remove_friend', { friendUuid });
|
||||
friends = friends.filter((f) => f.uuid !== friendUuid);
|
||||
if (activeChatFriend?.uuid === friendUuid) {
|
||||
activeChatFriend = null;
|
||||
messages = [];
|
||||
}
|
||||
toast('Friend removed', 'ok');
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to remove friend', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function selectChatFriend(friend: FriendInfo) {
|
||||
activeChatFriend = friend;
|
||||
activeSection = 'messages';
|
||||
try {
|
||||
messages = await invoke<DirectMessage[]>('get_direct_messages', {
|
||||
friendUuid: friend.uuid,
|
||||
limit: 50
|
||||
});
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to load messages', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSendMessage() {
|
||||
if (!activeChatFriend || !messageInput.trim()) return;
|
||||
sendingMessage = true;
|
||||
const text = messageInput.trim();
|
||||
try {
|
||||
const msg = await invoke<DirectMessage>('send_direct_message', {
|
||||
toUuid: activeChatFriend.uuid,
|
||||
content: text
|
||||
});
|
||||
messages = [...messages, msg];
|
||||
messageInput = '';
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to send message', 'error');
|
||||
} finally {
|
||||
sendingMessage = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openInviteModal(friend: FriendInfo) {
|
||||
inviteTargetFriend = friend;
|
||||
inviteModalOpen = true;
|
||||
}
|
||||
|
||||
async function handleSendInvite() {
|
||||
if (!inviteTargetFriend) return;
|
||||
sendingInvite = true;
|
||||
try {
|
||||
const inst = instances().find((i) => i.id === inviteInstanceId);
|
||||
await invoke('send_game_invite', {
|
||||
toUuid: inviteTargetFriend.uuid,
|
||||
instanceId: inviteInstanceId,
|
||||
serverAddress: inst?.server?.address ?? 'localhost',
|
||||
serverName: inst?.name ?? 'Minecraft Server'
|
||||
});
|
||||
toast(`Game invite sent to ${inviteTargetFriend.username}!`, 'ok');
|
||||
inviteModalOpen = false;
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to send game invite', 'error');
|
||||
} finally {
|
||||
sendingInvite = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRespondInvite(inviteId: string, accept: boolean) {
|
||||
try {
|
||||
await invoke('respond_game_invite', { inviteId, accept });
|
||||
invites = invites.map((inv) =>
|
||||
inv.id === inviteId ? { ...inv, status: accept ? 'accepted' : 'declined' } : inv
|
||||
);
|
||||
toast(accept ? 'Game invite accepted!' : 'Invite declined.', 'ok');
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to respond to invite', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
const acceptedFriends = $derived(friends.filter((f) => f.status === 'accepted'));
|
||||
const pendingReceived = $derived(friends.filter((f) => f.status === 'pending_received'));
|
||||
const pendingSent = $derived(friends.filter((f) => f.status === 'pending_sent'));
|
||||
|
||||
const displayedFriends = $derived(
|
||||
friends.filter((f) => {
|
||||
if (friendsFilter === 'online') return f.status === 'accepted' && f.is_online;
|
||||
if (friendsFilter === 'pending') return f.status !== 'accepted';
|
||||
return f.status === 'accepted';
|
||||
})
|
||||
);
|
||||
|
||||
onMount(() => {
|
||||
loadData();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="social-page">
|
||||
<!-- Page Header -->
|
||||
<div class="page-header">
|
||||
<div class="title-wrap">
|
||||
<h1><Users class="users-icon" size={26} /> Friends & Social</h1>
|
||||
<p class="lead">Connect with friends, send direct messages, and team up with game invites.</p>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<button class="ghost icon" onclick={loadData} title="Refresh" aria-label="Refresh">
|
||||
<RefreshCw size={17} class={loading ? 'spin' : ''} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Social Navigation Tabs -->
|
||||
<div class="tabs-row">
|
||||
<div class="tabs-segmented">
|
||||
<button class:active={activeSection === 'friends'} onclick={() => (activeSection = 'friends')}>
|
||||
<Users size={15} /> Friends ({acceptedFriends.length})
|
||||
</button>
|
||||
<button class:active={activeSection === 'messages'} onclick={() => (activeSection = 'messages')}>
|
||||
<MessageSquare size={15} /> Direct Messages
|
||||
</button>
|
||||
<button class:active={activeSection === 'invites'} onclick={() => (activeSection = 'invites')}>
|
||||
<Gamepad2 size={15} /> Invites ({invites.filter((i) => i.status === 'pending').length})
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Content Sections -->
|
||||
{#if activeSection === 'friends'}
|
||||
<div class="friends-layout">
|
||||
<!-- Add Friend Bar -->
|
||||
<div class="add-friend-bar glass">
|
||||
<UserPlus size={18} class="muted" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Enter a player's username to add them..."
|
||||
bind:value={addFriendUsername}
|
||||
onkeydown={(e) => e.key === 'Enter' && handleSendFriendRequest()}
|
||||
class="add-friend-input"
|
||||
/>
|
||||
<button
|
||||
class="primary sm"
|
||||
onclick={handleSendFriendRequest}
|
||||
disabled={sendingFriendReq || !addFriendUsername.trim()}
|
||||
>
|
||||
{#if sendingFriendReq}<LoaderCircle size={14} class="spin" />{:else}Send Request{/if}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Filter Sub-tabs -->
|
||||
<div class="filter-pills">
|
||||
<button class="pill" class:active={friendsFilter === 'all'} onclick={() => (friendsFilter = 'all')}>
|
||||
All ({acceptedFriends.length})
|
||||
</button>
|
||||
<button class="pill" class:active={friendsFilter === 'online'} onclick={() => (friendsFilter = 'online')}>
|
||||
Online ({acceptedFriends.filter((f) => f.is_online).length})
|
||||
</button>
|
||||
<button class="pill" class:active={friendsFilter === 'pending'} onclick={() => (friendsFilter = 'pending')}>
|
||||
Pending ({pendingReceived.length + pendingSent.length})
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Pending Incoming Requests Alert -->
|
||||
{#if pendingReceived.length > 0 && friendsFilter !== 'pending'}
|
||||
<div class="pending-alert glass">
|
||||
<span class="tiny bold">You have {pendingReceived.length} pending friend request(s)</span>
|
||||
<button class="ghost sm" onclick={() => (friendsFilter = 'pending')}>Review</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Friends List -->
|
||||
{#if friendsFilter === 'pending'}
|
||||
<div class="pending-lists">
|
||||
{#if pendingReceived.length > 0}
|
||||
<h4 class="subheading">Incoming Requests ({pendingReceived.length})</h4>
|
||||
<div class="friends-grid">
|
||||
{#each pendingReceived as req (req.uuid)}
|
||||
<div class="friend-card glass">
|
||||
<div class="card-left" role="button" tabindex="0" onclick={() => (app.viewProfileUuid = req.uuid)} onkeydown={(e) => e.key === 'Enter' && (app.viewProfileUuid = req.uuid)}>
|
||||
<Avatar uuid={req.uuid} name={req.username} size={2.5} />
|
||||
<div class="name-block">
|
||||
<span class="user-title">{req.username}</span>
|
||||
<span class="tiny muted">Wants to be friends</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="req-actions">
|
||||
<button class="primary icon sm" onclick={() => handleRespondRequest(req.uuid, true)} title="Accept">
|
||||
<Check size={14} />
|
||||
</button>
|
||||
<button class="ghost icon sm" onclick={() => handleRespondRequest(req.uuid, false)} title="Decline">
|
||||
<X size={14} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if pendingSent.length > 0}
|
||||
<h4 class="subheading" style:margin-top="1rem">Outgoing Requests ({pendingSent.length})</h4>
|
||||
<div class="friends-grid">
|
||||
{#each pendingSent as req (req.uuid)}
|
||||
<div class="friend-card glass">
|
||||
<div class="card-left">
|
||||
<Avatar uuid={req.uuid} name={req.username} size={2.5} />
|
||||
<div class="name-block">
|
||||
<span class="user-title">{req.username}</span>
|
||||
<span class="tiny muted">Request pending...</span>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ghost icon sm" onclick={() => handleRemoveFriend(req.uuid)} title="Cancel Request">
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if pendingReceived.length === 0 && pendingSent.length === 0}
|
||||
<div class="empty-state glass">
|
||||
<p class="muted">No pending friend requests.</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if displayedFriends.length === 0}
|
||||
<div class="empty-state glass">
|
||||
<Users size={32} class="muted" />
|
||||
<p class="muted">No friends found in this view. Add friends by typing their username above!</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="friends-grid">
|
||||
{#each displayedFriends as friend (friend.uuid)}
|
||||
<div class="friend-card glass">
|
||||
<div
|
||||
class="card-left"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onclick={() => (app.viewProfileUuid = friend.uuid)}
|
||||
onkeydown={(e) => e.key === 'Enter' && (app.viewProfileUuid = friend.uuid)}
|
||||
title="View Profile"
|
||||
>
|
||||
<div class="avatar-holder">
|
||||
<Avatar uuid={friend.uuid} name={friend.username} size={2.6} />
|
||||
<span class="status-dot" class:online={friend.is_online}></span>
|
||||
</div>
|
||||
<div class="name-block">
|
||||
<span class="user-title">{friend.username}</span>
|
||||
{#if friend.is_online && friend.playing_on}
|
||||
<span class="tiny playing-on">Playing on {friend.playing_on}</span>
|
||||
{:else if friend.is_online}
|
||||
<span class="tiny online-label">Online in Launcher</span>
|
||||
{:else}
|
||||
<span class="tiny muted">Offline</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="friend-actions">
|
||||
<button class="ghost icon sm" onclick={() => selectChatFriend(friend)} title="Message">
|
||||
<MessageSquare size={15} />
|
||||
</button>
|
||||
<button class="ghost icon sm" onclick={() => openInviteModal(friend)} title="Invite to Game">
|
||||
<Gamepad2 size={15} />
|
||||
</button>
|
||||
<button class="ghost icon sm danger-hover" onclick={() => handleRemoveFriend(friend.uuid)} title="Remove Friend">
|
||||
<UserX size={15} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if activeSection === 'messages'}
|
||||
<!-- Direct Messages Split View -->
|
||||
<div class="messages-split glass">
|
||||
<!-- Conversation Sidebar -->
|
||||
<div class="conv-sidebar">
|
||||
<span class="conv-head tiny uppercase muted">Conversations</span>
|
||||
<div class="conv-list">
|
||||
{#each acceptedFriends as friend (friend.uuid)}
|
||||
<button
|
||||
class="conv-item"
|
||||
class:active={activeChatFriend?.uuid === friend.uuid}
|
||||
onclick={() => selectChatFriend(friend)}
|
||||
>
|
||||
<div class="avatar-holder">
|
||||
<Avatar uuid={friend.uuid} name={friend.username} size={2} />
|
||||
<span class="status-dot" class:online={friend.is_online}></span>
|
||||
</div>
|
||||
<div class="conv-meta">
|
||||
<span class="conv-name">{friend.username}</span>
|
||||
{#if friend.playing_on}
|
||||
<span class="tiny muted">{friend.playing_on}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Chat Thread Main -->
|
||||
<div class="chat-thread">
|
||||
{#if activeChatFriend}
|
||||
<div class="thread-header">
|
||||
<div
|
||||
class="thread-user"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onclick={() => (app.viewProfileUuid = activeChatFriend!.uuid)}
|
||||
onkeydown={(e) => e.key === 'Enter' && (app.viewProfileUuid = activeChatFriend!.uuid)}
|
||||
>
|
||||
<Avatar uuid={activeChatFriend.uuid} name={activeChatFriend.username} size={2.2} />
|
||||
<div>
|
||||
<strong>{activeChatFriend.username}</strong>
|
||||
<span class="tiny muted block">{activeChatFriend.is_online ? 'Active now' : 'Offline'}</span>
|
||||
</div>
|
||||
</div>
|
||||
<button class="primary sm" onclick={() => openInviteModal(activeChatFriend!)}>
|
||||
<Gamepad2 size={13} /> Invite
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="messages-scroll">
|
||||
{#if messages.length === 0}
|
||||
<div class="empty-state">
|
||||
<MessageSquare size={28} class="muted" />
|
||||
<p class="tiny muted">No messages yet with {activeChatFriend.username}. Say hello!</p>
|
||||
</div>
|
||||
{:else}
|
||||
{#each messages as msg (msg.id)}
|
||||
{@const isMine = msg.from_uuid === activeAccount()?.uuid}
|
||||
<div class="bubble-row" class:is-mine={isMine}>
|
||||
<div class="bubble" class:is-mine={isMine}>
|
||||
<p class="bubble-text">{msg.content}</p>
|
||||
<span class="bubble-time tiny">{new Date(msg.created_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="message-composer">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Type a message..."
|
||||
bind:value={messageInput}
|
||||
onkeydown={(e) => e.key === 'Enter' && handleSendMessage()}
|
||||
class="composer-input"
|
||||
/>
|
||||
<button
|
||||
class="primary icon"
|
||||
onclick={handleSendMessage}
|
||||
disabled={sendingMessage || !messageInput.trim()}
|
||||
aria-label="Send Message"
|
||||
>
|
||||
{#if sendingMessage}<LoaderCircle size={15} class="spin" />{:else}<Send size={15} />{/if}
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="center-state">
|
||||
<MessageSquare size={36} class="muted" />
|
||||
<p class="muted">Select a friend to start chatting</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{:else if activeSection === 'invites'}
|
||||
<!-- Game Invites View -->
|
||||
<div class="invites-view">
|
||||
{#if invites.length === 0}
|
||||
<div class="empty-state glass">
|
||||
<Gamepad2 size={36} class="muted" />
|
||||
<p class="muted">No game invites received. When friends invite you to join their server, they will appear here!</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="invites-grid">
|
||||
{#each invites as inv (inv.id)}
|
||||
<div class="invite-card glass">
|
||||
<div class="invite-top">
|
||||
<Avatar uuid={inv.from_uuid} name={inv.from_username} size={2.5} />
|
||||
<div class="invite-meta">
|
||||
<span class="inviter-name"><strong>{inv.from_username}</strong> invited you to play</span>
|
||||
<span class="server-title">{inv.server_name}</span>
|
||||
<span class="tiny muted server-addr">{inv.server_address}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="invite-footer">
|
||||
<span class="tiny muted">{new Date(inv.created_at).toLocaleDateString()}</span>
|
||||
{#if inv.status === 'pending'}
|
||||
<div class="invite-btns">
|
||||
<button class="primary sm" onclick={() => handleRespondInvite(inv.id, true)}>
|
||||
<Check size={13} /> Accept
|
||||
</button>
|
||||
<button class="ghost sm" onclick={() => handleRespondInvite(inv.id, false)}>
|
||||
Decline
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<span class="badge status-badge {inv.status}">{inv.status}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Send Game Invite Modal -->
|
||||
<Modal bind:open={inviteModalOpen} title="Invite {inviteTargetFriend?.username} to Play" width={24}>
|
||||
<div class="invite-modal-body">
|
||||
<p class="tiny muted">
|
||||
Choose which instance / server you want to invite {inviteTargetFriend?.username} to join:
|
||||
</p>
|
||||
<label>
|
||||
<span class="field-label">Instance</span>
|
||||
<select bind:value={inviteInstanceId} class="modal-select">
|
||||
{#each instances() as inst}
|
||||
<option value={inst.id}>{inst.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
{#snippet footer()}
|
||||
<button class="ghost" onclick={() => (inviteModalOpen = false)}>Cancel</button>
|
||||
<button class="primary" onclick={handleSendInvite} disabled={sendingInvite}>
|
||||
{#if sendingInvite}<LoaderCircle size={14} class="spin" />{:else}<Gamepad2 size={14} />{/if}
|
||||
Send Game Invite
|
||||
</button>
|
||||
{/snippet}
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
.social-page {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: auto;
|
||||
padding: 1.6rem 2.2rem 2.5rem;
|
||||
gap: 1.2rem;
|
||||
}
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
border-bottom: 1px solid var(--line);
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
.title-wrap h1 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
:global(.users-icon) {
|
||||
color: var(--accent);
|
||||
}
|
||||
.lead {
|
||||
color: var(--muted);
|
||||
font-size: 0.88rem;
|
||||
margin-top: 0.2rem;
|
||||
}
|
||||
.tabs-row {
|
||||
display: flex;
|
||||
}
|
||||
.tabs-segmented {
|
||||
display: flex;
|
||||
background: color-mix(in srgb, var(--surface) 80%, transparent);
|
||||
padding: 0.25rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--line);
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.tabs-segmented button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0.45rem 1rem;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 560;
|
||||
color: var(--muted);
|
||||
border-radius: calc(var(--radius-sm) - 2px);
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.tabs-segmented button.active {
|
||||
background: color-mix(in srgb, var(--text) 10%, transparent);
|
||||
color: var(--text);
|
||||
}
|
||||
.friends-layout {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
.add-friend-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
padding: 0.6rem 1rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.add-friend-input {
|
||||
flex: 1;
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 0.88rem;
|
||||
color: var(--text);
|
||||
outline: none;
|
||||
}
|
||||
.filter-pills {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.pill {
|
||||
padding: 0.3rem 0.75rem;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 560;
|
||||
border-radius: 99rem;
|
||||
background: color-mix(in srgb, var(--text) 6%, transparent);
|
||||
border: 1px solid transparent;
|
||||
color: var(--muted);
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.pill.active {
|
||||
background: color-mix(in srgb, var(--accent) 18%, transparent);
|
||||
border-color: color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
color: var(--text);
|
||||
}
|
||||
.pending-alert {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.6rem 1rem;
|
||||
border-radius: var(--radius-sm);
|
||||
background: color-mix(in srgb, var(--accent) 12%, transparent);
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
|
||||
}
|
||||
.friends-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
|
||||
gap: 0.9rem;
|
||||
}
|
||||
.friend-card {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.9rem 1.1rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
transition: border-color 0.15s, transform 0.12s;
|
||||
}
|
||||
.friend-card:hover {
|
||||
border-color: var(--line-strong);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
.card-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
cursor: pointer;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.avatar-holder {
|
||||
position: relative;
|
||||
}
|
||||
.status-dot {
|
||||
position: absolute;
|
||||
bottom: -1px;
|
||||
right: -1px;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border-radius: 50%;
|
||||
background: var(--muted);
|
||||
border: 2px solid var(--surface);
|
||||
}
|
||||
.status-dot.online {
|
||||
background: var(--success);
|
||||
}
|
||||
.name-block {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
.user-title {
|
||||
font-weight: 650;
|
||||
font-size: 0.92rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.playing-on {
|
||||
color: var(--accent);
|
||||
font-weight: 560;
|
||||
}
|
||||
.online-label {
|
||||
color: var(--success);
|
||||
}
|
||||
.friend-actions, .req-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
.danger-hover:hover {
|
||||
color: var(--danger);
|
||||
}
|
||||
.subheading {
|
||||
font-size: 0.92rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.6rem;
|
||||
}
|
||||
/* Direct Messages Split */
|
||||
.messages-split {
|
||||
display: flex;
|
||||
height: 32rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
overflow: hidden;
|
||||
}
|
||||
.conv-sidebar {
|
||||
width: 15rem;
|
||||
border-right: 1px solid var(--line);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: color-mix(in srgb, var(--surface) 90%, black);
|
||||
}
|
||||
.conv-head {
|
||||
padding: 0.8rem 1rem 0.5rem;
|
||||
letter-spacing: 0.06em;
|
||||
font-weight: 700;
|
||||
}
|
||||
.conv-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0.3rem 0.5rem;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.conv-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.65rem;
|
||||
padding: 0.55rem 0.7rem;
|
||||
border-radius: var(--radius-sm);
|
||||
background: transparent;
|
||||
border: none;
|
||||
text-align: left;
|
||||
transition: background 0.12s;
|
||||
}
|
||||
.conv-item:hover {
|
||||
background: color-mix(in srgb, var(--text) 6%, transparent);
|
||||
}
|
||||
.conv-item.active {
|
||||
background: color-mix(in srgb, var(--accent) 15%, transparent);
|
||||
}
|
||||
.conv-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
.conv-name {
|
||||
font-size: 0.86rem;
|
||||
font-weight: 650;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.chat-thread {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.thread-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.8rem 1.2rem;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.thread-user {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.block {
|
||||
display: block;
|
||||
}
|
||||
.messages-scroll {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1.2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
.bubble-row {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.bubble-row.is-mine {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.bubble {
|
||||
max-width: 22rem;
|
||||
padding: 0.6rem 0.9rem;
|
||||
border-radius: var(--radius);
|
||||
background: color-mix(in srgb, var(--surface) 90%, var(--text));
|
||||
border: 1px solid var(--line);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.bubble.is-mine {
|
||||
background: color-mix(in srgb, var(--accent) 25%, transparent);
|
||||
border-color: color-mix(in srgb, var(--accent) 50%, transparent);
|
||||
}
|
||||
.bubble-text {
|
||||
font-size: 0.88rem;
|
||||
margin: 0;
|
||||
line-height: 1.35;
|
||||
word-break: break-word;
|
||||
}
|
||||
.bubble-time {
|
||||
align-self: flex-end;
|
||||
color: var(--muted);
|
||||
font-size: 0.68rem;
|
||||
}
|
||||
.message-composer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
padding: 0.75rem 1.2rem;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
.composer-input {
|
||||
flex: 1;
|
||||
background: color-mix(in srgb, var(--bg) 60%, transparent);
|
||||
border: 1px solid var(--line);
|
||||
color: var(--text);
|
||||
padding: 0.5rem 0.85rem;
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
/* Invites View */
|
||||
.invites-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
.invite-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.9rem;
|
||||
padding: 1.2rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.invite-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.9rem;
|
||||
}
|
||||
.invite-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.15rem;
|
||||
}
|
||||
.server-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.invite-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-top: 1px solid color-mix(in srgb, var(--line) 40%, transparent);
|
||||
padding-top: 0.7rem;
|
||||
}
|
||||
.invite-btns {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.status-badge {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
.status-badge.accepted {
|
||||
background: color-mix(in srgb, var(--success) 20%, transparent);
|
||||
color: var(--success);
|
||||
}
|
||||
.status-badge.declined {
|
||||
background: color-mix(in srgb, var(--danger) 20%, transparent);
|
||||
color: var(--danger);
|
||||
}
|
||||
.invite-modal-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
.modal-select {
|
||||
width: 100%;
|
||||
background: color-mix(in srgb, var(--bg) 60%, transparent);
|
||||
border: 1px solid var(--line);
|
||||
color: var(--text);
|
||||
padding: 0.45rem 0.75rem;
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 600;
|
||||
padding: 0.16rem 0.5rem;
|
||||
border-radius: 99rem;
|
||||
}
|
||||
.center-state, .empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.8rem;
|
||||
padding: 3rem 1.5rem;
|
||||
text-align: center;
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user