1 package net.systemeD.halcyon.styleparser {
6 import net.systemeD.halcyon.Globals;
7 import net.systemeD.halcyon.Map;
8 import net.systemeD.halcyon.connection.Entity;
9 import bustin.dev.Inspector;
11 public class RuleSet {
14 public var choosers:Array=new Array(); // list of StyleChoosers
15 public var images:Object=new Object(); // loaded images
16 private var iconCallback:Function=null; // function to call when all icons loaded
17 private var iconsToLoad:uint=0; // number of icons left to load (fire callback when ==0)
19 // variables for name, author etc.
21 public function RuleSet(m:Map,f:Function=null):void {
26 // Get styles for an object
28 public function getStyles(obj:Entity,tags:Object):StyleList {
29 var sl:StyleList=new StyleList();
30 for each (var sc:StyleChooser in choosers) {
31 sc.updateStyles(obj,tags,sl);
36 // ---------------------------------------------------------------------------------------------------------
39 public function loadFromCSS(url:String):void {
40 var request:URLRequest=new URLRequest(url);
41 var loader:URLLoader=new URLLoader();
43 request.method=URLRequestMethod.GET;
44 loader.dataFormat = URLLoaderDataFormat.TEXT;
45 loader.addEventListener(Event.COMPLETE, loadedCSS, false, 0, true);
46 loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler, false, 0, true);
47 loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, false, 0, true);
48 loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
52 private function loadedCSS(event:Event):void {
53 var css:MapCSS=new MapCSS(map);
54 choosers=css.parse(event.target.data);
55 Inspector.getInstance().show();
56 Inspector.getInstance().shelf('Choosers', choosers);
60 private function httpStatusHandler( event:HTTPStatusEvent ):void { }
61 private function securityErrorHandler( event:SecurityErrorEvent ):void { Globals.vars.root.addDebug("securityerrorevent"); }
62 private function ioErrorHandler( event:IOErrorEvent ):void { Globals.vars.root.addDebug("ioerrorevent"); }
65 // ------------------------------------------------------------------------------------------------
66 // Load all referenced images
67 // ** will duplicate if referenced twice, shouldn't
69 public function loadImages():void {
70 Globals.vars.root.addDebug("entering loadImages");
72 for each (var chooser:StyleChooser in choosers) {
73 for each (var style:Style in chooser.styles) {
74 if (style is PointStyle && PointStyle(style).icon_image ) { filename=PointStyle(style).icon_image; }
75 else if (style is ShapeStyle && ShapeStyle(style).fill_image ) { filename=ShapeStyle(style).fill_image; }
76 else if (style is ShieldStyle && ShieldStyle(style).shield_image) { filename=ShieldStyle(style).shield_image; }
78 Globals.vars.root.addDebug("need "+filename);
81 var request:URLRequest=new URLRequest(filename);
82 var loader:ImageLoader=new ImageLoader();
83 loader.dataFormat=URLLoaderDataFormat.BINARY;
84 loader.filename=filename;
85 loader.addEventListener(Event.COMPLETE, loadedImage, false, 0, true);
86 loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler, false, 0, true);
87 loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, false, 0, true);
88 loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
96 private function loadedImage(event:Event):void {
97 images[event.target.filename]=event.target.data;
99 if (iconsToLoad==0 && iconCallback!=null) { iconCallback(); }