meiro 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,92 @@
1
+ module Meiro
2
+ class TileManager
3
+ class << self
4
+ def set_tile_class(class_map)
5
+ @class_map ||= {}
6
+ @class_map.merge!(class_map)
7
+
8
+ [
9
+ RogueLikeTileManager,
10
+ DetailedTileManager,
11
+ ].each do |m|
12
+ m.clear_class_map
13
+ end
14
+ end
15
+
16
+ def class_map
17
+ @class_map || TileManager.instance_variable_get(:@class_map)
18
+ end
19
+
20
+ def clear_class_map
21
+ @class_map = nil
22
+ end
23
+
24
+ [
25
+ :wall,
26
+ :flat,
27
+ :gate,
28
+ :passage,
29
+ :binary_wall,
30
+
31
+ # for rogue_like
32
+ :l_wall,
33
+ :r_wall,
34
+ :t_wall,
35
+ :b_wall,
36
+
37
+ # for detail
38
+ :chipped_1,
39
+ :chipped_2,
40
+ :chipped_3,
41
+ :chipped_4,
42
+ :chipped_6,
43
+ :chipped_7,
44
+ :chipped_8,
45
+ :chipped_9,
46
+ :chipped_13,
47
+ :chipped_16,
48
+ :chipped_17,
49
+ :chipped_18,
50
+ :chipped_19,
51
+ :chipped_24,
52
+ :chipped_26,
53
+ :chipped_27,
54
+ :chipped_28,
55
+ :chipped_29,
56
+ :chipped_34,
57
+ :chipped_37,
58
+ :chipped_38,
59
+ :chipped_39,
60
+ :chipped_46,
61
+ :chipped_48,
62
+ :chipped_49,
63
+ :chipped_67,
64
+ :chipped_68,
65
+ :chipped_79,
66
+ :chipped_137,
67
+ :chipped_138,
68
+ :chipped_139,
69
+ :chipped_167,
70
+ :chipped_168,
71
+ :chipped_179,
72
+ :chipped_246,
73
+ :chipped_248,
74
+ :chipped_249,
75
+ :chipped_267,
76
+ :chipped_268,
77
+ :chipped_279,
78
+ :chipped_348,
79
+ :chipped_349,
80
+ :chipped_379,
81
+ :chipped_468,
82
+ :chipped_1379,
83
+ :chipped_2468,
84
+ ].each do |name|
85
+ define_method(name) { class_map[name] }
86
+ end
87
+
88
+ # def classify(tiles)
89
+ # end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,15 @@
1
+ module Meiro
2
+ class BinaryTileManager < TileManager
3
+ class << self
4
+ def classify(tiles)
5
+ target = tiles[1, 1]
6
+ klass = target.walkable? ? flat : binary_wall
7
+ if target.instance_of?(klass)
8
+ target
9
+ else
10
+ klass.new
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,347 @@
1
+ module Meiro
2
+ class DetailedTileManager < TileManager
3
+ class << self
4
+ def classify(tiles)
5
+ target = tiles[1, 1]
6
+ if target.walkable?
7
+ target
8
+ else
9
+ pattern = get_3x3_tile_pattern(tiles)
10
+ pattern_tile_map[pattern].new
11
+ end
12
+ end
13
+
14
+ def get_3x3_tile_pattern(tiles)
15
+ pattern = ""
16
+ tiles.each_tile do |x, y, tile|
17
+ if tile
18
+ s = tile.walkable? ? '1' : '0'
19
+ else
20
+ s = '0'
21
+ end
22
+ pattern << s
23
+ end
24
+ pattern.to_i(2)
25
+ end
26
+
27
+ # 3x3のタイルパターンから、中心のタイルが何に分類されるかを
28
+ # 示すマップを返す。1は歩行可能な床を、0は歩行不可能な床(壁)を意
29
+ # 味する。よって、
30
+ #
31
+ # 0b000_000_000 は
32
+ #
33
+ # 000
34
+ # 000
35
+ # 000
36
+ #
37
+ # を、すなわち9マス全て歩行不可能となっている状態を意味する。
38
+ def pattern_tile_map
39
+ @pattern_tile_map ||
40
+ @pattern_tile_map = {
41
+ 0b000_000_000 => wall,
42
+
43
+ 0b100_000_000 => chipped_1,
44
+
45
+ 0b010_000_000 => chipped_2,
46
+ 0b110_000_000 => chipped_2,
47
+ 0b011_000_000 => chipped_2,
48
+ 0b111_000_000 => chipped_2,
49
+
50
+ 0b001_000_000 => chipped_3,
51
+
52
+ 0b000_100_000 => chipped_4,
53
+ 0b100_100_000 => chipped_4,
54
+ 0b000_100_100 => chipped_4,
55
+ 0b100_100_100 => chipped_4,
56
+
57
+ 0b000_001_000 => chipped_6,
58
+ 0b001_001_000 => chipped_6,
59
+ 0b000_001_001 => chipped_6,
60
+ 0b001_001_001 => chipped_6,
61
+
62
+ 0b000_000_100 => chipped_7,
63
+
64
+ 0b000_000_010 => chipped_8,
65
+ 0b000_000_011 => chipped_8,
66
+ 0b000_000_110 => chipped_8,
67
+ 0b000_000_111 => chipped_8,
68
+
69
+ 0b000_000_001 => chipped_9,
70
+
71
+ 0b101_000_000 => chipped_13,
72
+
73
+ 0b100_001_000 => chipped_16,
74
+ 0b100_001_001 => chipped_16,
75
+ 0b101_001_000 => chipped_16,
76
+ 0b101_001_001 => chipped_16,
77
+
78
+ 0b100_000_100 => chipped_17,
79
+
80
+ 0b100_000_010 => chipped_18,
81
+ 0b100_000_011 => chipped_18,
82
+ 0b100_000_110 => chipped_18,
83
+ 0b100_000_111 => chipped_18,
84
+
85
+ 0b100_000_001 => chipped_19,
86
+
87
+ 0b010_100_000 => chipped_24,
88
+ 0b011_100_000 => chipped_24,
89
+ 0b110_100_000 => chipped_24,
90
+ 0b111_100_000 => chipped_24,
91
+ 0b010_100_100 => chipped_24,
92
+ 0b011_100_100 => chipped_24,
93
+ 0b110_100_100 => chipped_24,
94
+ 0b111_100_100 => chipped_24,
95
+
96
+ 0b010_001_000 => chipped_26,
97
+ 0b011_001_000 => chipped_26,
98
+ 0b110_001_000 => chipped_26,
99
+ 0b111_001_000 => chipped_26,
100
+ 0b010_001_001 => chipped_26,
101
+ 0b011_001_001 => chipped_26,
102
+ 0b110_001_001 => chipped_26,
103
+ 0b111_001_001 => chipped_26,
104
+
105
+ 0b010_000_100 => chipped_27,
106
+ 0b110_000_100 => chipped_27,
107
+ 0b011_000_100 => chipped_27,
108
+ 0b111_000_100 => chipped_27,
109
+
110
+ 0b010_000_010 => chipped_28,
111
+ 0b110_000_010 => chipped_28,
112
+ 0b011_000_010 => chipped_28,
113
+ 0b111_000_010 => chipped_28,
114
+ 0b010_000_011 => chipped_28,
115
+ 0b110_000_011 => chipped_28,
116
+ 0b011_000_011 => chipped_28,
117
+ 0b111_000_011 => chipped_28,
118
+ 0b010_000_110 => chipped_28,
119
+ 0b110_000_110 => chipped_28,
120
+ 0b011_000_110 => chipped_28,
121
+ 0b111_000_110 => chipped_28,
122
+ 0b010_000_111 => chipped_28,
123
+ 0b110_000_111 => chipped_28,
124
+ 0b011_000_111 => chipped_28,
125
+ 0b111_000_111 => chipped_28,
126
+
127
+ 0b010_000_001 => chipped_29,
128
+ 0b110_000_001 => chipped_29,
129
+ 0b011_000_001 => chipped_29,
130
+ 0b111_000_001 => chipped_29,
131
+
132
+ 0b001_100_000 => chipped_34,
133
+ 0b101_100_000 => chipped_34,
134
+ 0b001_100_100 => chipped_34,
135
+ 0b101_100_100 => chipped_34,
136
+
137
+ 0b001_000_100 => chipped_37,
138
+
139
+ 0b001_000_010 => chipped_38,
140
+ 0b001_000_110 => chipped_38,
141
+ 0b001_000_011 => chipped_38,
142
+ 0b001_000_111 => chipped_38,
143
+
144
+ 0b001_000_001 => chipped_39,
145
+
146
+ 0b000_101_000 => chipped_46,
147
+ 0b100_101_000 => chipped_46,
148
+ 0b000_101_100 => chipped_46,
149
+ 0b100_101_100 => chipped_46,
150
+ 0b001_101_000 => chipped_46,
151
+ 0b101_101_000 => chipped_46,
152
+ 0b001_101_100 => chipped_46,
153
+ 0b101_101_100 => chipped_46,
154
+ 0b000_101_001 => chipped_46,
155
+ 0b100_101_001 => chipped_46,
156
+ 0b000_101_101 => chipped_46,
157
+ 0b100_101_101 => chipped_46,
158
+ 0b001_101_001 => chipped_46,
159
+ 0b101_101_001 => chipped_46,
160
+ 0b001_101_101 => chipped_46,
161
+ 0b101_101_101 => chipped_46,
162
+
163
+ 0b000_100_010 => chipped_48,
164
+ 0b100_100_010 => chipped_48,
165
+ 0b000_100_110 => chipped_48,
166
+ 0b100_100_110 => chipped_48,
167
+ 0b000_100_011 => chipped_48,
168
+ 0b100_100_011 => chipped_48,
169
+ 0b000_100_111 => chipped_48,
170
+ 0b100_100_111 => chipped_48,
171
+
172
+ 0b000_100_001 => chipped_49,
173
+ 0b100_100_001 => chipped_49,
174
+ 0b000_100_101 => chipped_49,
175
+ 0b100_100_101 => chipped_49,
176
+
177
+ 0b000_001_100 => chipped_67,
178
+ 0b001_001_100 => chipped_67,
179
+ 0b000_001_101 => chipped_67,
180
+ 0b001_001_101 => chipped_67,
181
+
182
+ 0b000_001_010 => chipped_68,
183
+ 0b001_001_010 => chipped_68,
184
+ 0b000_001_011 => chipped_68,
185
+ 0b001_001_011 => chipped_68,
186
+ 0b000_001_110 => chipped_68,
187
+ 0b001_001_110 => chipped_68,
188
+ 0b000_001_111 => chipped_68,
189
+ 0b001_001_111 => chipped_68,
190
+
191
+ 0b000_000_101 => chipped_79,
192
+
193
+ 0b101_000_100 => chipped_137,
194
+
195
+ 0b101_000_010 => chipped_138,
196
+ 0b101_000_110 => chipped_138,
197
+ 0b101_000_011 => chipped_138,
198
+ 0b101_000_111 => chipped_138,
199
+
200
+ 0b101_000_001 => chipped_139,
201
+
202
+ 0b100_001_100 => chipped_167,
203
+ 0b101_001_100 => chipped_167,
204
+ 0b100_001_101 => chipped_167,
205
+ 0b101_001_101 => chipped_167,
206
+
207
+ 0b100_001_010 => chipped_168,
208
+ 0b101_001_010 => chipped_168,
209
+ 0b100_001_011 => chipped_168,
210
+ 0b101_001_011 => chipped_168,
211
+ 0b100_001_110 => chipped_168,
212
+ 0b101_001_110 => chipped_168,
213
+ 0b100_001_111 => chipped_168,
214
+ 0b101_001_111 => chipped_168,
215
+
216
+ 0b100_000_101 => chipped_179,
217
+
218
+ 0b010_101_000 => chipped_246,
219
+ 0b110_101_000 => chipped_246,
220
+ 0b011_101_000 => chipped_246,
221
+ 0b111_101_000 => chipped_246,
222
+ 0b010_101_100 => chipped_246,
223
+ 0b110_101_100 => chipped_246,
224
+ 0b011_101_100 => chipped_246,
225
+ 0b111_101_100 => chipped_246,
226
+ 0b010_101_001 => chipped_246,
227
+ 0b110_101_001 => chipped_246,
228
+ 0b011_101_001 => chipped_246,
229
+ 0b111_101_001 => chipped_246,
230
+ 0b010_101_101 => chipped_246,
231
+ 0b110_101_101 => chipped_246,
232
+ 0b011_101_101 => chipped_246,
233
+ 0b111_101_101 => chipped_246,
234
+
235
+ 0b010_100_010 => chipped_248,
236
+ 0b110_100_010 => chipped_248,
237
+ 0b011_100_010 => chipped_248,
238
+ 0b111_100_010 => chipped_248,
239
+ 0b010_100_110 => chipped_248,
240
+ 0b110_100_110 => chipped_248,
241
+ 0b011_100_110 => chipped_248,
242
+ 0b111_100_110 => chipped_248,
243
+ 0b010_100_011 => chipped_248,
244
+ 0b110_100_011 => chipped_248,
245
+ 0b011_100_011 => chipped_248,
246
+ 0b111_100_011 => chipped_248,
247
+ 0b010_100_111 => chipped_248,
248
+ 0b110_100_111 => chipped_248,
249
+ 0b011_100_111 => chipped_248,
250
+ 0b111_100_111 => chipped_248,
251
+
252
+ 0b010_100_001 => chipped_249,
253
+ 0b110_100_001 => chipped_249,
254
+ 0b011_100_001 => chipped_249,
255
+ 0b111_100_001 => chipped_249,
256
+ 0b010_100_101 => chipped_249,
257
+ 0b110_100_101 => chipped_249,
258
+ 0b011_100_101 => chipped_249,
259
+ 0b111_100_101 => chipped_249,
260
+
261
+ 0b010_001_100 => chipped_267,
262
+ 0b110_001_100 => chipped_267,
263
+ 0b011_001_100 => chipped_267,
264
+ 0b111_001_100 => chipped_267,
265
+ 0b010_001_101 => chipped_267,
266
+ 0b110_001_101 => chipped_267,
267
+ 0b011_001_101 => chipped_267,
268
+ 0b111_001_101 => chipped_267,
269
+
270
+ 0b010_001_010 => chipped_268,
271
+ 0b110_001_010 => chipped_268,
272
+ 0b011_001_010 => chipped_268,
273
+ 0b111_001_010 => chipped_268,
274
+ 0b010_001_110 => chipped_268,
275
+ 0b110_001_110 => chipped_268,
276
+ 0b011_001_110 => chipped_268,
277
+ 0b111_001_110 => chipped_268,
278
+ 0b010_001_011 => chipped_268,
279
+ 0b110_001_011 => chipped_268,
280
+ 0b011_001_011 => chipped_268,
281
+ 0b111_001_011 => chipped_268,
282
+ 0b010_001_111 => chipped_268,
283
+ 0b110_001_111 => chipped_268,
284
+ 0b011_001_111 => chipped_268,
285
+ 0b111_001_111 => chipped_268,
286
+
287
+ 0b010_000_101 => chipped_279,
288
+ 0b110_000_101 => chipped_279,
289
+ 0b011_000_101 => chipped_279,
290
+ 0b111_000_101 => chipped_279,
291
+
292
+ 0b001_100_010 => chipped_348,
293
+ 0b101_100_010 => chipped_348,
294
+ 0b001_100_110 => chipped_348,
295
+ 0b101_100_110 => chipped_348,
296
+ 0b001_100_011 => chipped_348,
297
+ 0b101_100_011 => chipped_348,
298
+ 0b001_100_111 => chipped_348,
299
+ 0b101_100_111 => chipped_348,
300
+
301
+ 0b001_100_001 => chipped_349,
302
+ 0b101_100_001 => chipped_349,
303
+ 0b001_100_101 => chipped_349,
304
+ 0b101_100_101 => chipped_349,
305
+
306
+ 0b001_000_101 => chipped_379,
307
+
308
+ 0b000_101_010 => chipped_468,
309
+ 0b100_101_010 => chipped_468,
310
+ 0b000_101_110 => chipped_468,
311
+ 0b100_101_110 => chipped_468,
312
+ 0b001_101_010 => chipped_468,
313
+ 0b101_101_010 => chipped_468,
314
+ 0b001_101_110 => chipped_468,
315
+ 0b101_101_110 => chipped_468,
316
+ 0b000_101_011 => chipped_468,
317
+ 0b100_101_011 => chipped_468,
318
+ 0b000_101_111 => chipped_468,
319
+ 0b100_101_111 => chipped_468,
320
+ 0b001_101_011 => chipped_468,
321
+ 0b101_101_011 => chipped_468,
322
+ 0b001_101_111 => chipped_468,
323
+ 0b101_101_111 => chipped_468,
324
+
325
+ 0b101_000_101 => chipped_1379,
326
+
327
+ 0b010_101_010 => chipped_2468,
328
+ 0b110_101_010 => chipped_2468,
329
+ 0b011_101_010 => chipped_2468,
330
+ 0b111_101_010 => chipped_2468,
331
+ 0b010_101_110 => chipped_2468,
332
+ 0b110_101_110 => chipped_2468,
333
+ 0b011_101_110 => chipped_2468,
334
+ 0b111_101_110 => chipped_2468,
335
+ 0b010_101_011 => chipped_2468,
336
+ 0b110_101_011 => chipped_2468,
337
+ 0b011_101_011 => chipped_2468,
338
+ 0b111_101_011 => chipped_2468,
339
+ 0b010_101_111 => chipped_2468,
340
+ 0b110_101_111 => chipped_2468,
341
+ 0b011_101_111 => chipped_2468,
342
+ 0b111_101_111 => chipped_2468,
343
+ }
344
+ end
345
+ end
346
+ end
347
+ end