Files
Bubberstation/tgui/packages/tgui-panel/chat/model.js
Jeremiah 2e5642f4d9 Fully converts tgui to use tgui-core (#88648)
## About The Pull Request
Giant file diff, but 99% of this PR is just swapping imports

We've tested changes slowly with #83789, #84660, and #87763. I think
tgui-core is in a good place and the risk of not fully switching is
outweighing inaction (in that people are getting confused that there's
two sets of ui components #86495).

This PR makes some small changes here and there that I saw, spot checks
like importing `TableCell` when you don't need to, triple boolean casts
`!!!` etc.
## Why It's Good For The Game
Most of all, code improvement. Tgui has been sitting in limbo as I
ironed out errors with tgui core.

We now have one source of all components, common functions etc for tgui.
This enables cross-game collaboration between the different versions of
SS13 running TGUI.
2025-01-03 07:35:58 +00:00

61 lines
1.3 KiB
JavaScript

/**
* @file
* @copyright 2020 Aleksej Komarov
* @license MIT
*/
import { createUuid } from 'tgui-core/uuid';
import { MESSAGE_TYPE_INTERNAL, MESSAGE_TYPES } from './constants';
export const canPageAcceptType = (page, type) =>
type.startsWith(MESSAGE_TYPE_INTERNAL) || page.acceptedTypes[type];
export const createPage = (obj) => {
let acceptedTypes = {};
for (let typeDef of MESSAGE_TYPES) {
acceptedTypes[typeDef.type] = !!typeDef.important;
}
return {
isMain: false,
id: createUuid(),
name: 'New Tab',
acceptedTypes: acceptedTypes,
unreadCount: 0,
hideUnreadCount: false,
createdAt: Date.now(),
...obj,
};
};
export const createMainPage = () => {
const acceptedTypes = {};
for (let typeDef of MESSAGE_TYPES) {
acceptedTypes[typeDef.type] = true;
}
return createPage({
isMain: true,
name: 'Main',
acceptedTypes,
});
};
export const createMessage = (payload) => ({
createdAt: Date.now(),
...payload,
});
export const serializeMessage = (message) => ({
type: message.type,
text: message.text,
html: message.html,
times: message.times,
createdAt: message.createdAt,
});
export const isSameMessage = (a, b) =>
(typeof a.text === 'string' && a.text === b.text) ||
(typeof a.html === 'string' && a.html === b.html);