Better support for MapCSS 0.2, including subparts
[potlatch2.git] / net / systemeD / halcyon / styleparser / StyleChooser.as
index 1a3f86fa83a64c2e2ce317f70fe504e1ba872114..c2d29809c3d2b741db42459c6d757d8e418b42fb 100644 (file)
@@ -38,7 +38,7 @@ package net.systemeD.halcyon.styleparser {
                public function get currentChain():RuleChain {
                        return ruleChains[rcpos];
                }
-
+               
                // Update the current StyleList from this StyleChooser
 
                public function updateStyles(obj:Entity, tags:Object, sl:StyleList, imageWidths:Object, zoom:uint):void {
@@ -46,53 +46,50 @@ package net.systemeD.halcyon.styleparser {
 
                        // Are any of the ruleChains fulfilled?
                        var w:Number;
-                       var fulfilled:Boolean=false;
                        for each (var c:RuleChain in ruleChains) {
                                if (c.test(-1,obj,tags,zoom)) {
-                                       fulfilled=true; break;
-                               }
-                       }
-                       if (!fulfilled) { return; }
+                                       sl.addSubpart(c.subpart);
 
-                       // Update StyleList
-                       for each (var r:Style in styles) {
-                               var a:*;
-                               if (r is ShapeStyle) {
-                                       a=sl.shapeStyles;
-                                       if (ShapeStyle(r).width>sl.maxwidth && !r.evals['width']) { sl.maxwidth=ShapeStyle(r).width; }
-                               } else if (r is ShieldStyle) {
-                                       a=sl.shieldStyles;
-                               } else if (r is TextStyle) { 
-                                       a=sl.textStyles;
-                               } else if (r is PointStyle) { 
-                                       a=sl.pointStyles;
-                                       w=0;
-                                       if (PointStyle(r).icon_width && !PointStyle(r).evals['icon_width']) {
-                                               w=PointStyle(r).icon_width;
-                                       } else if (PointStyle(r).icon_image && imageWidths[PointStyle(r).icon_image]) {
-                                               w=imageWidths[PointStyle(r).icon_image];
-                                       }
-                                       if (w>sl.maxwidth) { sl.maxwidth=w; }
-                               } else if (r is InstructionStyle) {
-                                       if (InstructionStyle(r).breaker) { return; }
-                                       if (InstructionStyle(r).set_tags) {
-                                               for (var k:String in InstructionStyle(r).set_tags) { tags[k]=InstructionStyle(r).set_tags[k]; }
-                                       }
-                                       continue;
-                               }
-                               if (r.drawn) { tags[':drawn']='yes'; }
-                               tags['_width']=sl.maxwidth;
+                                       // Update StyleList
+                                       for each (var r:Style in styles) {
+                                               var a:Object;
+                                               if (r is ShapeStyle) {
+                                                       a=sl.shapeStyles;
+                                                       if (ShapeStyle(r).width>sl.maxwidth && !r.evals['width']) { sl.maxwidth=ShapeStyle(r).width; }
+                                               } else if (r is ShieldStyle) {
+                                                       a=sl.shieldStyles;
+                                               } else if (r is TextStyle) { 
+                                                       a=sl.textStyles;
+                                               } else if (r is PointStyle) { 
+                                                       a=sl.pointStyles;
+                                                       w=0;
+                                                       if (PointStyle(r).icon_width && !PointStyle(r).evals['icon_width']) {
+                                                               w=PointStyle(r).icon_width;
+                                                       } else if (PointStyle(r).icon_image && imageWidths[PointStyle(r).icon_image]) {
+                                                               w=imageWidths[PointStyle(r).icon_image];
+                                                       }
+                                                       if (w>sl.maxwidth) { sl.maxwidth=w; }
+                                               } else if (r is InstructionStyle) {
+                                                       if (InstructionStyle(r).breaker) { return; }
+                                                       if (InstructionStyle(r).set_tags) {
+                                                               for (var k:String in InstructionStyle(r).set_tags) { tags[k]=InstructionStyle(r).set_tags[k]; }
+                                                       }
+                                                       continue;
+                                               }
+                                               if (r.drawn) { tags[':drawn']='yes'; }
+                                               tags['_width']=sl.maxwidth;
                                
-                               r.runEvals(tags);
-                               sl.addSublayer(r.sublayer);
-                               if (a[r.sublayer]) {
-                                       // If there's already a style on this sublayer, then merge them
-                                       // (making a deep copy if necessary to avoid altering the root style)
-                                       if (!a[r.sublayer].merged) { a[r.sublayer]=a[r.sublayer].deepCopy(); }
-                                       a[r.sublayer].mergeWith(r);
-                               } else {
-                                       // Otherwise, just assign it
-                                       a[r.sublayer]=r;
+                                               r.runEvals(tags);
+                                               if (a[c.subpart]) {
+                                                       // If there's already a style on this sublayer, then merge them
+                                                       // (making a deep copy if necessary to avoid altering the root style)
+                                                       if (!a[c.subpart].merged) { a[c.subpart]=a[c.subpart].deepCopy(); }
+                                                       a[c.subpart].mergeWith(r);
+                                               } else {
+                                                       // Otherwise, just assign it
+                                                       a[c.subpart]=r;
+                                               }
+                                       }
                                }
                        }
                }
@@ -108,10 +105,9 @@ package net.systemeD.halcyon.styleparser {
                        }
                }
 
-               // addStyles    <- adds to this.styles
                public function addStyles(a:Array):void {
                        styles=styles.concat(a);
                }
-               
+
        }
 }