public string ToBzs() { var builder = new StringBuilder(); builder.AppendLine("[objects]"); foreach (var obj in Objects) { builder.AppendLine(obj.ToString()); } builder.AppendLine(); builder.AppendLine("[positions]"); foreach (var position in Positions) { builder.AppendLine(position.ToString()); } builder.AppendLine(); builder.AppendLine("[variables]"); foreach (var variable in Variables) { builder.AppendLine(variable.ToString()); } builder.AppendLine(); builder.Append("[text]"); foreach (var text in Texts) { builder.AppendLine(text.ToString()); } foreach (var routine in Routines) { builder.AppendLine(); builder.AppendLine(routine.ToString()); foreach (var line in routine.Lines) { var text = line switch { ScripterRoutineCommand c => "\t" + c, _ => line.ToString() }; builder.AppendLine(text); } } return(builder.ToString()); }
private void TranslateCommand(ScripterRoutineCommand command, int lineIdx) { var idx = ++_commandIdx; var lines = new List <LuaLine>(); var needNewScope = true; if (InstructionTranslator.Instructions.TryGetValue(command.Name, out var translator)) { var instruction = translator(command.Params, new TranslatorContext { LineIdx = idx, LastReturnVariable = _lastReturnVariable, Routine = this, }); lines.AddRange(instruction.Statements); needNewScope = instruction.NeedNewScope; if (instruction.ReturnVariable != null) { _lastReturnVariable = instruction.ReturnVariable; } OdfPreloads.AddRange(instruction.OdfPreloads); AudioPreloads.AddRange(instruction.AudioPreloads); if (!string.IsNullOrWhiteSpace(instruction.ReturnVariable)) { ReturnVariables.Add(instruction.ReturnVariable); } } else { Console.WriteLine($"Unable to translate {command.Name} on line {command.LineNumber + 1}"); lines.Add(new LuaStatement { Text = $"{command.Name}({string.Join(", ", command.Params)})", Comment = "Could not translate", }); } _currentScope.Statements.AddRange(lines); if (needNewScope) { TerminateCurrentScope(false); } }