Exemple #1
0
    public void prepare(Dictionary <string, int> variables)
    {
        //Attempt to replace variables
        if (resourcePath.IndexOf('{') > 0)
        {
            int    varStart         = resourcePath.IndexOf('$') + 1;
            int    varLength        = resourcePath.IndexOf('}') - varStart;
            string variableName     = resourcePath.Substring(varStart, varLength);
            string substituteString = "{$" + variableName + "}";

            Debug.Log("Replacing variable " + variableName + " in " + resourcePath + " with " + variables[variableName]);

            if (variables.ContainsKey(variableName))
            {
                resourcePath = resourcePath.Replace(substituteString, variables[variableName].ToString());
            }
        }

        Debug.Log("Attempting to jump to script file at " + resourcePath);
        if (!File.Exists(novelPath + "/script/" + resourcePath))
        {
            using (ZipFile scriptZip = ZipFile.Read(novelPath + "/script.zip")) {
                string fileName = resourcePath.Substring(resourcePath.LastIndexOf('/') + 1);
                resourcePath = ArchiveUtil.extractFromZipFile(scriptZip, fileName, VisualNovel.cacheDirectory);
            }
            //resourcePath = VisualNovel.cacheDirectory + "/script/" + resourcePath;
        }
        else
        {
            resourcePath = novelPath + "/script/" + resourcePath;
        }
    }
    //Load image, music, etc
    public virtual void prepare(Dictionary <string, int> variables)
    {
        if (!resourcePath.Equals("~") && resourceStream == null)
        {
            if (!File.Exists(novelPath + "/" + getType() + "/" + resourcePath))
            {
                if (!File.Exists(VisualNovel.cacheDirectory + "/" + getType() + "/" + resourcePath))
                {
                    Debug.Log("Couldn't find asset " + resourcePath + " outside of archive, checking " + getType() + ".zip");
                    if (File.Exists(novelPath + "/" + getType() + ".zip"))
                    {
                        using (ZipFile scriptZip = ZipFile.Read(novelPath + "/" + getType() + ".zip")) {
                            string fileName = resourcePath.Substring(resourcePath.LastIndexOf('/') + 1);
                            resourcePath = "file://" + ArchiveUtil.extractFromZipFile(scriptZip, fileName, VisualNovel.cacheDirectory);

                            //
                            //try {
                            //    scriptZip.ExtractSelectedEntries("name = " + fileName, null, VisualNovel.cacheDirectory);
                            //} catch (System.Exception e) {
                            //    Debug.Log("Could not find an entry in the " + getType() + " archive for resource " + resourcePath + ". Please ensure this file exists.");
                            //}
                        }
                    }
                    else
                    {
                        Debug.Log("Could not find " + resourcePath + " in folder or archive. Please ensure this file exists.");
                        resourcePath = "~";
                    }
                }
                else
                {
                    resourcePath = "file://" + VisualNovel.cacheDirectory + "/" + getType() + "/" + resourcePath;
                }
                //This doesn't report accurately?
                //if (!File.Exists(resourcePath)) {
                //    Debug.Log("Was not able to extract the " + getType() + " at " + resourcePath);
                //}
            }
            else
            {
                resourcePath = "file://" + novelPath + "/" + getType() + "/" + resourcePath;
            }

            //Now that we've extracted the resource, set up a WWW to load it
            resourceStream = new WWW(resourcePath);
        }
    }
Exemple #3
0
    public void start()
    {
        Debug.Log("About to parse novel in " + novelDirectory);
        string[] subFolders    = Directory.GetDirectories(novelDirectory);
        string[] topLevelFiles = Directory.GetFiles(novelDirectory);

        //Find out where our scripts live
        Debug.Log(cacheDirectory);
        if (Directory.Exists(cacheDirectory))
        {
            try {
                Directory.Delete(cacheDirectory, true);
            } catch (System.Exception e) {
                Debug.Log("Couldn't delete stuff! IDK Why!");
            }
        }

        try {
            Directory.CreateDirectory(cacheDirectory);
        } catch (System.Exception e) {
            Debug.Log("Couldn't create cache directory! You're gonna have a bad time!");
        }

        if (!Directory.Exists(cacheDirectory + "/script"))
        {
            Directory.CreateDirectory(cacheDirectory + "/script");
        }


        //Extract the main script file
        string scriptPath    = novelDirectory + "/script/main.scr"; //By default assume it's in the normal script folder
        string scriptZipPath = novelDirectory + "/script.zip";

        if (!File.Exists(scriptPath) && File.Exists(scriptZipPath))
        {
            //Extract main.scr to start with

            using (ZipFile scriptZip = ZipFile.Read(scriptZipPath)) {
                try {
                    Debug.Log("ATTEMPTING TO EXTRACT MAIN SCRIPT");
                    //scriptZip.ExtractSelectedEntries("name = main.scr", null, cacheDirectory);
                    //scriptZip.ExtractAll(cacheDirectory);

                    scriptPath = ArchiveUtil.extractFromZipFile(scriptZip, "/main.scr", cacheDirectory);

                    //foreach (ZipEntry e in scriptZip.Entries) {
                    //    e.Extract(cacheDirectory);
                    //}
                } catch (System.Exception e) {
                    Debug.Log("Error extracting main.scr: " + e.Message);
                }
            }
        }

        //Read the main script file
        currentScript = new VisualNovelScript(scriptPath, novelDirectory);



        //Extract scripts
        //Load first script?
    }