DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 89bbb3e7d988f5064e775a6a398c5b53096fa186 deck-builder/client-old-for-ref/src/plugins/menu_old/accountscreenloggedin.rs -rw-r--r-- 1.8 KiB
89bbb3e7 — skye feat(client): change parser to just take &Game 1 year, 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * This file is part of sdbclient
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use bevy::prelude::*;
use iyes_loopless::prelude::*;

use belly::prelude::*;

use crate::{
    cfg::CfgUser,
    plugins::config::{SaveEvent, SaveEventValue},
};

use super::MenuState;

pub(super) struct LogoutEvent;

pub(super) fn account_loggedin_setup(mut commands: Commands, cfg_user: Res<CfgUser>) {
    let username = cfg_user.username.clone();

    commands.add(eml! {
        <body>
            <div c:menu>
                <span c:menutitle>
                    "Account"
                </span>
                <span>
                    "Logged in as:"
                </span>
                <span>
                    { username }
                </span>
                <button c:menubutton on:press=connect!(|ctx| {
                    ctx.send_event(LogoutEvent)
                })>
                    "Logout"
                </button>
                <button c:menubutton on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(MenuState::Main))
                })>
                    "Back"
                </button>
            </div>
        </body>
    });
}

pub(super) fn handle_logout_event(
    mut events: EventReader<LogoutEvent>,
    mut commands: Commands,
    mut cfg_user: ResMut<CfgUser>,
    mut save_event_writer: EventWriter<SaveEvent>,
) {
    for _event in events.iter() {
        // Reset CfgUser to default
        *cfg_user = CfgUser::default();

        save_event_writer.send(SaveEvent {
            value: SaveEventValue::User(cfg_user.clone()),
        });

        commands.insert_resource(NextState(MenuState::AccountLoggedOut));
    }
}