draco 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +11 -1
- data/lib/draco.rb +57 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 363ccf9c3649a752219bca392bdc13b88defbd864a63afb5615969986e59c070
|
4
|
+
data.tar.gz: 81dcbc8225646cec6efc357ecaacfd89334e9a183caad035cf4bd2ece9a01470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa089a7a6abe9b615d07e8def023fad13fedcbca605e78bc1acf181431b1659961811074a9238f79702b7e1e9ddd76782a173fd079ed5f7ae04a2ee83905c660
|
7
|
+
data.tar.gz: e6a70346719b8cf5e5269924158bcbad7ed4ea66440686c57931b7dc6232d467adf6abeac5740970e6d16a573d61a66af27c5626599ed115a7a87624d9ac9bdf
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -47,7 +47,7 @@ These can be shared across many different types of game objects.
|
|
47
47
|
class Visible < Draco::Component; end
|
48
48
|
```
|
49
49
|
|
50
|
-
`Visible` is an example of a
|
50
|
+
`Visible` is an example of a tag component. An entity either has it, or it doesn't. We can also associate data with our
|
51
51
|
components.
|
52
52
|
|
53
53
|
```ruby
|
@@ -68,6 +68,16 @@ component.x
|
|
68
68
|
# => 110
|
69
69
|
```
|
70
70
|
|
71
|
+
#### Tag Components
|
72
|
+
|
73
|
+
The `Visible` class above is an example of a tag component. These are common enough that we don't necessarily want to
|
74
|
+
define a bunch of empty component classes. Draco provides a way to generate these classes at runtime.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
Draco::Tag(:visible)
|
78
|
+
# => Visible
|
79
|
+
```
|
80
|
+
|
71
81
|
### Entities
|
72
82
|
|
73
83
|
Entities are independant game objects. They consist of a unique id and a list of components.
|
data/lib/draco.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# An Entity Component System is an architectural pattern used in game development to decouple behavior from objects.
|
6
6
|
module Draco
|
7
7
|
# Public: The version of the library. Draco uses semver to version releases.
|
8
|
-
VERSION = "0.
|
8
|
+
VERSION = "0.5.0"
|
9
9
|
|
10
10
|
# Public: A general purpose game object that consists of a unique id and a collection of Components.
|
11
11
|
class Entity
|
@@ -300,6 +300,23 @@ module Draco
|
|
300
300
|
end
|
301
301
|
end
|
302
302
|
|
303
|
+
# Internal: Empty module to enable Tag() method.
|
304
|
+
module Tag; end
|
305
|
+
|
306
|
+
# Public: Creates a new empty component at runtime. If the given Class already exists, it reuses the existing Class.
|
307
|
+
#
|
308
|
+
# name - The symbol or string name of the component. It can be either camelcase or underscored.
|
309
|
+
#
|
310
|
+
# Returns a Class with superclass of Draco::Component.
|
311
|
+
def self.Tag(name) # rubocop:disable Naming/MethodName
|
312
|
+
klass_name = camelize(name)
|
313
|
+
|
314
|
+
return Object.const_get(klass_name) if Object.const_defined?(klass_name)
|
315
|
+
|
316
|
+
klass = Class.new(Component)
|
317
|
+
Object.const_set(klass_name, klass)
|
318
|
+
end
|
319
|
+
|
303
320
|
# Public: Systems contain the logic of the game.
|
304
321
|
# The System runs on each tick and manipulates the Entities in the World.
|
305
322
|
class System
|
@@ -518,16 +535,23 @@ module Draco
|
|
518
535
|
def [](*components_or_ids)
|
519
536
|
components_or_ids
|
520
537
|
.flatten
|
521
|
-
.map
|
522
|
-
if component_or_id.is_a?(Numeric)
|
523
|
-
Array(@entity_ids[component_or_id])
|
524
|
-
else
|
525
|
-
@component_to_entities[component_or_id]
|
526
|
-
end
|
527
|
-
end
|
538
|
+
.map { |component_or_id| select_entities(component_or_id) }
|
528
539
|
.reduce { |acc, i| i & acc }
|
529
540
|
end
|
530
541
|
|
542
|
+
# Internal: Gets entities by component or id.
|
543
|
+
#
|
544
|
+
# component_or_id - The Component Class or entity id to select.
|
545
|
+
#
|
546
|
+
# Returns an Array of Entities.
|
547
|
+
def select_entities(component_or_id)
|
548
|
+
if component_or_id.is_a?(Numeric)
|
549
|
+
Array(@entity_ids[component_or_id])
|
550
|
+
else
|
551
|
+
@component_to_entities[component_or_id]
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
531
555
|
# Internal: Adds Entities to the EntityStore
|
532
556
|
#
|
533
557
|
# entities - The Entity or Array list of Entities to add to the EntityStore.
|
@@ -717,13 +741,36 @@ module Draco
|
|
717
741
|
#
|
718
742
|
# Returns a String.
|
719
743
|
def self.underscore(string)
|
720
|
-
string.split("::").last.bytes.map.with_index do |byte, i|
|
744
|
+
string.to_s.split("::").last.bytes.map.with_index do |byte, i|
|
721
745
|
if byte > 64 && byte < 97
|
722
|
-
downcased = byte + 32
|
746
|
+
downcased = byte + 32
|
723
747
|
i.zero? ? downcased.chr : "_#{downcased.chr}"
|
724
748
|
else
|
725
749
|
byte.chr
|
726
750
|
end
|
727
751
|
end.join
|
728
752
|
end
|
753
|
+
|
754
|
+
# Internal: Converts an underscored string into a camel case string.
|
755
|
+
#
|
756
|
+
# Examples
|
757
|
+
#
|
758
|
+
# camlize("camel_case")
|
759
|
+
# # => "CamelCase"
|
760
|
+
#
|
761
|
+
# Returns a string.
|
762
|
+
def self.camelize(string) # rubocop:disable Metrics/MethodLength
|
763
|
+
modifier = -32
|
764
|
+
|
765
|
+
string.to_s.bytes.map do |byte|
|
766
|
+
if byte == 95
|
767
|
+
modifier = -32
|
768
|
+
nil
|
769
|
+
else
|
770
|
+
char = (byte + modifier).chr
|
771
|
+
modifier = 0
|
772
|
+
char
|
773
|
+
end
|
774
|
+
end.compact.join
|
775
|
+
end
|
729
776
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: draco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Pruitt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library for Entities, Components, and Systems in games.
|
14
14
|
email:
|
@@ -22,6 +22,7 @@ files:
|
|
22
22
|
- ".gitignore"
|
23
23
|
- ".rspec"
|
24
24
|
- ".rubocop.yml"
|
25
|
+
- CHANGELOG.md
|
25
26
|
- CODE_OF_CONDUCT.md
|
26
27
|
- COMM-LICENSE
|
27
28
|
- Gemfile
|