mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-12-12 06:14:09 +01:00
reorganize resource directories
This commit is contained in:
86
resources/[gameplay]/chat/html/Message.js
Normal file
86
resources/[gameplay]/chat/html/Message.js
Normal file
@@ -0,0 +1,86 @@
|
||||
Vue.component('message', {
|
||||
template: '#message_template',
|
||||
data() {
|
||||
return {};
|
||||
},
|
||||
computed: {
|
||||
textEscaped() {
|
||||
let s = this.template ? this.template : this.templates[this.templateId];
|
||||
|
||||
if (this.template) {
|
||||
//We disable templateId since we are using a direct raw template
|
||||
this.templateId = -1;
|
||||
}
|
||||
|
||||
//This hack is required to preserve backwards compatability
|
||||
if (this.templateId == CONFIG.defaultTemplateId
|
||||
&& this.args.length == 1) {
|
||||
s = this.templates[CONFIG.defaultAltTemplateId] //Swap out default template :/
|
||||
}
|
||||
|
||||
s = s.replace(/{(\d+)}/g, (match, number) => {
|
||||
const argEscaped = this.args[number] != undefined ? this.escape(this.args[number]) : match
|
||||
if (number == 0 && this.color) {
|
||||
//color is deprecated, use templates or ^1 etc.
|
||||
return this.colorizeOld(argEscaped);
|
||||
}
|
||||
return argEscaped;
|
||||
});
|
||||
return this.colorize(s);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
colorizeOld(str) {
|
||||
return `<span style="color: rgb(${this.color[0]}, ${this.color[1]}, ${this.color[2]})">${str}</span>`
|
||||
},
|
||||
colorize(str) {
|
||||
let s = "<span>" + (str.replace(/\^([0-9])/g, (str, color) => `</span><span class="color-${color}">`)) + "</span>";
|
||||
|
||||
const styleDict = {
|
||||
'*': 'font-weight: bold;',
|
||||
'_': 'text-decoration: underline;',
|
||||
'~': 'text-decoration: line-through;',
|
||||
'=': 'text-decoration: underline line-through;',
|
||||
'r': 'text-decoration: none;font-weight: normal;',
|
||||
};
|
||||
|
||||
const styleRegex = /\^(\_|\*|\=|\~|\/|r)(.*?)(?=$|\^r|<\/em>)/;
|
||||
while (s.match(styleRegex)) { //Any better solution would be appreciated :P
|
||||
s = s.replace(styleRegex, (str, style, inner) => `<em style="${styleDict[style]}">${inner}</em>`)
|
||||
}
|
||||
return s.replace(/<span[^>]*><\/span[^>]*>/g, '');
|
||||
},
|
||||
escape(unsafe) {
|
||||
return String(unsafe)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
},
|
||||
},
|
||||
props: {
|
||||
templates: {
|
||||
type: Object,
|
||||
},
|
||||
args: {
|
||||
type: Array,
|
||||
},
|
||||
template: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
templateId: {
|
||||
type: String,
|
||||
default: CONFIG.defaultTemplateId,
|
||||
},
|
||||
multiline: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
color: { //deprecated
|
||||
type: Array,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user