tmxed 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 tmxed.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Franklin Webber
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,23 @@
1
+ # Tmxed
2
+
3
+ A library for parsing the **Tiled Map Editor** file format.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tmxed'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install tmxed
23
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ require 'ostruct'
2
+ require 'json'
3
+
4
+ require "tmxed/version"
5
+ require "tmxed/parsers/parsers"
6
+ require "tmxed/map"
7
+
8
+ module Tmxed
9
+ extend self
10
+
11
+ #
12
+ # Parse the specified TMX file and return a Map that was found.
13
+ #
14
+ def parse(filename,options={})
15
+ options[:format] = File.extname(filename)[1..-1] unless options[:format]
16
+ file_contents = File.read(filename)
17
+ contents = parser(options).parse(file_contents)
18
+ Map.new contents.merge(contents: contents)
19
+ end
20
+
21
+ private
22
+
23
+ def parser(options)
24
+ format = options[:format].to_sym
25
+ parsers[format].new(options)
26
+ end
27
+
28
+ def parsers
29
+ Parsers.parsers
30
+ end
31
+
32
+ end
@@ -0,0 +1,5 @@
1
+ module Tmxed
2
+ class Layer < OpenStruct
3
+
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'tile_set'
2
+ require_relative 'layer'
3
+
4
+ module Tmxed
5
+
6
+ class Map < OpenStruct
7
+ def layers
8
+ @layers ||= Array(contents['layers']).map {|layer| Layer.new layer.merge(contents: layer) }
9
+ end
10
+
11
+ def tilesets
12
+ @tilesets ||= Array(contents['tilesets']).map {|set| TileSet.new set.merge(contents: set) }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module Tmxed
2
+ module Parser
3
+
4
+ #
5
+ # Parses the JSON formatted output from Tiled.
6
+ #
7
+ class Json
8
+ attr_reader :options
9
+
10
+ def initialize(options)
11
+ @options = options
12
+ end
13
+
14
+ def parse(contents)
15
+ JSON.parse(contents)
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ Parsers.register :json, Parser::Json
22
+ end
@@ -0,0 +1,29 @@
1
+ module Tmxed
2
+
3
+ #
4
+ # This module defines the parsers for the formats of various
5
+ # TMX output formats.
6
+ #
7
+ module Parsers
8
+ extend self
9
+
10
+ def format(format)
11
+ parsers[format]
12
+ end
13
+
14
+ def parsers
15
+ @parsers ||= {}
16
+ end
17
+
18
+ def register(format,parser)
19
+ parsers[format] = parser
20
+ end
21
+
22
+ def default=(parser)
23
+ parsers.default = parser
24
+ end
25
+ end
26
+ end
27
+
28
+ require_relative 'unknown'
29
+ require_relative 'json'
@@ -0,0 +1,24 @@
1
+ module Tmxed
2
+ module Parser
3
+
4
+ #
5
+ # The Unknown Parser is used to generate an error when the format
6
+ # is not supported or unknown.
7
+ #
8
+ class Unknown
9
+ attr_reader :options
10
+
11
+ def initialize(options)
12
+ @options = options
13
+ end
14
+
15
+ def parse(contents)
16
+ raise "Unknown Parser Type: Could not find an available parser for format #{options[:format]}"
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ Parsers.default = Parser::Unknown
23
+
24
+ end
@@ -0,0 +1,5 @@
1
+ module Tmxed
2
+ class TileSet < OpenStruct
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Tmxed
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tmxed/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "tmxed"
8
+ gem.version = Tmxed::VERSION
9
+ gem.authors = ["Franklin Webber"]
10
+ gem.email = ["franklin.webber@gmail.com"]
11
+ gem.description = %q{A library for parsing the Tiled Map Editor file format.}
12
+ gem.summary = %q{A library for parsing the Tiled Map Editor file format.}
13
+ gem.homepage = "https://github.com/burtlo/tmxed"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tmxed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Franklin Webber
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A library for parsing the Tiled Map Editor file format.
15
+ email:
16
+ - franklin.webber@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/tmxed.rb
27
+ - lib/tmxed/layer.rb
28
+ - lib/tmxed/map.rb
29
+ - lib/tmxed/parsers/json.rb
30
+ - lib/tmxed/parsers/parsers.rb
31
+ - lib/tmxed/parsers/unknown.rb
32
+ - lib/tmxed/tile_set.rb
33
+ - lib/tmxed/version.rb
34
+ - tmxed.gemspec
35
+ homepage: https://github.com/burtlo/tmxed
36
+ licenses:
37
+ - MIT
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.24
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: A library for parsing the Tiled Map Editor file format.
60
+ test_files: []
61
+ has_rdoc: