예제 #1
0
        /// <summary>
        /// Create a new <see cref="RabotoraGameProject"/> instance by absolute base path of target game project.
        /// </summary>
        /// <param name="gameBasePath">Absolute base path of the Rabotora game project which is ready to be initialized.</param>
        /// <param name="isDebugMode">Determines whatever Rabotora Debug Mode is on after initialization or not. Default is <see langword="false"/> .</param>
        /// <returns>New <see cref="RabotoraGameProject"/> instance of the target Rabotora game project when success; otherwise, null.</returns>
        /// <exception cref="RabotoraInitializeException" />
        public async static Task <RabotoraGameProject?> CreateFromGamePathAsync(string gameBasePath, bool isDebugMode = false)
        {
            try
            {
                RabotoraDataPack.CheckPackTreeIntegrity(gameBasePath);
                var packList = new Dictionary <PackageType, RabotoraDataPack>();
                foreach (var packType in RabotoraDataPack.RequiredPackageTypes)
                {
                    var pack = await RabotoraDataPack.LoadAsync(Path.Combine(gameBasePath, RabotoraDataPack.PackTypeToFileName(packType)));

                    packList.Add(packType, pack);
                }
                return(new RabotoraGameProject(packList)
                {
                    IsDebugMode = isDebugMode
                });
            }
            catch (RabotoraInitializeException)
            {
                throw;
            }
            catch (RabotoraFormatException)
            {
                return(null);
            }
        }
예제 #2
0
        public static async Task <Tuple <RabotoraGameProject, RabotoraScript> > InitializeAsync(string gameBasePath)
        {
            try
            {
                var project = await RabotoraGameProject.CreateFromGamePathAsync(gameBasePath);

                if (project != null)
                {
                    var entryScriptDataWrapper = project.SystemPack["/main.rts"];
                    if (entryScriptDataWrapper.HasValue)
                    {
                        var entryScript = RabotoraScript.LoadScript("%system%/main.rts", "main", entryScriptDataWrapper.Value.ToArray());
                        return(Tuple.Create(project, entryScript));
                    }
                    else
                    {
                        throw new RabotoraException($"Failed to initialize Rabotora Game Project: Cannot find entry script data in {RabotoraDataPack.PackTypeToFileName(PackageType.SystemPack)}.");
                    }
                }
                else
                {
                    throw new RabotoraException($"Failed to initialize Rabotora Game Project.");
                }
            }
            catch (RabotoraException)
            {
                throw;
            }
        }