Beispiel #1
0
    private void ProcessLoop()
    {
        while (true)
        {
            // If held, break as not to cause infinite loop :3
            if (hold == HoldState.Held)
            {
                break;
            }

            // Using XPath, finds current label, finds the step (any type) with the current step no (Note: XPath order selector starts at 1, not 0)
            var command = vnScript.SelectSingleNode($"/Script/Label[@name='{route}']/*[{step}]");

            switch (command.Name) // wew thats a large switch
            {
            case "Text":          // A plain VN Dialogue, nothing hard
                view.SetDialogue(command.InnerText);
                break;

            case "Element-Create":
                XMLElementAction.Create(command);
                break;

            case "Element-Destroy":
                Element.Destroy(command.Attributes["name"].Value);
                break;

            case "Music-Play":     // TODO: Not sure what this does, replace!
                var clip = ResourceController.Get <AudioClip>(command.InnerText);
                musicPlayer.PlayOneShot(clip);
                break;

            case "Load":
                if (command.Attributes?["type"]?.Value == "sprite")
                {
                    ResourceController.Load <Sprite>(command.InnerText);
                }
                else
                {
                    ResourceController.Load(command.InnerText);
                }
                break;

            case "Unload":
                ResourceController.Unload(command.InnerText);
                break;

            case "Jump":
                route = command.Attributes["label"].Value;
                step  = 0;    // somewhat hacky way to handle the increment at the end, will fix if this errs or something
                break;

            case "JS":     // JS Exec
                jsEngine.Execute(command.InnerText);
                break;

            default:
                throw new Exception($"{command.Name} is not a valid tag");
            }
            hold = Hold.GetHoldState(command);
            if (hold == HoldState.Clear)
            {
                step++;                          // Only progress to next step when HoldState is clear.
            }
        }
    }