Browse code

Merge pull request #220 from stefanbeller/multipleLayerRules

Automapping: 2 bugfixes and an updated sewers example.

Thorbjørn Lindeijer authored on 09/06/2012 20:13:40
Showing 7 changed files
... ...
@@ -26,23 +26,4 @@
26 26
    eJxjYMAPeKG0DJRWIqAeBAAMkABM
27 27
   </data>
28 28
  </layer>
29
- <layer name="Output_Over" width="7" height="3">
30
-  <data encoding="base64" compression="zlib">
31
-   eJxjYKA+AAAAVAAB
32
-  </data>
33
- </layer>
34
- <layer name="Output_Over2" width="7" height="3">
35
-  <data encoding="base64" compression="zlib">
36
-   eJxjYKA+AAAAVAAB
37
-  </data>
38
- </layer>
39
- <objectgroup name="Output_Effect" width="7" height="3">
40
-  <object name="StinkingAcid" type="DMG" x="80" y="34">
41
-   <properties>
42
-    <property name="DamagePerSecond" value="1"/>
43
-    <property name="anotherValue" value=""/>
44
-   </properties>
45
-   <polygon points="0,0 8,-6 9,9 2,8"/>
46
-  </object>
47
- </objectgroup>
48 29
 </map>
... ...
@@ -27,13 +27,4 @@
27 27
    eJxjYCAesBKQ5yXBLGoBAAmIABM=
28 28
   </data>
29 29
  </layer>
30
- <objectgroup name="Output_Effect" width="8" height="6">
31
-  <object name="NearRightWall" type="INFORMATION" x="120" y="24" width="24" height="24">
32
-   <properties>
33
-    <property name="anotherValue" value=""/>
34
-    <property name="informationType" value="useless"/>
35
-    <property name="predefinedValue" value=""/>
36
-   </properties>
37
-  </object>
38
- </objectgroup>
39 30
 </map>
40 31
new file mode 100644
... ...
@@ -0,0 +1,35 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE map SYSTEM "http://mapeditor.org/dtd/1.0/map.dtd">
3
+<map version="1.0" orientation="orthogonal" width="4" height="4" tilewidth="24" tileheight="24">
4
+ <properties>
5
+  <property name="NoOverlappingRules" value="1"/>
6
+ </properties>
7
+ <tileset firstgid="1" name="sewer_tileset" tilewidth="24" tileheight="24">
8
+  <image source="../sewer_tileset.png" trans="ff00ff" width="192" height="217"/>
9
+ </tileset>
10
+ <tileset firstgid="73" name="rules_sewers" tilewidth="24" tileheight="24">
11
+  <image source="rules_sewers.png" width="72" height="48"/>
12
+ </tileset>
13
+ <layer name="regions_input" width="4" height="4">
14
+  <data encoding="base64" compression="zlib">
15
+   eJxjYCAMfKAYGwAAD7AAmQ==
16
+  </data>
17
+ </layer>
18
+ <layer name="regions_output" width="4" height="4">
19
+  <data encoding="base64" compression="zlib">
20
+   eJxjYMAEPljEcAEADVAATQ==
21
+  </data>
22
+ </layer>
23
+ <layer name="input_Over" width="4" height="4">
24
+  <data encoding="base64" compression="zlib">
25
+   eJxjYCAMWICYF4ccAAHoABI=
26
+  </data>
27
+ </layer>
28
+ <objectgroup name="output_GroundEffects" width="4" height="4">
29
+  <object name="1" type="Effect" x="24" y="24" width="24" height="24">
30
+   <properties>
31
+    <property name="predefined Value" value=""/>
32
+   </properties>
33
+  </object>
34
+ </objectgroup>
35
+</map>
0 36
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE map SYSTEM "http://mapeditor.org/dtd/1.0/map.dtd">
3
+<map version="1.0" orientation="orthogonal" width="4" height="3" tilewidth="24" tileheight="24">
4
+ <properties>
5
+  <property name="NoOverlappingRules" value="1"/>
6
+ </properties>
7
+ <tileset firstgid="1" name="sewer_tileset" tilewidth="24" tileheight="24">
8
+  <image source="../sewer_tileset.png" trans="ff00ff" width="192" height="217"/>
9
+ </tileset>
10
+ <tileset firstgid="73" name="rules_sewers" tilewidth="24" tileheight="24">
11
+  <image source="rules_sewers.png" width="72" height="48"/>
12
+ </tileset>
13
+ <layer name="regions" width="4" height="3">
14
+  <data encoding="base64" compression="zlib">
15
+   eJxjYMAEPlCMDQAAD6AAmQ==
16
+  </data>
17
+ </layer>
18
+ <layer name="input_Ground" width="4" height="3">
19
+  <data encoding="base64" compression="zlib">
20
+   eJxjYMAESkCshUUcBAAH2ABN
21
+  </data>
22
+ </layer>
23
+ <objectgroup name="output_GroundEffects" width="4" height="3">
24
+  <object name="2" type="Trigger" x="48" y="24" width="24" height="24">
25
+   <properties>
26
+    <property name="triggering" value="trigger42"/>
27
+   </properties>
28
+  </object>
29
+ </objectgroup>
30
+</map>
... ...
@@ -31,7 +31,7 @@
31 31
 # to trigger the specific rule.
32 32
 # The layers Rule_Ground, Rule_Over and Rule_Over2 define the output of the rules.
33 33
 #
34
-# Which tiles should I use in RuleRegions?
34
+# Which tiles should I use in the regions layer?
35 35
 # Actually there can be any tiles, but it should be the same tiles for one rule.
36 36
 # So use whatever you want, maybe a colorful tile so you can see easily that these
37 37
 # tiles are used for defining the rule region.
... ...
@@ -44,8 +44,8 @@
44 44
 #                                   That is useful, when not all layers are covered
45 45
 #                                   at all places. (Check the Over and Over2 layer!)
46 46
 # "AutoMappingRadius" = 0,1,2...  - This property determines which regions are
47
-#                                   automatically remapped.
48
-#                                   When you draw directly into the "set" layer,
47
+#                                   automatically remapped at live Automapping.
48
+#                                   When you draw directly into the map,
49 49
 #                                   not the whole map is remapped, but only a little
50 50
 #                                   place around. Here you can specify how many
51 51
 #                                   tiles at least should be remapped.
... ...
@@ -53,6 +53,8 @@
53 53
 ./rule_001.tmx
54 54
 
55 55
 
56
+
57
+
56 58
 # Setup the right transition tiles at the border of light blue stone tiles
57 59
 #
58 60
 # Basically it is the same as the first rule, we are just using bigger rules.
... ...
@@ -62,17 +64,21 @@
62 64
 ./rule_002.tmx
63 65
 
64 66
 
67
+
68
+
65 69
 # Now put straight walls
66 70
 #
67
-# Note: Compare the RuleRegions and the RuleSet layer!
68
-# Not at all places where a rule is defined, there is a tile in the ruleset layer.
71
+# Note: Compare the regions and the set layer!
72
+# Not at all places where a rule is defined, there is a tile in the input_set layer.
69 73
 # This means that there can be any tiles except those used by the rule.
70
-# So there are no black tiles allowed, when there are no tiles in the ruleset
74
+# So there are no black tiles allowed, when there are no tiles in the input_set
71 75
 # layer.
72 76
 
73 77
 ./rule_003.tmx
74 78
 
75 79
 
80
+
81
+
76 82
 # Now we add inner corners for walls
77 83
 #
78 84
 # (No new features introduced)
... ...
@@ -80,6 +86,8 @@
80 86
 ./rule_004.tmx
81 87
 
82 88
 
89
+
90
+
83 91
 # Now we add the corners for walls
84 92
 #
85 93
 # (No new features introduced)
... ...
@@ -87,23 +95,48 @@
87 95
 ./rule_005.tmx
88 96
 
89 97
 
98
+
99
+
90 100
 # Correct the error we got in the two previous rulefiles (overwrite it once more)
91 101
 #
92
-# Here we can see the use of RuleSet and RuleNotSet
93
-# With the RuleNotSet we can define which tiles must not be used at certain places
102
+# Here we can see the use of input_set and input_NotSet
103
+# With the input_NotSet we can define which tiles must not be used at certain places
94 104
 # Important sideeffect: the empty regions in ruleSet can be anything now, including
95 105
 # black tiles as used here!
96 106
 #
97
-# So when you use both RuleSet and RuleNotSet, you need to specify exactly what
107
+# So when you use both input_Set and input_NotSet, you need to specify exactly what
98 108
 # is allowed at which places.
99 109
 
100 110
 ./rule_006.tmx
101 111
 
102 112
 
113
+
114
+
103 115
 # Setup the corner stones for light blue stone tiles
104 116
 #
105
-# Hey, there are multiple layers called RuleNotSet!
117
+# Hey, there are multiple layers called input_NotSet!
106 118
 # Yes, when you need to specify multiple allowed or disallowed tiles per
107
-# position, you can use multiple layers of RuleSet and RuleNotSet
119
+# position, you can use multiple layers of input_Set and input_NotSet
108 120
 
109 121
 ./rule_007.tmx
122
+
123
+
124
+
125
+
126
+
127
+# Setup objects now
128
+# The objects '1' will be placed. They will be placed based on the
129
+# Over layer, which was created by previous rules.
130
+# The placement of objects is done in south-east corners.
131
+
132
+./rule_008.tmx
133
+
134
+
135
+
136
+
137
+# Setup another object.
138
+# This object is based on input from the Ground layer.
139
+# It will put objects to borderstones which are near an end of that borderline.
140
+#
141
+
142
+./rule_009.tmx
... ...
@@ -331,9 +331,6 @@ bool AutoMapper::prepareAutoMap()
331 331
     mError.clear();
332 332
     mWarning.clear();
333 333
 
334
-    if (!setupRulesUsedCheck())
335
-        return false;
336
-
337 334
     if (!setupMissingLayers())
338 335
         return false;
339 336
 
... ...
@@ -346,34 +343,6 @@ bool AutoMapper::prepareAutoMap()
346 343
     return true;
347 344
 }
348 345
 
349
-bool AutoMapper::setupRulesUsedCheck()
350
-{
351
-    foreach (const QString &index, mInputRules.indexes) {
352
-        foreach (const QString &name, mInputRules[index].names) {
353
-            const InputIndex &ii = mInputRules[index];
354
-            const int i = mMapWork->indexOfLayer(name, Layer::TileLayerType);
355
-            if (i == -1)
356
-                continue;
357
-
358
-            const TileLayer *setLayer = mMapWork->layerAt(i)->asTileLayer();
359
-            QList<Tileset*> tilesetWork = setLayer->usedTilesets().toList();
360
-
361
-            foreach (const TileLayer *tilelayer, ii[name].listYes)
362
-                foreach (Tileset *tileset, tilelayer->usedTilesets())
363
-                    if (tileset->findSimilarTileset(tilesetWork)
364
-                            || tilesetWork.contains(tileset))
365
-                        return true;
366
-
367
-            foreach (const TileLayer *tilelayer, ii[name].listNo)
368
-                foreach (Tileset *tileset, tilelayer->usedTilesets())
369
-                    if (tileset->findSimilarTileset(tilesetWork)
370
-                            || tilesetWork.contains(tileset))
371
-                        return true;
372
-        }
373
-    }
374
-    return false;
375
-}
376
-
377 346
 bool AutoMapper::setupMissingLayers()
378 347
 {
379 348
     // make sure all needed layers are there:
... ...
@@ -574,14 +543,18 @@ QRect AutoMapper::applyRule(const int ruleIndex, const QRect &where)
574 543
             const InputIndex &ii = mInputRules[index];
575 544
 
576 545
             bool allLayerNamesMatch = true;
577
-            foreach (const QString &name, mInputRules[index].names) {
578
-                const int index = mMapWork->indexOfLayer(name,
579
-                                                         Layer::TileLayerType);
580
-                const TileLayer *setLayer = mMapWork->layerAt(index)->asTileLayer();
581
-                allLayerNamesMatch &= compareLayerTo(setLayer,
582
-                                                     ii[name].listYes,
583
-                                                     ii[name].listNo,
584
-                                                     ruleInput, QPoint(x, y));
546
+            foreach (const QString &name, ii.names) {
547
+                const int i = mMapWork->indexOfLayer(name, Layer::TileLayerType);
548
+                if (i == -1) {
549
+                    allLayerNamesMatch = false;
550
+                } else {
551
+                    const TileLayer *setLayer = mMapWork->layerAt(i)->asTileLayer();
552
+                    allLayerNamesMatch &= compareLayerTo(setLayer,
553
+                                                         ii[name].listYes,
554
+                                                         ii[name].listNo,
555
+                                                         ruleInput,
556
+                                                         QPoint(x, y));
557
+                }
585 558
             }
586 559
             if (allLayerNamesMatch) {
587 560
                 anymatch = true;
... ...
@@ -256,12 +256,6 @@ private:
256 256
     void cleanTileLayers();
257 257
 
258 258
     /**
259
-     * Checks if this the rules from the given rules map could be used anyway
260
-     * by comparing the used tilesets of the set layers and ruleset layer.
261
-     */
262
-    bool setupRulesUsedCheck();
263
-
264
-    /**
265 259
      * where to work in
266 260
      */
267 261
     MapDocument *mMapDocument;