Skip to content

Commit

Permalink
Fixed various loader bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrivener07 committed Mar 7, 2019
1 parent f1173eb commit 44eb43b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 107 deletions.
117 changes: 14 additions & 103 deletions Data/Interface/Source/FO4_Overlays/Overlays/OverlayMenu/OverlayLoader.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
{
import Components.LoaderType;
import F4SE.Extensions;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import System.Diagnostics.Debug;
import System.Diagnostics.Utility;
import System.Display;
Expand All @@ -17,144 +12,60 @@
import System.IO.Path;

/**
* TODO: Check `Debug.WriteLine` for correct member names.
* TODO: See about `File.Exists` for other loadable file types.
*
*/
public dynamic class OverlayLoader extends LoaderType
{
private static const ImageMountID:String = "OverlayMenu_ImageMount";

// Initialize
//---------------------------------------------

// Events
//---------------------------------------------

override protected function OnLoadComplete(e:Event):void
{
// Note: Scale to default height of 720 works for dds files. The stage height works for swf files.
Display.ScaleToHeight(Content, Display.DefaultHeight);
super.OnLoadComplete(e);
Utility.TraceDisplayList(MovieClip(stage.getChildAt(0)));
Debug.WriteLine("[OverlayLoader]", "(OnLoadComplete)", e.toString()+", "+toString());
}


override protected function OnLoadError(e:IOErrorEvent):void
{
var extension:String = Path.GetExtension(FilePath)

if (extension == File.SWF)
{
var filepath = Path.ChangeExtension(FilePath, File.DDS);
if (File.ExistsIn(XSE, FileSystem.Textures, filepath))
{
Unmount(FilePath);
F4SE.Extensions.MountImage(XSE, OverlayMenu.Name, filepath, ImageMountID);
Load(filepath, "img://"+ImageMountID);
Debug.WriteLine("[OverlayLoader]", "(OnLoadError)", "No SWF file was found, converting file path from '"+FilePath+"' to '"+filepath+"'.");
}
else
{
Debug.WriteLine("[OverlayLoader]", "(OnLoadError)", "The file '"+filepath+"' does not exist.");
}
}
else if (extension == File.DDS)
{
Debug.WriteLine("[OverlayLoader]", "(OnLoadError)", "No overlay file was found.", FilePath);
}
else
{
Debug.WriteLine("[OverlayLoader]", "(OnLoadError)", e.toString()+", The error was unhandled. "+toString());
}

this.dispatchEvent(new Event(LOAD_ERROR));
}


// Methods
//---------------------------------------------

// (?) Allow initial filepath to go through, then switch extensions in the Error event.
override public function Load(filepath:String, mountID:String=null):Boolean
override public function Load(filepath:String):Boolean
{
// Swap any NIF file path to SWF.
var extension:String = Path.GetExtension(filepath);
var path:String = filepath;

if (extension == File.NIF)
{
extension = File.SWF;
filepath = Path.ChangeExtension(filepath, extension);
path = Path.ChangeExtension(filepath, extension);
}

if (extension == File.SWF)
{
return super.Load(filepath);
}
else if (extension == File.DDS)
if (extension == File.SWF && File.ExistsIn(XSE, FileSystem.Interface, path))
{
if (File.ExistsIn(XSE, FileSystem.Textures, filepath))
{
Debug.WriteLine("[OverlayLoader]", "(Load)", "DDS: '"+ImageMountID+"' as '"+filepath+"'.", "OLD:"+FilePath);
Unmount(FilePath);
F4SE.Extensions.MountImage(XSE, OverlayMenu.Name, filepath, ImageMountID);
return super.Load(filepath, "img://"+ImageMountID);
}
else
{
Debug.WriteLine("[OverlayLoader]", "(Load)", "File does not exist. '"+filepath+"'.");
return false;
}
Debug.WriteLine("[OverlayLoader]", "Found SWF:", "path:"+path);
return super.Load(path);
}
else
{
Debug.WriteLine("[OverlayLoader]", "(Load)", "Unhandled: '"+filepath+"' with extension '"+extension+"'.");
return false;
extension = File.DDS;
path = Path.ChangeExtension(filepath, extension);
}
}


// override public function Unload():Boolean
// {
// return super.Unload();
// }


private function Unmount(filepath:String):Boolean
{
if (filepath != null)
if (extension == File.DDS && File.ExistsIn(XSE, FileSystem.Textures, path))
{
if (Path.GetExtension(filepath) == File.DDS)
{
F4SE.Extensions.UnmountImage(XSE, OverlayMenu.Name, filepath);
Debug.WriteLine("[OverlayLoader]", "(Unmount)", "Unmounted the texture '"+filepath+"' from "+OverlayMenu.Name+" with resource ID "+ImageMountID);
return true;
}
else
{
Debug.WriteLine("[OverlayLoader]", "(Unmount)", "Only DDS texture files may be unmounted. '"+filepath+"'");
return false;
}
Debug.WriteLine("[OverlayLoader]", "Found DDS:", "path:"+path);
return super.Load(path);
}
else
{
Debug.WriteLine("[OverlayLoader]", "(Unmount)", "Cannot unmount a null filepath.");
Debug.WriteLine("[OverlayLoader]", "No overlay file was found.");
return false;
}
}

// Functions
//---------------------------------------------

// override public function toString():String
// {
// var sResolution = "Resolution: "+stage.width+"x"+stage.height;
// var sPosition = " Position: "+this.x+"x"+this.y;
// var sURI = "Uri: '"+Uri+"'";
// var sLastFile = "Requested: '"+Requested+"'";
// var sUrl = "Url: '"+Url+"'";
// return sResolution+", "+sPosition+", "+sURI+", "+sLastFile+", "+sUrl;
// }


}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import System.Diagnostics.Debug;

public class OverlayMenu extends MovieClip
{
public var Overlay:OverlayLoader;
public static const Name:String = "OverlayMenu";
private const Name:String = "OverlayMenu";
private const MountID:String = "OverlayMenu_ImageMount";

public function get Visible():Boolean { return this.visible; }
public function set Visible(value:Boolean):void { this.visible = value; }
Expand All @@ -23,6 +21,9 @@

public function OverlayMenu()
{
System.Diagnostics.Debug.Prefix = "Overlay Framework";
Overlay.MenuName = Name;
Overlay.MountID = MountID;
Debug.WriteLine("[OverlayMenu]", "(ctor)", "Constructor Code", this.loaderInfo.url);
}

Expand Down

0 comments on commit 44eb43b

Please sign in to comment.