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
data/lib/bevy/system.rb
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bevy
|
|
4
|
+
class SystemBuilder
|
|
5
|
+
attr_reader :name, :schedule, :run_conditions, :ordering
|
|
6
|
+
|
|
7
|
+
def initialize(name = nil)
|
|
8
|
+
@name = name || "system_#{object_id}"
|
|
9
|
+
@schedule = Schedule::UPDATE
|
|
10
|
+
@run_conditions = []
|
|
11
|
+
@ordering = { before: [], after: [] }
|
|
12
|
+
@proc = nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def in_schedule(schedule)
|
|
16
|
+
@schedule = schedule
|
|
17
|
+
self
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def run_if(&condition)
|
|
21
|
+
@run_conditions << condition
|
|
22
|
+
self
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def before(system_name)
|
|
26
|
+
@ordering[:before] << system_name
|
|
27
|
+
self
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def after(system_name)
|
|
31
|
+
@ordering[:after] << system_name
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def with_block(&block)
|
|
36
|
+
@proc = block
|
|
37
|
+
self
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def build
|
|
41
|
+
System.new(
|
|
42
|
+
name: @name,
|
|
43
|
+
schedule: @schedule,
|
|
44
|
+
run_conditions: @run_conditions,
|
|
45
|
+
ordering: @ordering,
|
|
46
|
+
&@proc
|
|
47
|
+
)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class SystemRunner
|
|
52
|
+
def initialize(systems)
|
|
53
|
+
@systems = systems
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def run(context)
|
|
57
|
+
sorted_systems.each do |system|
|
|
58
|
+
next unless should_run?(system, context)
|
|
59
|
+
|
|
60
|
+
system.run(context)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def sorted_systems
|
|
67
|
+
@systems
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def should_run?(system, context)
|
|
71
|
+
return true if system.run_conditions.empty?
|
|
72
|
+
|
|
73
|
+
system.run_conditions.all? { |cond| cond.call(context) }
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
class ParallelSystemConfig
|
|
78
|
+
attr_reader :systems
|
|
79
|
+
|
|
80
|
+
def initialize
|
|
81
|
+
@systems = []
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def add(system)
|
|
85
|
+
@systems << system
|
|
86
|
+
self
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
module SystemParam
|
|
91
|
+
class Query
|
|
92
|
+
attr_reader :component_types, :filters
|
|
93
|
+
|
|
94
|
+
def initialize(*component_types)
|
|
95
|
+
@component_types = component_types
|
|
96
|
+
@filters = { with: [], without: [], changed: [], added: [] }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def with(*components)
|
|
100
|
+
@filters[:with].concat(components)
|
|
101
|
+
self
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def without(*components)
|
|
105
|
+
@filters[:without].concat(components)
|
|
106
|
+
self
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def changed(*components)
|
|
110
|
+
@filters[:changed].concat(components)
|
|
111
|
+
self
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def added(*components)
|
|
115
|
+
@filters[:added].concat(components)
|
|
116
|
+
self
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def each(world, &block)
|
|
120
|
+
world.each(*@component_types, &block)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
class Res
|
|
125
|
+
attr_reader :resource_type
|
|
126
|
+
|
|
127
|
+
def initialize(resource_type)
|
|
128
|
+
@resource_type = resource_type
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def get(resources)
|
|
132
|
+
resources.get(@resource_type)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
class ResMut < Res
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
class Commands
|
|
140
|
+
def initialize(world)
|
|
141
|
+
@world = world
|
|
142
|
+
@pending = []
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def spawn(*components)
|
|
146
|
+
@pending << [:spawn, components]
|
|
147
|
+
self
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def despawn(entity)
|
|
151
|
+
@pending << [:despawn, entity]
|
|
152
|
+
self
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def insert(entity, *components)
|
|
156
|
+
@pending << [:insert, entity, components]
|
|
157
|
+
self
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def remove(entity, *component_types)
|
|
161
|
+
@pending << [:remove, entity, component_types]
|
|
162
|
+
self
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def apply
|
|
166
|
+
@pending.each do |command|
|
|
167
|
+
case command[0]
|
|
168
|
+
when :spawn
|
|
169
|
+
@world.spawn_entity(*command[1])
|
|
170
|
+
when :despawn
|
|
171
|
+
@world.despawn(command[1])
|
|
172
|
+
when :insert
|
|
173
|
+
command[2].each { |c| @world.add_component(command[1], c) }
|
|
174
|
+
when :remove
|
|
175
|
+
command[2].each { |t| @world.remove_component(command[1], t) }
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
@pending.clear
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
class EventReader
|
|
183
|
+
attr_reader :event_type
|
|
184
|
+
|
|
185
|
+
def initialize(event_type)
|
|
186
|
+
@event_type = event_type
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def read(events)
|
|
190
|
+
events.reader(@event_type)
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
class EventWriter
|
|
195
|
+
attr_reader :event_type
|
|
196
|
+
|
|
197
|
+
def initialize(event_type)
|
|
198
|
+
@event_type = event_type
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def get(events)
|
|
202
|
+
events.writer(@event_type)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
data/lib/bevy/text.rb
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bevy
|
|
4
|
+
class Text2d
|
|
5
|
+
attr_reader :content, :font_size, :color
|
|
6
|
+
|
|
7
|
+
def initialize(content, font_size: 24.0, color: Color.white)
|
|
8
|
+
@content = content.to_s
|
|
9
|
+
@font_size = font_size.to_f
|
|
10
|
+
@color = color
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def type_name
|
|
14
|
+
'Text2d'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def with_content(content)
|
|
18
|
+
self.class.new(content, font_size: @font_size, color: @color)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def with_font_size(font_size)
|
|
22
|
+
self.class.new(@content, font_size: font_size, color: @color)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def with_color(color)
|
|
26
|
+
self.class.new(@content, font_size: @font_size, color: color)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def to_sync_hash
|
|
30
|
+
{
|
|
31
|
+
content: @content,
|
|
32
|
+
font_size: @font_size,
|
|
33
|
+
color_r: @color.r,
|
|
34
|
+
color_g: @color.g,
|
|
35
|
+
color_b: @color.b,
|
|
36
|
+
color_a: @color.a
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_native
|
|
41
|
+
native = Component.new('Text2d')
|
|
42
|
+
native['content'] = @content
|
|
43
|
+
native['font_size'] = @font_size
|
|
44
|
+
native['color_r'] = @color.r
|
|
45
|
+
native['color_g'] = @color.g
|
|
46
|
+
native['color_b'] = @color.b
|
|
47
|
+
native['color_a'] = @color.a
|
|
48
|
+
native
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.from_native(native)
|
|
52
|
+
color = Color.rgba(
|
|
53
|
+
native['color_r'] || 1.0,
|
|
54
|
+
native['color_g'] || 1.0,
|
|
55
|
+
native['color_b'] || 1.0,
|
|
56
|
+
native['color_a'] || 1.0
|
|
57
|
+
)
|
|
58
|
+
new(
|
|
59
|
+
native['content'] || '',
|
|
60
|
+
font_size: native['font_size'] || 24.0,
|
|
61
|
+
color: color
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class TextStyle
|
|
67
|
+
attr_reader :font_size, :color
|
|
68
|
+
|
|
69
|
+
def initialize(font_size: 24.0, color: Color.white)
|
|
70
|
+
@font_size = font_size.to_f
|
|
71
|
+
@color = color
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def with_font_size(font_size)
|
|
75
|
+
self.class.new(font_size: font_size, color: @color)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def with_color(color)
|
|
79
|
+
self.class.new(font_size: @font_size, color: color)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
class TextSection
|
|
84
|
+
attr_reader :value, :style
|
|
85
|
+
|
|
86
|
+
def initialize(value, style: TextStyle.new)
|
|
87
|
+
@value = value.to_s
|
|
88
|
+
@style = style
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def with_value(value)
|
|
92
|
+
self.class.new(value, style: @style)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def with_style(style)
|
|
96
|
+
self.class.new(@value, style: style)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|