bevy 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Cargo.lock +4279 -0
- data/Cargo.toml +36 -0
- data/README.md +226 -0
- data/crates/bevy/Cargo.toml +52 -0
- data/crates/bevy/src/app.rs +43 -0
- data/crates/bevy/src/component.rs +111 -0
- data/crates/bevy/src/entity.rs +30 -0
- data/crates/bevy/src/error.rs +32 -0
- data/crates/bevy/src/event.rs +190 -0
- data/crates/bevy/src/input_bridge.rs +300 -0
- data/crates/bevy/src/lib.rs +42 -0
- data/crates/bevy/src/mesh_renderer.rs +328 -0
- data/crates/bevy/src/query.rs +53 -0
- data/crates/bevy/src/render_app.rs +689 -0
- data/crates/bevy/src/resource.rs +28 -0
- data/crates/bevy/src/schedule.rs +186 -0
- data/crates/bevy/src/sprite_renderer.rs +355 -0
- data/crates/bevy/src/system.rs +44 -0
- data/crates/bevy/src/text_renderer.rs +258 -0
- data/crates/bevy/src/types/color.rs +114 -0
- data/crates/bevy/src/types/dynamic.rs +131 -0
- data/crates/bevy/src/types/math.rs +260 -0
- data/crates/bevy/src/types/mod.rs +9 -0
- data/crates/bevy/src/types/transform.rs +166 -0
- data/crates/bevy/src/world.rs +163 -0
- data/crates/bevy_ruby_render/Cargo.toml +22 -0
- data/crates/bevy_ruby_render/src/asset.rs +360 -0
- data/crates/bevy_ruby_render/src/audio.rs +511 -0
- data/crates/bevy_ruby_render/src/camera.rs +365 -0
- data/crates/bevy_ruby_render/src/gamepad.rs +398 -0
- data/crates/bevy_ruby_render/src/lib.rs +26 -0
- data/crates/bevy_ruby_render/src/material.rs +310 -0
- data/crates/bevy_ruby_render/src/mesh.rs +491 -0
- data/crates/bevy_ruby_render/src/sprite.rs +289 -0
- data/ext/bevy/Cargo.toml +20 -0
- data/ext/bevy/extconf.rb +6 -0
- data/ext/bevy/src/conversions.rs +137 -0
- data/ext/bevy/src/lib.rs +29 -0
- data/ext/bevy/src/ruby_app.rs +65 -0
- data/ext/bevy/src/ruby_color.rs +149 -0
- data/ext/bevy/src/ruby_component.rs +189 -0
- data/ext/bevy/src/ruby_entity.rs +33 -0
- data/ext/bevy/src/ruby_math.rs +384 -0
- data/ext/bevy/src/ruby_query.rs +64 -0
- data/ext/bevy/src/ruby_render_app.rs +779 -0
- data/ext/bevy/src/ruby_system.rs +122 -0
- data/ext/bevy/src/ruby_world.rs +107 -0
- data/lib/bevy/animation.rb +597 -0
- data/lib/bevy/app.rb +675 -0
- data/lib/bevy/asset.rb +613 -0
- data/lib/bevy/audio.rb +545 -0
- data/lib/bevy/audio_effects.rb +224 -0
- data/lib/bevy/camera.rb +412 -0
- data/lib/bevy/component.rb +91 -0
- data/lib/bevy/diagnostics.rb +227 -0
- data/lib/bevy/ecs_advanced.rb +296 -0
- data/lib/bevy/event.rb +199 -0
- data/lib/bevy/gizmos.rb +158 -0
- data/lib/bevy/gltf.rb +227 -0
- data/lib/bevy/hierarchy.rb +444 -0
- data/lib/bevy/input.rb +514 -0
- data/lib/bevy/lighting.rb +369 -0
- data/lib/bevy/material.rb +248 -0
- data/lib/bevy/mesh.rb +257 -0
- data/lib/bevy/navigation.rb +344 -0
- data/lib/bevy/networking.rb +335 -0
- data/lib/bevy/particle.rb +337 -0
- data/lib/bevy/physics.rb +396 -0
- data/lib/bevy/plugins/default_plugins.rb +34 -0
- data/lib/bevy/plugins/input_plugin.rb +49 -0
- data/lib/bevy/reflect.rb +361 -0
- data/lib/bevy/render_graph.rb +210 -0
- data/lib/bevy/resource.rb +185 -0
- data/lib/bevy/scene.rb +254 -0
- data/lib/bevy/shader.rb +319 -0
- data/lib/bevy/shape.rb +195 -0
- data/lib/bevy/skeletal.rb +248 -0
- data/lib/bevy/sprite.rb +152 -0
- data/lib/bevy/sprite_sheet.rb +444 -0
- data/lib/bevy/state.rb +277 -0
- data/lib/bevy/system.rb +206 -0
- data/lib/bevy/text.rb +99 -0
- data/lib/bevy/text_advanced.rb +455 -0
- data/lib/bevy/timer.rb +147 -0
- data/lib/bevy/transform.rb +158 -0
- data/lib/bevy/ui.rb +454 -0
- data/lib/bevy/ui_advanced.rb +568 -0
- data/lib/bevy/version.rb +5 -0
- data/lib/bevy/visibility.rb +250 -0
- data/lib/bevy/window.rb +302 -0
- data/lib/bevy.rb +390 -0
- metadata +150 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
use std::any::TypeId;
|
|
2
|
+
use std::collections::HashMap;
|
|
3
|
+
use crate::types::DynamicValue;
|
|
4
|
+
|
|
5
|
+
#[derive(Debug, Clone)]
|
|
6
|
+
pub struct Event {
|
|
7
|
+
pub type_name: String,
|
|
8
|
+
pub data: HashMap<String, DynamicValue>,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
impl Event {
|
|
12
|
+
pub fn new(type_name: &str) -> Self {
|
|
13
|
+
Self {
|
|
14
|
+
type_name: type_name.to_string(),
|
|
15
|
+
data: HashMap::new(),
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
pub fn with_data(type_name: &str, data: HashMap<String, DynamicValue>) -> Self {
|
|
20
|
+
Self {
|
|
21
|
+
type_name: type_name.to_string(),
|
|
22
|
+
data,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
pub fn set(&mut self, key: &str, value: DynamicValue) {
|
|
27
|
+
self.data.insert(key.to_string(), value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub fn get(&self, key: &str) -> Option<&DynamicValue> {
|
|
31
|
+
self.data.get(key)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
pub fn type_name(&self) -> &str {
|
|
35
|
+
&self.type_name
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
pub struct EventQueue {
|
|
40
|
+
events: Vec<Event>,
|
|
41
|
+
read_index: usize,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
impl EventQueue {
|
|
45
|
+
pub fn new() -> Self {
|
|
46
|
+
Self {
|
|
47
|
+
events: Vec::new(),
|
|
48
|
+
read_index: 0,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
pub fn send(&mut self, event: Event) {
|
|
53
|
+
self.events.push(event);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub fn read(&mut self) -> impl Iterator<Item = &Event> {
|
|
57
|
+
let start = self.read_index;
|
|
58
|
+
self.read_index = self.events.len();
|
|
59
|
+
self.events[start..].iter()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
pub fn clear(&mut self) {
|
|
63
|
+
self.events.clear();
|
|
64
|
+
self.read_index = 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pub fn len(&self) -> usize {
|
|
68
|
+
self.events.len()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
pub fn is_empty(&self) -> bool {
|
|
72
|
+
self.events.is_empty()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
pub fn unread_count(&self) -> usize {
|
|
76
|
+
self.events.len().saturating_sub(self.read_index)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
impl Default for EventQueue {
|
|
81
|
+
fn default() -> Self {
|
|
82
|
+
Self::new()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
pub struct Events {
|
|
87
|
+
queues: HashMap<String, EventQueue>,
|
|
88
|
+
type_ids: HashMap<TypeId, String>,
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
impl Events {
|
|
92
|
+
pub fn new() -> Self {
|
|
93
|
+
Self {
|
|
94
|
+
queues: HashMap::new(),
|
|
95
|
+
type_ids: HashMap::new(),
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
pub fn register(&mut self, type_name: &str) {
|
|
100
|
+
if !self.queues.contains_key(type_name) {
|
|
101
|
+
self.queues.insert(type_name.to_string(), EventQueue::new());
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
pub fn register_with_type_id(&mut self, type_name: &str, type_id: TypeId) {
|
|
106
|
+
self.register(type_name);
|
|
107
|
+
self.type_ids.insert(type_id, type_name.to_string());
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
pub fn send(&mut self, event: Event) {
|
|
111
|
+
let type_name = event.type_name.clone();
|
|
112
|
+
if let Some(queue) = self.queues.get_mut(&type_name) {
|
|
113
|
+
queue.send(event);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
pub fn read(&mut self, type_name: &str) -> Option<impl Iterator<Item = &Event>> {
|
|
118
|
+
self.queues.get_mut(type_name).map(|q| q.read())
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
pub fn clear(&mut self, type_name: &str) {
|
|
122
|
+
if let Some(queue) = self.queues.get_mut(type_name) {
|
|
123
|
+
queue.clear();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
pub fn clear_all(&mut self) {
|
|
128
|
+
for queue in self.queues.values_mut() {
|
|
129
|
+
queue.clear();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
pub fn get_queue(&self, type_name: &str) -> Option<&EventQueue> {
|
|
134
|
+
self.queues.get(type_name)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
pub fn get_queue_mut(&mut self, type_name: &str) -> Option<&mut EventQueue> {
|
|
138
|
+
self.queues.get_mut(type_name)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
pub fn is_registered(&self, type_name: &str) -> bool {
|
|
142
|
+
self.queues.contains_key(type_name)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
impl Default for Events {
|
|
147
|
+
fn default() -> Self {
|
|
148
|
+
Self::new()
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
pub struct EventReader<'a> {
|
|
153
|
+
queue: &'a mut EventQueue,
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
impl<'a> EventReader<'a> {
|
|
157
|
+
pub fn new(queue: &'a mut EventQueue) -> Self {
|
|
158
|
+
Self { queue }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
pub fn read(&mut self) -> impl Iterator<Item = &Event> {
|
|
162
|
+
self.queue.read()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
pub fn is_empty(&self) -> bool {
|
|
166
|
+
self.queue.unread_count() == 0
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
pub fn len(&self) -> usize {
|
|
170
|
+
self.queue.unread_count()
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
pub struct EventWriter<'a> {
|
|
175
|
+
queue: &'a mut EventQueue,
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
impl<'a> EventWriter<'a> {
|
|
179
|
+
pub fn new(queue: &'a mut EventQueue) -> Self {
|
|
180
|
+
Self { queue }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
pub fn send(&mut self, event: Event) {
|
|
184
|
+
self.queue.send(event);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
pub fn send_default(&mut self, type_name: &str) {
|
|
188
|
+
self.queue.send(Event::new(type_name));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
//! Input bridge module for converting Bevy input to Ruby-compatible format.
|
|
2
|
+
|
|
3
|
+
use std::collections::{HashMap, HashSet};
|
|
4
|
+
|
|
5
|
+
#[cfg(feature = "rendering")]
|
|
6
|
+
use bevy_ecs::world::World;
|
|
7
|
+
#[cfg(feature = "rendering")]
|
|
8
|
+
use bevy_input::{ButtonInput, keyboard::KeyCode, mouse::MouseButton};
|
|
9
|
+
#[cfg(feature = "rendering")]
|
|
10
|
+
use bevy_window::{PrimaryWindow, Window};
|
|
11
|
+
|
|
12
|
+
/// Holds the current input state for Ruby.
|
|
13
|
+
#[derive(Debug, Default, Clone)]
|
|
14
|
+
pub struct InputState {
|
|
15
|
+
pub keys_pressed: HashSet<String>,
|
|
16
|
+
pub keys_just_pressed: HashSet<String>,
|
|
17
|
+
pub keys_just_released: HashSet<String>,
|
|
18
|
+
pub mouse_buttons_pressed: HashSet<String>,
|
|
19
|
+
pub mouse_buttons_just_pressed: HashSet<String>,
|
|
20
|
+
pub mouse_position: (f32, f32),
|
|
21
|
+
pub mouse_delta: (f32, f32),
|
|
22
|
+
pub gamepads: HashMap<u64, GamepadInputState>,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#[derive(Debug, Default, Clone)]
|
|
26
|
+
pub struct GamepadInputState {
|
|
27
|
+
pub id: u64,
|
|
28
|
+
pub name: String,
|
|
29
|
+
pub buttons_pressed: HashSet<String>,
|
|
30
|
+
pub buttons_just_pressed: HashSet<String>,
|
|
31
|
+
pub buttons_just_released: HashSet<String>,
|
|
32
|
+
pub axes: HashMap<String, f32>,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
impl InputState {
|
|
36
|
+
/// Creates a new empty input state.
|
|
37
|
+
pub fn new() -> Self {
|
|
38
|
+
Self::default()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// Updates the input state from Bevy's world.
|
|
42
|
+
#[cfg(feature = "rendering")]
|
|
43
|
+
pub fn update_from_bevy(&mut self, world: &mut World) {
|
|
44
|
+
self.update_keyboard(world);
|
|
45
|
+
self.update_mouse(world);
|
|
46
|
+
self.update_cursor_position(world);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#[cfg(feature = "rendering")]
|
|
50
|
+
fn update_keyboard(&mut self, world: &World) {
|
|
51
|
+
if let Some(keyboard) = world.get_resource::<ButtonInput<KeyCode>>() {
|
|
52
|
+
self.keys_pressed.clear();
|
|
53
|
+
self.keys_just_pressed.clear();
|
|
54
|
+
self.keys_just_released.clear();
|
|
55
|
+
|
|
56
|
+
for key in keyboard.get_pressed() {
|
|
57
|
+
self.keys_pressed.insert(keycode_to_string(*key));
|
|
58
|
+
}
|
|
59
|
+
for key in keyboard.get_just_pressed() {
|
|
60
|
+
self.keys_just_pressed.insert(keycode_to_string(*key));
|
|
61
|
+
}
|
|
62
|
+
for key in keyboard.get_just_released() {
|
|
63
|
+
self.keys_just_released.insert(keycode_to_string(*key));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#[cfg(feature = "rendering")]
|
|
69
|
+
fn update_mouse(&mut self, world: &World) {
|
|
70
|
+
if let Some(mouse) = world.get_resource::<ButtonInput<MouseButton>>() {
|
|
71
|
+
self.mouse_buttons_pressed.clear();
|
|
72
|
+
self.mouse_buttons_just_pressed.clear();
|
|
73
|
+
|
|
74
|
+
for button in mouse.get_pressed() {
|
|
75
|
+
self.mouse_buttons_pressed
|
|
76
|
+
.insert(mouse_button_to_string(*button));
|
|
77
|
+
}
|
|
78
|
+
for button in mouse.get_just_pressed() {
|
|
79
|
+
self.mouse_buttons_just_pressed
|
|
80
|
+
.insert(mouse_button_to_string(*button));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
#[cfg(feature = "rendering")]
|
|
86
|
+
fn update_cursor_position(&mut self, world: &mut World) {
|
|
87
|
+
// Query for primary window to get cursor position
|
|
88
|
+
let mut query = world.query_filtered::<&Window, bevy_ecs::query::With<PrimaryWindow>>();
|
|
89
|
+
if let Some(window) = query.iter(world).next() {
|
|
90
|
+
if let Some(pos) = window.cursor_position() {
|
|
91
|
+
let old_pos = self.mouse_position;
|
|
92
|
+
self.mouse_position = (pos.x, pos.y);
|
|
93
|
+
self.mouse_delta = (pos.x - old_pos.0, pos.y - old_pos.1);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/// Checks if a key is currently pressed.
|
|
99
|
+
pub fn key_pressed(&self, key: &str) -> bool {
|
|
100
|
+
self.keys_pressed.contains(key)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// Checks if a key was just pressed this frame.
|
|
104
|
+
pub fn key_just_pressed(&self, key: &str) -> bool {
|
|
105
|
+
self.keys_just_pressed.contains(key)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/// Checks if a key was just released this frame.
|
|
109
|
+
pub fn key_just_released(&self, key: &str) -> bool {
|
|
110
|
+
self.keys_just_released.contains(key)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// Checks if a mouse button is currently pressed.
|
|
114
|
+
pub fn mouse_button_pressed(&self, button: &str) -> bool {
|
|
115
|
+
self.mouse_buttons_pressed.contains(button)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Checks if a mouse button was just pressed this frame.
|
|
119
|
+
pub fn mouse_button_just_pressed(&self, button: &str) -> bool {
|
|
120
|
+
self.mouse_buttons_just_pressed.contains(button)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/// Returns all currently pressed keys.
|
|
124
|
+
pub fn get_pressed_keys(&self) -> Vec<String> {
|
|
125
|
+
self.keys_pressed.iter().cloned().collect()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/// Returns all gamepad states currently known for this frame.
|
|
129
|
+
pub fn gamepad_states(&self) -> Vec<GamepadInputState> {
|
|
130
|
+
self.gamepads.values().cloned().collect()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/// Clears all input state for a new frame.
|
|
134
|
+
pub fn clear(&mut self) {
|
|
135
|
+
self.keys_pressed.clear();
|
|
136
|
+
self.keys_just_pressed.clear();
|
|
137
|
+
self.keys_just_released.clear();
|
|
138
|
+
self.mouse_buttons_pressed.clear();
|
|
139
|
+
self.mouse_buttons_just_pressed.clear();
|
|
140
|
+
self.gamepads.clear();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/// Sets a key as pressed.
|
|
144
|
+
pub fn set_pressed(&mut self, key: &str) {
|
|
145
|
+
self.keys_pressed.insert(key.to_string());
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/// Sets a key as just pressed.
|
|
149
|
+
pub fn set_just_pressed(&mut self, key: &str) {
|
|
150
|
+
self.keys_just_pressed.insert(key.to_string());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/// Sets a key as just released.
|
|
154
|
+
pub fn set_just_released(&mut self, key: &str) {
|
|
155
|
+
self.keys_just_released.insert(key.to_string());
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/// Sets a mouse button as pressed.
|
|
159
|
+
pub fn set_mouse_pressed(&mut self, button: &str) {
|
|
160
|
+
self.mouse_buttons_pressed.insert(button.to_string());
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/// Sets a mouse button as just pressed.
|
|
164
|
+
pub fn set_mouse_just_pressed(&mut self, button: &str) {
|
|
165
|
+
self.mouse_buttons_just_pressed.insert(button.to_string());
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// Ensures a gamepad slot exists for this frame and updates its display name.
|
|
169
|
+
pub fn set_gamepad_connected(&mut self, id: u64, name: &str) {
|
|
170
|
+
let state = self
|
|
171
|
+
.gamepads
|
|
172
|
+
.entry(id)
|
|
173
|
+
.or_insert_with(|| GamepadInputState {
|
|
174
|
+
id,
|
|
175
|
+
..Default::default()
|
|
176
|
+
});
|
|
177
|
+
state.name = name.to_string();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/// Marks a gamepad button as currently pressed.
|
|
181
|
+
pub fn set_gamepad_button_pressed(&mut self, id: u64, button: &str) {
|
|
182
|
+
let state = self
|
|
183
|
+
.gamepads
|
|
184
|
+
.entry(id)
|
|
185
|
+
.or_insert_with(|| GamepadInputState {
|
|
186
|
+
id,
|
|
187
|
+
..Default::default()
|
|
188
|
+
});
|
|
189
|
+
state.buttons_pressed.insert(button.to_string());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/// Marks a gamepad button as just pressed.
|
|
193
|
+
pub fn set_gamepad_button_just_pressed(&mut self, id: u64, button: &str) {
|
|
194
|
+
let state = self
|
|
195
|
+
.gamepads
|
|
196
|
+
.entry(id)
|
|
197
|
+
.or_insert_with(|| GamepadInputState {
|
|
198
|
+
id,
|
|
199
|
+
..Default::default()
|
|
200
|
+
});
|
|
201
|
+
state.buttons_just_pressed.insert(button.to_string());
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/// Marks a gamepad button as just released.
|
|
205
|
+
pub fn set_gamepad_button_just_released(&mut self, id: u64, button: &str) {
|
|
206
|
+
let state = self
|
|
207
|
+
.gamepads
|
|
208
|
+
.entry(id)
|
|
209
|
+
.or_insert_with(|| GamepadInputState {
|
|
210
|
+
id,
|
|
211
|
+
..Default::default()
|
|
212
|
+
});
|
|
213
|
+
state.buttons_just_released.insert(button.to_string());
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/// Sets a gamepad axis value.
|
|
217
|
+
pub fn set_gamepad_axis(&mut self, id: u64, axis: &str, value: f32) {
|
|
218
|
+
let state = self
|
|
219
|
+
.gamepads
|
|
220
|
+
.entry(id)
|
|
221
|
+
.or_insert_with(|| GamepadInputState {
|
|
222
|
+
id,
|
|
223
|
+
..Default::default()
|
|
224
|
+
});
|
|
225
|
+
state.axes.insert(axis.to_string(), value);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/// Converts a Bevy KeyCode to a Ruby-compatible string.
|
|
230
|
+
#[cfg(feature = "rendering")]
|
|
231
|
+
fn keycode_to_string(key: KeyCode) -> String {
|
|
232
|
+
match key {
|
|
233
|
+
KeyCode::KeyA => "A".to_string(),
|
|
234
|
+
KeyCode::KeyB => "B".to_string(),
|
|
235
|
+
KeyCode::KeyC => "C".to_string(),
|
|
236
|
+
KeyCode::KeyD => "D".to_string(),
|
|
237
|
+
KeyCode::KeyE => "E".to_string(),
|
|
238
|
+
KeyCode::KeyF => "F".to_string(),
|
|
239
|
+
KeyCode::KeyG => "G".to_string(),
|
|
240
|
+
KeyCode::KeyH => "H".to_string(),
|
|
241
|
+
KeyCode::KeyI => "I".to_string(),
|
|
242
|
+
KeyCode::KeyJ => "J".to_string(),
|
|
243
|
+
KeyCode::KeyK => "K".to_string(),
|
|
244
|
+
KeyCode::KeyL => "L".to_string(),
|
|
245
|
+
KeyCode::KeyM => "M".to_string(),
|
|
246
|
+
KeyCode::KeyN => "N".to_string(),
|
|
247
|
+
KeyCode::KeyO => "O".to_string(),
|
|
248
|
+
KeyCode::KeyP => "P".to_string(),
|
|
249
|
+
KeyCode::KeyQ => "Q".to_string(),
|
|
250
|
+
KeyCode::KeyR => "R".to_string(),
|
|
251
|
+
KeyCode::KeyS => "S".to_string(),
|
|
252
|
+
KeyCode::KeyT => "T".to_string(),
|
|
253
|
+
KeyCode::KeyU => "U".to_string(),
|
|
254
|
+
KeyCode::KeyV => "V".to_string(),
|
|
255
|
+
KeyCode::KeyW => "W".to_string(),
|
|
256
|
+
KeyCode::KeyX => "X".to_string(),
|
|
257
|
+
KeyCode::KeyY => "Y".to_string(),
|
|
258
|
+
KeyCode::KeyZ => "Z".to_string(),
|
|
259
|
+
KeyCode::Digit0 => "0".to_string(),
|
|
260
|
+
KeyCode::Digit1 => "1".to_string(),
|
|
261
|
+
KeyCode::Digit2 => "2".to_string(),
|
|
262
|
+
KeyCode::Digit3 => "3".to_string(),
|
|
263
|
+
KeyCode::Digit4 => "4".to_string(),
|
|
264
|
+
KeyCode::Digit5 => "5".to_string(),
|
|
265
|
+
KeyCode::Digit6 => "6".to_string(),
|
|
266
|
+
KeyCode::Digit7 => "7".to_string(),
|
|
267
|
+
KeyCode::Digit8 => "8".to_string(),
|
|
268
|
+
KeyCode::Digit9 => "9".to_string(),
|
|
269
|
+
KeyCode::ArrowUp => "UP".to_string(),
|
|
270
|
+
KeyCode::ArrowDown => "DOWN".to_string(),
|
|
271
|
+
KeyCode::ArrowLeft => "LEFT".to_string(),
|
|
272
|
+
KeyCode::ArrowRight => "RIGHT".to_string(),
|
|
273
|
+
KeyCode::Space => "SPACE".to_string(),
|
|
274
|
+
KeyCode::Enter => "ENTER".to_string(),
|
|
275
|
+
KeyCode::Escape => "ESCAPE".to_string(),
|
|
276
|
+
KeyCode::Tab => "TAB".to_string(),
|
|
277
|
+
KeyCode::Backspace => "BACKSPACE".to_string(),
|
|
278
|
+
KeyCode::Delete => "DELETE".to_string(),
|
|
279
|
+
KeyCode::ShiftLeft => "SHIFT_LEFT".to_string(),
|
|
280
|
+
KeyCode::ShiftRight => "SHIFT_RIGHT".to_string(),
|
|
281
|
+
KeyCode::ControlLeft => "CONTROL_LEFT".to_string(),
|
|
282
|
+
KeyCode::ControlRight => "CONTROL_RIGHT".to_string(),
|
|
283
|
+
KeyCode::AltLeft => "ALT_LEFT".to_string(),
|
|
284
|
+
KeyCode::AltRight => "ALT_RIGHT".to_string(),
|
|
285
|
+
_ => format!("{:?}", key),
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/// Converts a Bevy MouseButton to a Ruby-compatible string.
|
|
290
|
+
#[cfg(feature = "rendering")]
|
|
291
|
+
fn mouse_button_to_string(button: MouseButton) -> String {
|
|
292
|
+
match button {
|
|
293
|
+
MouseButton::Left => "LEFT".to_string(),
|
|
294
|
+
MouseButton::Right => "RIGHT".to_string(),
|
|
295
|
+
MouseButton::Middle => "MIDDLE".to_string(),
|
|
296
|
+
MouseButton::Back => "BACK".to_string(),
|
|
297
|
+
MouseButton::Forward => "FORWARD".to_string(),
|
|
298
|
+
MouseButton::Other(id) => format!("OTHER_{}", id),
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
pub mod app;
|
|
2
|
+
pub mod component;
|
|
3
|
+
pub mod entity;
|
|
4
|
+
pub mod error;
|
|
5
|
+
pub mod event;
|
|
6
|
+
pub mod input_bridge;
|
|
7
|
+
pub mod mesh_renderer;
|
|
8
|
+
pub mod query;
|
|
9
|
+
pub mod render_app;
|
|
10
|
+
pub mod resource;
|
|
11
|
+
pub mod schedule;
|
|
12
|
+
pub mod sprite_renderer;
|
|
13
|
+
pub mod system;
|
|
14
|
+
pub mod text_renderer;
|
|
15
|
+
pub mod types;
|
|
16
|
+
pub mod world;
|
|
17
|
+
|
|
18
|
+
pub use app::AppBuilder;
|
|
19
|
+
pub use component::{ComponentData, ComponentRegistry};
|
|
20
|
+
pub use entity::EntityWrapper;
|
|
21
|
+
pub use error::BevyRubyError;
|
|
22
|
+
pub use event::{Event, EventQueue, EventReader, EventWriter, Events};
|
|
23
|
+
pub use input_bridge::InputState;
|
|
24
|
+
pub use mesh_renderer::{MeshData, MeshSync, MeshTransformData, ShapeType};
|
|
25
|
+
pub use query::QueryBuilder;
|
|
26
|
+
#[cfg(feature = "rendering")]
|
|
27
|
+
pub use render_app::{
|
|
28
|
+
GamepadRumbleCommand, PickingEventData, RenderApp, RubyBridge, RubyBridgeState, WindowConfig,
|
|
29
|
+
};
|
|
30
|
+
#[cfg(not(feature = "rendering"))]
|
|
31
|
+
pub use render_app::{RenderApp, WindowConfig};
|
|
32
|
+
pub use resource::ResourceWrapper;
|
|
33
|
+
pub use schedule::{Schedule, ScheduleConfig, Schedules, SystemOrdering, SystemSet};
|
|
34
|
+
#[cfg(feature = "rendering")]
|
|
35
|
+
pub use sprite_renderer::DefaultSpriteTexture;
|
|
36
|
+
pub use sprite_renderer::{SpriteData, SpriteSync, TransformData};
|
|
37
|
+
pub use text_renderer::{TextData, TextSync, TextTransformData};
|
|
38
|
+
pub use types::{
|
|
39
|
+
DynamicComponent, DynamicComponents, DynamicValue, RubyColor, RubyQuat, RubyTransform,
|
|
40
|
+
RubyVec2, RubyVec3,
|
|
41
|
+
};
|
|
42
|
+
pub use world::WorldWrapper;
|