/// <summary> /// Initialize the story, bookmark and internal runner. /// This method should only be called once. /// </summary> public static void Init() { isInitialized = false; var settings = KataruSettings.Get(createIfMissing: true); targetPath = Application.streamingAssetsPath + "/" + settings.targetPath; bookmarkPath = Application.streamingAssetsPath + "/" + settings.bookmarkPath; savePath = Application.persistentDataPath + "/" + settings.savePath; codegenPath = settings.codegenPath; Debug.Log( $@"Kataru.Init(StoryPath: '{targetPath}', BookmarkPath: '{bookmarkPath}', SavePath: '{savePath}')"); #if UNITY_EDITOR if (!File.Exists(targetPath)) { Debug.LogWarning("Missing target. Retriggering compilation..."); storyPath = Application.dataPath + "/" + settings.storyPath; Compile(storyPath, bookmarkPath, targetPath, codegenPath); } #endif isRunning = false; isWaiting = false; // Only load the story on Init. FFI.LoadStory(targetPath); isInitialized = true; }
/// <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()}"); } }