1 package net.systemeD.halcyon.styleparser {
3 import net.systemeD.halcyon.connection.*;
5 /** A descendant list of MapCSS selectors (Rules).
8 relation[type=route] way[highway=primary]
9 ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
10 first Rule second Rule
11 |------------|---------|
17 public class RuleChain {
18 public var rules:Array=[]; // should eventually become a Vector of Rules
19 public var subpart:String='default'; // subpart name, as in way[highway=primary]::centreline
22 // - run a set of tests in the chain
23 // works backwards from at position "pos" in array, or -1 for the last
24 // separate tags object is required in case they've been dynamically retagged
25 // - if they fail, return false
26 // - if they succeed, and it's the last in the chain, return happily
27 // - if they succeed, and there's more in the chain, rerun this for each parent until success
29 public function test(pos:int, obj:Entity, tags:Object, zoom:uint):Boolean {
30 if (length==0) { return false; }
31 if (pos==-1) { pos=rules.length-1; }
33 var r:Rule=rules[pos];
34 if (!r.test(obj, tags, zoom)) { return false; }
35 if (pos==0) { return true; }
37 var o:Array=obj.parentObjects;
38 for each (var p:Entity in o) {
39 if (test(pos-1, p, p.getTagsHash(), zoom)) { return true; }
44 public function get length():int {
48 public function setSubpart(s:String):void {
49 subpart = s=='' ? 'default' : s;
52 // ---------------------------------------------------------------------------------------------
53 // Methods to add properties (used by parsers such as MapCSS)
55 public function addRule(e:String=''):void {
56 rules.push(new Rule(e));
59 public function addConditionToLast(c:Condition):void {
60 rules[rules.length-1].conditions.push(c);
63 public function addZoomToLast(z1:uint,z2:uint):void {
64 rules[rules.length-1].minZoom=z1;
65 rules[rules.length-1].maxZoom=z2;