jemini 2010.1.24 → 2010.2.17

Sign up to get free protection for your applications and to get access to all the features.
data/README.txt CHANGED
@@ -1,4 +1,4 @@
1
- Jemini 2010.1.24
1
+ Jemini 2010.2.17
2
2
 
3
3
  == Description
4
4
 
Binary file
@@ -9,7 +9,6 @@ $LOAD_PATH << 'game_objects'
9
9
  #$LOAD_PATH << 'states'
10
10
  $LOAD_PATH << 'input_helpers'
11
11
 
12
- require 'file_system'
13
12
  require 'platform'
14
13
  require 'color'
15
14
  require 'vector'
@@ -18,7 +17,6 @@ require 'inflector'
18
17
 
19
18
  require 'math'
20
19
  require 'proc_enhancement'
21
- require 'resource'
22
20
  require 'game_object'
23
21
  require 'message_queue'
24
22
  require 'managers/input_manager'
@@ -1,10 +1,10 @@
1
- require 'resource'
2
-
3
1
  class ResourceManager < Jemini::GameObject
4
2
  java_import 'org.newdawn.slick.Image'
5
3
  java_import 'org.newdawn.slick.Music'
6
4
  java_import 'org.newdawn.slick.Sound'
7
-
5
+
6
+ attr_accessor :base_path
7
+
8
8
  #Sets a default data directory path of "data".
9
9
  def load
10
10
  enable_listeners_for :resources_loaded
@@ -12,17 +12,20 @@ class ResourceManager < Jemini::GameObject
12
12
  @images = {}
13
13
  @sounds = {}
14
14
  @songs = {}
15
+ @base_path ||= choose_base_path
15
16
  end
16
17
 
17
18
  #Load resources for the given state.
18
19
  #Uses the current state if none specified.
19
- def load_resources(state_name = nil)
20
- state_name ||= game_state.name
21
- log.debug "Loading resources for state: #{state_name}"
22
- subdirectory = File.join(Jemini::Resource.base_path, state_name)
23
- log.debug "Looking for subdirectory: #{subdirectory}"
24
- load_directory(subdirectory) if File.directory?(subdirectory) || File.in_jar?(subdirectory)
25
- load_directory(Jemini::Resource.base_path, true)
20
+ def load_resources(state_name = game_state.name)
21
+ subdirectory = File.join(@base_path, state_name)
22
+ [subdirectory, @base_path].each do |directory|
23
+ begin
24
+ load_directory(directory)
25
+ rescue Errno::ENOENT
26
+ log.debug "#{directory} not found"
27
+ end
28
+ end
26
29
  notify :resources_loaded
27
30
  end
28
31
 
@@ -30,28 +33,28 @@ class ResourceManager < Jemini::GameObject
30
33
  def cache_config(key, path)
31
34
  log.debug "Caching config for #{key} with path: #{path}"
32
35
  log.warn "Skipping duplicate config for #{key} with path: #{path}" and return if @configs[key]
33
- @configs[key] = load_resource(path, :config)
36
+ @configs[key] = File.read(path)
34
37
  end
35
38
 
36
39
  #Load the image at the given path, and make it accessible via the given key.
37
40
  def cache_image(key, path)
38
41
  log.debug "Caching image for #{key} with path: #{path}"
39
42
  log.warn "Skipping duplicate image for #{key} with path: #{path}" and return if @images[key]
40
- @images[key] = load_resource(path, :image)
43
+ @images[key] = Image.new(strip_jar_path(path))
41
44
  end
42
45
 
43
46
  #Load the sound at the given path, and make it accessible via the given key.
44
47
  def cache_sound(key, path)
45
48
  log.debug "Caching sound for #{key} with path: #{path}"
46
49
  log.warn "Skipping duplicate sound for #{key} with path: #{path}" and return if @sounds[key]
47
- @sounds[key] = load_resource(path, :sound)
50
+ @sounds[key] = Sound.new(strip_jar_path(path))
48
51
  end
49
52
 
50
53
  #Load the song at the given path, and make it accessible via the given key.
51
54
  def cache_song(key, path)
52
55
  log.debug "Caching song for #{key} with path: #{path}"
53
56
  log.warn "Skipping duplicate song for #{key} with path: #{path}" and return if @songs[key]
54
- @songs[key] = load_resource(path, :music)
57
+ @songs[key] = Music.new(strip_jar_path(path))
55
58
  end
56
59
 
57
60
  #Get a config stored previously with cache_config.
@@ -66,10 +69,11 @@ class ResourceManager < Jemini::GameObject
66
69
  end
67
70
  alias_method :configs, :get_all_configs
68
71
 
72
+ #Get keys for all configurations stored previously with cache_config.
69
73
  def config_names
70
74
  @configs.keys
71
75
  end
72
-
76
+
73
77
  #Get an image stored previously with cache_image.
74
78
  def get_image(key)
75
79
  @images[key] or raise "Could not find image: #{key} - cached images: #{@images.keys}"
@@ -82,10 +86,11 @@ class ResourceManager < Jemini::GameObject
82
86
  end
83
87
  alias_method :images, :get_all_images
84
88
 
89
+ #Get keys for all images stored previously with cache_config.
85
90
  def image_names
86
91
  @images.keys
87
92
  end
88
-
93
+
89
94
  #Get a sound stored previously with cache_sound.
90
95
  def get_sound(key)
91
96
  @sounds[key] or raise "Could not find sound: #{key}"
@@ -111,77 +116,68 @@ class ResourceManager < Jemini::GameObject
111
116
  alias_method :songs, :get_all_songs
112
117
 
113
118
  private
114
-
115
- def load_resource(path, type_name)
116
- # due to some JRuby trickery involved with java_import, we can't use metaprogramming tricks here.
117
- case type_name
118
- when :config
119
- File.read(Jemini::Resource.path_of(path))
120
- when :image
121
- Image.new(Jemini::Resource.path_of(path))
122
- when :sound
123
- Sound.new(Jemini::Resource.path_of(path))
124
- when :music
125
- Music.new(Jemini::Resource.path_of(path))
126
- end
127
- end
128
-
129
- # root dirs can't be skipped
130
- def load_directory(directory, root = false)
131
- log.debug "Loading contents of #{directory}"
132
- begin
119
+
120
+ def load_directory(directory)
133
121
  resources_for(directory).each do |file|
134
122
  next if file =~ /^\./
135
- path = File.in_jar?(directory) ? file : File.join(directory, file)
136
- log.debug "Dir in jar? #{File.in_jar?(directory)}"
137
- log.debug "Using path #{path} for #{file}"
138
- extension = File.extname(file).downcase
139
- key = File.basename(file, extension).downcase.to_sym
140
- log.debug "Extension: #{extension}"
141
- case extension
142
- when '.png', '.gif'
143
- cache_image(key, path)
144
- when '.wav'
145
- cache_sound(key, path)
146
- when '.ogg'
147
- cache_song(key, path)
148
- when '.ini'
149
- cache_config(key, path)
150
- else
151
- log.warn "Skipping unknown file: #{path}"
152
- end
123
+ log.debug "directory: #{directory} file: #{file}"
124
+ load_file(File.join(directory, file))
153
125
  end
154
- rescue Errno::ENOENT => e
155
- if root
156
- raise
126
+ end
127
+
128
+ def load_file(file)
129
+ extension = File.extname(file)
130
+ key = File.basename(file, extension).downcase.to_sym
131
+ log.debug "Extension: #{extension}"
132
+ case extension.downcase
133
+ when '.png', '.gif'
134
+ cache_image(key, file)
135
+ when '.wav'
136
+ cache_sound(key, file)
137
+ when '.ogg'
138
+ cache_song(key, file)
139
+ when '.ini'
140
+ cache_config(key, file)
157
141
  else
158
- log.debug "#{directory} directory not found. Skipping."
142
+ log.warn "Skipping unknown file: #{file}"
159
143
  end
160
144
  end
161
- end
162
145
 
163
- def resources_for(directory)
164
- if File.in_jar?(directory)
165
- scan_entire_jar(directory)
166
- else
167
- log.debug "opening #{directory}"
168
- Dir.open(directory)
146
+ def resources_for(directory)
147
+ log.debug("resources_for(#{directory})")
148
+ if directory =~ /^(?:file\:)?(.*data\.jar)\!(.*)/
149
+ #Example: "/mygame/data.jar!/data/mystate/foo.png" - we need "data/mystate/" and "foo.png"
150
+ jar_path = $1
151
+ jarred_directory = $2.sub(/^[\\\/]/, '')
152
+ jar = java.util.jar.JarFile.new(jar_path)
153
+ jarred_directory_regex = Regexp.new("^#{jarred_directory}")
154
+ resources = jar.entries.map{|f| f.name} #Gives us all resources in jar.
155
+ resources = resources.select{|f| f =~ jarred_directory_regex} #Keep only entries under desired directory.
156
+ resources = resources.reject{|f| f =~ /#{jarred_directory}[\\\/](.*)[\\\/]/} #Discard entries in subdirectories of desired directory.
157
+ return resources.map{|f| File.basename(f)}
158
+ else
159
+ return Dir.open(directory)
160
+ end
161
+ end
162
+
163
+ def choose_base_path
164
+ #If running from jar, use data jar.
165
+ if $0 =~ /(\.jar!)|(^-$)/
166
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'data.jar!', 'data'))
167
+ #Otherwise use data directory.
168
+ else
169
+ 'data'
170
+ end
171
+ end
172
+
173
+ #If given path is within a jar, return only the path within the jar.
174
+ #Example: "/mygame/data.jar!/data/mystate/foo.png" - we need "data/mystate/foo.png"
175
+ def strip_jar_path(path)
176
+ if path =~ /\bdata\.jar\![\\\/](.*)$/
177
+ return $1
178
+ else
179
+ return path
180
+ end
169
181
  end
170
- end
171
182
 
172
- # globs MUST start at the base dir of the jar, or it won't work.
173
- def scan_entire_jar(directory)
174
- just_dir = File.basename(directory)
175
- log.debug "just dir: #{just_dir}"
176
- log.debug "dir: #{directory}"
177
- jar_name = File.jar_of(directory, 'data') # we're always going to get our data from the data jar
178
- log.debug "opening jar #{jar_name}"
179
- jar_file = java.util.jar.JarFile.new(jar_name)
180
- dir_regex = Regexp.new(just_dir)
181
- all_entries = jar_file.entries.map {|e| e.name }
182
- entries_under_directory = all_entries.select {|e| e =~ dir_regex }
183
- # need a shallow resultset
184
- entries_directly_under_directory = entries_under_directory.reject {|e| e =~ /#{just_dir}\/.*\//}
185
- entries_directly_under_directory
186
- end
187
183
  end
@@ -120,15 +120,16 @@ ENDL
120
120
  puts `rawr install #{@rawr_install_args} #{@project_dir}`
121
121
  build_config_path = File.join(@project_dir, 'build_configuration.rb')
122
122
  build_config = File.read build_config_path
123
- build_config.sub!('#c.java_library_path = "lib/java/native"', <<-CONFIG)
124
- c.java_library_path = "lib/java/native_files"'
123
+
124
+ #TODO: Fail on substitution failure.
125
+ build_config.sub!(/\#c.java_library_path = .*/, <<-CONFIG)
126
+ c.java_library_path = "lib/java/native_files"
125
127
  c.mac_icon_path = File.expand_path('icons/jemini.icns')
126
128
  c.windows_icon_path = File.expand_path('icons/jemini.ico')
127
129
  CONFIG
128
-
129
- build_config.sub!('#c.jvm_arguments = "-server"', 'c.jvm_arguments = "-XX:+UseConcMarkSweepGC -Djruby.compile.mode=FORCE -Xms256m -Xmx512m"')
130
- build_config.sub!(%Q{#c.jars[:data] = { :directory => 'data/images', :location_in_jar => 'images', :exclude => /bak/}}, %Q{c.jars[:data] = { :directory => 'data', :location_in_jar => 'data', :exclude => /bak/}})
131
- build_config.sub!(%Q{#c.files_to_copy = Dir['other_files/dir/**/*']}, %Q{c.files_to_copy = Dir['lib/java/native_files/**/*']})
130
+ build_config.sub!(/\#c.jvm_arguments = .*/, 'c.jvm_arguments = "-XX:+UseConcMarkSweepGC -Djruby.compile.mode=FORCE -Xms256m -Xmx512m"')
131
+ build_config.sub!(/\#c.extra_user_jars\[:data\] = \{.*?\}/m, %Q{c.extra_user_jars[:data] = { :directory => 'data', :location_in_jar => 'data', :exclude => /bak/}})
132
+ build_config.sub!(/\#c.files_to_copy = .*/, %Q{c.files_to_copy = Dir['lib/java/native_files/**/*']})
132
133
  File.open(build_config_path, 'w') {|f| f << build_config}
133
134
  end
134
135
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jemini
3
3
  version: !ruby/object:Gem::Version
4
- version: 2010.1.24
4
+ version: 2010.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Barnett, David Koontz, Jay McGavren
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-24 00:00:00 -07:00
12
+ date: 2010-02-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -18,9 +18,9 @@ dependencies:
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">="
21
+ - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.3.7
23
+ version: 1.3.9
24
24
  version:
25
25
  description: Jemini is a game library designed to allow creation of reusable features. How many times has someone implemented the aiming on a first person shooter, or a minimap on a real time strategy? Jemini comes packaged with lots of behaviors out of the box, with the ability to easily author more. Jemini uses Phys2D and Slick for physics and graphics, with 3D on the roadmap.
26
26
  email: logustus@gmail.com
@@ -34,7 +34,6 @@ files:
34
34
  - src/behavior.rb
35
35
  - src/behavior_event.rb
36
36
  - src/color.rb
37
- - src/file_system.rb
38
37
  - src/game.rb
39
38
  - src/game_object.rb
40
39
  - src/game_state.rb
@@ -47,7 +46,6 @@ files:
47
46
  - src/platform.rb
48
47
  - src/proc_enhancement.rb
49
48
  - src/project_generator.rb
50
- - src/resource.rb
51
49
  - src/spline.rb
52
50
  - src/vector.rb
53
51
  - src/behaviors/animated_image.rb
@@ -1,17 +0,0 @@
1
- class File
2
- def self.in_jar?(path)
3
- path =~ /(\.jar!)|(^-$)/
4
- end
5
-
6
- def self.jar_of(path, jar_name=nil)
7
- base_dir_plus_jar = path.split('.jar!').first
8
- if jar_name
9
- dirs = base_dir_plus_jar.split('/')
10
- base_dir_plus_jar = (dirs[0..dirs.size - 2] + ['data']).join('/')
11
- end
12
- # jar_name = base_dir_plus_jar.split('/').last
13
- # jar_name + '.jar'
14
- base_dir_plus_jar.sub('file:', '') + '.jar'
15
- end
16
-
17
- end
@@ -1,31 +0,0 @@
1
- module Jemini
2
- class Resource
3
- puts "+++++++++++++++++++"
4
- puts $0
5
- puts "In jar? #{File.in_jar?($0)}"
6
- puts "+++++++++++++++++++"
7
- # go up two dirs from lib/java
8
- @@base_path = File.in_jar?($0) ? File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'data.jar!', 'data')) : 'data'
9
-
10
- def self.base_path
11
- @@base_path
12
- end
13
-
14
- def self.path_of(file)
15
- #TODO: Find the JRuby classloader and use that?
16
- class_loader = org.newdawn.slick.geom.Vector2f.java_class.class_loader
17
- jarred_path = file
18
- dev_path = File.join('..', file)
19
-
20
- # log.debug "jarred path: #{jarred_path}"
21
- # log.debug "dev path: #{dev_path}"
22
- if class_loader.find_resource(jarred_path)
23
- jarred_path
24
- elsif File.exist?(dev_path)
25
- dev_path
26
- else
27
- jarred_path
28
- end
29
- end
30
- end
31
- end