initial work on tag editor
[potlatch2.git] / net / systemeD / halcyon / mapfeatures / MapFeatures.as
1 package net.systemeD.halcyon.mapfeatures {
2
3     import flash.events.Event;
4     import flash.net.URLLoader;
5     import flash.net.URLRequest;
6
7         import flash.system.Security;
8         import flash.net.*;
9
10     import net.systemeD.halcyon.connection.*;
11
12
13         public class MapFeatures {
14         private static var instance:MapFeatures;
15
16         public static function getInstance():MapFeatures {
17             if ( instance == null ) {
18                 instance = new MapFeatures();
19                 instance.loadFeatures();
20             }
21             return instance;
22         }
23
24
25
26         private var xml:XML = null;
27
28         protected function loadFeatures():void {
29             var request:URLRequest = new URLRequest("map_features.xml");
30             var loader:URLLoader = new URLLoader();
31             loader.addEventListener(Event.COMPLETE, onFeatureLoad);
32             loader.load(request);
33         }
34
35         private function onFeatureLoad(event:Event):void {
36             xml = new XML(URLLoader(event.target).data);
37         }
38
39         public function hasLoaded():Boolean {
40             return xml != null;
41         }
42
43         public function findMatchingFeature(entity:Entity):XML {
44             if ( xml == null )
45                 return null;
46
47             for each(var feature:XML in xml.feature) {
48                 // check for matching tags
49                 var match:Boolean = true;
50                 for each(var tag:XML in feature.tag) {
51                     var entityTag:String = entity.getTag(tag.@k);
52                     match = entityTag == tag.@v || (entityTag != null && tag.@v == "*");
53                     if ( !match ) break;
54                 }
55                 if ( match )
56                     return feature;
57             }
58             return null;
59         }
60     }
61
62 }
63
64