Skip to content

Commit

Permalink
comm: more generic transformMarkup
Browse files Browse the repository at this point in the history
transformMarkup may use additional data to make a new markup
  • Loading branch information
le-jeu committed Feb 28, 2024
1 parent 4ec0cea commit 947b226
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/code/comm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <faction> + "Link"/"Field". Example: "Agent <player> destroyed the <faction> Link ..."
if (newMarkup.length > 4) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 947b226

Please sign in to comment.