DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 266a4f354ad61f6acba8a12409aff529887b7c55 deck-builder/client/src/plugins/game/mod.rs -rw-r--r-- 1.8 KiB
266a4f35Jonni Liljamo chore(client): fmt, clippy, cleanup 1 year, 5 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
70
71
72
73
74
75
76
77
78
79
/*
 * This file is part of laurelin_client
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use bevy::prelude::*;
use bevy_rapier3d::prelude::*;

use crate::{api::game::Game, game_status::GameStatus, AppState, Global};

use self::card::VisualCardBundle;

use super::GameDetailsCallEvent;

mod card;
mod supply;
mod ui;

pub struct GamePlugin;

impl Plugin for GamePlugin {
    fn build(&self, app: &mut App) {
        app.insert_resource(GameData::default())
            .add_plugin(ui::GameUIPlugin)
            .add_plugin(card::CardPlugin)
            .add_plugin(supply::SupplyPlugin)
            .add_system(game_setup.in_schedule(OnEnter(AppState::InGame)));
    }
}

#[derive(Resource)]
pub struct GameData {
    pub game: Option<Game>,
    pub game_status: Option<GameStatus>,

    pub parsing_data: bool,
}

impl Default for GameData {
    fn default() -> Self {
        Self {
            game: None,
            game_status: None,

            parsing_data: false,
        }
    }
}

fn game_setup(
    mut commands: Commands,
    mut details_ev_w: EventWriter<GameDetailsCallEvent>,
    global: Res<Global>,
) {
    details_ev_w.send(GameDetailsCallEvent {
        game_id: global.cur_game_id.clone(),
    });

    // create the playing surface
    commands
        .spawn(Collider::cuboid(20., 0.5, 20.))
        .insert(TransformBundle::from(Transform::from_xyz(0., -0.5, 0.)));

    commands.spawn(VisualCardBundle {
        transform: Transform {
            translation: Vec3 {
                x: 0.,
                y: 3.,
                z: 0.,
            },
            rotation: Quat::from_euler(EulerRot::XYZ, -90., 0., 0.),
            ..Default::default()
        },
        ..Default::default()
    });
}