Browse Source

Added filesystem.SetAssetsDir.

Mark Sibly 7 years ago
parent
commit
bc732a911f
1 changed files with 22 additions and 7 deletions
  1. 22 7
      modules/std/filesystem/filesystem.monkey2

+ 22 - 7
modules/std/filesystem/filesystem.monkey2

@@ -211,6 +211,10 @@ Function SetConfig( name:String,value:String )
 	If value _config[name]=value Else _config.Remove( name )
 	If value _config[name]=value Else _config.Remove( name )
 End
 End
 
 
+Private 
+Global _assetsDir:String
+Public
+
 #rem monkeydoc Gets the filesystem directory of the app's assets directory.
 #rem monkeydoc Gets the filesystem directory of the app's assets directory.
 
 
 Note that only the desktop and web targets have an assets directory. Other targets will return an empty string.
 Note that only the desktop and web targets have an assets directory. Other targets will return an empty string.
@@ -219,16 +223,28 @@ Note that only the desktop and web targets have an assets directory. Other targe
 
 
 #end
 #end
 Function AssetsDir:String()
 Function AssetsDir:String()
+	If Not _assetsDir
 #If __TARGET__="macos"
 #If __TARGET__="macos"
-	Return AppDir()+"../Resources/"
-	'Return ExtractDir( AppDir() )+"/Resources/"	'enable me!
+		_assetsDir=ExtractDir( AppDir() )+"Resources/"	'enable me!
 #Else If __DESKTOP_TARGET__ Or __WEB_TARGET__
 #Else If __DESKTOP_TARGET__ Or __WEB_TARGET__
-	Return AppDir()+"assets/"
+		_assetsDir=AppDir()+"assets/"
 #Else If __TARGET__="ios"
 #Else If __TARGET__="ios"
-	Return GetSpecialDir( "assets" )
+		_assetsDir=GetSpecialDir( "assets" )
 #Else
 #Else
-	Return "asset::"
+		_assetsDir="asset::"
 #Endif
 #Endif
+	Endif
+	Return _assetsDir
+End
+
+#rem monkeydoc Changes the assets dir.
+
+Set to an empty string to use the default assets dir.
+
+#end
+Function SetAssetsDir( dir:String )
+	If dir dir=RealPath( FixFilePath( dir ) )+"/"
+	_assetsDir=dir
 End
 End
 
 
 #rem monkeydoc Gets the filesystem directory of the user's desktop directory.
 #rem monkeydoc Gets the filesystem directory of the user's desktop directory.
@@ -311,7 +327,7 @@ A root directory is a directory path that:
  
  
 #end
 #end
 Function ExtractRootDir:String( path:String )
 Function ExtractRootDir:String( path:String )
-
+	
 	If path.StartsWith( "//" ) Return "//"
 	If path.StartsWith( "//" ) Return "//"
 	
 	
 	Local i:=path.Find( "/" )
 	Local i:=path.Find( "/" )
@@ -329,7 +345,6 @@ Function ExtractRootDir:String( path:String )
 	If j>0 And j<i Return path.Slice( 0,j+2 )
 	If j>0 And j<i Return path.Slice( 0,j+2 )
 	
 	
 	Return ""
 	Return ""
-	
 End
 End
 
 
 #rem monkeydoc Checks if a path is a root directory.
 #rem monkeydoc Checks if a path is a root directory.