home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 164 / MOBICLIC164.ISO / mac / Milan.swf / scripts / com / milanpresse / capsule / GameEngineCapsule.as next >
Text File  |  2014-05-13  |  5KB  |  162 lines

  1. package com.milanpresse.capsule
  2. {
  3.    import com.milanpresse.engine.Context;
  4.    import com.milanpresse.engine.Engine;
  5.    import com.milanpresse.engine.HostContainer;
  6.    import com.milanpresse.engine.config.Config;
  7.    import com.milanpresse.engine.typeargument.ModuleCallerParameter;
  8.    import flash.display.Sprite;
  9.    import flash.system.Security;
  10.    
  11.    public class GameEngineCapsule extends Sprite implements ICapsule
  12.    {
  13.        
  14.       
  15.       private var _engine;
  16.       
  17.       protected var _host;
  18.       
  19.       public var isHost:Boolean = false;
  20.       
  21.       protected var _callback:Function = null;
  22.       
  23.       private var _config:ICapsuleConfig = null;
  24.       
  25.       private var _inHost:Boolean;
  26.       
  27.       private var _initParams:Object = null;
  28.       
  29.       private var _engineLib:LoadLib;
  30.       
  31.       private var _contextInitParams:Object = null;
  32.       
  33.       public function GameEngineCapsule()
  34.       {
  35.          super();
  36.          Security.allowDomain("*");
  37.          if(parent != null)
  38.          {
  39.             this._inHost = false;
  40.             this.init();
  41.          }
  42.          else
  43.          {
  44.             this._inHost = true;
  45.          }
  46.       }
  47.       
  48.       public function get config() : ICapsuleConfig
  49.       {
  50.          return this._config as Config;
  51.       }
  52.       
  53.       public function set config(param1:ICapsuleConfig) : void
  54.       {
  55.          this._config = param1;
  56.       }
  57.       
  58.       public function get host() : *
  59.       {
  60.          return this._host as HostContainer;
  61.       }
  62.       
  63.       public function get engine() : *
  64.       {
  65.          return this._engine as Engine;
  66.       }
  67.       
  68.       public function init(param1:Object = null) : void
  69.       {
  70.          this._initParams = param1 == null ? {} : param1;
  71.          this._contextInitParams = this._initParams.initParams == undefined ? {} : this._initParams.initParams;
  72.          this.loadEngine(this.engineLoaded);
  73.       }
  74.       
  75.       private function loadEngine(param1:Function) : void
  76.       {
  77.          var _loc2_:* = null;
  78.          if(this._inHost == false && this.isHost == false)
  79.          {
  80.             _loc2_ = "../../HOTE/gameEngine_as3/bin/GameEngine/library.swf";
  81.          }
  82.          else if(this._inHost == false && this.isHost == true)
  83.          {
  84.             _loc2_ = "DATA/HOTE/gameEngine_as3/bin/GameEngine/library.swf";
  85.          }
  86.          else
  87.          {
  88.             _loc2_ = this.getDirectoryPathOfFile(this._initParams.context.path) + "/DATA/HOTE/gameEngine_as3/bin/GameEngine/library.swf";
  89.          }
  90.          this._engineLib = new LoadLib("com.milanpresse.engine.Engine",_loc2_,this.engineLoaded,{"app":this});
  91.       }
  92.       
  93.       private function engineLoaded() : void
  94.       {
  95.          if(this._inHost == false)
  96.          {
  97.             this.initAsHost();
  98.          }
  99.          else
  100.          {
  101.             this.initAsChild();
  102.          }
  103.       }
  104.       
  105.       private function initAsHost() : void
  106.       {
  107.          var _loc1_:Context = new Context();
  108.          _loc1_.urlParameters = this.loaderInfo.parameters;
  109.          _loc1_.hostContext = _loc1_;
  110.          _loc1_.path = this.loaderInfo.url;
  111.          _loc1_.data = this;
  112.          this._contextInitParams.callerParameters = new ModuleCallerParameter();
  113.          _loc1_.initParams = this._contextInitParams;
  114.          this._host = new HostContainer(this);
  115.          this._engine = new Engine(this.start,_loc1_) as Engine;
  116.       }
  117.       
  118.       private function initAsChild(param1:* = null) : void
  119.       {
  120.          this._callback = this._initParams.callback;
  121.          var _loc2_:Context = this._initParams.context;
  122.          this._host = new HostContainer(_loc2_.data);
  123.          var _loc3_:Context = new Context();
  124.          _loc3_.hostContext = _loc2_;
  125.          _loc3_.path = this.loaderInfo.url;
  126.          _loc3_.data = this;
  127.          _loc3_.initParams = this._contextInitParams;
  128.          this._engine = new Engine(this.initEnd,_loc3_);
  129.       }
  130.       
  131.       private function initEnd(param1:* = null) : void
  132.       {
  133.          this._callback();
  134.       }
  135.       
  136.       private function getDirectoryPathOfFile(param1:String) : String
  137.       {
  138.          var _loc2_:Array = unescape(param1).replace(/\\/g,"/").split("/");
  139.          _loc2_.pop();
  140.          return _loc2_.join("/");
  141.       }
  142.       
  143.       public function start(param1:Object = null) : void
  144.       {
  145.       }
  146.       
  147.       public function destroy() : void
  148.       {
  149.          this._engine.destroy();
  150.          this._engineLib.destroy();
  151.       }
  152.       
  153.       public function sleep() : void
  154.       {
  155.       }
  156.       
  157.       public function wake() : void
  158.       {
  159.       }
  160.    }
  161. }
  162.