gosu_texture_packer 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/examples/random_map.rb +1 -1
- data/lib/gosu_texture_packer.rb +2 -2
- data/lib/gosu_texture_packer/tileset.rb +22 -7
- data/lib/gosu_texture_packer/version.rb +1 -1
- data/spec/gosu_texture_packer/tileset_spec.rb +45 -31
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 046d95ce5242ce706baeace9c3f6c19352653e69
|
4
|
+
data.tar.gz: e42056791386d088d652c4aa92b1e88e3870b058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4c5d8fe9097783475afc48cceab860d3e69ddeafdbbc1c00f9e2e566541f1bb8fcc8d8806888ea8fbb1ad1b5a41291f253c79d19f6959b0675428ae72eaa9e7
|
7
|
+
data.tar.gz: fe16383639f2bd4fb094c4f34498eeb5d8b5850eec8d847d3ba5d4d4b974575f9b0918bf33fe31ad6a1d00cb8593871f096abd500c146bb6f9a46535f4a80a46
|
data/README.md
CHANGED
@@ -28,6 +28,17 @@ tile = tileset.frame(frame_names.first)
|
|
28
28
|
tile.draw(0, 0, 0) # tile is Gosu::Image
|
29
29
|
```
|
30
30
|
|
31
|
+
You may find that your tiles have "bleeding edges" when you stack them together. To avoid that,
|
32
|
+
either use `--extrude 1` or `--reduce-border-artifacts` when exporting Texture Packer tileset, or
|
33
|
+
provide `:precise` mode parameter to `load_json`:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
tileset = Gosu::TexturePacker.load_json(gosu_window, '/path/to/tileset.json', :precise)
|
37
|
+
```
|
38
|
+
|
39
|
+
However, loading with `:precise` mode will significantly increase memory consumption and reduce
|
40
|
+
load time, so use it carefully.
|
41
|
+
|
31
42
|
## Example Code
|
32
43
|
|
33
44
|
Run
|
data/examples/random_map.rb
CHANGED
@@ -14,7 +14,7 @@ class GameWindow < Gosu::Window
|
|
14
14
|
super(WIDTH, HEIGHT, false)
|
15
15
|
self.caption = 'Click space to toggle random redraws'
|
16
16
|
json_path = File.join(ROOT_DIR, 'spec', 'files', 'ground.json')
|
17
|
-
@tileset = Gosu::TexturePacker.load_json(self, json_path)
|
17
|
+
@tileset = Gosu::TexturePacker.load_json(self, json_path, :precise)
|
18
18
|
end
|
19
19
|
|
20
20
|
def needs_cursor?
|
data/lib/gosu_texture_packer.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'rmagick'
|
3
2
|
module Gosu
|
4
3
|
module TexturePacker
|
5
4
|
class Tileset
|
6
5
|
|
7
|
-
def self.load_json(window, json)
|
8
|
-
self.new(window, json)
|
6
|
+
def self.load_json(window, json, mode = :fast)
|
7
|
+
self.new(window, json, mode)
|
9
8
|
end
|
10
9
|
|
11
|
-
def initialize(window, json)
|
10
|
+
def initialize(window, json, mode)
|
11
|
+
@mode = mode
|
12
12
|
@window = window
|
13
13
|
@json = JSON.parse(File.read(json))
|
14
14
|
@source_dir = File.dirname(json)
|
15
|
-
@main_image =
|
15
|
+
@main_image = build_main_image(mode)
|
16
16
|
@tile_cache = {}
|
17
17
|
end
|
18
18
|
|
@@ -33,8 +33,24 @@ module Gosu
|
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
+
def build_main_image(mode)
|
37
|
+
case mode
|
38
|
+
when :fast
|
39
|
+
Gosu::Image.new(@window, image_file, true)
|
40
|
+
when :precise
|
41
|
+
require 'rmagick' unless defined?(Magick)
|
42
|
+
Magick::ImageList.new(image_file).first
|
43
|
+
else
|
44
|
+
raise "Unsupported mode #{mode}. Use :fast or :precise."
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
36
48
|
def build_tile(f)
|
37
|
-
|
49
|
+
if @mode == :fast
|
50
|
+
@main_image.subimage(f['x'], f['y'], f['w'], f['h'])
|
51
|
+
else
|
52
|
+
Gosu::Image.new(@window, @main_image, true, f['x'], f['y'], f['w'], f['h'])
|
53
|
+
end
|
38
54
|
end
|
39
55
|
|
40
56
|
def image_file
|
@@ -48,7 +64,6 @@ module Gosu
|
|
48
64
|
def frames
|
49
65
|
@json['frames']
|
50
66
|
end
|
51
|
-
|
52
67
|
end
|
53
68
|
end
|
54
69
|
end
|
@@ -7,51 +7,65 @@ RSpec.describe Gosu::TexturePacker::Tileset do
|
|
7
7
|
let(:game_window) { Gosu::Window.new(640, 480, false) }
|
8
8
|
let(:target_frame) { 'alientech.png' }
|
9
9
|
let(:tileset) { File.join(media_dir, '_UI.json') }
|
10
|
+
let(:mode) { :fast }
|
10
11
|
|
11
12
|
subject(:instance) do
|
12
|
-
tileset_class.load_json(game_window, tileset)
|
13
|
+
tileset_class.load_json(game_window, tileset, mode)
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
shared_examples 'tileset' do
|
17
|
+
|
18
|
+
describe '.load_json' do
|
19
|
+
it 'loads existing file' do
|
20
|
+
expect { subject }.to_not raise_error
|
21
|
+
end
|
18
22
|
end
|
19
|
-
end
|
20
23
|
|
21
|
-
|
22
|
-
|
24
|
+
describe '#frame_list' do
|
25
|
+
subject(:frame_list) { instance.frame_list }
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
it 'contains all the frames' do
|
28
|
+
expect(frame_list.size).to be 514
|
29
|
+
end
|
27
30
|
|
28
|
-
|
29
|
-
|
31
|
+
it 'includes target frame' do
|
32
|
+
expect(frame_list).to include target_frame
|
33
|
+
end
|
30
34
|
end
|
31
|
-
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
# Frame format in JSON:
|
37
|
+
# {"frame"=>{"x"=>129, "y"=>0, "w"=>32, "h"=>32}, "rotated"=>false, "trimmed"=>false,
|
38
|
+
# "spriteSourceSize"=>{"x"=>0, "y"=>0, "w"=>32, "h"=>32}, "sourceSize"=>{"w"=>32, "h"=>32}}
|
39
|
+
describe '#frame' do
|
40
|
+
subject(:loaded_frame) { instance.frame(target_frame) }
|
41
|
+
let(:source_size) { instance.send(:frames)[target_frame]['sourceSize'] }
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
it 'loads' do
|
44
|
+
expect { subject }.to_not raise_error
|
45
|
+
end
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
it 'produces a Gosu::Image' do
|
48
|
+
should be_a(Gosu::Image)
|
49
|
+
end
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
it 'produces correctly sized image' do
|
52
|
+
expect(loaded_frame.width).to be source_size['w']
|
53
|
+
expect(loaded_frame.height).to be source_size['h']
|
54
|
+
end
|
52
55
|
|
53
|
-
|
54
|
-
|
56
|
+
it 'caches the image' do
|
57
|
+
expect(instance.frame(target_frame)).to eq instance.frame(target_frame)
|
58
|
+
end
|
55
59
|
end
|
56
60
|
end
|
61
|
+
|
62
|
+
context 'default mode' do
|
63
|
+
it_behaves_like 'tileset'
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'precise mode' do
|
67
|
+
let(:mode) { :precise }
|
68
|
+
it_behaves_like 'tileset'
|
69
|
+
end
|
70
|
+
|
57
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gosu_texture_packer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Varaneckas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|