Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line breaks in messages #9

Open
akselw opened this issue Jun 6, 2022 · 2 comments
Open

Line breaks in messages #9

akselw opened this issue Jun 6, 2022 · 2 comments

Comments

@akselw
Copy link

akselw commented Jun 6, 2022

Hi, is there a way to do line breaks in a message?

I just recently discovered the plugin and it is really great! Thank you for making it ❤️

@fogo5
Copy link

fogo5 commented Feb 14, 2024

I would like to know this as well

@azulika
Copy link

azulika commented Oct 8, 2024

Replace renderDialogue() in main.js with this:

  renderDialogue() {
    const lines = this.src.split(/\r?\n/);
    let currentMessage = null;
    let currentSide = null;

    const processCurrentMessage = () => {
      if (currentMessage && currentSide) {
        this.registerParticipant(currentSide === SIDES.LEFT ?
          this.dialogueSettings.leftParticipant.title :
          this.dialogueSettings.rightParticipant.title);
        new Message(currentMessage.trim(), currentSide, this.dialogueSettings);
        currentMessage = null;
        currentSide = null;
      }
    };

    for (const line of lines) {
      if (KEYWORDS.LEFT_PATTERN.test(line)) {
        processCurrentMessage();
        this.dialogueSettings.leftParticipant.title = line.split(":").splice(1).join(":").trim();
        this.dialogueSettings.leftParticipant.renderedOnce = false;
        this.dialogueSettings.leftParticipant.enforcedId = this.getEnforcedId(KEYWORDS.LEFT_PATTERN, line);
      } else if (KEYWORDS.RIGHT_PATTERN.test(line)) {
        processCurrentMessage();
        this.dialogueSettings.rightParticipant.title = line.split(":").splice(1).join(":").trim();
        this.dialogueSettings.rightParticipant.renderedOnce = false;
        this.dialogueSettings.rightParticipant.enforcedId = this.getEnforcedId(KEYWORDS.RIGHT_PATTERN, line);
      } else if (line.startsWith(KEYWORDS.TITLE_MODE)) {
        processCurrentMessage();
        const modeName = line.substr(KEYWORDS.TITLE_MODE.length).trim().toLowerCase();
        if (Object.values(DialogueTitleMode).some((mode) => mode == modeName)) {
          this.dialogueSettings.titleMode = modeName;
        }
      } else if (line.startsWith(KEYWORDS.MESSAGE_MAX_WIDTH)) {
        processCurrentMessage();
        this.dialogueSettings.messageMaxWidth = line.substr(KEYWORDS.MESSAGE_MAX_WIDTH.length).trim();
      } else if (line.startsWith(KEYWORDS.COMMENT_MAX_WIDTH)) {
        processCurrentMessage();
        this.dialogueSettings.commentMaxWidth = line.substr(KEYWORDS.COMMENT_MAX_WIDTH.length).trim();
      } else if (KEYWORDS.DELIMITER.test(line)) {
        processCurrentMessage();
        new Delimiter(this.dialogueSettings);
      } else if (line.startsWith(KEYWORDS.COMMENT)) {
        processCurrentMessage();
        const content = line.substr(KEYWORDS.COMMENT.length);
        new Comment(content, this.dialogueSettings);
      } else if (line.startsWith(KEYWORDS.MESSAGE_LEFT)) {
        processCurrentMessage();
        currentMessage = line.substr(KEYWORDS.MESSAGE_LEFT.length);
        currentSide = SIDES.LEFT;
      } else if (line.startsWith(KEYWORDS.MESSAGE_RIGHT)) {
        processCurrentMessage();
        currentMessage = line.substr(KEYWORDS.MESSAGE_RIGHT.length);
        currentSide = SIDES.RIGHT;
      } else if (currentMessage !== null) {
        currentMessage += '                                                                ' + line;
      }
    }

    processCurrentMessage(); // Process any remaining message
  }
};

This is a very rough way, but it at least works for rendering multiple lines. I couldn't find a way to properly render a line break(\n) within dialogue, as simply doing

currentMessage += '\n\n' + line;

didn't work - it seems the rendering ignores '\n' marker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants