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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* 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 api::user::User;
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use bevy_editor_pls::EditorPlugin;
use bevy_egui::EguiPlugin;
mod api;
mod macros;
mod util;
mod plugins;
mod game_status;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, States)]
enum AppState {
#[default]
Menu,
InGame,
}
fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: String::from("Laurelin Client"),
..Default::default()
}),
..Default::default()
}));
app.add_plugin(RapierPhysicsPlugin::<NoUserData>::default());
info!("laurelin client initializing");
// dev
app.add_plugin(RapierDebugRenderPlugin::default());
app.add_plugin(EditorPlugin::new());
app.insert_resource(editor_controls());
// the egui plugin is also added by the editor plugin
if !app.is_plugin_added::<EguiPlugin>() {
app.add_plugin(EguiPlugin);
}
// clear color
app.insert_resource(ClearColor(Color::rgb(0.53, 0.53, 0.7)));
// add the top level app state
app.add_state::<AppState>();
// holds networking options and a request agent
app.insert_resource(NetworkingOptions {
api_address: "http://localhost:3000/api".to_string(),
req: reqwest::blocking::Client::new(),
user_token: "".to_string(),
});
app.insert_resource(Global {
user: None,
cur_game_id: "".to_string(),
});
// has handlers for all async tasks
app.add_plugin(plugins::AsyncTasksPlugin);
app.add_plugin(plugins::MenuPlugin);
app.add_plugin(plugins::GamePlugin);
app.add_startup_system(setup);
app.run();
info!("goodbye");
}
#[derive(Component)]
struct PlayerCamera;
fn setup(mut commands: Commands) {
commands.spawn(Camera3dBundle {
transform: Transform {
translation: Vec3::new(0., 8., 8.),
rotation: Quat::from_rotation_x(-0.5),
..Default::default()
},
..Default::default()
})
.insert(PlayerCamera);
}
fn editor_controls() -> bevy_editor_pls::controls::EditorControls {
use bevy_editor_pls::controls;
let mut editor_controls = controls::EditorControls::default_bindings();
editor_controls.unbind(controls::Action::PlayPauseEditor);
editor_controls.insert(
controls::Action::PlayPauseEditor,
controls::Binding {
input: controls::UserInput::Single(controls::Button::Keyboard(KeyCode::Escape)),
conditions: vec![controls::BindingCondition::ListeningForText(false)],
},
);
editor_controls
}
#[derive(Clone, Resource)]
pub struct NetworkingOptions {
/// api address with no trailing slash
api_address: String,
/// reqwest agent
/// NOTE: mainly for the future, because it can hold cookies
req: reqwest::blocking::Client,
/// feels wrong storing this here but "it's temporary"
user_token: String,
}
#[derive(Resource)]
pub struct Global {
/// details of the logged in user
user: Option<User>,
/// current game id, set from browse
cur_game_id: String,
}