Merge remote-tracking branch 'systemed/filebank' into filebank
authorTom Hughes <tom@compton.nu>
Sat, 24 Mar 2012 10:32:44 +0000 (10:32 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 24 Mar 2012 10:32:44 +0000 (10:32 +0000)
1  2 
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/styleparser/RuleSet.as
net/systemeD/halcyon/styleparser/StyleChooser.as

index f7a5945247f0f140752c152fb14c158798d02540,6b30d91cf73bd1ab5cccfc38bb45397eae3dfbeb..990f43bbe946681b92ee50e37e46bcd95101cd0a
@@@ -9,7 -9,7 +9,7 @@@ package net.systemeD.halcyon 
        
        import net.systemeD.halcyon.connection.*;
        import net.systemeD.halcyon.styleparser.*;
-     import net.systemeD.halcyon.ImageBank;
+     import net.systemeD.halcyon.FileBank;
  
        /** The graphical representation of a Way. */ 
        public class WayUI extends EntityUI {
                                                fill=new Shape(); addToLayer(fill,FILLSPRITE,s.sublayer);
                                                fill.graphics.moveTo(x0,y0);
                                                if (s.fill_image) {
-                                                       fill.graphics.beginBitmapFill(ImageBank.getInstance().getAsBitmapData(s.fill_image));
+                                                       fill.graphics.beginBitmapFill(FileBank.getInstance().getAsBitmapData(s.fill_image));
                                                } else {
                                                        s.applyFill(fill.graphics);
                                                }
                /* Interaction */
          // TODO: can this be sped up? Hit testing for long ways (that go off the screen) seems to be very slow. */
                public function hitTest(x:Number, y:Number):Way {
 -                      if (hitzone.hitTestPoint(x,y,true)) { return entity as Way; }
 +                      if (hitzone && hitzone.hitTestPoint(x,y,true)) { return entity as Way; }
                        return null;
                }
        }
index 6a8d6a015fef1dda52b38a08015078c7a0bf23f5,99183d5c61a46f2ac1956a853df5816739da0342..d0842145ce594d55702a28b1c891750a8de6e025
@@@ -6,18 -6,16 +6,18 @@@ package net.systemeD.halcyon.styleparse
        import net.systemeD.halcyon.ExtendedURLLoader;
        import net.systemeD.halcyon.DebugURLRequest;
      import net.systemeD.halcyon.connection.Entity;
-     import net.systemeD.halcyon.ImageBank;
+     import net.systemeD.halcyon.FileBank;
  
      import net.systemeD.halcyon.connection.*;
 -      
 -      /** A complete stylesheet, as loaded from a MapCSS file. It contains all selectors, declarations, 
 -              and embedded images.                                                                                                                                                            </p><p>
 -              
 -              The RuleSet class has two principal methods: getStyles, which calculates the styles that apply
 -              to an entity (returned as a StyleList); and parse, which parses a MapCSS stylesheet into
 -              a complete RuleSet. */
 +
 +    /**
 +    * A complete stylesheet, as loaded from a MapCSS file. It contains all selectors, declarations,
 +    * and embedded images.
 +    *
 +    * <p>The RuleSet class has two principal methods: getStyles, which calculates the styles that apply
 +    * to an entity (returned as a StyleList); and parse, which parses a MapCSS stylesheet into
 +    * a complete RuleSet.</p>
 +    */
  
        public class RuleSet {
  
                private static const CONDITION_LE:RegExp        =/^ \s* ([:\w]+) \s* <= \s* (.+) \s* $/sx;
                private static const CONDITION_REGEX:RegExp     =/^ \s* ([:\w]+) \s* =~\/ \s* (.+) \/ \s* $/sx;
  
 -              private static const ASSIGNMENT_EVAL:RegExp     =/^ \s* (\S+) \s* \:      \s* eval \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
 -              private static const ASSIGNMENT:RegExp          =/^ \s* (\S+) \s* \:      \s*          (.+?) \s*                   $/sx;
 -              private static const SET_TAG_EVAL:RegExp        =/^ \s* set \s+(\S+)\s* = \s* eval \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
 -              private static const SET_TAG:RegExp                     =/^ \s* set \s+(\S+)\s* = \s*          (.+?) \s*                   $/isx;
 -              private static const SET_TAG_TRUE:RegExp        =/^ \s* set \s+(\S+)\s* $/isx;
 -              private static const EXIT:RegExp                        =/^ \s* exit \s* $/isx;
 +              private static const ASSIGNMENT_EVAL:RegExp             =/^ \s* (\S+) \s* \:      \s* eval \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
 +              private static const ASSIGNMENT_TAGVALUE:RegExp =/^ \s* (\S+) \s* \:      \s* tag  \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
 +              private static const ASSIGNMENT:RegExp                  =/^ \s* (\S+) \s* \:      \s*          (.+?) \s*                   $/sx;
 +              private static const SET_TAG_EVAL:RegExp                =/^ \s* set \s+(\S+)\s* = \s* eval \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
 +              private static const SET_TAG_TAGVALUE:RegExp    =/^ \s* set \s+(\S+)\s* = \s* tag  \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
 +              private static const SET_TAG:RegExp                             =/^ \s* set \s+(\S+)\s* = \s*          (.+?) \s*                   $/isx;
 +              private static const SET_TAG_TRUE:RegExp                =/^ \s* set \s+(\S+)\s* $/isx;
 +              private static const DELETE_TAG:RegExp                  =/^ \s* delete \s+(\S+)\s* $/isx;
 +              private static const EXIT:RegExp                                =/^ \s* exit \s* $/isx;
  
                private static const oZOOM:uint=2;
                private static const oGROUP:uint=3;
                        return sl;
                }
  
 +              /** Run instruction styles only, for CSSTransform. */
 +              public function runInstructions(obj:Entity, tags:Object):Object {
 +                      for each (var sc:StyleChooser in choosers) {
 +                              tags=sc.runInstructions(obj,tags);
 +                      }
 +                      return tags;
 +              }
 +
                // ---------------------------------------------------------------------------------------------------------
                // Loading stylesheet
  
                /** Load all images referenced in the RuleSet (for example, icons or bitmap fills). */
                
                private function loadImages():void {
-                       ImageBank.getInstance().addEventListener(ImageBank.IMAGES_LOADED,doIconCallback);
+                       FileBank.getInstance().addEventListener(FileBank.FILES_LOADED,doIconCallback);
                        var filename:String;
                        for each (var chooser:StyleChooser in choosers) {
                                for each (var style:Style in chooser.styles) {
                                        else { continue; }
  
                                        if (filename!='square' && filename!='circle')
-                                               ImageBank.getInstance().loadImage(filename);
+                                               FileBank.getInstance().addFromFile(filename);
                                }
                        }
                }
                        var xs:InstructionStyle=new InstructionStyle(); 
  
                        for each (a in s.split(';')) {
 -                              if ((o=ASSIGNMENT_EVAL.exec(a)))   { t[o[1].replace(DASH,'_')]=saveEval(o[2]); }
 -                              else if ((o=ASSIGNMENT.exec(a)))   { t[o[1].replace(DASH,'_')]=o[2]; }
 -                              else if ((o=SET_TAG_EVAL.exec(a))) { xs.addSetTag(o[1],saveEval(o[2])); }
 -                              else if ((o=SET_TAG.exec(a)))      { xs.addSetTag(o[1],o[2]); }
 -                              else if ((o=SET_TAG_TRUE.exec(a))) { xs.addSetTag(o[1],true); }
 +                              if      ((o=ASSIGNMENT_EVAL.exec(a)))           { t[o[1].replace(DASH,'_')]=saveEval(o[2]); }
 +                              else if ((o=ASSIGNMENT_TAGVALUE.exec(a)))       { t[o[1].replace(DASH,'_')]=new TagValue(o[2]); }
 +                              else if ((o=ASSIGNMENT.exec(a)))                        { t[o[1].replace(DASH,'_')]=o[2]; }
 +                              else if ((o=SET_TAG_EVAL.exec(a)))                      { xs.addSetTag(o[1],saveEval(o[2])); }
 +                              else if ((o=SET_TAG_TAGVALUE.exec(a)))          { xs.addSetTag(o[1],new TagValue(o[2])); }
 +                              else if ((o=SET_TAG.exec(a)))                           { xs.addSetTag(o[1],o[2]); }
 +                              else if ((o=SET_TAG_TRUE.exec(a)))                      { xs.addSetTag(o[1],true); }
 +                              else if ((o=DELETE_TAG.exec(a)))                        { xs.addSetTag(o[1],''); }
                                else if ((o=EXIT.exec(a))) { xs.setPropertyFromString('breaker',true); }
                        }
  
  
          public static function parseCSSColor(colorStr:String):uint {
              colorStr = colorStr.toLowerCase();
 -            if (CSSCOLORS[colorStr]) {
 +            if (CSSCOLORS[colorStr] != undefined) {
                  return CSSCOLORS[colorStr];
              } else {
                  var match:Object = HEX.exec(colorStr);
index 9d9d2f93fc4648a94287b5f8d3582eafedb6ff83,9ae6343839f7b72ccc5d6b24b9bc0f2c7d8094b2..f0e95bc50745152858eabec3721315a1b5927622
@@@ -1,7 -1,7 +1,7 @@@
  package net.systemeD.halcyon.styleparser {
  
        import net.systemeD.halcyon.connection.Entity;
-     import net.systemeD.halcyon.ImageBank;
+     import net.systemeD.halcyon.FileBank;
  
        public class StyleChooser {
  
@@@ -52,8 -52,7 +52,8 @@@
                                        sl.addSubpart(c.subpart);
  
                                        // Update StyleList
 -                                      for each (var r:Style in styles) {
 +                                      for (var i:uint=0; i<styles.length; i++) {
 +                                              var r:Style=styles[i];
                                                var a:Object;
                                                if (r is ShapeStyle) {
                                                        a=sl.shapeStyles;
                                                        if (PointStyle(r).icon_width && !PointStyle(r).evals['icon_width']) {
                                                                // ** FIXME: we should check this is the bit being used for 'square', 'circle' etc.
                                                                w=PointStyle(r).icon_width;
-                                                       } else if (PointStyle(r).icon_image && ImageBank.getInstance().hasImage(PointStyle(r).icon_image)) {
-                                                               w=ImageBank.getInstance().getWidth(PointStyle(r).icon_image);
+                                                       } else if (PointStyle(r).icon_image && FileBank.getInstance().hasFile(PointStyle(r).icon_image)) {
+                                                               w=FileBank.getInstance().getWidth(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]; }
 -                                                      }
 +                                                      InstructionStyle(r).assignSetTags(tags);
                                                        continue;
                                                }
                                                if (r.drawn) { tags[':drawn']='yes'; }
                        }
                }
                
 +              /** Cut-down version of updateStyles that runs InstructionStyles only - for CSSTransform usage. */
 +
 +              public function runInstructions(obj:Entity, tags:Object):Object {
 +                      for each (var c:RuleChain in ruleChains) {
 +                              if (c.test(-1,obj,tags,10)) {
 +                                      for (var i:uint=0; i<styles.length; i++) {
 +                                              var r:Style=styles[i];
 +                                              if (r is InstructionStyle) {
 +                                                      if (InstructionStyle(r).breaker) { return tags; }
 +                                                      InstructionStyle(r).assignSetTags(tags);
 +                                              }
 +                                              r.runEvals(tags);
 +                                      }
 +                              }
 +                      }
 +                      return tags;
 +              }
 +              
                
                // ---------------------------------------------------------------------------------------------
                // Methods to add properties (used by parsers such as MapCSS)