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,365 @@
|
|
|
1
|
+
use bevy_ecs::bundle::Bundle;
|
|
2
|
+
use bevy_ecs::component::Component;
|
|
3
|
+
use bevy_math::{Vec2, Vec3};
|
|
4
|
+
use bevy_render::camera::{Camera, OrthographicProjection, Projection};
|
|
5
|
+
use bevy_transform::components::{GlobalTransform, Transform};
|
|
6
|
+
|
|
7
|
+
#[derive(Debug, Clone)]
|
|
8
|
+
pub struct CameraConfig {
|
|
9
|
+
pub position: Vec3,
|
|
10
|
+
pub look_at: Option<Vec3>,
|
|
11
|
+
pub clear_color: Option<[f32; 4]>,
|
|
12
|
+
pub is_active: bool,
|
|
13
|
+
pub viewport: Option<ViewportConfig>,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
#[derive(Debug, Clone)]
|
|
17
|
+
pub struct ViewportConfig {
|
|
18
|
+
pub physical_position: [u32; 2],
|
|
19
|
+
pub physical_size: [u32; 2],
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
impl Default for CameraConfig {
|
|
23
|
+
fn default() -> Self {
|
|
24
|
+
Self {
|
|
25
|
+
position: Vec3::new(0.0, 0.0, 1000.0),
|
|
26
|
+
look_at: None,
|
|
27
|
+
clear_color: None,
|
|
28
|
+
is_active: true,
|
|
29
|
+
viewport: None,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
impl CameraConfig {
|
|
35
|
+
pub fn new() -> Self {
|
|
36
|
+
Self::default()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
pub fn with_position(mut self, x: f32, y: f32, z: f32) -> Self {
|
|
40
|
+
self.position = Vec3::new(x, y, z);
|
|
41
|
+
self
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
pub fn with_look_at(mut self, x: f32, y: f32, z: f32) -> Self {
|
|
45
|
+
self.look_at = Some(Vec3::new(x, y, z));
|
|
46
|
+
self
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
pub fn with_clear_color(mut self, r: f32, g: f32, b: f32, a: f32) -> Self {
|
|
50
|
+
self.clear_color = Some([r, g, b, a]);
|
|
51
|
+
self
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pub fn active(mut self, active: bool) -> Self {
|
|
55
|
+
self.is_active = active;
|
|
56
|
+
self
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
pub fn with_viewport(mut self, x: u32, y: u32, width: u32, height: u32) -> Self {
|
|
60
|
+
self.viewport = Some(ViewportConfig {
|
|
61
|
+
physical_position: [x, y],
|
|
62
|
+
physical_size: [width, height],
|
|
63
|
+
});
|
|
64
|
+
self
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#[derive(Bundle)]
|
|
69
|
+
pub struct Camera2dBundle {
|
|
70
|
+
pub camera: Camera,
|
|
71
|
+
pub projection: Projection,
|
|
72
|
+
pub transform: Transform,
|
|
73
|
+
pub global_transform: GlobalTransform,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
impl Camera2dBundle {
|
|
77
|
+
pub fn new(config: &CameraConfig) -> Self {
|
|
78
|
+
let mut transform = Transform::from_translation(config.position);
|
|
79
|
+
|
|
80
|
+
if let Some(target) = config.look_at {
|
|
81
|
+
transform.look_at(target, Vec3::Y);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Self {
|
|
85
|
+
camera: Camera {
|
|
86
|
+
is_active: config.is_active,
|
|
87
|
+
..Default::default()
|
|
88
|
+
},
|
|
89
|
+
projection: Projection::Orthographic(OrthographicProjection::default_2d()),
|
|
90
|
+
transform,
|
|
91
|
+
global_transform: GlobalTransform::default(),
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
pub fn default_2d() -> Self {
|
|
96
|
+
Self::new(&CameraConfig::default())
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
impl Default for Camera2dBundle {
|
|
101
|
+
fn default() -> Self {
|
|
102
|
+
Self::default_2d()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#[derive(Bundle)]
|
|
107
|
+
pub struct Camera3dBundle {
|
|
108
|
+
pub camera: Camera,
|
|
109
|
+
pub projection: Projection,
|
|
110
|
+
pub transform: Transform,
|
|
111
|
+
pub global_transform: GlobalTransform,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
impl Camera3dBundle {
|
|
115
|
+
pub fn new(config: &CameraConfig) -> Self {
|
|
116
|
+
let mut transform = Transform::from_translation(config.position);
|
|
117
|
+
|
|
118
|
+
if let Some(target) = config.look_at {
|
|
119
|
+
transform.look_at(target, Vec3::Y);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
Self {
|
|
123
|
+
camera: Camera {
|
|
124
|
+
is_active: config.is_active,
|
|
125
|
+
..Default::default()
|
|
126
|
+
},
|
|
127
|
+
projection: Projection::default(),
|
|
128
|
+
transform,
|
|
129
|
+
global_transform: GlobalTransform::default(),
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
pub fn default_3d() -> Self {
|
|
134
|
+
Self::new(&CameraConfig::new().with_position(0.0, 5.0, 10.0).with_look_at(0.0, 0.0, 0.0))
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
impl Default for Camera3dBundle {
|
|
139
|
+
fn default() -> Self {
|
|
140
|
+
Self::default_3d()
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
pub struct CameraController {
|
|
145
|
+
pub speed: f32,
|
|
146
|
+
pub sensitivity: f32,
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
impl Default for CameraController {
|
|
150
|
+
fn default() -> Self {
|
|
151
|
+
Self {
|
|
152
|
+
speed: 10.0,
|
|
153
|
+
sensitivity: 0.1,
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
impl CameraController {
|
|
159
|
+
pub fn new(speed: f32, sensitivity: f32) -> Self {
|
|
160
|
+
Self { speed, sensitivity }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#[derive(Component, Debug, Clone)]
|
|
165
|
+
pub struct SmoothFollow {
|
|
166
|
+
pub target: Option<Vec3>,
|
|
167
|
+
pub offset: Vec3,
|
|
168
|
+
pub smoothness: f32,
|
|
169
|
+
pub enabled: bool,
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
impl Default for SmoothFollow {
|
|
173
|
+
fn default() -> Self {
|
|
174
|
+
Self {
|
|
175
|
+
target: None,
|
|
176
|
+
offset: Vec3::ZERO,
|
|
177
|
+
smoothness: 5.0,
|
|
178
|
+
enabled: true,
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
impl SmoothFollow {
|
|
184
|
+
pub fn new(smoothness: f32) -> Self {
|
|
185
|
+
Self {
|
|
186
|
+
smoothness,
|
|
187
|
+
..Default::default()
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
pub fn with_offset(mut self, x: f32, y: f32, z: f32) -> Self {
|
|
192
|
+
self.offset = Vec3::new(x, y, z);
|
|
193
|
+
self
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
pub fn with_target(mut self, x: f32, y: f32, z: f32) -> Self {
|
|
197
|
+
self.target = Some(Vec3::new(x, y, z));
|
|
198
|
+
self
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
pub fn lerp_position(&self, current: Vec3, delta_time: f32) -> Vec3 {
|
|
202
|
+
if let Some(target) = self.target {
|
|
203
|
+
let desired = target + self.offset;
|
|
204
|
+
let t = (self.smoothness * delta_time).min(1.0);
|
|
205
|
+
current.lerp(desired, t)
|
|
206
|
+
} else {
|
|
207
|
+
current
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
#[derive(Component, Debug, Clone)]
|
|
213
|
+
pub struct CameraShake {
|
|
214
|
+
pub intensity: f32,
|
|
215
|
+
pub duration: f32,
|
|
216
|
+
pub decay: f32,
|
|
217
|
+
pub remaining_time: f32,
|
|
218
|
+
pub frequency: f32,
|
|
219
|
+
time_elapsed: f32,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
impl Default for CameraShake {
|
|
223
|
+
fn default() -> Self {
|
|
224
|
+
Self {
|
|
225
|
+
intensity: 0.0,
|
|
226
|
+
duration: 0.0,
|
|
227
|
+
decay: 1.0,
|
|
228
|
+
remaining_time: 0.0,
|
|
229
|
+
frequency: 20.0,
|
|
230
|
+
time_elapsed: 0.0,
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
impl CameraShake {
|
|
236
|
+
pub fn new() -> Self {
|
|
237
|
+
Self::default()
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
pub fn trigger(&mut self, intensity: f32, duration: f32) {
|
|
241
|
+
self.intensity = intensity;
|
|
242
|
+
self.duration = duration;
|
|
243
|
+
self.remaining_time = duration;
|
|
244
|
+
self.time_elapsed = 0.0;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
pub fn trigger_with_decay(&mut self, intensity: f32, duration: f32, decay: f32) {
|
|
248
|
+
self.intensity = intensity;
|
|
249
|
+
self.duration = duration;
|
|
250
|
+
self.decay = decay;
|
|
251
|
+
self.remaining_time = duration;
|
|
252
|
+
self.time_elapsed = 0.0;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
pub fn update(&mut self, delta_time: f32) -> Vec2 {
|
|
256
|
+
if self.remaining_time <= 0.0 {
|
|
257
|
+
return Vec2::ZERO;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
self.remaining_time -= delta_time;
|
|
261
|
+
self.time_elapsed += delta_time;
|
|
262
|
+
|
|
263
|
+
let progress = 1.0 - (self.remaining_time / self.duration);
|
|
264
|
+
let decay_factor = (1.0 - progress).powf(self.decay);
|
|
265
|
+
let current_intensity = self.intensity * decay_factor;
|
|
266
|
+
|
|
267
|
+
let angle = self.time_elapsed * self.frequency * std::f32::consts::TAU;
|
|
268
|
+
let x = angle.sin() * current_intensity;
|
|
269
|
+
let y = (angle * 1.3).cos() * current_intensity;
|
|
270
|
+
|
|
271
|
+
Vec2::new(x, y)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
pub fn is_active(&self) -> bool {
|
|
275
|
+
self.remaining_time > 0.0
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
pub fn stop(&mut self) {
|
|
279
|
+
self.remaining_time = 0.0;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
#[derive(Component, Debug, Clone)]
|
|
284
|
+
pub struct CameraBounds {
|
|
285
|
+
pub min: Vec2,
|
|
286
|
+
pub max: Vec2,
|
|
287
|
+
pub enabled: bool,
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
impl Default for CameraBounds {
|
|
291
|
+
fn default() -> Self {
|
|
292
|
+
Self {
|
|
293
|
+
min: Vec2::new(f32::MIN, f32::MIN),
|
|
294
|
+
max: Vec2::new(f32::MAX, f32::MAX),
|
|
295
|
+
enabled: false,
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
impl CameraBounds {
|
|
301
|
+
pub fn new(min_x: f32, min_y: f32, max_x: f32, max_y: f32) -> Self {
|
|
302
|
+
Self {
|
|
303
|
+
min: Vec2::new(min_x, min_y),
|
|
304
|
+
max: Vec2::new(max_x, max_y),
|
|
305
|
+
enabled: true,
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
pub fn clamp(&self, position: Vec3) -> Vec3 {
|
|
310
|
+
if !self.enabled {
|
|
311
|
+
return position;
|
|
312
|
+
}
|
|
313
|
+
Vec3::new(
|
|
314
|
+
position.x.clamp(self.min.x, self.max.x),
|
|
315
|
+
position.y.clamp(self.min.y, self.max.y),
|
|
316
|
+
position.z,
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
#[derive(Component, Debug, Clone)]
|
|
322
|
+
pub struct CameraZoom {
|
|
323
|
+
pub current: f32,
|
|
324
|
+
pub min: f32,
|
|
325
|
+
pub max: f32,
|
|
326
|
+
pub speed: f32,
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
impl Default for CameraZoom {
|
|
330
|
+
fn default() -> Self {
|
|
331
|
+
Self {
|
|
332
|
+
current: 1.0,
|
|
333
|
+
min: 0.1,
|
|
334
|
+
max: 10.0,
|
|
335
|
+
speed: 1.0,
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
impl CameraZoom {
|
|
341
|
+
pub fn new(initial: f32) -> Self {
|
|
342
|
+
Self {
|
|
343
|
+
current: initial,
|
|
344
|
+
..Default::default()
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
pub fn with_limits(mut self, min: f32, max: f32) -> Self {
|
|
349
|
+
self.min = min;
|
|
350
|
+
self.max = max;
|
|
351
|
+
self
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
pub fn zoom_in(&mut self, amount: f32) {
|
|
355
|
+
self.current = (self.current - amount * self.speed).clamp(self.min, self.max);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
pub fn zoom_out(&mut self, amount: f32) {
|
|
359
|
+
self.current = (self.current + amount * self.speed).clamp(self.min, self.max);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
pub fn set_zoom(&mut self, value: f32) {
|
|
363
|
+
self.current = value.clamp(self.min, self.max);
|
|
364
|
+
}
|
|
365
|
+
}
|