Esempio n. 1
0
        /// <summary>
        /// Compiles the story at `storyPath` with bookmark at `bookmarkPath` to `targetPath`.
        /// Generates a constants file and saves it to the Kataru source directory.
        /// </summary>
        /// <param name="storyPath"></param>
        /// <param name="bookmarkPath"></param>
        /// <param name="targetPath"></param>
        /// <param name="codegenPath"></param>
        public static void Compile(string storyPath, string bookmarkPath, string targetPath, string codegenPath)
        {
            Debug.Log($@"Runner.Compile(storyPath: '{storyPath}'
                bookmarkPath: '{bookmarkPath}'
                targetPath: '{targetPath}'
                codegenPath: '{codegenPath}')");
            try
            {
                FFI.LoadStory(storyPath);
                FFI.LoadBookmark(bookmarkPath);
                FFI.Validate();

                Debug.Log($"Story at '{storyPath}' validated. Saving compiled story to '{targetPath}'.");
                FFI.SaveStory(targetPath);
                FFI.CodegenConsts(codegenPath);

                // Force unity to recompile using the newly generated source code.
                if (FFI.CodegenWasUpdated())
                {
                    Debug.Log($"Constants file generated at {targetPath}");
                    UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation();
                }
            }
            catch (System.EntryPointNotFoundException e)
            {
                Debug.LogError($"Kataru error: could not find FFI command named '{e.Message}'");
            }
            catch (Exception e)
            {
                Debug.LogError($"Kataru error: {e.ToString()}");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Load bookmark from the save path path.
        /// Call this when wanting to load save file.
        /// </summary>
        public static void Load()
        {
            if (!isInitialized)
            {
                Debug.LogError($"Have not initialized. Call Runner.Init() before calling this.");
                return;
            }

            if (SaveExists())
            {
                FFI.LoadBookmark(savePath);
            }
            else
            {
                Debug.Log($"Loading bookmark {bookmarkPath}");
                FFI.LoadBookmark(bookmarkPath);
            }

            Debug.Log("Initializing runner...");
            FFI.InitRunner();
        }