tmx 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/tmx.rb +3 -1
- data/lib/tmx/parsers/tmx.rb +22 -3
- data/lib/tmx/version.rb +1 -1
- data/spec/features/xml_source_tileset_spec.rb +45 -0
- data/spec/fixtures/map-source-tileset.tmx +9 -0
- data/spec/fixtures/tileset.tsx +4 -0
- metadata +13 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2269a75b8e1f1dd7ce9a4ac399cae4a3538ad5df
|
4
|
+
data.tar.gz: 98f6cb5462d7245e495595dbf851cc1458fee5e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc07f67ec4b9bd782be6c2749ab34424f0ab165e467afb6504d1c46edc7384406e2ba5f62e73c54d70bde545eb6e7d9f42da9399f3c1db96c34ad9094def1477
|
7
|
+
data.tar.gz: 52caa2aef41c92361b404bfaae226d68cb9255b8eab2827c202e75288f4f8e4a3a3874f33a6e4ebcf7547901df4a4122e9b6d98c9274a053fa952d6e4cb38a26
|
data/lib/tmx.rb
CHANGED
@@ -17,7 +17,9 @@ module Tmx
|
|
17
17
|
#
|
18
18
|
def load(filename,options={})
|
19
19
|
options = default_options(filename).merge(options)
|
20
|
-
|
20
|
+
|
21
|
+
# Pass :filename in options for resolving relative "source" paths
|
22
|
+
parse contents(filename), options.merge(:filename => filename)
|
21
23
|
end
|
22
24
|
|
23
25
|
#
|
data/lib/tmx/parsers/tmx.rb
CHANGED
@@ -66,7 +66,7 @@ module Tmx
|
|
66
66
|
|
67
67
|
layer_hash["type"] = layer_attr(layer,"type",default: "tilelayer")
|
68
68
|
layer_hash["opacity"] = layer_attr(layer,"opacity",default: 1.0).to_f
|
69
|
-
layer_hash["visible"] = (layer.xpath("@visible").text
|
69
|
+
layer_hash["visible"] = to_boolean(layer.xpath("@visible").text)
|
70
70
|
|
71
71
|
layer_hash["x"] = layer.xpath("@x").text.to_i
|
72
72
|
layer_hash["y"] = layer.xpath("@y").text.to_i
|
@@ -118,12 +118,29 @@ module Tmx
|
|
118
118
|
data.unpack("V" * (data.length / 4))
|
119
119
|
end
|
120
120
|
|
121
|
+
def to_boolean(text)
|
122
|
+
![ "false", "0" ].include?(text)
|
123
|
+
end
|
124
|
+
|
121
125
|
def map_tilesets(xml)
|
122
126
|
xml.xpath("map/tileset").map do |tileset|
|
127
|
+
# Firstgid is usually set in the main file,
|
128
|
+
# even if a tileset is read from a separate file.
|
129
|
+
firstgid = tileset.xpath("@firstgid").text.to_i
|
130
|
+
|
131
|
+
source = tileset.xpath("@source")
|
132
|
+
if source && source.size > 0
|
133
|
+
this_dir = @options[:filename] ? File.dirname(@options[:filename]) : "."
|
134
|
+
tileset_path = File.join(this_dir, source.text)
|
135
|
+
contents = File.read(tileset_path)
|
136
|
+
results = Nokogiri::XML(contents)
|
137
|
+
tileset = results.xpath("tileset")
|
138
|
+
end
|
139
|
+
|
123
140
|
image = tileset.xpath("image")
|
124
141
|
|
125
142
|
properties = {
|
126
|
-
"firstgid" => tileset.xpath("@firstgid").text.to_i,
|
143
|
+
"firstgid" => firstgid || tileset.xpath("@firstgid").text.to_i,
|
127
144
|
"name" => tileset.xpath("@name").text,
|
128
145
|
"tilewidth" => tileset.xpath("@tilewidth").text.to_i,
|
129
146
|
"tileheight" => tileset.xpath("@tileheight").text.to_i,
|
@@ -132,6 +149,8 @@ module Tmx
|
|
132
149
|
"image" => image.xpath("@source").text,
|
133
150
|
"imageheight" => image.xpath("@height").text.to_i,
|
134
151
|
"imagewidth" => image.xpath("@width").text.to_i,
|
152
|
+
# "imagetrans" is a color to treat as transparent, like "ff00ff" for magenta.
|
153
|
+
"imagetrans" => image.xpath("@trans").text,
|
135
154
|
"properties" => properties(xml)
|
136
155
|
}
|
137
156
|
end
|
@@ -148,7 +167,7 @@ module Tmx
|
|
148
167
|
"y" => object.xpath("@y").text.to_i,
|
149
168
|
"width" => object.xpath("@width").text.to_i,
|
150
169
|
"height" => object.xpath("@height").text.to_i,
|
151
|
-
"visible" => (object.xpath("@visible").text
|
170
|
+
"visible" => to_boolean(object.xpath("@visible").text),
|
152
171
|
"properties" => properties(object)
|
153
172
|
}
|
154
173
|
|
data/lib/tmx/version.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tmx, "Map with Source Tileset" do
|
4
|
+
|
5
|
+
let(:fixture_file) { File.join File.dirname(__FILE__), "..", "fixtures", "map-source-tileset.tmx" }
|
6
|
+
|
7
|
+
let(:map) do
|
8
|
+
described_class.load(fixture_file)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:subject) { map }
|
12
|
+
|
13
|
+
its(:width) { should eq 10 }
|
14
|
+
its(:height) { should eq 20 }
|
15
|
+
its(:tilewidth) { should eq 32 }
|
16
|
+
its(:tileheight) { should eq 32 }
|
17
|
+
|
18
|
+
describe '#layers' do
|
19
|
+
it "has the correct number of layers" do
|
20
|
+
expect(subject.layers).to have(1).item
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#tilesets' do
|
25
|
+
it "has the correct number of tilesets" do
|
26
|
+
expect(subject.tilesets).to have(1).item
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when evaluating the first tileset" do
|
30
|
+
let(:subject) { map.tilesets.first }
|
31
|
+
|
32
|
+
its(:firstgid) { should eq 1 }
|
33
|
+
its(:image) { should eq "tiles.png" }
|
34
|
+
its(:imageheight) { should eq 400 }
|
35
|
+
its(:imagewidth) { should eq 640 }
|
36
|
+
its(:margin) { should eq 0 }
|
37
|
+
its(:spacing) { should eq 2 }
|
38
|
+
its(:tileheight) { should eq 32 }
|
39
|
+
its(:tilewidth) { should eq 32 }
|
40
|
+
its(:properties) { should eq({}) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<map version="1.0" orientation="orthogonal" width="10" height="20" tilewidth="32" tileheight="32">
|
3
|
+
<tileset firstgid="1" source="tileset.tsx"> </tileset>
|
4
|
+
<layer name="Tile Layer 1" width="10" height="20">
|
5
|
+
<data encoding="base64" compression="zlib">
|
6
|
+
eJxjZmBgYIZiRjTMhISZR9WNqhuB6gBbPgF9
|
7
|
+
</data>
|
8
|
+
</layer>
|
9
|
+
</map>
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tmx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Shawn Anderson
|
@@ -10,12 +9,11 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2013-
|
12
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: multi_json
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
18
|
- - ~>
|
21
19
|
- !ruby/object:Gem::Version
|
@@ -23,7 +21,6 @@ dependencies:
|
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
25
|
- - ~>
|
29
26
|
- !ruby/object:Gem::Version
|
@@ -31,7 +28,6 @@ dependencies:
|
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: nokogiri
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
32
|
- - ~>
|
37
33
|
- !ruby/object:Gem::Version
|
@@ -39,7 +35,6 @@ dependencies:
|
|
39
35
|
type: :runtime
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
39
|
- - ~>
|
45
40
|
- !ruby/object:Gem::Version
|
@@ -78,11 +73,13 @@ files:
|
|
78
73
|
- spec/features/xml_format_spec.rb
|
79
74
|
- spec/features/xml_isometric_spec.rb
|
80
75
|
- spec/features/xml_isometric_staggered_spec.rb
|
76
|
+
- spec/features/xml_source_tileset_spec.rb
|
81
77
|
- spec/fixtures/iso.png
|
82
78
|
- spec/fixtures/map-isometric-staggered.json
|
83
79
|
- spec/fixtures/map-isometric-staggered.tmx
|
84
80
|
- spec/fixtures/map-isometric.json
|
85
81
|
- spec/fixtures/map-isometric.tmx
|
82
|
+
- spec/fixtures/map-source-tileset.tmx
|
86
83
|
- spec/fixtures/map.json
|
87
84
|
- spec/fixtures/map_csv.tmx
|
88
85
|
- spec/fixtures/map_gzip.tmx
|
@@ -90,32 +87,32 @@ files:
|
|
90
87
|
- spec/fixtures/map_xml.tmx
|
91
88
|
- spec/fixtures/map_zlib.tmx
|
92
89
|
- spec/fixtures/tiles.png
|
90
|
+
- spec/fixtures/tileset.tsx
|
93
91
|
- spec/spec_helper.rb
|
94
92
|
- tmx.gemspec
|
95
93
|
homepage: https://github.com/shawn42/tmx
|
96
94
|
licenses:
|
97
95
|
- MIT
|
96
|
+
metadata: {}
|
98
97
|
post_install_message:
|
99
98
|
rdoc_options: []
|
100
99
|
require_paths:
|
101
100
|
- lib
|
102
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
-
none: false
|
104
102
|
requirements:
|
105
|
-
- -
|
103
|
+
- - '>='
|
106
104
|
- !ruby/object:Gem::Version
|
107
105
|
version: '0'
|
108
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
107
|
requirements:
|
111
|
-
- -
|
108
|
+
- - '>='
|
112
109
|
- !ruby/object:Gem::Version
|
113
110
|
version: '0'
|
114
111
|
requirements: []
|
115
112
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 2.1.9
|
117
114
|
signing_key:
|
118
|
-
specification_version:
|
115
|
+
specification_version: 4
|
119
116
|
summary: A library for parsing the Tiled Map Editor file format.
|
120
117
|
test_files:
|
121
118
|
- spec/features/json_format_spec.rb
|
@@ -125,11 +122,13 @@ test_files:
|
|
125
122
|
- spec/features/xml_format_spec.rb
|
126
123
|
- spec/features/xml_isometric_spec.rb
|
127
124
|
- spec/features/xml_isometric_staggered_spec.rb
|
125
|
+
- spec/features/xml_source_tileset_spec.rb
|
128
126
|
- spec/fixtures/iso.png
|
129
127
|
- spec/fixtures/map-isometric-staggered.json
|
130
128
|
- spec/fixtures/map-isometric-staggered.tmx
|
131
129
|
- spec/fixtures/map-isometric.json
|
132
130
|
- spec/fixtures/map-isometric.tmx
|
131
|
+
- spec/fixtures/map-source-tileset.tmx
|
133
132
|
- spec/fixtures/map.json
|
134
133
|
- spec/fixtures/map_csv.tmx
|
135
134
|
- spec/fixtures/map_gzip.tmx
|
@@ -137,5 +136,5 @@ test_files:
|
|
137
136
|
- spec/fixtures/map_xml.tmx
|
138
137
|
- spec/fixtures/map_zlib.tmx
|
139
138
|
- spec/fixtures/tiles.png
|
139
|
+
- spec/fixtures/tileset.tsx
|
140
140
|
- spec/spec_helper.rb
|
141
|
-
has_rdoc:
|