baku 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1d2763ede4661622889dd5408420549df6cd9abc
4
- data.tar.gz: 03d33e683578f3df73f38d41a458492864281dcb
2
+ SHA256:
3
+ metadata.gz: 53f4e7b623eac99e2c4ecbbc31d94cfddb83f385ce312b4dcd140d53b22c9ba7
4
+ data.tar.gz: a0e5df631d32755e2cf7c783981bede609d92e6bb1526229e1936bfe2549cb12
5
5
  SHA512:
6
- metadata.gz: 712e0526dfdff24c604c5ebdda331c30b4b27c3be0e4b3b6cfc2340c7293ef9f6221f9e93763ae38811dcfae8ce97a75b5aa5111de22bba760d4d206c08dc76d
7
- data.tar.gz: 650c477a001bc33e34ea1ad2544529bea93ecfb0a51d9faa2e7ac59a0f23f0b932c98c699f9521b573e1aa42b33624e97d29e0fcc5accc845740c3a156244a55
6
+ metadata.gz: 4fe0db7915bc10d2f523a6a8961b63a0ab4bb013d1cec3c4b28d3dfa922f785dd4b54ab7365fa80d518d302b7473c5f2fd01bc2f4ecb53b5500cbce9a49cac7b
7
+ data.tar.gz: a8f2c0261f124e16045135205dc87955b18818cb0e12f18f227b159a2e6718b9047e713478c6058da2a191dc27704b1dcc7251e469b10e1ef05117cae043422f
data/.gitignore CHANGED
@@ -1,15 +1,52 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
1
+ *.gem
2
+ *.rbc
3
+ /.config
5
4
  /coverage/
6
- /doc/
5
+ /InstalledFiles
7
6
  /pkg/
8
7
  /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
9
11
  /tmp/
10
12
 
11
- # rspec failure tracking
12
- .rspec_status
13
- .byebug_history
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
14
46
  .ruby-version
15
- .ruby-gemset
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ .rspec_status
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
+ # 0.3.0
2
+
3
+ * Add tag system that processes entities by tag.
4
+
1
5
  # 0.2.6
2
6
 
3
- * Fix bug with entity component removal.
7
+ * Replace internal event listener with miru gem.
4
8
 
5
9
  # 0.2.5
6
10
 
data/baku.gemspec CHANGED
@@ -1,28 +1,28 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "baku/version"
3
+ require 'baku/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "baku"
6
+ spec.name = 'baku'
8
7
  spec.version = Baku::VERSION
9
- spec.authors = ["John Tuttle"]
10
- spec.email = ["jtuttle.develops@gmail.com"]
8
+ spec.authors = ['John Tuttle']
9
+ spec.email = ['jtuttle.develops@gmail.com']
11
10
 
12
- spec.summary = "An Entity Component System framework for Ruby"
13
- spec.description = "An Entity Component System framework for Ruby"
14
- spec.homepage = "https://github.com/jtuttle/baku"
15
- spec.license = "MIT"
11
+ spec.summary = 'An Entity Component System framework for Ruby'
12
+ spec.description = 'An Entity Component System framework for Ruby'
13
+ spec.homepage = 'https://github.com/jtuttle/baku'
14
+ spec.license = 'MIT'
16
15
 
16
+ # use double quotes for "\x0" (https://github.com/bundler/bundler/issues/4133)
17
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
18
  f.match(%r{^(test|spec|features)/})
19
19
  end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
23
21
 
24
- spec.add_development_dependency "bundler", "~> 1.15"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3.0"
27
- spec.add_development_dependency "pry-byebug", "~> 3.5.0"
22
+ spec.add_development_dependency 'bundler', '~> 2.0.2'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency 'pry-byebug', '~> 3.5.0'
26
+
27
+ spec.add_dependency 'miru', '~> 0.1.0'
28
28
  end
@@ -0,0 +1,35 @@
1
+ require_relative 'system'
2
+
3
+ module Baku
4
+ class ComponentSystem < System
5
+ attr_reader :components
6
+
7
+ def initialize(components, game_loop_step)
8
+ @components = components
9
+ @game_loop_step = game_loop_step
10
+ end
11
+
12
+ def register_world(world)
13
+ super(world)
14
+
15
+ world.entity_manager.register_component_mask(component_mask)
16
+ end
17
+
18
+ def process_entities(entities)
19
+ entities.each do |entity|
20
+ entity_components = @components.map { |c| entity.get_component(c) }
21
+ process_entity(entity, *entity_components)
22
+ end
23
+ end
24
+
25
+ def component_mask
26
+ @component_mask ||= ComponentMask.from_components(@components)
27
+ end
28
+
29
+ protected
30
+
31
+ def retrieve_entities
32
+ @world.entity_manager.get_entities(component_mask)
33
+ end
34
+ end
35
+ end
data/lib/baku/entity.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Baku
2
2
  class Entity
3
- include Baku::EventDispatcher
3
+ include Miru::EventDispatcher
4
4
 
5
5
  attr_reader :components, :tags
6
6
 
@@ -21,10 +21,14 @@ module Baku
21
21
  def add_entity(entity)
22
22
  add_entity_to_matching_component_lists(entity)
23
23
 
24
- entity.add_event_listener(:component_added,
25
- method(:on_entity_component_added))
26
- entity.add_event_listener(:component_removed,
27
- method(:on_entity_component_removed))
24
+ entity.add_event_listener(
25
+ :component_added,
26
+ method(:on_entity_component_added)
27
+ )
28
+ entity.add_event_listener(
29
+ :component_removed,
30
+ method(:on_entity_component_removed)
31
+ )
28
32
 
29
33
  entity.tags.each do |tag|
30
34
  @entities_by_tag[tag] ||= []
@@ -37,10 +41,14 @@ module Baku
37
41
  @entities_by_tag[tag].delete(entity)
38
42
  end
39
43
 
40
- entity.remove_event_listener(:component_added,
41
- method(:on_entity_component_added))
42
- entity.remove_event_listener(:component_removed,
43
- method(:on_entity_component_removed))
44
+ entity.remove_event_listener(
45
+ :component_added,
46
+ method(:on_entity_component_added)
47
+ )
48
+ entity.remove_event_listener(
49
+ :component_removed,
50
+ method(:on_entity_component_removed)
51
+ )
44
52
 
45
53
  @entities_by_component_mask.each do |component_mask, entities|
46
54
  if component_mask.matches?(entity.component_mask)
data/lib/baku/system.rb CHANGED
@@ -1,42 +1,34 @@
1
1
  module Baku
2
2
  class System
3
3
  attr_reader :components, :game_loop_step
4
- attr_writer :world
5
4
 
6
5
  def initialize(components, game_loop_step)
7
6
  @components = components
8
7
  @game_loop_step = game_loop_step
9
8
  end
10
9
 
10
+ def register_world(world)
11
+ @world = world
12
+ end
13
+
11
14
  def execute
12
15
  if @world.nil?
13
16
  raise StandardError.new("Must set :world property of System.")
14
17
  end
15
18
 
16
- entities = @world.entity_manager.get_entities(component_mask)
19
+ entities = retrieve_entities
17
20
 
18
21
  process_entities(entities)
19
22
  end
20
-
21
- def process_entities(entities)
22
- entities.each do |entity|
23
- entity_components = @components.map { |c| entity.get_component(c) }
24
- process_entity(entity, *entity_components)
25
- end
26
- end
27
23
 
28
24
  def process_entity(entity)
29
25
  raise NotImplementedError
30
26
  end
31
27
 
32
- def component_mask
33
- @component_mask ||= ComponentMask.from_components(@components)
34
- end
35
-
36
- private
28
+ protected
37
29
 
38
30
  def retrieve_entities
39
- @world.entity_manager.get_entities(component_mask)
31
+ raise NotImplementedError
40
32
  end
41
33
  end
42
34
  end
@@ -0,0 +1,24 @@
1
+ require_relative 'system'
2
+
3
+ module Baku
4
+ class TagSystem < System
5
+ attr_reader :tag
6
+
7
+ def initialize(tag, game_loop_step)
8
+ @tag = tag
9
+ @game_loop_step = game_loop_step
10
+ end
11
+
12
+ def process_entities(entities)
13
+ entities.each do |entity|
14
+ process_entity(entity)
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def retrieve_entities
21
+ @world.entity_manager.get_entities_by_tag(@tag)
22
+ end
23
+ end
24
+ end
data/lib/baku/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Baku
2
- VERSION = "0.2.6"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/baku/world.rb CHANGED
@@ -31,12 +31,10 @@ module Baku
31
31
  if system_list.map(&:class).include?(system.class)
32
32
  raise StandardError.new("Already added #{system.class} system to world.")
33
33
  end
34
-
35
- system_list << system
36
34
 
37
- @entity_manager.register_component_mask(system.component_mask)
35
+ system.register_world(self)
38
36
 
39
- system.world = self
37
+ system_list << system
40
38
  end
41
39
 
42
40
  def create_entity(tags = [])
data/lib/baku.rb CHANGED
@@ -6,9 +6,10 @@ module Baku
6
6
  rescue LoadError
7
7
  # development dependencies
8
8
  end
9
-
9
+
10
10
  require 'set'
11
+
12
+ require 'miru'
11
13
 
12
- require_relative "baku/event_dispatcher.rb"
13
14
  Gem.find_files("baku/**/*.rb").each { |path| require path }
14
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Tuttle
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-05 00:00:00.000000000 Z
11
+ date: 2019-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: 2.0.2
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: 2.0.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: miru
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.0
69
83
  description: An Entity Component System framework for Ruby
70
84
  email:
71
85
  - jtuttle.develops@gmail.com
@@ -87,10 +101,11 @@ files:
87
101
  - lib/baku.rb
88
102
  - lib/baku/component.rb
89
103
  - lib/baku/component_mask.rb
104
+ - lib/baku/component_system.rb
90
105
  - lib/baku/entity.rb
91
106
  - lib/baku/entity_manager.rb
92
- - lib/baku/event_dispatcher.rb
93
107
  - lib/baku/system.rb
108
+ - lib/baku/tag_system.rb
94
109
  - lib/baku/version.rb
95
110
  - lib/baku/world.rb
96
111
  homepage: https://github.com/jtuttle/baku
@@ -112,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
127
  - !ruby/object:Gem::Version
113
128
  version: '0'
114
129
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.6.12
130
+ rubygems_version: 3.0.6
117
131
  signing_key:
118
132
  specification_version: 4
119
133
  summary: An Entity Component System framework for Ruby
@@ -1,19 +0,0 @@
1
- module Baku
2
- module EventDispatcher
3
- def add_event_listener(event_name, method)
4
- @event_listeners ||= {}
5
- @event_listeners[event_name] ||= []
6
-
7
- @event_listeners[event_name] << method
8
- end
9
-
10
- def remove_event_listener(event_name, method)
11
- @event_listeners[event_name].delete(method)
12
- end
13
-
14
- def dispatch_event(event_name, *args)
15
- return unless @event_listeners && @event_listeners.has_key?(event_name)
16
- @event_listeners[event_name].each { |f| f.call(*args) }
17
- end
18
- end
19
- end