shattered 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/bin/console +22 -0
  2. data/bin/generate +7 -0
  3. data/bin/runner +9 -0
  4. data/bin/shatter +29 -0
  5. data/lib/game_loader.rb +49 -0
  6. data/lib/rails_generator.rb +43 -0
  7. data/lib/rails_generator/base.rb +203 -0
  8. data/lib/rails_generator/commands.rb +445 -0
  9. data/lib/rails_generator/generators/applications/shattered_app/USAGE +10 -0
  10. data/lib/rails_generator/generators/applications/shattered_app/shattered_app_generator.rb +104 -0
  11. data/lib/rails_generator/generators/components/actor/actor_generator.rb +23 -0
  12. data/lib/rails_generator/generators/components/controller/USAGE +30 -0
  13. data/lib/rails_generator/generators/components/controller/controller_generator.rb +32 -0
  14. data/lib/rails_generator/generators/components/controller/templates/controller.rb +5 -0
  15. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +18 -0
  16. data/lib/rails_generator/generators/components/controller/templates/helper.rb +2 -0
  17. data/lib/rails_generator/generators/components/controller/templates/view.rhtml +2 -0
  18. data/lib/rails_generator/generators/components/model/USAGE +17 -0
  19. data/lib/rails_generator/generators/components/model/model_generator.rb +17 -0
  20. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +5 -0
  21. data/lib/rails_generator/generators/components/model/templates/model.rb +2 -0
  22. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +11 -0
  23. data/lib/rails_generator/generators/components/state/USAGE +30 -0
  24. data/lib/rails_generator/generators/components/state/state_generator.rb +19 -0
  25. data/lib/rails_generator/generators/components/state/templates/state.rb +4 -0
  26. data/lib/rails_generator/generators/components/view/USAGE +30 -0
  27. data/lib/rails_generator/generators/components/view/templates/material +4 -0
  28. data/lib/rails_generator/generators/components/view/templates/view.rb +3 -0
  29. data/lib/rails_generator/generators/components/view/view_generator.rb +18 -0
  30. data/lib/rails_generator/lookup.rb +206 -0
  31. data/lib/rails_generator/manifest.rb +53 -0
  32. data/lib/rails_generator/options.rb +135 -0
  33. data/lib/rails_generator/scripts.rb +83 -0
  34. data/lib/rails_generator/scripts/destroy.rb +7 -0
  35. data/lib/rails_generator/scripts/generate.rb +7 -0
  36. data/lib/rails_generator/scripts/update.rb +12 -0
  37. data/lib/rails_generator/simple_logger.rb +46 -0
  38. data/lib/rails_generator/spec.rb +44 -0
  39. data/lib/shatter.rb +11 -0
  40. data/lib/templates/MIT-LICENSE +20 -0
  41. data/lib/templates/README +35 -0
  42. data/lib/templates/Rakefile +15 -0
  43. data/lib/templates/configs/Mac/shattered.app/Contents/Info.plist +22 -0
  44. data/lib/templates/configs/Mac/shattered.app/Contents/MacOS/shattered_mac +0 -0
  45. data/lib/templates/configs/Mac/shattered.app/Contents/PkgInfo +1 -0
  46. data/lib/templates/configs/Mac/shattered.app/Contents/Resources/English.lproj/InfoPlist.strings +0 -0
  47. data/lib/templates/configs/Mac/shattered.app/Contents/Resources/English.lproj/MainMenu.nib/classes.nib +4 -0
  48. data/lib/templates/configs/Mac/shattered.app/Contents/Resources/English.lproj/MainMenu.nib/info.nib +20 -0
  49. data/lib/templates/configs/Mac/shattered.app/Contents/Resources/English.lproj/MainMenu.nib/objects.nib +0 -0
  50. data/lib/templates/configs/Mac/shattered.app/Contents/Resources/rb_main.rb +3 -0
  51. data/lib/templates/configs/Mac/shattered.app/Contents/pbdevelopment.plist +8 -0
  52. data/lib/templates/configs/Mac/shattered.app/OgreLeaks.log +144 -0
  53. data/lib/templates/configs/Mac/shattered.app/OgreMemory.log +29 -0
  54. data/lib/templates/configs/Mac/shattered.app/config +1 -0
  55. data/lib/templates/configs/boot.rb +33 -0
  56. data/lib/templates/configs/empty.log +0 -0
  57. data/lib/templates/configs/ogre.cfg +4 -0
  58. data/lib/templates/configs/plugins.cfg +16 -0
  59. data/lib/templates/configs/plugins.darwin.cfg +13 -0
  60. data/lib/templates/configs/plugins.linux.cfg +16 -0
  61. data/lib/templates/configs/plugins.win32.cfg +9 -0
  62. data/lib/templates/configs/runner.rb +5 -0
  63. data/lib/templates/doc/README_FOR_APP +2 -0
  64. data/lib/templates/environments/environment.rb +7 -0
  65. data/lib/templates/media/basic.rmaterial +17 -0
  66. data/lib/templates/media/offset_map.rmaterial +117 -0
  67. metadata +194 -0
@@ -0,0 +1,53 @@
1
+ module Rails
2
+ module Generator
3
+
4
+ # Manifest captures the actions a generator performs. Instantiate
5
+ # a manifest with an optional target object, hammer it with actions,
6
+ # then replay or rewind on the object of your choice.
7
+ #
8
+ # Example:
9
+ # manifest = Manifest.new { |m|
10
+ # m.make_directory '/foo'
11
+ # m.create_file '/foo/bar.txt'
12
+ # }
13
+ # manifest.replay(creator)
14
+ # manifest.rewind(destroyer)
15
+ class Manifest
16
+ attr_reader :target
17
+
18
+ # Take a default action target. Yield self if block given.
19
+ def initialize(target = nil)
20
+ @target, @actions = target, []
21
+ yield self if block_given?
22
+ end
23
+
24
+ # Record an action.
25
+ def method_missing(action, *args, &block)
26
+ @actions << [action, args, block]
27
+ end
28
+
29
+ # Replay recorded actions.
30
+ def replay(target = nil)
31
+ send_actions(target || @target, @actions)
32
+ end
33
+
34
+ # Rewind recorded actions.
35
+ def rewind(target = nil)
36
+ send_actions(target || @target, @actions.reverse)
37
+ end
38
+
39
+ # Erase recorded actions.
40
+ def erase
41
+ @actions = []
42
+ end
43
+
44
+ private
45
+ def send_actions(target, actions)
46
+ actions.each do |method, args, block|
47
+ target.send(method, *args, &block)
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,135 @@
1
+ require 'optparse'
2
+
3
+ module Rails
4
+ module Generator
5
+ module Options
6
+ def self.append_features(base)
7
+ super
8
+ base.extend(ClassMethods)
9
+ class << base
10
+ if respond_to?(:inherited)
11
+ alias_method :inherited_without_options, :inherited
12
+ end
13
+ alias_method :inherited, :inherited_with_options
14
+ end
15
+ end
16
+
17
+ module ClassMethods
18
+ def inherited_with_options(sub)
19
+ inherited_without_options(sub) if respond_to?(:inherited_without_options)
20
+ sub.extend(Rails::Generator::Options::ClassMethods)
21
+ end
22
+
23
+ def mandatory_options(options = nil)
24
+ if options
25
+ write_inheritable_attribute(:mandatory_options, options)
26
+ else
27
+ read_inheritable_attribute(:mandatory_options) or write_inheritable_attribute(:mandatory_options, {})
28
+ end
29
+ end
30
+
31
+ def default_options(options = nil)
32
+ if options
33
+ write_inheritable_attribute(:default_options, options)
34
+ else
35
+ read_inheritable_attribute(:default_options) or write_inheritable_attribute(:default_options, {})
36
+ end
37
+ end
38
+
39
+ # Merge together our class options. In increasing precedence:
40
+ # default_options (class default options)
41
+ # runtime_options (provided as argument)
42
+ # mandatory_options (class mandatory options)
43
+ def full_options(runtime_options = {})
44
+ default_options.merge(runtime_options).merge(mandatory_options)
45
+ end
46
+
47
+ end
48
+
49
+ # Each instance has an options hash that's populated by #parse.
50
+ def options
51
+ @options ||= {}
52
+ end
53
+ attr_writer :options
54
+
55
+ protected
56
+ # Convenient access to class mandatory options.
57
+ def mandatory_options
58
+ self.class.mandatory_options
59
+ end
60
+
61
+ # Convenient access to class default options.
62
+ def default_options
63
+ self.class.default_options
64
+ end
65
+
66
+ # Merge together our instance options. In increasing precedence:
67
+ # default_options (class default options)
68
+ # options (instance options)
69
+ # runtime_options (provided as argument)
70
+ # mandatory_options (class mandatory options)
71
+ def full_options(runtime_options = {})
72
+ self.class.full_options(options.merge(runtime_options))
73
+ end
74
+
75
+ # Parse arguments into the options hash. Classes may customize
76
+ # parsing behavior by overriding these methods:
77
+ # #banner Usage: ./script/generate [options]
78
+ # #add_options! Options:
79
+ # some options..
80
+ # #add_general_options! General Options:
81
+ # general options..
82
+ def parse!(args, runtime_options = {})
83
+ self.options = {}
84
+
85
+ @option_parser = OptionParser.new do |opt|
86
+ opt.banner = banner
87
+ add_options!(opt)
88
+ add_general_options!(opt)
89
+ opt.parse!(args)
90
+ end
91
+
92
+ return args
93
+ ensure
94
+ self.options = full_options(runtime_options)
95
+ end
96
+
97
+ # Raise a usage error. Override usage_message to provide a blurb
98
+ # after the option parser summary.
99
+ def usage
100
+ raise UsageError, "#{@option_parser}\n#{usage_message}"
101
+ end
102
+
103
+ def usage_message
104
+ ''
105
+ end
106
+
107
+ # Override with your own usage banner.
108
+ def banner
109
+ "Usage: #{$0} [options]"
110
+ end
111
+
112
+ # Override to add your options to the parser:
113
+ # def add_options!(opt)
114
+ # opt.on('-v', '--verbose') { |value| options[:verbose] = value }
115
+ # end
116
+ def add_options!(opt)
117
+ end
118
+
119
+ # Adds general options like -h and --quiet. Usually don't override.
120
+ def add_general_options!(opt)
121
+ opt.separator ''
122
+ opt.separator 'General Options:'
123
+
124
+ opt.on('-p', '--pretend', 'Run but do not make any changes.') { |options[:pretend]| }
125
+ opt.on('-f', '--force', 'Overwrite files that already exist.') { options[:collision] = :force }
126
+ opt.on('-s', '--skip', 'Skip files that already exist.') { options[:collision] = :skip }
127
+ opt.on('-q', '--quiet', 'Suppress normal output.') { |options[:quiet]| }
128
+ opt.on('-t', '--backtrace', 'Debugging: show backtrace on errors.') { |options[:backtrace]| }
129
+ opt.on('-h', '--help', 'Show this help message.') { |options[:help]| }
130
+ opt.on('-c', '--svn', 'Modify files with subversion. (Note: svn must be in path)') { options[:svn] = Hash[*`svn status`.collect { |e| e.chop.split.reverse unless e.chop.split.size != 2 }.flatten] }
131
+ end
132
+
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,83 @@
1
+ require File.dirname(__FILE__) + '/options'
2
+
3
+ module Rails
4
+ module Generator
5
+ module Scripts
6
+
7
+ # Generator scripts handle command-line invocation. Each script
8
+ # responds to an invoke! class method which handles option parsing
9
+ # and generator invocation.
10
+ class Base
11
+ include Options
12
+ default_options :collision => :ask, :quiet => false
13
+
14
+ # Run the generator script. Takes an array of unparsed arguments
15
+ # and a hash of parsed arguments, takes the generator as an option
16
+ # or first remaining argument, and invokes the requested command.
17
+ def run(args = [], runtime_options = {})
18
+ begin
19
+ parse!(args.dup, runtime_options)
20
+ rescue OptionParser::InvalidOption => e
21
+ # Don't cry, script. Generators want what you think is invalid.
22
+ end
23
+
24
+ # Generator name is the only required option.
25
+ unless options[:generator]
26
+ usage if args.empty?
27
+ options[:generator] ||= args.shift
28
+ end
29
+
30
+ # Look up generator instance and invoke command on it.
31
+ Rails::Generator::Base.instance(options[:generator], args, options).command(options[:command]).invoke!
32
+ rescue => e
33
+ puts e
34
+ puts " #{e.backtrace.join("\n ")}\n" if options[:backtrace]
35
+ raise SystemExit
36
+ end
37
+
38
+ protected
39
+ # Override with your own script usage banner.
40
+ def banner
41
+ "Usage: #{$0} [options] generator [args]"
42
+ end
43
+
44
+ def usage_message
45
+ usage = "\nInstalled Generators\n"
46
+ Rails::Generator::Base.sources.each do |source|
47
+ label = source.label.to_s.capitalize
48
+ names = source.names
49
+ usage << " #{label}: #{names.join(', ')}\n" unless names.empty?
50
+ end
51
+
52
+ usage << <<end_blurb
53
+
54
+ More are available at http://rubyonrails.org/show/Generators
55
+ 1. Download, for example, login_generator.zip
56
+ 2. Unzip to directory #{Dir.user_home}/.rails/generators/login
57
+ to use the generator with all your Rails apps
58
+ end_blurb
59
+
60
+ if Object.const_defined?(:SHATTERED_ROOT)
61
+ usage << <<end_blurb
62
+ or to #{File.expand_path(SHATTERED_ROOT)}/generators/login
63
+ to use with this app only.
64
+ end_blurb
65
+ end
66
+
67
+ usage << <<end_blurb
68
+ 3. Run generate with no arguments for usage information
69
+ #{$0} login
70
+
71
+ Generator gems are also available:
72
+ 1. gem list generator -s http://gems.rubyonrails.org
73
+ 2. gem install login_generator -s http://gems.rubyonrails.org
74
+ 3. #{$0} login
75
+
76
+ end_blurb
77
+ return usage
78
+ end
79
+ end # Base
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../scripts'
2
+
3
+ module Rails::Generator::Scripts
4
+ class Destroy < Base
5
+ mandatory_options :command => :destroy
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../scripts'
2
+
3
+ module Rails::Generator::Scripts
4
+ class Generate < Base
5
+ mandatory_options :command => :create
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../scripts'
2
+
3
+ module Rails::Generator::Scripts
4
+ class Update < Base
5
+ mandatory_options :command => :update
6
+
7
+ protected
8
+ def banner
9
+ "Usage: #{$0} [options] scaffold"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,46 @@
1
+ module Rails
2
+ module Generator
3
+ class SimpleLogger # :nodoc:
4
+ attr_reader :out
5
+ attr_accessor :quiet
6
+
7
+ def initialize(out = $stdout)
8
+ @out = out
9
+ @quiet = false
10
+ @level = 0
11
+ end
12
+
13
+ def log(status, message, &block)
14
+ @out.print("%12s %s%s\n" % [status, ' ' * @level, message]) unless quiet
15
+ indent(&block) if block_given?
16
+ end
17
+
18
+ def indent(&block)
19
+ @level += 1
20
+ if block_given?
21
+ begin
22
+ block.call
23
+ ensure
24
+ outdent
25
+ end
26
+ end
27
+ end
28
+
29
+ def outdent
30
+ @level -= 1
31
+ if block_given?
32
+ begin
33
+ block.call
34
+ ensure
35
+ indent
36
+ end
37
+ end
38
+ end
39
+
40
+ private
41
+ def method_missing(method, *args, &block)
42
+ log(method.to_s, args.first, &block)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,44 @@
1
+ module Rails
2
+ module Generator
3
+ # A spec knows where a generator was found and how to instantiate it.
4
+ # Metadata include the generator's name, its base path, and the source
5
+ # which yielded it (PathSource, GemSource, etc.)
6
+ class Spec
7
+ attr_reader :name, :path, :source
8
+
9
+ def initialize(name, path, source)
10
+ @name, @path, @source = name, path, source
11
+ end
12
+
13
+ # Look up the generator class. Require its class file, find the class
14
+ # in ObjectSpace, tag it with this spec, and return.
15
+ def klass
16
+ unless @klass
17
+ require class_file
18
+ @klass = lookup_class
19
+ @klass.spec = self
20
+ end
21
+ @klass
22
+ end
23
+
24
+ def class_file
25
+ "#{path}/#{name}_generator.rb"
26
+ end
27
+
28
+ def class_name
29
+ "#{name.camelize}Generator"
30
+ end
31
+
32
+ private
33
+ # Search for the first Class descending from Rails::Generator::Base
34
+ # whose name matches the requested class name.
35
+ def lookup_class
36
+ ObjectSpace.each_object(Class) do |obj|
37
+ return obj if obj.ancestors.include?(Rails::Generator::Base) and
38
+ obj.name.split('::').last == class_name
39
+ end
40
+ raise NameError, "Missing #{class_name} class in #{class_file}"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,11 @@
1
+ ["shattered_model", "shattered_view","shattered_controller"].each do |component|
2
+ begin
3
+ # require File.dirname(__FILE__) + "/../../#{component}/lib/#{component}"
4
+ require component
5
+ rescue MissingSourceFile
6
+ require 'rubygems'
7
+ require component
8
+ end
9
+ end
10
+
11
+ require File.dirname(__FILE__) + '/game_loader'
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2004 David Heinemeier Hansson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ == Description of contents
2
+
3
+ A large part of this is inspired (cp -R) by Rails. The fact that a web framework and a game framework have so much in common amazes me.
4
+
5
+ Each project is created with the following directory structure:
6
+
7
+ log/
8
+ Ogre.log - For Ogre's errors
9
+ Shattered.log - For all of shattered's messages
10
+
11
+ test/
12
+ Anything that matches /.*_test.rb/ will be executed when testing.
13
+
14
+ app/
15
+ models/
16
+ All models here.
17
+ controllers/
18
+ All model controllers(AI, keyboard) here.
19
+ views/
20
+ The views are here, each with a corresponding directory.
21
+ puppy_view.rb
22
+ puppy/
23
+ puppy.mesh
24
+ puppy.skeleton
25
+ puppy.material
26
+ puppy.png
27
+ puppy_normals.png
28
+
29
+ config/
30
+ Here you will define the ogre and other configuration
31
+
32
+ script/
33
+ This contains the generators/runners/executable scripts
34
+ doc/
35
+ The documentation in this directory will be generated by rails rdoc.