gubby 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gubby.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Justin Basinger
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Gubby
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gubby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gubby
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gubby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gubby"
8
+ spec.version = Gubby::VERSION
9
+ spec.authors = ["Justin Basinger"]
10
+ spec.email = ["justin.m.basinger@gmail.com"]
11
+ spec.description = "This is a system used to create component based objects. Primarily for games, but you don't have to use it just for that if you don't want to."
12
+ spec.summary = "Gubby component system"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ end
@@ -0,0 +1,15 @@
1
+ require "gubby/extensions/object"
2
+ require "gubby/version"
3
+ require "gubby/game_engine"
4
+ require "gubby/game_entity"
5
+ require "gubby/components/position_2d"
6
+ require "gubby/systems/game_system"
7
+
8
+ #Dir["gubby/extensions/*.rb","gubby/*.rb","gubby/systems/*.rb","gubby/components/*.rb"].each { |f| require File.basename(f,File.extname(f)) }
9
+
10
+
11
+
12
+ module Gubby
13
+ # Bundler: Your code goes here...
14
+ # Me: Don't tell me what to do computer!
15
+ end
@@ -0,0 +1,26 @@
1
+
2
+ module Gubby
3
+
4
+ module Components
5
+
6
+ module Position2D
7
+
8
+ attr_accessor :x, :y, :z, :angle, :center_x, :center_y, :factor_x, :factor_y
9
+
10
+ def Position2D.extend_object(e)
11
+ super(e)
12
+ e.x = 0
13
+ e.y = 0
14
+ e.z = 1
15
+ e.angle = 0
16
+ e.center_x = 0.5
17
+ e.center_y = 0.5
18
+ e.factor_x = 1
19
+ e.factor_y = 1
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,11 @@
1
+
2
+ class Object
3
+
4
+ def unextend(mod)
5
+
6
+ metaclass = class << self; self end
7
+ mod.instance_methods.each {|method_name| metaclass.class_eval { undef_method(method_name.to_sym) }}
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,68 @@
1
+
2
+ module Gubby
3
+ class GameEngine
4
+
5
+ attr_accessor :systems
6
+ attr_reader :entities
7
+
8
+ def initialize(*systems)
9
+ @systems = []
10
+ @entities = []
11
+
12
+ systems.each do |s|
13
+
14
+ @systems.push(s)
15
+
16
+ end
17
+
18
+ end
19
+
20
+ def run(command, *args)
21
+
22
+ @systems.select{ |s| s.respond_to?(command) }.each do |s|
23
+ s.send(command.to_s, *args)
24
+ end
25
+
26
+ end
27
+
28
+ def add_entity(e)
29
+ @entities.push(e) unless @entities.include?(e)
30
+ e.engine = self
31
+ @systems.each do |s|
32
+ s.refresh_entity(e)
33
+ end
34
+ end
35
+
36
+ def refresh_entity(e)
37
+ @systems.each do |s|
38
+ s.refresh_entity(e)
39
+ end
40
+ end
41
+
42
+ def remove_entity(e)
43
+ @entities.delete(e)
44
+ @systems.each do |s|
45
+ if s.entities.include?(e) then
46
+ s.entities.delete(e)
47
+ end
48
+ end
49
+ e.engine = nil
50
+ end
51
+
52
+ def [](*selectors)
53
+
54
+ found = []
55
+
56
+ selectors.each do |s|
57
+
58
+ found.concat(@entities.select{|e| e.name == s}) if s.is_a?(String)
59
+ found.concat(@entities.select{|e| e.is_a?(s)}) if s.is_a?(Module)
60
+
61
+ end
62
+
63
+ return found
64
+
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,45 @@
1
+
2
+ module Gubby
3
+ class GameEntity
4
+
5
+ attr_accessor :entity_name,
6
+ :engine
7
+
8
+ attr_reader :components
9
+
10
+ def initialize(name = nil, *components)
11
+
12
+ @components = []
13
+ @entity_name = name unless name.nil?
14
+ add_component(*components)
15
+
16
+ end
17
+
18
+ def add_component(*components)
19
+
20
+ components.each do |c|
21
+ extend(c)
22
+ @components.push(c)
23
+ end
24
+
25
+ @engine.refresh_entity(self) unless @engine.nil?
26
+
27
+ end
28
+
29
+ def remove_component(*components)
30
+
31
+ components.each do |c|
32
+ unextend(c)
33
+ @components.delete(c)
34
+ end
35
+
36
+ @engine.refresh_entity(self) unless @engine.nil?
37
+
38
+ end
39
+
40
+ def destroy()
41
+ @engine.remove_entity(self)
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,40 @@
1
+
2
+ module Gubby
3
+
4
+ module Systems
5
+
6
+ class GameSystem
7
+
8
+ attr_reader :entities
9
+
10
+ def initialize(*args)
11
+
12
+ @entities = []
13
+ @component_types = args
14
+
15
+ end
16
+
17
+ def refresh_entity(e)
18
+
19
+ #We need to make sure the entity is all the types it needs to be
20
+ is_compatible = true
21
+
22
+ @component_types.each do |c|
23
+ is_compatible = is_compatible && e.is_a?(c)
24
+ end
25
+
26
+ if is_compatible && !@entities.include?(e)
27
+ @entities.push(e)
28
+ end
29
+
30
+ if not is_compatible && @entities.include?(e)
31
+ @entities.delete(e)
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,3 @@
1
+ module Gubby
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gubby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin Basinger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &23540316 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *23540316
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &23540064 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *23540064
36
+ description: This is a system used to create component based objects. Primarily for
37
+ games, but you don't have to use it just for that if you don't want to.
38
+ email:
39
+ - justin.m.basinger@gmail.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - gubby.gemspec
50
+ - lib/gubby.rb
51
+ - lib/gubby/components/position_2d.rb
52
+ - lib/gubby/extensions/object.rb
53
+ - lib/gubby/game_engine.rb
54
+ - lib/gubby/game_entity.rb
55
+ - lib/gubby/systems/game_system.rb
56
+ - lib/gubby/version.rb
57
+ homepage: ''
58
+ licenses:
59
+ - MIT
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.11
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Gubby component system
82
+ test_files: []