コード例 #1
0
            public void FormatMethod(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext)
            {
                String methodName = GetMethodName(formatterContext);

                sw.AppendLine($"public void {methodName}()");
                {
                    sw.AppendLine("{");
                    sw.Indent++;

                    FormatMethodBody(sw, formatterContext, executionContext);

                    sw.Indent--;
                    sw.AppendLine("}");
                }
            }
コード例 #2
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.Append("else if(");
     ((JPF)_list[0]).Format(sw, formatterContext, services);
     sw.AppendLine(")");
     FormatBranch(sw, formatterContext, services, GetBodyInstructions());
 }
コード例 #3
0
        public static void FormatGlobalSet <T>(GlobalVariableId <T> globalVariable, IJsmExpression value, Int32[] knownVariables, ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext) where T : unmanaged
        {
            sw.Append("G");

            if (knownVariables == null || Array.BinarySearch(knownVariables, globalVariable.VariableId) < 0)
            {
                sw.Append("[");
                sw.Append(globalVariable.VariableId.ToString(CultureInfo.InvariantCulture));
                sw.Append("]");
                sw.Append(" = ");
                sw.Append("(");
                sw.Append(GlobalVariableId <T> .TypeName);
                sw.Append(")");
            }
            else
            {
                sw.Append(GlobalVariableId <T> .TypeName);
                sw.Append("[");
                sw.Append(globalVariable.VariableId.ToString(CultureInfo.InvariantCulture));
                sw.Append("]");
                sw.Append(" = ");
            }

            value.Format(sw, formatterContext, executionContext);
            sw.AppendLine(";");
        }
コード例 #4
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.Append($"R{_index.ResultId}");
     sw.Append(" = ");
     _value.Format(sw, formatterContext, services);
     sw.AppendLine(";");
 }
コード例 #5
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.Append("while(");
     ((JPF)_list[0]).Format(sw, formatterContext, services);
     sw.AppendLine(")");
     FormatBranch(sw, formatterContext, services, _list.Skip(1));
 }
コード例 #6
0
            protected void FormatBranch(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext, IEnumerable <IJsmInstruction> items)
            {
                sw.AppendLine("{");
                sw.Indent++;

                var state = sw.RememberState();

                FormatItems(sw, formatterContext, executionContext, items);
                if (!state.IsChanged)
                {
                    sw.AppendLine("// do nothing");
                }

                sw.Indent--;
                sw.AppendLine("}");
            }
コード例 #7
0
        public static void FormatMonologue(ScriptWriter sw, String message)
        {
            if (!sw.HasWhiteLine)
            {
                sw.AppendLine();
            }

            foreach (String str in SplitMonologue(message))
            {
                if (String.IsNullOrEmpty(str))
                {
                    continue;
                }

                sw.Append("// ");
                sw.AppendLine(str);
            }
        }
コード例 #8
0
                    public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
                    {
                        sw.Append("if(");
                        Jpf.Format(sw, formatterContext, services);
                        sw.AppendLine(")");
                        FormatBranch(sw, formatterContext, services, GetBodyInstructions());

                        foreach (var item in _aggregator.EnumerateElseBlocks())
                        {
                            item.Format(sw, formatterContext, services);
                        }
                    }
コード例 #9
0
 private static void FormatItems(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext, IEnumerable <IJsmInstruction> items)
 {
     foreach (var item in items)
     {
         if (item is IFormattableScript formattable)
         {
             formattable.Format(sw, formatterContext, executionContext);
         }
         else
         {
             sw.AppendLine(item.ToString());
         }
     }
 }
コード例 #10
0
            public void FormatType(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext)
            {
                formatterContext.GetObjectScriptNamesById(Id, out String typeName, out _);
                sw.AppendLine($"public sealed class {typeName}");
                {
                    sw.AppendLine("{");
                    sw.Indent++;

                    if (Scripts.Count > 0)
                    {
                        FormatConstructor(typeName, sw, formatterContext, executionContext);

                        foreach (var script in Scripts.Skip(1))
                        {
                            sw.AppendLine();
                            script.FormatMethod(sw, formatterContext, executionContext);
                        }
                    }

                    sw.Indent--;
                    sw.AppendLine("}");
                }
            }
コード例 #11
0
            private void FormatConstructor(String typeName, ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext)
            {
                sw.AppendLine($"private readonly {nameof(IServices)} _ctx;");
                sw.AppendLine();

                sw.AppendLine($"public {typeName}({nameof(IServices)} executionContext)");
                {
                    sw.AppendLine("{");
                    sw.Indent++;

                    sw.AppendLine("_ctx = executionContext;");
                    Scripts[0].FormatMethodBody(sw, formatterContext, executionContext);

                    sw.Indent--;
                    sw.AppendLine("}");
                }
            }
コード例 #12
0
ファイル: JsmInstruction.cs プロジェクト: rustyworks/OpenVIII
 public virtual void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine(this.ToString());
 }
コード例 #13
0
 public void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"goto LABEL{_label};");
 }
コード例 #14
0
ファイル: IRET.cs プロジェクト: rustyworks/OpenVIII
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"return {nameof(IRET)}({Unknown});");
 }
コード例 #15
0
ファイル: REQEW.cs プロジェクト: rustyworks/OpenVIII
        public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
        {
            formatterContext.GetObjectScriptNamesById(_scriptId, out String typeName, out String methodName);

            sw.AppendLine($"{nameof(REQEW)}(priority: {_priority}, GetObject<{typeName}>().{methodName}());");
        }
コード例 #16
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"R{ResultVariable.ResultId} = {nameof(Rnd)}.{nameof(Rnd.NextByte)}();");
 }
コード例 #17
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"// ScriptId: {Label}");
 }
コード例 #18
0
        public static void FormatAnswers(ScriptWriter sw, String message, IJsmExpression top, IJsmExpression bottom, IJsmExpression begin, IJsmExpression cancel)
        {
            if (!(top is IConstExpression t) || !(bottom is IConstExpression b))
            {
                FormatMonologue(sw, message);
                return;
            }

            if (!sw.HasWhiteLine)
            {
                sw.AppendLine();
            }

            // Question
            //☞ Answer 1
            //   Answer 2
            //   Answer 3
            //☜ Answer 4

            Int32 to = t.Int32();
            Int32 bo = b.Int32();
            Int32 be = -1;
            Int32 ca = -1;

            if (begin is IConstExpression beg)
            {
                be = beg.Int32();
            }

            if (cancel is IConstExpression can)
            {
                ca = can.Int32();
            }

            String[] lines = SplitMonologue(message);

            for (Int32 i = 0; i < lines.Length; i++)
            {
                sw.Append("//");
                if (i >= to && i <= bo)
                {
                    if (i == be)
                    {
                        sw.Append("☞ ");
                    }
                    else if (i == ca)
                    {
                        sw.Append("☜ ");
                    }
                    else
                    {
                        sw.Append("   ");
                    }
                }
                else
                {
                    sw.Append(" ");
                }

                sw.AppendLine(lines[i]);
            }
        }
コード例 #19
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine("else");
     FormatBranch(sw, formatterContext, services, GetBodyInstructions());
 }