private static string GetCode(ScriptLoader.Chunk chunk, DialogueActionStage stage)
        {
            var          sb        = new StringBuilder();
            var          stageName = GetStageName(stage);
            const string stageKey  = "stage";

            foreach (var block in chunk.blocks)
            {
                if (block.type == BlockType.LazyExecution)
                {
                    if (!block.attributes.TryGetValue(stageKey, out var stageValue))
                    {
                        stageValue = "";
                    }

                    if (!stageValue.Equals(stageName))
                    {
                        continue;
                    }

                    sb.Append(block.content);
                    sb.Append("\n");
                }
            }

            var code = sb.ToString().Trim();

            if (code == "")
            {
                code = null;
            }

            // if (code != null) Debug.Log($"code: <color=blue>{code}</color>");
            return(code);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Execute the action stored in this dialogue entry.
 /// </summary>
 public void ExecuteAction(DialogueActionStage stage, bool isRestoring)
 {
     if (actions.TryGetValue(stage, out var action))
     {
         LuaRuntime.Instance.UpdateExecutionContext(new ExecutionContext(ExecutionMode.Lazy, stage, isRestoring));
         try
         {
             action.Call();
         }
         catch (LuaException e)
         {
             throw new ScriptActionException(
                       $"Nova: Exception occurred when executing action: {I18n.__(dialogues)}", e);
         }
     }
 }
        private static string GetStageName(DialogueActionStage stage)
        {
            switch (stage)
            {
            case DialogueActionStage.BeforeCheckpoint:
                return("before_checkpoint");

            case DialogueActionStage.Default:
                return("");

            case DialogueActionStage.AfterDialogue:
                return("after_dialogue");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 4
0
 public ExecutionContext(ExecutionMode mode, DialogueActionStage stage, bool isRestoring)
 {
     this.stage       = stage;
     this.mode        = mode;
     this.isRestoring = isRestoring;
 }