Exemplo n.º 1
0
        public void buildToLua(BackgroundWorker worker, bool isCustomBuild, float XRatio, float YRatio, bool isDebug)
        {
            if (this.project != null)
            {
                try
                {
                    float moyenneRatio = (XRatio + YRatio) / 2;

                    //Report progress
                    worker.ReportProgress(10);

                    if (Directory.Exists(this.project.BuildFolderPath))
                    {
                        Directory.Delete(this.project.BuildFolderPath, true);
                    }

                    Directory.CreateDirectory(this.project.BuildFolderPath);

                    //Report progress
                    worker.ReportProgress(20);

                    CreateConfigLua(isCustomBuild, XRatio, YRatio);

                    CreateBuildSettings();

                    //Report progress
                    worker.ReportProgress(30);

                    createMain(isDebug);

                    //Report progress
                    worker.ReportProgress(40);

                    ImageResizer ImageResizer = new ImageResizer(this.project);
                    if (!ImageResizer.GenerateIconFile())
                    {
                        MessageBox.Show("can't create Icon!");
                    }

                    if (isCustomBuild == false)
                    {
                        if (!ImageResizer.GenerateImageFile())
                        {
                            MessageBox.Show("can't create Images!");
                        }
                    }
                    else
                    {
                        if (!ImageResizer.generateImageFilesWithRatio(XRatio, YRatio))
                        {
                            MessageBox.Show("can't create Images!");
                        }
                    }

                    //Report progress
                    worker.ReportProgress(50);

                    CreateLuaLangue(this.project);

                    //Report progress
                    worker.ReportProgress(60);



                    //Importer les fichiers necessaires
                    List <string> filenames = this.getLuaFilesUsed(isDebug);
                    if (filenames != null)
                    {
                        for (int i = 0; i < filenames.Count; i++)
                        {
                            File.Copy(this.PATH_REPOSITORY_DIR + "\\" + filenames[i], this.project.BuildFolderPath + "\\" + filenames[i].Replace("Krea Remote\\", ""), true);
                        }
                    }

                    for (int i = 0; i < project.Scenes.Count; i++)
                    {
                        Scene scene = project.Scenes[i];
                        if (scene.isEnabled == true)
                        {
                            for (int j = 0; j < scene.Layers.Count; j++)
                            {
                                CoronaLayer layer = scene.Layers[j];
                                if (layer.isEnabled == true)
                                {
                                    for (int k = 0; k < layer.CoronaObjects.Count; k++)
                                    {
                                        CoronaObject objectToBuild = layer.CoronaObjects[k];
                                        if (objectToBuild.isEnabled == true)
                                        {
                                            if (objectToBuild.isEntity == false)
                                            {
                                                PhysicsBody ph = objectToBuild.PhysicsBody;
                                                if (ph.Mode != PhysicsBody.PhysicBodyMode.Inactive)
                                                {
                                                    string objName = objectToBuild.DisplayObject.Name.Replace(" ", "");
                                                    //Creer le fichier lua associé
                                                    PhysicBodyLuaGenerator gen = new PhysicBodyLuaGenerator(ph);
                                                    gen.writeToLua(new DirectoryInfo(project.BuildFolderPath), XRatio, YRatio);

                                                    if (File.Exists(project.SourceFolderPath + "\\body" + objName.ToLower() + ".lua"))
                                                    {
                                                        File.Delete(project.SourceFolderPath + "\\body" + objName.ToLower() + ".lua");
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                for (int l = 0; l < objectToBuild.Entity.CoronaObjects.Count; l++)
                                                {
                                                    CoronaObject child = objectToBuild.Entity.CoronaObjects[l];
                                                    if (child.isEnabled == true)
                                                    {
                                                        PhysicsBody ph = child.PhysicsBody;
                                                        if (ph.Mode != PhysicsBody.PhysicBodyMode.Inactive)
                                                        {
                                                            string objName = child.DisplayObject.Name.Replace(" ", "");
                                                            //Creer le fichier lua associé
                                                            PhysicBodyLuaGenerator gen = new PhysicBodyLuaGenerator(ph);
                                                            gen.writeToLua(new DirectoryInfo(project.BuildFolderPath), XRatio, YRatio);

                                                            if (File.Exists(project.SourceFolderPath + "\\body" + objName.ToLower() + ".lua"))
                                                            {
                                                                File.Delete(project.SourceFolderPath + "\\body" + objName.ToLower() + ".lua");
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    CopyFolder(this.project.SourceFolderPath, this.project.BuildFolderPath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Build Failed!\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Build Failed ! ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }