Represents a Sphere Studio project.
Inheritance: IProject
Example #1
0
        /// <summary>
        /// Creates a new Sphere Studio project from a Sphere 1.x game.sgm file.
        /// </summary>
        /// <param name="fileName">The fully qualified filename of the game.sgm to import.</param>
        /// <returns>A Project object representing the new project.</returns>
        public static Project FromSgm(string fileName)
        {
            if (!File.Exists(fileName))
                throw new FileNotFoundException();

            var rootPath = Path.GetDirectoryName(fileName);
            Project project = new Project(Path.Combine(rootPath, "game.ssproj"))
            {
                BackCompatible = true,
                Name = "Untitled",
                Author = "Author Unknown",
                Summary = "",
                ScreenWidth = 320,
                ScreenHeight = 240,
                MainScript = "main.js",
            };

            string[] sgmText = File.ReadAllLines(fileName);
            foreach (string line in sgmText)
            {
                try
                {
                    Match match = new Regex("(.+)=(.*)").Match(line);
                    if (match.Success)
                    {
                        string key = match.Groups[1].Value;
                        string value = match.Groups[2].Value;
                        switch (key)
                        {
                            case "name": project.Name = value; break;
                            case "author": project.Author = value; break;
                            case "description": project.Summary = value; break;
                            case "script": project.MainScript = value; break;
                            case "screen_width": project.ScreenWidth = int.Parse(value); break;
                            case "screen_height": project.ScreenHeight = int.Parse(value); break;
                        }
                    }
                }
                catch
                {
                    // ignore any parsing errors. if an error occurs parsing the manifest,
                    // we'll just use the default values. this ensures it is always possible
                    // to upgrade a Sphere 1.x project even if the game.sgm is damaged.
                }
            }

            project.FileName = Path.Combine(rootPath, MakeFileName(project.Name));
            project.Compiler = "Vanilla";
            project.User.Engine = "Sphere 1.x";
            return project;
        }
Example #2
0
 /// <summary>
 /// Creates a new, empty Sphere Studio project.
 /// </summary>
 /// <param name="rootPath">Path of the directory where the project will reside. Must be empty.</param>
 /// <param name="name">The name of the project to create.</param>
 /// <returns>A Project object representing the new project.</returns>
 public static Project Create(string rootPath, string name)
 {
     DirectoryInfo dirInfo = new DirectoryInfo(rootPath);
     if (dirInfo.Exists && dirInfo.GetFileSystemInfos().Length > 0)
         throw new ArgumentException("Root directory for a new project must be empty.");
     dirInfo.Create();
     var project = new Project(Path.Combine(dirInfo.FullName, MakeFileName(name)))
     {
         Name = name
     };
     return project;
 }