Browse Source

Adding way to define AppDelegate class and namespace for project

Josh Engebretson 9 years ago
parent
commit
92c13506ea

+ 3 - 1
Data/AtomicEditor/AtomicNET/ProjectTemplate/Platforms/Android/MainActivity.cs

@@ -5,6 +5,8 @@ using Android.OS;
 using Android.Views;
 using AtomicEngine;
 
+$$APPLICATION_NAMESPACE$$
+
 namespace AtomicPlayer
 {
     [Activity(Label = "AtomicPlayer", MainLauncher = true,
@@ -17,7 +19,7 @@ namespace AtomicPlayer
         {
             base.OnCreate(bundle);
             var mLayout = new AbsoluteLayout(this);
-            var surface = AndroidSDLSurface.CreateSurface(this, false, typeof(AtomicMain));
+            var surface = AndroidSDLSurface.CreateSurface(this, false, typeof($$APPLICATION_APPDELEGATECLASS$$));
             mLayout.AddView(surface);
             SetContentView(mLayout);
         }

+ 2 - 1
Data/AtomicEditor/AtomicNET/ProjectTemplate/Platforms/Desktop/Program.cs

@@ -4,6 +4,7 @@ using System.Reflection;
 using System.Linq;
 
 using AtomicEngine;
+$$APPLICATION_NAMESPACE$$
 
 namespace AtomicPlayer
 {
@@ -11,7 +12,7 @@ namespace AtomicPlayer
     {
         public static void Main(string[] args)
         {
-            Application.Run<AtomicMain>(args);
+            Application.Run<$$APPLICATION_APPDELEGATECLASS$$>(args);
         }
     }
 }

+ 2 - 1
Data/AtomicEditor/AtomicNET/ProjectTemplate/Platforms/iOS/AppUIDelegate.cs

@@ -3,6 +3,7 @@ using UIKit;
 using System.Threading.Tasks;
 
 using AtomicEngine;
+$$APPLICATION_NAMESPACE$$
 
 namespace AtomicPlayer
 {
@@ -18,7 +19,7 @@ namespace AtomicPlayer
         async void LaunchGame()
         {
             await Task.Yield();
-            Application.Run<AtomicMain>(new string[0]);
+            Application.Run<$$APPLICATION_APPDELEGATECLASS$$>(new string[0]);
         }
     }
 }

+ 2 - 0
Data/AtomicEditor/ExampleInfo/Examples.json

@@ -29,6 +29,8 @@
             "name": "AtomicBlaster",
             "desc" : "Port of ShapeBlaster for XNA by Michael Hoffman",
             "screenshot" : "Example.png",
+            "namespace" : "AtomicBlaster",
+            "appDelegateClass" : "GameRoot",
             "folder" : "AtomicBlaster"
         },
         {

+ 17 - 2
Script/AtomicEditor/resources/ProjectTemplates.ts

@@ -30,6 +30,8 @@ export interface ProjectTemplateDefinition {
     screenshot: string;
     folder: string;
     languages: string[];
+    appDelegateClass: string;
+    namespace: string[];
 }
 
 // Supported project languages
@@ -143,6 +145,7 @@ export interface AtomicNETProjectInfo {
     appID: string;
     platforms: string[];
     projectFolder: string;
+    projectTemplate: ProjectTemplateDefinition;
 }
 
 var atomicNETProjectInfo:AtomicNETProjectInfo;
@@ -164,8 +167,20 @@ function processAtomicNETTemplate(filename:string, templateFilename:string) : bo
 
     let text = file.readText();
 
+    let _namespace = "";
+    if (atomicNETProjectInfo.projectTemplate.namespace) {
+        _namespace = "using " + atomicNETProjectInfo.projectTemplate.namespace + ";";
+    }
+
+    let appDelegateClass = "AtomicMain";
+    if (atomicNETProjectInfo.projectTemplate.appDelegateClass) {
+        appDelegateClass = atomicNETProjectInfo.projectTemplate.appDelegateClass;
+    }
+
     text = text.split("$$APPLICATION_NAME$$").join(atomicNETProjectInfo.name);
     text = text.split("$$APPLICATION_ID$$").join(atomicNETProjectInfo.appID);
+    text = text.split("$$APPLICATION_APPDELEGATECLASS$$").join(appDelegateClass);
+    text = text.split("$$APPLICATION_NAMESPACE$$").join(_namespace);
 
     let fileOut = new Atomic.File(filename, Atomic.FILE_WRITE);
 
@@ -317,10 +332,10 @@ function generateAtomicNETDesktopProject():boolean {
             return false;
     }
 
-    if (!fileSystem.copy(templateFolder + "Platforms/Desktop/Program.cs", desktopFolder + "Program.cs")) {
+    if (!processAtomicNETTemplate(desktopFolder + "Program.cs", templateFolder + "Platforms/Desktop/Program.cs")) {
         return false;
     }
-
+    
     return true;
 }
 

+ 2 - 1
Script/AtomicEditor/ui/modal/CreateProject.ts

@@ -242,7 +242,8 @@ class CreateProject extends ModalWindow {
                         name: name,
                         appID : this.appIDField.text,
                         platforms : platforms,
-                        projectFolder : folder
+                        projectFolder : folder,
+                        projectTemplate : this.projectTemplate
                     })) {
                         var message = "Unable to generate AtomicNET project: " + folder;
                         EditorUI.showModalError("New Project Editor Error", message);