From 947b2265808df5f3184c0462e12ff20a6883dd70 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 11 Feb 2024 12:47:12 +0100 Subject: [PATCH] comm: more generic transformMarkup transformMarkup may use additional data to make a new markup --- core/code/comm.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/code/comm.js b/core/code/comm.js index 907b73300..f5219143c 100644 --- a/core/code/comm.js +++ b/core/code/comm.js @@ -561,15 +561,17 @@ function renderMarkup(markup) { } /** - * Transforms a given markup array into an older, more straightforward format for easier understanding. + * Transforms a the markup array into an older, more straightforward format for easier understanding. + * + * May be used to build an entirely new markup to be rendered without altering the original one. * * @function IITC.comm.transformMessage - * @param {Array} markup - An array representing the markup to be transformed. + * @param {Object} data - The data for the message, including time, player, and message content. * @returns {Array} The transformed markup array with a simplified structure. */ -function transformMessage(markup) { +function transformMessage(data) { // Make a copy of the markup array to avoid modifying the original input - let newMarkup = JSON.parse(JSON.stringify(markup)); + let newMarkup = JSON.parse(JSON.stringify(data.markup)); // Collapse + "Link"/"Field". Example: "Agent destroyed the Link ..." if (newMarkup.length > 4) { @@ -662,7 +664,7 @@ function renderMsgRow(data) { } var nickCell = IITC.comm.renderNickCell(data.player.name, nickClasses.join(' ')); - const markup = IITC.comm.transformMessage(data.markup); + const markup = IITC.comm.transformMessage(data); var msg = IITC.comm.renderMarkup(markup); var msgClass = data.narrowcast ? 'system_narrowcast' : ''; var msgCell = IITC.comm.renderMsgCell(msg, msgClass);