From ea0db8f13f3737abeec4c48948be97059d6a3685 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 19 Mar 2015 14:16:31 -0700 Subject: [PATCH] Populate additional Config values, use company name and file name for preference path --- lime/app/Config.hx | 8 ++++++- lime/system/System.hx | 32 ++++++++++++++++++++++----- project/include/system/System.h | 2 +- project/src/ExternalInterface.cpp | 12 +++++++--- project/src/backend/sdl/SDLSystem.cpp | 8 +++---- templates/haxe/ApplicationMain.hx | 4 ++++ 6 files changed, 50 insertions(+), 16 deletions(-) diff --git a/lime/app/Config.hx b/lime/app/Config.hx index bfc9d12e2..b501a84cf 100644 --- a/lime/app/Config.hx +++ b/lime/app/Config.hx @@ -4,20 +4,26 @@ package lime.app; typedef Config = { @:optional var antialiasing:Int; + #if (js && html5) + @:optional var assetsPrefix:String; + #end @:optional var background:Null; @:optional var borderless:Bool; + @:optional var company:String; @:optional var depthBuffer:Bool; #if (js && html5) @:optional var element:#if (haxe_ver >= "3.2") js.html.Element #else js.html.HtmlElement #end; - @:optional var assetsPrefix:String; #end + @:optional var file:String; @:optional var fps:Int; @:optional var fullscreen:Bool; @:optional var height:Int; @:optional var orientation:String; + @:optional var packageName:String; @:optional var resizable:Bool; @:optional var stencilBuffer:Bool; @:optional var title:String; + @:optional var version:String; @:optional var vsync:Bool; @:optional var width:Int; diff --git a/lime/system/System.hx b/lime/system/System.hx index e39ba1adb..fd7b4051b 100644 --- a/lime/system/System.hx +++ b/lime/system/System.hx @@ -1,4 +1,5 @@ package lime.system; +import lime.app.Application; #if flash @@ -409,7 +410,7 @@ class System { private static function get_applicationDirectory ():String { #if (cpp || neko || nodejs) - return lime_system_get_directory (SystemDirectory.APPLICATION); + return lime_system_get_directory (SystemDirectory.APPLICATION, null, null); #else return null; #end @@ -419,8 +420,27 @@ class System { private static function get_applicationStorageDirectory ():String { + var company = "MyCompany"; + var file = "MyApplication"; + + if (Application.current != null && Application.current.config != null) { + + if (Application.current.config.company != null) { + + company = Application.current.config.company; + + } + + if (Application.current.config.file != null) { + + file = Application.current.config.file; + + } + + } + #if (cpp || neko || nodejs) - return lime_system_get_directory (SystemDirectory.APPLICATION_STORAGE); + return lime_system_get_directory (SystemDirectory.APPLICATION_STORAGE, company, file); #else return null; #end @@ -431,7 +451,7 @@ class System { private static function get_desktopDirectory ():String { #if (cpp || neko || nodejs) - return lime_system_get_directory (SystemDirectory.DESKTOP); + return lime_system_get_directory (SystemDirectory.DESKTOP, null, null); #else return null; #end @@ -442,7 +462,7 @@ class System { private static function get_documentsDirectory ():String { #if (cpp || neko || nodejs) - return lime_system_get_directory (SystemDirectory.DOCUMENTS); + return lime_system_get_directory (SystemDirectory.DOCUMENTS, null, null); #else return null; #end @@ -453,7 +473,7 @@ class System { private static function get_userDirectory ():String { #if (cpp || neko || nodejs) - return lime_system_get_directory (SystemDirectory.USER); + return lime_system_get_directory (SystemDirectory.USER, null, null); #else return null; #end @@ -469,7 +489,7 @@ class System { #if (cpp || neko || nodejs) - private static var lime_system_get_directory = System.load ("lime", "lime_system_get_directory", 1); + private static var lime_system_get_directory = System.load ("lime", "lime_system_get_directory", 3); private static var lime_system_get_timer = System.load ("lime", "lime_system_get_timer", 0); #end diff --git a/project/include/system/System.h b/project/include/system/System.h index dff94c87f..18ad00b81 100644 --- a/project/include/system/System.h +++ b/project/include/system/System.h @@ -23,7 +23,7 @@ namespace lime { public: - static const char* GetDirectory (SystemDirectory type); + static const char* GetDirectory (SystemDirectory type, const char* company, const char* title); static double GetTimer (); diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index f7f29b25b..00e3f5b70 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -559,9 +559,15 @@ namespace lime { } - value lime_system_get_directory (value type) { + value lime_system_get_directory (value type, value company, value title) { - return alloc_string (System::GetDirectory ((SystemDirectory)val_int (type))); + const char* companyName = ""; + const char* titleName = ""; + + if (!val_is_null (company)) companyName = val_string (company); + if (!val_is_null (title)) titleName = val_string (title); + + return alloc_string (System::GetDirectory ((SystemDirectory)val_int (type), companyName, titleName)); } @@ -764,7 +770,7 @@ namespace lime { DEFINE_PRIM (lime_renderer_create, 1); DEFINE_PRIM (lime_renderer_flip, 1); DEFINE_PRIM (lime_render_event_manager_register, 2); - DEFINE_PRIM (lime_system_get_directory, 1); + DEFINE_PRIM (lime_system_get_directory, 3); DEFINE_PRIM (lime_system_get_timer, 0); DEFINE_PRIM (lime_text_layout_create, 3); DEFINE_PRIM (lime_text_layout_position, 5); diff --git a/project/src/backend/sdl/SDLSystem.cpp b/project/src/backend/sdl/SDLSystem.cpp index 95cc8a65c..3a8a0c1f5 100644 --- a/project/src/backend/sdl/SDLSystem.cpp +++ b/project/src/backend/sdl/SDLSystem.cpp @@ -28,20 +28,18 @@ namespace lime { - const char* System::GetDirectory (SystemDirectory type) { + const char* System::GetDirectory (SystemDirectory type, const char* company, const char* title) { switch (type) { case APPLICATION: - // TODO: Need to get the user's company and title or package name - // previous behavior was the company + file - return SDL_GetPrefPath ("My Company", "My Awesome SDL 2 Game"); + return SDL_GetBasePath (); break; case APPLICATION_STORAGE: - return SDL_GetBasePath (); + return SDL_GetPrefPath (company, title); break; case DESKTOP: { diff --git a/templates/haxe/ApplicationMain.hx b/templates/haxe/ApplicationMain.hx index 97ef97394..8f578cb93 100644 --- a/templates/haxe/ApplicationMain.hx +++ b/templates/haxe/ApplicationMain.hx @@ -64,14 +64,18 @@ class ApplicationMain { antialiasing: Std.int (::WIN_ANTIALIASING::), background: Std.int (::WIN_BACKGROUND::), borderless: ::WIN_BORDERLESS::, + company: "::META_COMPANY::", depthBuffer: ::WIN_DEPTH_BUFFER::, + file: "::APP_FILE::", fps: Std.int (::WIN_FPS::), fullscreen: ::WIN_FULLSCREEN::, height: Std.int (::WIN_HEIGHT::), orientation: "::WIN_ORIENTATION::", + packageName: "::META_PACKAGE_NAME::", resizable: ::WIN_RESIZABLE::, stencilBuffer: ::WIN_STENCIL_BUFFER::, title: "::APP_TITLE::", + version: "::META_VERSION::", vsync: ::WIN_VSYNC::, width: Std.int (::WIN_WIDTH::),