home *** CD-ROM | disk | FTP | other *** search
- package com.je.model
- {
- import com.je.data.Queue;
- import com.je.data.QueueItem;
- import com.je.data.loader.ILoader;
- import com.je.data.loader.LoaderFactory;
- import com.je.events.AssetLoaderEvent;
- import com.je.events.AssetManagerEventFactory;
- import com.je.utils.FileUtils;
- import controller.LoadingController;
- import controller.VersionController;
- import mdm.Application;
- import org.robotlegs.mvcs.Actor;
-
- public class AssetManager extends Actor
- {
- [Inject]
- public var assets:Assets;
-
- private var _queue:Queue;
-
- private var _currentItem:QueueItem;
-
- private var _loaderFactory:LoaderFactory;
-
- private var _eventFactory:AssetManagerEventFactory;
-
- private var counter:int = 0;
-
- private var lc:LoadingController;
-
- private var isDone:Boolean = false;
-
- public function AssetManager()
- {
- super();
- this._loaderFactory = new LoaderFactory();
- this._eventFactory = new AssetManagerEventFactory();
- this.lc = LoadingController.getInstance();
- }
-
- public function addQueue(param1:Queue) : void
- {
- this._queue = param1;
- this._currentItem = this._queue.getItemAt(0);
- }
-
- public function load() : void
- {
- var _loc1_:String = this._currentItem.path;
- var _loc2_:String = FileUtils.getFileExtension(_loc1_);
- var _loc3_:ILoader = this._loaderFactory.getLoader(_loc2_);
- _loc3_.addEventListener(AssetLoaderEvent.COMPLETE,this.completeHandler);
- _loc3_.addEventListener(AssetLoaderEvent.IO_ERROR,this.errorHandler);
- if(VersionController.getInstance("").version == "linux")
- {
- _loc3_.loadUrl(VersionController.getInstance("").path + _loc1_);
- }
- else
- {
- _loc3_.loadUrl(Application.path + _loc1_);
- }
- }
-
- private function completeHandler(param1:AssetLoaderEvent) : void
- {
- ++this.counter;
- var _loc2_:ILoader = ILoader(param1.target);
- _loc2_.removeEventListener(AssetLoaderEvent.COMPLETE,this.completeHandler);
- _loc2_.removeEventListener(AssetLoaderEvent.IO_ERROR,this.errorHandler);
- this.assets.storeAsset(this._currentItem.linkedId,_loc2_.getContent());
- _loc2_.destroy();
- dispatch(this._eventFactory.getItemCompleteEvent(this._currentItem.itemLoadedEvent));
- this.lc.total = Number(this._queue.getQueueLenght() + this._queue.getQueueLenght());
- this.lc.loaded = this.counter;
- if(this.counter < this._queue.getQueueLenght())
- {
- this.loadNextItem();
- }
- else
- {
- this.done();
- }
- }
-
- private function errorHandler(param1:AssetLoaderEvent) : void
- {
- ++this.counter;
- var _loc2_:ILoader = ILoader(param1.target);
- _loc2_.removeEventListener(AssetLoaderEvent.COMPLETE,this.completeHandler);
- _loc2_.removeEventListener(AssetLoaderEvent.IO_ERROR,this.errorHandler);
- _loc2_.destroy();
- if(this.counter < this._queue.getQueueLenght())
- {
- this.loadNextItem();
- }
- else
- {
- this.done();
- }
- var _loc3_:AssetLoaderEvent = new AssetLoaderEvent(AssetLoaderEvent.IO_ERROR);
- _loc3_.message = param1.message;
- dispatch(_loc3_);
- }
-
- private function done() : void
- {
- if(this.isDone)
- {
- }
- this.isDone = true;
- dispatch(this._eventFactory.getCompleteEvent(this._queue.commpleteEvent));
- this.counter = 0;
- }
-
- private function loadNextItem() : void
- {
- this._currentItem = this._queue.getNextItem();
- if(this._currentItem != null || this._currentItem.path != null || this._currentItem.path != "")
- {
- this.load();
- }
- else if(this._currentItem == null || this._currentItem.path == null || this._currentItem.path == "")
- {
- this.loadNextItem();
- ++this.counter;
- }
- else if(this.counter < this._queue.getQueueLenght())
- {
- ++this.counter;
- this.loadNextItem();
- }
- }
-
- private function reset() : void
- {
- this._queue.clearQueue();
- this._queue = null;
- }
- }
- }
-
-