dxruby_tiled 0.1.0 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 988c6ed19ed82d78b9ccc6b7008715bbfa3c77ba
4
- data.tar.gz: 10d757dfb2fc8fbad7096ad8e963a715b73cd655
3
+ metadata.gz: cd27950429183efee1a4e4d07287721db316cd78
4
+ data.tar.gz: 1e244202d39f8042946a6ceb8154df41431cac2f
5
5
  SHA512:
6
- metadata.gz: 4a9926855f6b9eb883a07277e17fb472541755b895dc498661b9e9ef4c7e07b5075dc56ade5d60cad263a04773fe8495ec96d8d67f1f49cc2d2dd5c3ffca7e40
7
- data.tar.gz: cbc1023393139166e5bc420605629ddff1237351d79e932ad03bb45dbfe8886ac3eb7f4a7af49abdf1b4404a40481c5d0651c324c9f4230cea0bcdb01f083a14
6
+ metadata.gz: 7a1a46fb7df4f548a7eb747c6e3fb5dfa821c028a0e20a683adca64f0e6416028300420080695343767b207043dddd2e6456e5db6e07d2be8c911a3d7d9fb131
7
+ data.tar.gz: 52429c08c3c4af7b288da425bd7fb458902593b58c6c6ed1d81e06d87333289d43b32384b7b6562fbc4f5dc7d4588faa2d7cd93be192661aacb78df992661694
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 TODO: Write your name
3
+ Copyright (c) 2017 TODO: nodai2hITC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.ja.md CHANGED
@@ -7,51 +7,42 @@
7
7
 
8
8
  $ gem install dxruby_tiled
9
9
 
10
-
11
10
  ## 使用方法
12
11
 
13
12
  require "dxruby_tiled"
14
13
 
15
- x, y = 0, 0
16
- map = DXRuby::Tiled.load_json("tiledmapeditorfile.json")
14
+ pos_x, pos_y = 0, 0
15
+ map = DXRuby::Tiled.load("tiledmapeditorfile.tmx")
17
16
 
18
17
  Window.loop do
19
- map.draw(x, y)
18
+ map.draw(pos_x, pos_y)
20
19
  end
21
20
 
22
21
  詳しくは、 examples/dxruby_tiled_test.rb 等をご参照あれ。
23
22
 
24
-
25
23
  ## カスタムプロパティ
26
24
 
27
- - map - x_loop, y_loop
28
- -- x方向、y方向に関してループするマップになります。
29
- - imagelayer - fixed
25
+ - map - loop
26
+ -- ループするマップになります。
27
+ - layer - fixed
30
28
  -- スクロールしない固定表示になります。
29
+ - imagelayer - x_loop, y_loop
30
+ -- x方向、y方向に関して画像をループ表示します。
31
31
 
32
32
  ## サポート状況
33
33
 
34
34
  ### サポート済
35
35
 
36
36
  - タイルレイヤー(□型、◇型、六角形型)
37
- - 画像レイヤー
38
- - タイルのアニメーション
39
-
40
- ### サポート予定
41
-
42
37
  - オブジェクトレイヤー
43
38
  - 当たり判定
44
-
45
- ### サポート予定なし
46
-
47
- - TMX ファイルの読み込み
48
-
39
+ - 画像レイヤー
40
+ - タイルのアニメーション
49
41
 
50
42
  ## Contributing
51
43
 
52
44
  Bug reports and pull requests are welcome on GitHub at https://github.com/nodai2hITC/dxruby_tiled.
53
45
 
54
-
55
46
  ## ライセンス
56
47
 
57
48
  [MIT License](http://opensource.org/licenses/MIT).
data/README.md CHANGED
@@ -12,11 +12,11 @@ DXRuby::Tiled is a ruby library that draw [Tiled Map Editor](http://www.mapedito
12
12
 
13
13
  require "dxruby_tiled"
14
14
 
15
- x, y = 0, 0
16
- map = DXRuby::Tiled.load_json("tiledmapeditorfile.json")
15
+ pos_x, pos_y = 0, 0
16
+ map = DXRuby::Tiled.load("tiledmapeditorfile.tmx")
17
17
 
18
18
  Window.loop do
19
- map.draw(x, y)
19
+ map.draw(pos_x, pos_y)
20
20
  end
21
21
 
22
22
  For more information, examples/dxruby_tiled_test.rb
@@ -24,8 +24,9 @@ For more information, examples/dxruby_tiled_test.rb
24
24
 
25
25
  ## Custom properties
26
26
 
27
- - map - x_loop, y_loop(bool)
28
- - imagelayer - fixed(bool)
27
+ - map - loop(bool)
28
+ - layer - fixed(bool)
29
+ - imagelayer - x_loop, y_loop(bool)
29
30
 
30
31
  ## Support status
31
32
 
@@ -33,17 +34,9 @@ For more information, examples/dxruby_tiled_test.rb
33
34
 
34
35
  - tile layer (orthogonal, isometric, staggered, hexagonal)
35
36
  - image layer
36
- - animation
37
-
38
- ### Will support
39
-
40
37
  - object layer
41
38
  - collision
42
-
43
- ### Unsupported
44
-
45
- - load .tmx file
46
-
39
+ - animation
47
40
 
48
41
  ## Contributing
49
42
 
data/dxruby_tiled.gemspec CHANGED
@@ -6,16 +6,14 @@ require 'dxruby_tiled/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "dxruby_tiled"
8
8
  spec.version = DXRuby::Tiled::VERSION
9
- spec.authors = ["nodai2h-ITC"]
9
+ spec.authors = ["nodai2hITC"]
10
+ spec.email = ["nodai2h.itc@gmail.com"]
10
11
 
11
- spec.summary = %q{Draw TiledMapEditor JSON data by using DXRuby.}
12
- spec.description = %q{Draw TiledMapEditor JSON data by using DXRuby.}
12
+ spec.summary = %q{Draw TiledMapEditor data by using DXRuby.}
13
+ spec.description = %q{Draw TiledMapEditor data by using DXRuby.}
13
14
  spec.homepage = "https://github.com/nodai2hITC/dxruby_tiled"
14
15
  spec.license = "MIT"
15
-
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
-
16
+
19
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
18
  f.match(%r{^(test|spec|features)/})
21
19
  end
@@ -23,9 +21,9 @@ Gem::Specification.new do |spec|
23
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
22
  spec.require_paths = ["lib"]
25
23
 
26
- spec.add_dependency 'dxruby'
27
- spec.add_dependency 'json'
24
+ spec.add_dependency 'dxruby', ">= 1.4.1"
28
25
 
29
26
  spec.add_development_dependency "bundler", "~> 1.14"
30
27
  spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "pry"
31
29
  end
@@ -1,83 +1,255 @@
1
1
  require "dxruby_tiled"
2
2
 
3
- puts "DXRuby::tiled example - ver 1.0.0"
4
- if ARGV[0] == "--help" || ARGV[0] == "-h"
5
- puts " usage: ruby dxruby_tiled_test.rb [jsonfile] [WindowWidth] [WindowHeight]"
6
- exit
7
- end
8
- puts "Arrow Key: move (pressing the Shift key, slowly move)"
9
- puts "M: Display the mouseover tile."
10
- puts "L: Display layers."
3
+ puts <<'EOS'
4
+ usage: ruby dxruby_tiled_test.rb (TiledMapEditorFile) (width) (height) (scale)
5
+
6
+ CURSOR KEY : move
7
+ LEFT_SHIFT : speed down
8
+ RIGHT_SHIFT: speed up
9
+ M : show/hidden the tile on mouse
10
+ L : show/hidden layers
11
+ I : show/hidden information
12
+ S : save screenshot
13
+ P : start pry
14
+ ESCAPE : exit
15
+ EOS
11
16
 
12
- filename = ARGV[0] || Window.open_filename([["JSONファイル(*.json)", "*.json"]], "Tiled Map Editor JSON ファイルを選択")
17
+ filename = ARGV[0] || Window.open_filename([["JSON file(*.json)", "*.json"], ["TMX file(*.tmx)", "*.tmx"]], "Select json|tmx file of TiledMapEditor")
13
18
  exit unless filename
14
19
 
15
- map = DXRuby::Tiled.load_json(filename)
20
+ map = Tiled.load(filename)
16
21
  Window.width = ARGV[1].to_i if ARGV[1]
17
22
  Window.height = ARGV[2].to_i if ARGV[2]
23
+ Window.scale = ARGV[3].to_i if ARGV[3]
18
24
 
19
- x, y = 0, 0
20
- draw_mouseovertile = true
21
- draw_layers = false
25
+ pos_x, pos_y = 0, 0
26
+ draw_mousetile = true
27
+ draw_layers = true
28
+ draw_information = true
22
29
 
23
30
  font = Font.new(16)
24
31
 
25
- mouseover_image = Image.new(32, 32, [128,128,128,255])
32
+ selected_image = Image.new(32, 32, [128, 128, 128, 255])
33
+ selected_layer = map.layers.find { |layer| layer.is_a?(DXRuby::Tiled::TileLayer) }
34
+
35
+ tilelayer_image = Image.load_from_file_in_memory(Base64.decode64(<<'EOS'
36
+ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgI
37
+ fAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3
38
+ Lmlua3NjYXBlLm9yZ5vuPBoAAABSSURBVDiN7ZOxDYBADAMviJ1gDJiHFuZh
39
+ DBiBVaiOjhrk9iOlcGErPimlkkwXuYEeYJy332ec+1IAqAzT6nHd737RKmpe
40
+ IQ4otTFoDGIGlb7zA0m5s1NGNVw4AAAAAElFTkSuQmCC
41
+ EOS
42
+ ))
43
+ objectgroup_image = Image.load_from_file_in_memory(Base64.decode64(<<'EOS'
44
+ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgI
45
+ fAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3
46
+ Lmlua3NjYXBlLm9yZ5vuPBoAAAInSURBVDiNhZLBaxNBFMa/mZ3NzLamFJIe
47
+ EuqmlTQR+i8Ie+hWaLGgB2+CB08BvagHJVARSSvYg7dcrCB48CCSHr00NRQE
48
+ L0KxVNxCc4siBLw0O5udHQ/thhi3+p0eb9778X2PIVprAEClWM1yztfDMLyh
49
+ lBI4lRDiwPf9h/XD2hYSRGLAnYuP1mcKhbtLS0upiYkJAIDWGt88D41GoxeG
50
+ Ya5+WPs1CqBxYRjGTcdxBssAQAhBuVTC+enpEMBykgMWF1rrlGVZSTMQQqQp
51
+ pa9ul1dfAgClVBJC3gRB8JgND8ZxRmUwhsuLi+b8/LwJAL7viw+t1i3P89KD
52
+ CJSQT57n/UVQSqHdbsO2bQghIITA5OQk3IUF1u/3rw8c+FI+2W42L33Z3z+X
53
+ yWQIARBpjfbREWZmZzE1NfUHeHx8HFEUmWTYdqVY5Yyxn47jpMcsCyAE+VwO
54
+ 2Ww2MVptbe3kiJViNY2TK1uGYfQLto1cLpe4FOv4+BiU0tD48bp/lTH20bbt
55
+ K/l8fllrbXU6HcO2bXDOz1xu7uyobrf7jnHOn66srIyVSyWcXhi7u7t4sbmJ
56
+ Xq+XCKCU9k3TfCulfMCklOXS3NzgUQgB13Xhum7i8rONjV4QBBee769+B05/
57
+ IiHkn3mHNTpLCSHqLKujUkpBhaEBIBgAUqnU1nazGf0PEgQBWq0WmGl+rh/W
58
+ unGfSSnvfT04UHt7e9eiKGJnAQghEef8ve/794f7vwF7CtF64Q/xTAAAAABJ
59
+ RU5ErkJggg==
60
+ EOS
61
+ ))
62
+ imagelayer_image = Image.load_from_file_in_memory(Base64.decode64(<<'EOS'
63
+ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/
64
+ AP+gvaeTAAAACXBIWXMAAAsRAAALEQF/ZF+RAAAAB3RJTUUH3AsPDAQNlVwX
65
+ bgAAAfVJREFUOMudk0trU0EUx39z781NbvMwaRKaPoImatPgQnyBWlAEv4Qb
66
+ 92IR6qpfQBALgi4U3IjfQBSMuhNcCCIISh4LpYW0GNNXTNLcR2faRWxtNYXU
67
+ gYEzB+Z3/vM/Z8Tde3fwmSae63KQZfr9bEgXDdj8z/0duGwkEkkuXphkIpdH
68
+ StlXdV3XKVdKmddvC0+NpaU6E7k8Dx7ex3GdvgCWZXFrapoXL59nDAApJY7r
69
+ 8PXzR9rtDrbtEI9HEUL0BJw4eXYnNrYDIWA4opBBH42mR6Pxg9ihENHIAM1W
70
+ h+CAH03T/oEZuw9Doa4HqXAATbOo1hqUywscHokxHDFxXIe5xVXi2X0AqfAf
71
+ Eyvzq5zKRqnV6pzPRQAJCObm13srEEDqt4J1e4PTGYsPxQXCptrJO67EwNsD
72
+ 2POo0UHFWFIxntbIjepcu5Sk+vMXdruJ22nxrFDh+pWh/T3ITJ7DiGXYWK7g
73
+ LFZQzQ6Pbxzn5qMyntzkyVSeYEDwrkrvLvjTV0Fo6KEsvnAE9e09IdPHmaNB
74
+ hBCMRLcHtwdASkm79qVLAmTHY60uwVYsNRUrLY/Fte5lqdRegK7rKKWYmS3+
75
+ 1eVjXXVHxokDs5+62bH0LgWD8TjlSonb0zPYtt3XKAesAKVyEZ9pYqwsL1N4
76
+ 8+rA3zmRTOK5Llttt8XxvDkmFQAAAABJRU5ErkJggg==
77
+ EOS
78
+ ))
79
+ grouplayer_image = Image.load_from_file_in_memory(Base64.decode64(<<'EOS'
80
+ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMUlEQVR4nGNg
81
+ GB5As2FnExD/R8MgMUt8GNmAeVgMIISb4AZ4rXvxnxw8asDwMmBoAwAE/3w0
82
+ rfjXvAAAAABJRU5ErkJggg==
83
+ EOS
84
+ ))
85
+ visible_image = Image.load_from_file_in_memory(Base64.decode64(<<'EOS'
86
+ iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgI
87
+ fAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3
88
+ Lmlua3NjYXBlLm9yZ5vuPBoAAAAZdEVYdFRpdGxlAElua3NjYXBlIEljb24g
89
+ VGhlbWXo4pAiAAAAFXRFWHRBdXRob3IAQmFyYmFyYSBNdXJhdXMulXEFAAAB
90
+ t0lEQVQokZ2SMW/aUBSFz40fxsJSKoGXbpaVdmTrUJmhSAxZGPkDgJBQZFaW
91
+ Lh34A6DKkiuB1NW/IFsZ7KEd2NvUuFJHHBGEa6s8v9epKWmiqsoZ7z1nOecD
92
+ Hil66NjpdNRarfYcAJIk+ez7/s9/BgeDQYWIXhPRhRDiFACI6EZK+RbAxPO8
93
+ H/eCvV7vTFXVSyGEZVmWNE2TACCOYxlFEWma9j3Lslee5329DQ6HQwvAR8Mw
94
+ qt1ulyqVCsIwBADYto39fo/FYoHNZnMN4IXrupHiOM6pEOKDYRhPx+OxAgCT
95
+ yQTtdhu+72O5XKLVaqHZbGK1WpXSND2v1+vvTzjnc0VRzkajEdN1HWEYIs9z
96
+ +L6PLMuQ5zmCIICu63AchzHGnjHG3jEppSSie+3Gcfynwb/eREQnpVKpB+Db
97
+ bDaTaZrCtm1omnZr0jQNtm0jTVNMp9MD5/zqcDj0j8v5VK1Wn/T7fUXXdQRB
98
+ AABoNBrY7XaYz+c8SZJrInrpum50Z45yuXxZFIVlWRZM0wQArNdrGUURMcau
99
+ OOfnd+Y4BkBV1TdCiCHnXP8vAI71G7miKOR2u/3yEHKP1i+7XcWPCZS65wAA
100
+ AABJRU5ErkJggg==
101
+ EOS
102
+ ))
103
+ hidden_image = Image.load_from_file_in_memory(Base64.decode64(<<'EOS'
104
+ iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgI
105
+ fAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3
106
+ Lmlua3NjYXBlLm9yZ5vuPBoAAAAZdEVYdFRpdGxlAElua3NjYXBlIEljb24g
107
+ VGhlbWXo4pAiAAAAFXRFWHRBdXRob3IAQmFyYmFyYSBNdXJhdXMulXEFAAAB
108
+ KElEQVQoke2QvUojYRiFn/clwgT/LiBgZRUVOys7BcG9ABc0hcV8qQKBIFgO
109
+ WIoXkNGpghYWC1tZyGLvHch2SgzYqIVEkG/ONilEyYK9T/2cc+DAN2OxZrN5
110
+ KGl+OBzu9Hq9l//JjUZjMkmSU3f/65IKYD1JkrMsy3xcKMsyr1arZ2a25u4n
111
+ bmZ14N7MNvv9/nWr1Zr5GAohzA4Ggz+SfgD3ZVkuWAhhzt1fy7K8AJYkPQPH
112
+ ZnYNYGYrkgIwBTwAqwAGkKbpkZk9AVfAJZB8GB2YWQHcAfVut9v2Uet+nucH
113
+ krYlddx9y8xugBz4FWNclPQzxvhb0h6AA+R5/jZqvq3VarmkaUnnlUqlAywX
114
+ RfEI7MYYy3fuZ9I03QghLI2OaYcQJsbKX+UfFzV3yJtNDmoAAAAASUVORK5C
115
+ YII=
116
+ EOS
117
+ ))
26
118
 
27
- max_tile_width = map.tilesets.tile_images.max{|image| image.width }.width
28
- max_tile_height = map.tilesets.tile_images.max{|image| image.height }.height
29
119
 
30
120
  Window.loop do
31
- x += Input.x * (!Input.key_down?(K_LSHIFT) ? 5 : 1)
32
- y += Input.y * (!Input.key_down?(K_LSHIFT) ? 5 : 1)
33
- map.draw(x, y)
34
-
35
- tilelayer = map.layers.find{|layer| layer.is_a? DXRuby::Tiled::Layer }
36
- pos_x, pos_y = tilelayer.xy_at(x + Input.mouse_x, y + Input.mouse_y)
37
- vertexs = tilelayer.vertexs(pos_x, pos_y)
38
- if vertexs.size == 4
39
- Window.draw_morph(vertexs[0][0] - x, vertexs[0][1] - y,
40
- vertexs[1][0] - x, vertexs[1][1] - y,
41
- vertexs[2][0] - x, vertexs[2][1] - y,
42
- vertexs[3][0] - x, vertexs[3][1] - y, mouseover_image)
121
+ d = 5
122
+ d = 1 if Input.key_down?(K_LSHIFT)
123
+ d = 20 if Input.key_down?(K_RSHIFT)
124
+ if Input.key_down?(K_LCONTROL)
125
+ pos_x -= d if Input.key_push?(K_LEFT)
126
+ pos_x += d if Input.key_push?(K_RIGHT)
127
+ pos_y -= d if Input.key_push?(K_UP)
128
+ pos_y += d if Input.key_push?(K_DOWN)
43
129
  else
44
- Window.draw_morph(vertexs[0][0] - x, vertexs[0][1] - y,
45
- vertexs[1][0] - x, vertexs[1][1] - y,
46
- vertexs[2][0] - x, vertexs[2][1] - y,
47
- vertexs[3][0] - x, vertexs[3][1] - y, mouseover_image)
48
- Window.draw_morph(vertexs[3][0] - x, vertexs[3][1] - y,
49
- vertexs[4][0] - x, vertexs[4][1] - y,
50
- vertexs[5][0] - x, vertexs[5][1] - y,
51
- vertexs[0][0] - x, vertexs[0][1] - y, mouseover_image)
130
+ pos_x += Input.x * d
131
+ pos_y += Input.y * d
132
+ end
133
+ map.draw(pos_x, pos_y)
134
+
135
+ mouse_x, mouse_y = pos_x + Input.mouse_x, pos_y + Input.mouse_y
136
+ tile_x, tile_y = nil, nil
137
+
138
+ # highlight selected tile
139
+ if selected_layer.is_a?(Tiled::TileLayer)
140
+ tile_x, tile_y = selected_layer.xy_at(mouse_x, mouse_y)
141
+ vertexs = selected_layer.vertexs(tile_x, tile_y)
142
+ if vertexs.size == 4
143
+ Window.draw_morph(vertexs[0][0] - pos_x, vertexs[0][1] - pos_y,
144
+ vertexs[1][0] - pos_x, vertexs[1][1] - pos_y,
145
+ vertexs[2][0] - pos_x, vertexs[2][1] - pos_y,
146
+ vertexs[3][0] - pos_x, vertexs[3][1] - pos_y, selected_image)
147
+ else
148
+ Window.draw_morph(vertexs[0][0] - pos_x, vertexs[0][1] - pos_y,
149
+ vertexs[1][0] - pos_x, vertexs[1][1] - pos_y,
150
+ vertexs[2][0] - pos_x, vertexs[2][1] - pos_y,
151
+ vertexs[3][0] - pos_x, vertexs[3][1] - pos_y, selected_image)
152
+ Window.draw_morph(vertexs[3][0] - pos_x, vertexs[3][1] - pos_y,
153
+ vertexs[4][0] - pos_x, vertexs[4][1] - pos_y,
154
+ vertexs[5][0] - pos_x, vertexs[5][1] - pos_y,
155
+ vertexs[0][0] - pos_x, vertexs[0][1] - pos_y, selected_image)
156
+ end
157
+ end
158
+
159
+ # draw information
160
+ draw_information = !draw_information if Input.key_push?(K_I)
161
+ if draw_information
162
+ Window.draw_box_fill(Window.width - 200, Window.height - 60, Window.width, Window.height, [192, 92, 92, 92])
163
+ text1 = "(pos_x, pos_y) = (#{mouse_x}, #{mouse_y})"
164
+ text2 = selected_layer.is_a?(Tiled::TileLayer) ? "[tile_x, tile_y] = [#{tile_x}, #{tile_y}]" : ""
165
+ text3 = selected_layer.is_a?(Tiled::TileLayer) ? "tileid = #{selected_layer[tile_x, tile_y]}" : ""
166
+ Window.draw_font(Window.width - 197 , Window.height - 57, text1, font, color: [0, 0, 0])
167
+ Window.draw_font(Window.width - 197 , Window.height - 37, text2, font, color: [0, 0, 0])
168
+ Window.draw_font(Window.width - 197 , Window.height - 17, text3, font, color: [0, 0, 0])
169
+ Window.draw_font(Window.width - 198 , Window.height - 58, text1, font, color: [255, 255, 255])
170
+ Window.draw_font(Window.width - 198 , Window.height - 38, text2, font, color: [255, 255, 255])
171
+ Window.draw_font(Window.width - 198 , Window.height - 18, text3, font, color: [255, 255, 255])
52
172
  end
53
173
 
54
- draw_mouseovertile = !draw_mouseovertile if Input.key_push?(K_M)
55
- if draw_mouseovertile
56
- Window.draw_box_fill(Window.width - max_tile_width - 8, 0, Window.width, max_tile_height + 8, [92,92,92])
57
- image = map.tilesets.tile_images[tilelayer[pos_x, pos_y]]
58
- Window.draw(Window.width - max_tile_width / 2 - image.width / 2 - 4,
59
- max_tile_height / 2 - image.height / 2 + 4, image)
174
+ # draw tile on mouse
175
+ draw_mousetile = !draw_mousetile if Input.key_push?(K_M)
176
+ if draw_mousetile && selected_layer.is_a?(Tiled::TileLayer)
177
+ tile = map.tilesets[selected_layer[tile_x, tile_y]]
178
+ Window.draw_box_fill(Window.width - tile.width - 8, 0, Window.width, tile.height + 8, [192, 92, 92, 92])
179
+ Window.draw_ex(Window.width - tile.image.width - 4, 4, tile.image,
180
+ scale_x: tile.scale_x, scale_y: tile.scale_y, angle: tile.angle)
60
181
  end
61
182
 
183
+ # draw layers
62
184
  draw_layers = !draw_layers if Input.key_push?(K_L)
63
185
  if draw_layers
64
- tmp_y = Window.height
65
- map.layers.each do |layer|
66
- tmp_y -= 20
67
- Window.draw_font(23 , tmp_y + 1, layer.name.to_s, font, color: [0,0,0])
68
- Window.draw_font(22 , tmp_y, layer.name.to_s, font)
69
- Window.draw_box_fill(2, tmp_y + 2, 18, tmp_y + 18, [255,255,255])
70
- Window.draw_box_fill(3, tmp_y + 3, 17, tmp_y + 17, [0,0,0])
71
-
72
- if layer.visible
73
- Window.draw_circle_fill(10, tmp_y + 10, 6, [255,255,255])
186
+ tmp_y = min_y = Window.height
187
+ max_x = 0
188
+ get_max_x_proc = Proc.new do |layers, x|
189
+ layers.each do |layer|
190
+ get_max_x_proc.call(layer, x + 20) if layer.is_a? DXRuby::Tiled::GroupLayer
191
+ tmp_max_x = x + font.get_width(layer.name.to_s) + 36
192
+ max_x = tmp_max_x if max_x < tmp_max_x
193
+ min_y -= 20
74
194
  end
75
- if Input.mouse_push?(M_LBUTTON) && Input.mouse_x >= 2 && Input.mouse_x <= 18 && Input.mouse_y >= tmp_y+2 && Input.mouse_y <= tmp_y+18
76
- layer.visible = !layer.visible
195
+ end
196
+ get_max_x_proc.call(map.layers, 2)
197
+ Window.draw_box_fill(0, min_y, max_x, Window.height, [192, 92, 92, 92])
198
+
199
+ draw_layer_proc = Proc.new do |layers, x|
200
+ layers.each do |layer|
201
+ draw_layer_proc.call(layer, x + 20) if layer.is_a? DXRuby::Tiled::GroupLayer
202
+ tmp_y -= 20
203
+ text_width = font.get_width(layer.name.to_s)
204
+ if selected_layer == layer
205
+ Window.draw_box_fill(x + 19, tmp_y + 2, x + text_width + 35, tmp_y + 18, [192, 92, 92, 255])
206
+ end
207
+ Window.draw(x + 19, tmp_y + 2,
208
+ case layer
209
+ when DXRuby::Tiled::TileLayer; tilelayer_image
210
+ when DXRuby::Tiled::ObjectGroup; objectgroup_image
211
+ when DXRuby::Tiled::ImageLayer; imagelayer_image
212
+ when DXRuby::Tiled::GroupLayer; grouplayer_image
213
+ end
214
+ )
215
+ Window.draw_font(x + 37, tmp_y + 3, layer.name.to_s, font, color: [0, 0, 0])
216
+ Window.draw_font(x + 36, tmp_y + 2, layer.name.to_s, font, color: [255, 255, 255])
217
+ Window.draw(x + 2, tmp_y + 4, layer.visible ? visible_image : hidden_image)
218
+
219
+ if Input.mouse_push?(M_LBUTTON) && ((tmp_y + 2)..(tmp_y + 18)).include?(Input.mouse_y)
220
+ if ((x)..(x + 16)).include?(Input.mouse_x)
221
+ layer.visible = !layer.visible
222
+ end
223
+
224
+ if ((x + 20)..(x + text_width + 1)).include?(Input.mouse_x)
225
+ selected_layer = layer if layer.is_a?(DXRuby::Tiled::TileLayer)
226
+ end
227
+ end
77
228
  end
78
229
  end
79
230
 
231
+ draw_layer_proc.call(map.layers, 2)
232
+ end
233
+
234
+ # save screenshot
235
+ if Input.key_push?(K_S)
236
+ Window.get_screen_shot("tmp", FORMAT_PNG)
237
+ save_filename = Window.save_filename( [["PNG file(*.png)", "*.png"]], "ScreenShot filename")
238
+ if save_filename
239
+ save_filename << ".png" unless save_filename =~ /\.png$/
240
+ File.rename("tmp", save_filename)
241
+ else
242
+ File.delete("tmp")
243
+ end
80
244
  end
81
245
 
82
246
  Window.caption = "DXRuby_tiled - FPS:#{Window.real_fps} FILE:#{filename}"
247
+
248
+ exit if Input.key_push?(K_ESCAPE)
249
+
250
+ # start pry
251
+ if Input.key_push?(K_P)
252
+ require "pry"
253
+ binding.pry
254
+ end
83
255
  end