Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ImageBank->FileBank

  • Loading branch information...
commit 92736d135f2ba3fa401f4c410069489893c0ba7e 1 parent 8f6a150
@systemed systemed authored
View
146 net/systemeD/halcyon/ImageBank.as
@@ -1,146 +0,0 @@
-package net.systemeD.halcyon {
- import flash.events.*;
- import flash.display.*;
- import flash.net.*;
- import flash.utils.ByteArray;
- import nochump.util.zip.*;
-
- /*
- ImageBank stores and retrieves bitmap images.
- All images are internally stored as Loader.
-
- See blog.yoz.sk/2009/10/bitmap-bitmapdata-bytearray/ for a really useful conversion guide!
- */
-
- public class ImageBank extends EventDispatcher{
- private var images:Object={};
- private var imagesRequested:uint=0;
- private var imagesReceived:uint=0;
-
- public static const IMAGES_LOADED:String="imagesLoaded";
- public static const ZIP_LOADED:String="zipLoaded";
-
- private static const GLOBAL_INSTANCE:ImageBank = new ImageBank();
- public static function getInstance():ImageBank { return GLOBAL_INSTANCE; }
-
- public function hasImage(name:String):Boolean {
- if (images[name]) return true;
- return false;
- }
-
- /* ==========================================================================================
- Populate with images
- ========================================================================================== */
-
- public function loadImage(filename:String):void {
- if (images[filename]) return;
- imagesRequested++;
-
- var loader:Loader=new Loader();
- images[filename]=loader;
- var request:URLRequest=new URLRequest(filename);
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedImage);
- loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
- loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
- loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
- loader.load(request);
- }
-
- private function loadedImage(event:Event):void {
- imageReceived();
- }
- private function httpStatusHandler(event:HTTPStatusEvent):void { }
- private function securityErrorHandler(event:SecurityErrorEvent):void {
- trace("securityErrorEvent: "+event.target.url);
- imageReceived();
- }
- private function ioErrorHandler(event:IOErrorEvent):void {
- trace("ioErrorEvent: "+event.target.url);
- imageReceived();
- }
- private function imageReceived():void {
- imagesReceived++;
- if (imagesReceived==imagesRequested) { dispatchEvent(new Event(IMAGES_LOADED)); }
- }
-
- /* ==========================================================================================
- Load from .zip file
- ========================================================================================== */
-
- public function loadFromZip(filename:String, prefix:String=""):void {
- var loader:URLLoader = new URLLoader();
- loader.dataFormat="binary";
- loader.addEventListener(Event.COMPLETE, function(e:Event):void { zipReady(e,prefix); } );
- loader.load(new URLRequest(filename));
- }
- private function zipReady(event:Event, prefix:String):void {
- var zip:ZipFile = new ZipFile(event.target.data);
- for (var i:uint=0; i<zip.entries.length; i++) {
- var fileref:ZipEntry = zip.entries[i];
- var data:ByteArray = zip.getInput(fileref);
- var loader:Loader=new Loader();
- images[prefix+fileref.name]=loader;
- loader.loadBytes(data);
- }
- dispatchEvent(new Event(ZIP_LOADED));
- }
-
-
- /* ==========================================================================================
- Get images
- getAsDisplayObject(filename)
- getAsBitmapData(filename)
- getAsByteArray(filename)
- ========================================================================================== */
-
- public function getAsDisplayObject(name:String):DisplayObject {
- /* If the image hasn't loaded yet, then add an EventListener for when it does. */
- if (getWidth(name)==0) {
- var loader:Loader = new Loader();
- images[name].contentLoaderInfo.addEventListener(Event.COMPLETE,
- function(e:Event):void { loaderReady(e, loader) });
- return loader;
- }
- /* Otherwise, create a new Bitmap, because just returning the raw Loader
- (i.e. images[name]) would only allow it to be added to one parent. (The other
- way to do this would be by copying the bytes as loaderReady does.). */
- return new Bitmap(getAsBitmapData(name));
- }
-
- public function getOriginalDisplayObject(name:String):DisplayObject {
- /* But if we're going to clone it later, this'll work fine. */
- return images[name];
- }
-
- private function loaderReady(event:Event, loader:Loader):void {
- /* The file has loaded, so we can copy the data from there into our new Loader */
- var info:LoaderInfo = event.target as LoaderInfo;
- loader.loadBytes(info.bytes);
- }
-
- public function getAsBitmapData(name:String):BitmapData {
- var bitmapData:BitmapData=new BitmapData(getWidth(name), getHeight(name), true, 0xFFFFFF);
- bitmapData.draw(images[name]);
- return bitmapData;
- }
-
- public function getAsByteArray(name:String):ByteArray {
- return images[name].contentLoaderInfo.bytes;
- }
-
- /* ==========================================================================================
- Get file information
- ========================================================================================== */
-
- public function getWidth(name:String):int {
- try { return images[name].contentLoaderInfo.width; }
- catch (error:Error) { } return 0;
- }
-
- public function getHeight(name:String):int {
- try { return images[name].contentLoaderInfo.height; }
- catch (error:Error) { } return 0;
- }
-
- }
-}
View
6 net/systemeD/halcyon/MarkerUI.as
@@ -10,7 +10,7 @@ package net.systemeD.halcyon {
import flash.geom.Point;
import net.systemeD.halcyon.styleparser.*;
import net.systemeD.halcyon.connection.*;
- import net.systemeD.halcyon.ImageBank;
+ import net.systemeD.halcyon.FileBank;
public class MarkerUI extends EntityUI {
@@ -100,9 +100,9 @@ package net.systemeD.halcyon {
icon.graphics.drawCircle(w,w,w);
if (s.interactive) { maxwidth=Math.max(w,maxwidth); }
- } else if (ImageBank.getInstance().hasImage(s.icon_image)) {
+ } else if (FileBank.getInstance().hasFile(s.icon_image)) {
// load icon from library
- icon.addChild(ImageBank.getInstance().getAsDisplayObject(s.icon_image));
+ icon.addChild(FileBank.getInstance().getAsDisplayObject(s.icon_image));
// addHitSprite(icon.width); // ** check this - we're doing it below too
// loaded=true; updatePosition(); // ** check this
if (s.interactive) { maxwidth=Math.max(icon.width,maxwidth); }
View
6 net/systemeD/halcyon/NodeUI.as
@@ -10,7 +10,7 @@ package net.systemeD.halcyon {
import flash.geom.Point;
import net.systemeD.halcyon.styleparser.*;
import net.systemeD.halcyon.connection.*;
- import net.systemeD.halcyon.ImageBank;
+ import net.systemeD.halcyon.FileBank;
/** The graphical representation of a Node (including POIs and nodes that are part of Ways). */
public class NodeUI extends EntityUI {
@@ -122,9 +122,9 @@ package net.systemeD.halcyon {
icon.graphics.drawCircle(w,w,w);
if (s.interactive) { maxwidth=Math.max(w,maxwidth); }
- } else if (ImageBank.getInstance().hasImage(s.icon_image)) {
+ } else if (FileBank.getInstance().hasFile(s.icon_image)) {
// load icon from library
- icon.addChild(ImageBank.getInstance().getAsDisplayObject(s.icon_image));
+ icon.addChild(FileBank.getInstance().getAsDisplayObject(s.icon_image));
// addHitSprite(icon.width); // ** check this - we're doing it below too
loaded=true; updatePosition(); // ** check this
if (s.interactive) { maxwidth=Math.max(icon.width,maxwidth); }
View
4 net/systemeD/halcyon/WayUI.as
@@ -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 {
@@ -296,7 +296,7 @@ package net.systemeD.halcyon {
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);
}
View
6 net/systemeD/halcyon/styleparser/RuleSet.as
@@ -6,7 +6,7 @@ package net.systemeD.halcyon.styleparser {
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.*;
@@ -281,7 +281,7 @@ package net.systemeD.halcyon.styleparser {
/** 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) {
@@ -291,7 +291,7 @@ package net.systemeD.halcyon.styleparser {
else { continue; }
if (filename!='square' && filename!='circle')
- ImageBank.getInstance().loadImage(filename);
+ FileBank.getInstance().addFromFile(filename);
}
}
}
View
6 net/systemeD/halcyon/styleparser/StyleChooser.as
@@ -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 {
@@ -67,8 +67,8 @@ package net.systemeD.halcyon.styleparser {
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) {
View
6 net/systemeD/potlatch2/Preloader.as
@@ -6,7 +6,7 @@ package net.systemeD.potlatch2 {
import flash.geom.Matrix;
import flash.text.TextField;
import flash.text.TextFormat;
- import net.systemeD.halcyon.ImageBank;
+ import net.systemeD.halcyon.FileBank;
public class Preloader extends net.systemeD.potlatch2.PreloaderDisplayBase {
@@ -45,11 +45,11 @@ package net.systemeD.potlatch2 {
// request .zip files
if (loaderInfo.parameters['assets']) {
- ImageBank.getInstance().addEventListener(ImageBank.ZIP_LOADED, zipLoaded);
+ FileBank.getInstance().addEventListener(FileBank.ZIP_LOADED, zipLoaded);
for each (var file:String in loaderInfo.parameters['assets'].split(';')) {
var asset:Array=file.split('=');
assetscount++;
- ImageBank.getInstance().loadFromZip(asset[0],asset[1]);
+ FileBank.getInstance().addFromZip(asset[0],asset[1]);
}
}
}
View
6 net/systemeD/potlatch2/mapfeatures/Feature.as
@@ -8,7 +8,7 @@ package net.systemeD.potlatch2.mapfeatures {
import mx.core.BitmapAsset;
import mx.graphics.codec.PNGEncoder;
- import net.systemeD.halcyon.ImageBank;
+ import net.systemeD.halcyon.FileBank;
import net.systemeD.halcyon.connection.Entity;
import net.systemeD.potlatch2.utils.CachedDataLoader;
@@ -148,8 +148,8 @@ package net.systemeD.potlatch2.mapfeatures {
}
if ( imageURL ) {
- if (ImageBank.getInstance().hasImage(imageURL)) {
- return ImageBank.getInstance().getAsByteArray(imageURL)
+ if (FileBank.getInstance().hasFile(imageURL)) {
+ return FileBank.getInstance().getAsByteArray(imageURL);
} else {
return CachedDataLoader.loadData(imageURL, imageLoaded);
}
Please sign in to comment.
Something went wrong with that request. Please try again.