Here is the code for any of the scripter writers to review and understand what he/she did and maybe improve on it skip the first several lines that are in korean but the code itself is not. /* <a href="https://github.com/kibkibe/roll20-api-scripts/tree/master/visual_dialogue" rel="nofollow">https://github.com/kibkibe/roll20-api-scripts/tree/master/visual_dialogue</a> */
/* (visual_dialogue.js) 220118 ์ฝ๋ ์์ */
// define: global constant
state.api_tag = "<a href=\"#vd-permitted-api-chat\"></a>";
state.vd_divider = "โ";
state.last_displayed_time = 0;
// /define: global constant
// define: option
const vd_setting = {
// option: ํ ํ๋ฉด์ ํ์ํ ์ ์๋ ์คํ ๋ฉ ์ด๋ฏธ์ง์ ์ต๋ ๊ฐ์๋ฅผ ์ค์ ํฉ๋๋ค.
// ์ด ์ซ์๋ฅผ ๋์ด๊ฐ๋ฉด ์์คํธ๋ผ, ํน์ ์ฑํ
๊ธฐ๋ก์ด ๊ฐ์ฅ ์ค๋๋ ์บ๋ฆญํฐ์ ์คํ ๋ฉ์ด ์ญ์ ๋๊ณ ๊ทธ ์์น์ ์ ์คํ ๋ฉ์ด ์ถ๊ฐ๋ฉ๋๋ค.
max_number: 5,
// option: ํ์ํ ์คํ ๋ฉ ์ด๋ฏธ์ง๋ค์ ๊ฐ๋ก ์ฌ์ด์ฆ์
๋๋ค.
width: 420,
// option: ํ์ํ ์คํ ๋ฉ ์ด๋ฏธ์ง๋ค์ ์ธ๋ก ์ฌ์ด์ฆ์
๋๋ค.
height: 420,
// option: ์คํ ๋ฉ ์ด๋ฏธ์ง์ ๊ฐ๋ก ๋๋น ์ค ํ๋ฉด ๋ฐ์ผ๋ก ๋น ์ ธ๋๊ฐ์ง ์๋๋ก ๋ณด์ฅํ ๊ฐ๋ก ์ฌ์ด์ฆ์
๋๋ค.
fit_width: 200,
// option: ์บ๋ฆญํฐ๋ค์ด ์ฌ๋ฌ ๊ฐ์ ํํ์ ์ฌ์ฉํ ์ง(true) ๋ํ ์คํ ๋ฉ ํ๋๋ง ์ฌ์ฉํ ์ง(false) ์ค์ ํฉ๋๋ค.
// false์ผ ๊ฒฝ์ฐ deck_name์ ์ค์ ํ ์นด๋ ๋ฑ์์ ๋ชจ๋ ์บ๋ฆญํฐ์ ์คํ ๋ฉ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
use_emotion: true,
// option: /as๋ฅผ ์ด์ฉํด ์ ๋์ ์๋ ์บ๋ฆญํฐ๋ก ์ฑํ
ํ ๊ฒฝ์ฐ ์์คํธ๋ผ ์ ์ฉ ์คํ ๋ฉ์ ํ์ํ ์ง (true) ์คํ ๋ฉ์ ์๋ตํ ์ง(false) ์ค์ ํฉ๋๋ค.
// true์ผ ๊ฒฝ์ฐ extra_name์ ์ค์ ํ ์ด๋ฆ์ ๋ฐ๋ผ ์์คํธ๋ผ์ฉ ์คํ ๋ฉ์ ๊ฐ์ ธ์ต๋๋ค.
show_extra_standing: true,
// option: use_emotion๊ฐ false์ผ ๊ฒฝ์ฐ์ ์บ๋ฆญํฐ์ ์คํ ๋ฉ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ฌ ์นด๋๋ฑ์ ์ด๋ฆ์ ์ค์ ํฉ๋๋ค.
deck_name: "standings",
// option: use_emotion์ด true์ผ ๊ฒฝ์ฐ์ ์์คํธ๋ผ์ฉ ์คํ ๋ฉ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ฌ ์นด๋๋ฑ์ ์ด๋ฆ์ ์ค์ ํฉ๋๋ค.
extra_name: "extra",
// option: show_extra_standing ์ต์
๊ณผ ๋ณ๊ฐ๋ก ์คํ ๋ฉ์ ํ์ํ์ง ์์ ์บ๋ฆญํฐ์ ์ด๋ฆ์ ๊ธฐ์
ํฉ๋๋ค. ์ฌ๋ฌ๊ฐ์ผ ๊ฒฝ์ฐ ์ฝค๋ง(,)๋ก ๊ตฌ๋ถํฉ๋๋ค.
ignore_list: "GM",
// option: ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ ํ์ด์ง์ ์ด๋ฆ์ ์ง์ ํฉ๋๋ค. ์ฌ๋ฌ๊ฐ์ผ ๊ฒฝ์ฐ ์ฝค๋ง(,)๋ก ๊ตฌ๋ถํฉ๋๋ค.
// ํ์ด์ง๊ฐ ์ฌ๋ฟ์ผ ๊ฒฝ์ฐ Player ๋ถ๋งํฌ๊ฐ ์ค์ ๋ ํ์ด์ง์ ์ฐ์ ์ ์ผ๋ก ๋์ฌ๊ฐ ํ์๋ฉ๋๋ค.
page_list: "conversation,intro",
// option: ์บ๋ฆญํฐ์ ์ด๋ฆ์ด ํ์๋๋ ํ
์คํธ ๋ฐ์ค์ ํฐํธ ์ฌ์ด์ฆ๋ฅผ ์ค์ ํฉ๋๋ค.
name_font_size: 18,
// option: ์บ๋ฆญํฐ ์ด๋ฆ์ ๊ธ์จ์์ ์ค์ ํฉ๋๋ค.
name_font_color: "rgb(255, 255, 255)",
// option: ๋์ฌ ๋ด์ฉ์ด ํ์๋๋ ํ
์คํธ ๋ฐ์ค์ ํฐํธ ์ฌ์ด์ฆ๋ฅผ ์ค์ ํฉ๋๋ค.
dialogue_font_size: 16,
// option: ๋์ฌ ๋ด์ฉ์ ๊ธ์จ์์ ์ค์ ํฉ๋๋ค.
dialogue_font_color: "rgb(255, 255, 255)",
// option: /desc๋ /em์ผ๋ก ํ์๋๋ ๊ฐ์กฐ๋ ํ
์คํธ ๋ฐ์ค์ ํฐํธ ์ฌ์ด์ฆ๋ฅผ ์ค์ ํฉ๋๋ค.
desc_font_size: 20,
// option: /desc, /em์ ๊ธ์จ์์ ์ค์ ํฉ๋๋ค.
desc_font_color: "rgb(255, 255, 255)",
// option: ํ๋ฒ์ ์ฌ๋ฌ ์ฑํ
์ด ๋ชฐ๋ ค์ ์์ฐจ์ ์ผ๋ก ํ์ํด์ผ ํ ๊ฒฝ์ฐ ์ฑํ
๋น ์ต์ ๋
ธ์ถ์๊ฐ์ ์ค์ ํฉ๋๋ค. (1000=1์ด)
min_showtime: 1000,
// option: ์ฑํ
1๊ธ์๋น ํ์ ์๊ฐ. ์ซ์๊ฐ ์ปค์ง์๋ก ๊ธ์์ ๋๋น ๋์ฌ์ ํ์์๊ฐ์ด ๊ธธ์ด์ง๋๋ค.
showtime_ratio: 20,
// option: (๊ณ ๊ธ์ค์ ) ๊ฐ ์ด์ด ๊ฐ๊ฒฉ์ด font_size ๋๋น ์ผ๋ง๋งํผ์ ํฝ์
์ ์ฐจ์งํ๋์ง์ ๋น์จ์ ์ง์ ํฉ๋๋ค.
line_height: 1.7,
// option: (๊ณ ๊ธ์ค์ ) ๊ฐ ๊ธ์๊ฐ font_size ๋๋น ์ผ๋ง๋งํผ์ ํฝ์
์ ์ฐจ์งํ๋์ง์ ๋น์จ์ ์ง์ ํฉ๋๋ค.
letter_spacing: 0.85
};
// /define: option
on('ready', function() {
// on.ready
state.vd_stock = [];
// /on.ready
on("add:card", function(obj) {
updateMacro(obj);
});
});
on("change:card", function(obj,prev) {
// on.change:card
updateMacro(obj);
// /on.change:card
});
on("destroy:card", function(obj) {
// on.destroy:card
updateMacro(obj);
// /on.destroy:card
});
on("destroy:graphic", function(obj) {
// on.destroy:graphic
if (obj.get('name') == "vd_standing") {
arrangeStandings(false);
}
// /on.destroy:graphic
});
on("chat:message", function(msg)
{
// on.chat:message
if ((msg.type == "general" || msg.type == "desc" || msg.type == "emote")
&& (msg.playerid != 'API' || msg.content.includes(state.api_tag))
&& !msg.rolltemplate){
if (findCharacterWithName(msg.who) || findObjs({_type:'player',_displayname:msg.who.replace(' (GM)','')}).length == 0) {
if (msg.content.length > 0) {
msg.content = msg.content.replace(state.api_tag,'').replace(/<br>/g,state.vd_divider);
msg.time = new Date().getTime();
state.vd_stock.push(msg);
if (state.vd_stock.length == 1 || (state.vd_stock.length > 1 && state.last_displayed_time + 5000 < msg.time)) {
setTimeout(showDialogue, 100);
}
}
}
}
// /on.chat:message
// on.chat:message:api
if (msg.type == "api" && msg.content.indexOf("!@") === 0) {
const current_page_id = vdGetCurrentPage();
if (!current_page_id) {
return;
}
if (msg.content == '!@์จ๊น' || msg.content == '!@hide') {
showHideDecorations('vd_deco',false);
showHideDecorations('vd_panel',false);
let bg_name = findObjs({ _type: 'graphic', name:'vd_name', _pageid:current_page_id});
let bg_dialogue = findObjs({ _type: 'graphic', name:'vd_dialogue', _pageid:current_page_id});
if (bg_name.length > 0) {
bg_name = bg_name[0];
} else {
sendChat("error","/w gm **" + getObj('page',current_page_id).get('name') + "** ํ์ด์ง์ vd_name ํ ํฐ์ด ์์ต๋๋ค.",null,{noarchive:true});
return;
}
if (bg_dialogue.length > 0) {
bg_dialogue = bg_dialogue[0];
} else {
sendChat("error","/w gm **" + getObj('page',current_page_id).get('name') + "** ํ์ด์ง์ vd_dialogue ํ ํฐ์ด ์์ต๋๋ค.",null,{noarchive:true});
return;
}
let text_name = getObj('text', bg_name.get('gmnotes'));
let text_dialogue = getObj('text', bg_dialogue.get('gmnotes'));
text_name.remove();
text_dialogue.remove();
sendChat('vd-api-wildcard','!@ํด์ฅ:์ ์');
} else if (msg.content.indexOf("!@ํด์ฅ") == 0 || msg.content.indexOf("!@exit") == 0) {
const keyword = msg.content.replace("!@ํด์ฅ","").replace("!@exit","").replace(state.api_tag,'');
if (keyword.length == 0) {
removeStanding(msg);
} else if (playerIsGM(msg.playerid) || msg.playerid == 'API' || msg.who == 'vd-api-wildcard') {
if (keyword == ":์ ์" || keyword == ":์ ์ฒด" || keyword == ":all") {
let tokens = findObjs({ _type: 'graphic', name: 'vd_standing', _pageid: current_page_id});
tokens.forEach(token => {
token.remove();
});
} else if (keyword == ":์์คํธ๋ผ" || keyword == ":extra") {
let tokens = findObjs({ _type: 'graphic', name: 'vd_standing', represents: '', _pageid: current_page_id});
tokens.forEach(token => {
token.remove();
});
} else {
msg.who = keyword.replace(":","");
removeStanding(msg);
}
}
} else if (playerIsGM(msg.playerid) && (msg.content == "!@๋ฆฌ์
" || msg.content == "!@reset")) {
state.vd_stock = [];
sendChat("error","/w gm ํ์ ๋๊ธฐ์ด์ ์์ฌ์๋ ๋์ฌ๋ค์ ์ด๊ธฐํํ์ต๋๋ค.",null,{noarchive:true});
} else if (playerIsGM(msg.playerid) && (msg.content == "!@๊ฐ์ ์งํ" || msg.content == "!@force-progress")) {
showNextDialogue();
} else if (playerIsGM(msg.playerid) && (msg.content.indexOf("!@๋ฐฐ๊ฒฝ ") == 0 || msg.content.indexOf("!@background ") == 0)) {
let bg_background = findObjs({ _type: 'graphic', name:'vd_background', _pageid:current_page_id});
let bg_deck = findObjs({_type: 'deck', name:'background'});
if (bg_background.length == 0) {
sendChat("error","/w gm **" + getObj('page',current_page_id).get('name') + "** ํ์ด์ง์ vd_background ํ ํฐ์ด ์์ต๋๋ค.",null,{noarchive:true});
return;
}
bg_background = bg_background[0];
const current_url = bg_background.get('imgsrc');
const new_bg = msg.content.replace('!@๋ฐฐ๊ฒฝ ','').replace('!@background ','');
let is_url_input = (msg.content.indexOf('https://') > -1);
if (is_url_input) {
bg_background.set('imgsrc',new_bg.replace('med','thumb').replace('max','thumb').replace(' ',''));
if (current_url == bg_background.get('imgsrc')) {
sendChat("error","/w gm ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๊ฐ ์ ์์ ์ผ๋ก ๋ณ๊ฒฝ๋์ง ์์์ต๋๋ค. ์ฃผ์๋ ๋ช
๋ น์ด ํ์์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํด์ฃผ์ธ์. (ex: !@๋ฐฐ๊ฒฝ https://์ด๋ฏธ์ง์ฃผ์...)",null,{noarchive:true});
}
} else {
if (bg_deck.length == 0) {
sendChat("error","/w gm **background** ๋ฑ์ด ์ฝ๋ ์
์ ์์ต๋๋ค. ์ฌ์ฉํ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๋ฅผ background ๋ฑ์ ๋ฃ๊ฑฐ๋ !@๋ฐฐ๊ฒฝ https://์ด๋ฏธ์ง์ฃผ์... ํ์์ผ๋ก ์ด๋ฏธ์ง ์ฃผ์๋ฅผ ์ง์ ์
๋ ฅํ์ธ์.",null,{noarchive:true});
return;
} else {
let bg_cards = findObjs({_type:'card', _deckid: bg_deck[0].get('_id'), name: new_bg});
if (bg_cards.length == 0) {
sendChat("error","/w gm ์ด๋ฆ์ด '**" + new_bg + "'**์ธ ๋ฐฐ๊ฒฝ ์นด๋๊ฐ **background** ๋ฑ์ ์์ต๋๋ค.",
null,{noarchive:true});
return;
} else {
bg_background.set('imgsrc',bg_cards[0].get('avatar').replace('med','thumb').replace('max','thumb'));
}
}
}
} else if (vd_setting.use_emotion) {
let cha_name = msg.who;
let content_str = msg.content.replace(state.api_tag,'').replace('!@','');
let emot = content_str;
if (content_str.lastIndexOf(':') > -1 && (playerIsGM(msg.playerid) || msg.playerid == 'API')) {
cha_name = content_str.substring(0,content_str.lastIndexOf(':'));
emot = content_str.substring(content_str.lastIndexOf(':')+1,content_str.length);
}
let chat_cha = findCharacterWithName(cha_name);
let current_token = null;
if (chat_cha || vd_setting.show_extra_standing) {
current_token = findTokenWithCharacter(chat_cha?chat_cha.get('_id'):'', cha_name);
}
if (current_token) {
let rt = findObjs({ _type: 'deck', name: vd_setting.deck_name});
if (rt.length == 0) {
sendChat("error","/w gm ์ด๋ฆ์ด **" + vd_setting.deck_name +"**์ธ ์นด๋ ๋ฑ์ด ์์ต๋๋ค.",null,{noarchive:true});
return;
} else {
let opt = {
name: 'vd_standing',
_subtype: 'card',
_pageid: current_token.get('_pageid'),
width: vd_setting.width,
height: vd_setting.height,
bar1_value: cha_name,
left:current_token.get('left'),
top:current_token.get('top'),
layer: 'map',
represents: chat_cha? chat_cha.get('_id'): '',
tint_color: current_token.get('tint_color')
};
let search_opt = { _type: 'card', _deckid: rt[0].get('_id')};
if (!vd_setting.use_emotion) {
search_opt.name = chat_cha ? cha_name : vd_setting.extra_name;
} else if (emot.length > 0) {
search_opt.name = cha_name + "-" + emot;
} else {
search_opt.name = cha_name;
}
let rt_items = findObjs(search_opt);
if (rt_items.length > 0) {
opt.imgsrc = rt_items[0].get('avatar').replace('med','thumb').replace('max','thumb');
} else {
sendChat("error","/w gm **"+ vd_setting.deck_name + "** ์นด๋ ๋ฑ์ ์ด๋ฆ์ด **" + search_opt.name + "**์ธ ์นด๋๊ฐ ์์ต๋๋ค.",null,{noarchive:true});
return;
}
current_token.set(opt);
}
} else {
sendChat("error","/w \"" + msg.who + "\" ์ด๋ฆ์ด **" + cha_name +"**์ธ ์บ๋ฆญํฐ๊ฐ ์์ต๋๋ค.",null,{noarchive:true});
}
}
}
// /on.chat:message:api
});
// define: global function
const vdGetCurrentPage = function() {
const page_list = vd_setting.page_list.replace(/, /g,',').replace(/ ,/g,',').split(',');
if (page_list.indexOf(getObj('page',Campaign().get("playerpageid")).get('name')) > -1) {
return Campaign().get("playerpageid");
} else {
const page = findObjs({type:'page',name:page_list[0]});
if (page.length > 0) {
return page[0].get('_id');
} else {
sendChat("error","/w gm ์ด๋ฆ์ด **" + page_list[0] + "**์ธ ํ์ด์ง๊ฐ ์์ต๋๋ค.",null,{noarchive:true});
}
}
}
const showDialogue = function() {
let msg = state.vd_stock[0];
for (let index = 1; index < state.vd_stock.length; index++) {
const element = state.vd_stock[index];
if (element.who == msg.who && Math.abs(element.time - msg.time) < 100) {
msg.content = msg.content + state.vd_divider + element.content;
state.vd_stock.splice(index,1);
index--;
} else {
break;
}
}
const current_page_id = vdGetCurrentPage();
if (!current_page_id) {
return;
}
let is_general = msg.type == "general";
const font_color = vd_setting[is_general?'dialogue_font_color':'desc_font_color'];
let font_size = vd_setting[is_general ? 'dialogue_font_size' : 'desc_font_size'];
let bg_area = findObjs({ _type: 'graphic', name:'vd_area', _pageid:current_page_id});
let bg_name = findObjs({ _type: 'graphic', name:'vd_name', _pageid:current_page_id});
let bg_dialogue = findObjs({ _type: 'graphic', name:'vd_dialogue', _pageid:current_page_id});
let bg_panel = findObjs({ _type: 'graphic', name:'vd_panel', _pageid:current_page_id});
let split = [];
if (bg_area.length > 0) {
bg_area = bg_area[0];
} else {
sendChat("error","/w gm **" + getObj('page',current_page_id).get('name') + "** ํ์ด์ง์ vd_area ํ ํฐ์ด ์์ต๋๋ค.",null,{noarchive:true});
showNextDialogue();
return;
}
if (bg_name.length > 0) {
bg_name = bg_name[0];
} else {
sendChat("error","/w gm **" + getObj('page',current_page_id).get('name') + "** ํ์ด์ง์ vd_name ํ ํฐ์ด ์์ต๋๋ค.",null,{noarchive:true});
showNextDialogue();
return;
}
if (bg_dialogue.length > 0) {
bg_dialogue = bg_dialogue[0];
} else {
sendChat("error","/w gm **" + getObj('page',current_page_id).get('name') + "** ํ์ด์ง์ vd_dialogue ํ ํฐ์ด ์์ต๋๋ค.",null,{noarchive:true});
showNextDialogue();
return;
}
if (bg_panel.length > 0) {
bg_panel = bg_panel[0];
} else {
sendChat("error","/w gm **" + getObj('page',current_page_id).get('name') + "** ํ์ด์ง์ vd_panel ํ ํฐ์ด ์์ต๋๋ค.",null,{noarchive:true});
showNextDialogue();
return;
}
const width = bg_dialogue.get('width');
const name_width = bg_name.get('width');
let blank_name = '';
let blank_dialogue = '';
let text_name = getObj('text', bg_name.get('gmnotes'));
let text_dialogue = getObj('text', bg_dialogue.get('gmnotes'));
while (name_width > blank_name.length*vd_setting['name_font_size']*vd_setting['letter_spacing']*1.2) { blank_name += "โ"; }
while (width>blank_dialogue.length*font_size*vd_setting['letter_spacing']*1.15) { blank_dialogue += "โ"; }
if (text_name && text_name.get('_pageid') != current_page_id) {
text_name.remove();
text_name = null;
}
if (text_dialogue && text_dialogue.get('_pageid') != current_page_id) {
text_dialogue.remove();
text_dialogue = null;
}
if (!text_name) {
text_name = createObj('text', {
_pageid: bg_area.get('_pageid'),
left: bg_name.get('left'),
top: bg_name.get('top'),
width: bg_name.get('width'),
height: bg_name.get('height'),
layer: 'objects',
font_family: 'Arial',
text: '',
font_size: vd_setting['name_font_size'],
color: vd_setting['name_font_color']
});
bg_name.set({'gmnotes':text_name.get('_id')});
}
if (!text_dialogue) {
text_dialogue = createObj('text', {
_pageid: bg_dialogue.get('_pageid'),
left: bg_dialogue.get('left'),
top: bg_dialogue.get('top'),
width: width,
height: bg_dialogue.get('height'),
layer: 'objects',
font_family: 'Arial',
text: '',
font_size: font_size,
color: font_color
});
bg_dialogue.set({'gmnotes':text_dialogue.get('_id')});
}
// ์์ธ์ฒ๋ฆฌํ ํ
์คํธ ์ ์ธ
let name = msg.who + '\n' + blank_name;
let filtered = msg.content;
let filter_word = [
{regex:/\*.+\*/g,replace:/\*/g}, // *, **, ***
{regex:/``.+``/g,replace:/``/g}, // ``
{regex:/\[[^\(\)\[\]]*\]\(http[^\(\)\[\]]+\)/g,replace:/\[[^\(\)\[\]]*\]\(http[^\(\)\[\]]+\)/g}, // [](http...)
{regex:/<[^>]*>/g,replace:/<[^>]*>/g}, // <html>
{regex:/\(.{1}\" style=\"[^\)]+\)/g,replace:/\((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\)/g}, // [](#" style="...)
{regex:/\$\[\[.+\]\]/g,replace:/\$\[\[.+\]\]/g}]; // [[]]
for (let i=0;i<filter_word.length;i++) {
let match = filtered.match(filter_word[i].regex);
if (match) {
for (let j=0;j<match.length;j++) {
filtered = filtered.replace(match[j], match[j].replace(filter_word[i].replace,''));
}
}
}
let ruby_match = filtered.match(/\([^\(\)\[\]]+\)\[[^\(\)\[\]]*\]/g);
if (ruby_match) {
for (let j=0;j<ruby_match.length;j++) {
let rubystr_split = ruby_match[j].substring(1,ruby_match[j].length-1).split(')[');
filtered = filtered.replace(ruby_match[j], rubystr_split[1]+"("+rubystr_split[0]+")");
}
}
if (filtered.length == 0){
showNextDialogue();
return;
}
let str = filtered;
let desc_ratio = is_general ? 1 : 0.8;
let amount = Math.ceil(width/font_size/vd_setting['letter_spacing']*3) -3;
let idx = 0;
let length = 0;
const thirdchar = ['\'',' ',',','.','!',':',';','"'];
const halfchar = ['[',']','(',')','*','^','-','~','<','>','+','l','i','1'];
const arr = thirdchar.concat(halfchar);
let divided = false;
for (let i=0;i<str.length;i++){
let c = str[i];
length += 3;
for (let j=0;j<arr.length;j++) {
if (c==arr[j]) {
length -= (j<thirdchar.length ? 2 : 1);
break;
}
}
if (length >= amount * desc_ratio || c == state.vd_divider) {
let substr = str.substring(idx,i+1).replace(state.vd_divider,'');
split.push(is_general || msg.who.length > 0 ? substr:getStringWithMargin(amount,length,desc_ratio,substr));
idx = i+1;
length = 0;
if ((split.length+1) * font_size * vd_setting['letter_spacing']*3 > bg_dialogue.get('height')) {
state.vd_stock.splice(1,0,{content:filtered.substring(idx,str.length),time:msg.time,playerid:msg.playerid,type:msg.type,who:msg.who});
divided = true;
break;
}
}
}
if (idx < str.length && !divided) {
let substr = str.substring(idx,str.length);
split.push(is_general || msg.who.length > 0 ? substr:getStringWithMargin(amount,length,desc_ratio,substr));
}
if (is_general || msg.who.length > 0) {
while ((split.length+1) * font_size * vd_setting['line_height'] < bg_dialogue.get('height')) {
split.push(' ');
}
} else {
split.splice(0,0,' ');
}
split.push(blank_dialogue);
text_name.set({text:name,left:bg_name.get('left'),font_size: vd_setting['name_font_size'],color: vd_setting['name_font_color'],
top:bg_name.get('top')+vd_setting['name_font_size']*vd_setting['line_height']/2});
text_dialogue.set({text:split.join('\n'),font_size: font_size, color: font_color,
left: msg.type == 'desc' ? bg_panel.get('left'):bg_dialogue.get('left'),
top: msg.type == 'desc'? bg_panel.get('top'):bg_dialogue.get('top')});
toFront(text_name);
toFront(text_dialogue);
setTimeout(() => {
showHideDecorations('vd_panel',true);
showHideDecorations('vd_deco',msg.type != 'desc');
toFront(text_name);
toFront(text_dialogue);
}, 100);
clearTextWithout(text_name, text_dialogue);
const ignore_list = vd_setting.ignore_list.replace(/, /g,',').replace(/ ,/g,',').split(',');
if (msg.type != "desc" && ignore_list.indexOf(msg.who) < 0) {
let chat_cha = findCharacterWithName(msg.who);
let current_token = null;
if (chat_cha || vd_setting.show_extra_standing) {
current_token = findTokenWithCharacter(chat_cha?chat_cha.get('_id'):'', msg.who);
}
let tokens = findObjs({ _type: 'graphic', name: 'vd_standing', _pageid: current_page_id});
let lowest_priority = tokens[0];
for (var i=0;i<tokens.length;i++) {
var token = tokens[i];
token.set('tint_color','#000000');
if (parseInt(token.get('gmnotes')) < parseInt(lowest_priority.get('gmnotes'))) {
lowest_priority = token;
}
}
if (current_token == null && (chat_cha || vd_setting.show_extra_standing)) {
let nm = chat_cha?msg.who:vd_setting.extra_name;
let rt = findObjs({ _type: 'deck', name: vd_setting.deck_name});
if (rt.length == 0) {
sendChat("error","/w gm ์ด๋ฆ์ด **"+ vd_setting.deck_name + "**์ธ ์นด๋ ๋ฑ์ด ์์ต๋๋ค.",null,{noarchive:true});
showNextDialogue();
return;
} else {
let opt = {
name: 'vd_standing',
_pageid: bg_area.get('_pageid'),
width: vd_setting.width,
height: vd_setting.height,
bar1_value: msg.who,
layer: 'gmlayer',
imgsrc: rt[0].get('avatar').replace('med','thumb').replace('max','thumb'),
represents: chat_cha? chat_cha.get('_id'): ''
};
const std = findObjs({ _type: 'card', _deckid: rt[0].get('_id'), name: msg.who});
if (std.length > 0) {
opt.imgsrc = std[0].get('avatar').replace('med','thumb').replace('max','thumb');
}
if (tokens.length >= vd_setting.max_number) {
opt.left = lowest_priority.get('left');
} else {
opt.left = arrangeStandings(true);
}
opt.top = bg_area.get('top');
if (tokens.length >= vd_setting.max_number) {
lowest_priority.set(opt);
current_token = lowest_priority;
} else {
current_token = createObj('graphic', opt);
}
toFront(current_token);
setTimeout(() => {
current_token.set({tint_color:'transparent',gmnotes:Date.now(),layer:"map"});
}, 100);
}
} else if (current_token) {
toFront(current_token);
current_token.set({tint_color:'transparent',gmnotes:Date.now()});
}
}
state.last_displayed_time = new Date().getTime();
setTimeout(showNextDialogue, Math.max(vd_setting.min_showtime, str.length * vd_setting.showtime_ratio));
}
const clearTextWithout = function(name_txt, dial_txt) {
let filtered_txt = filterObjs(function(obj) {
return (obj.get('_type') == 'text' && obj.get("_pageid") == name_txt.get('_pageid')
&& obj.get("_id") != name_txt.get('_id') && obj.get("_id") != dial_txt.get('_id')
&& ((Math.abs(obj.get("left") - name_txt.get('left')) < 100 && Math.abs(obj.get("top") - name_txt.get('top')) < 100) ||
(Math.abs(obj.get("left") - dial_txt.get('left')) < 100 && Math.abs(obj.get("top") - dial_txt.get('top')) < 100)));
});
filtered_txt.forEach(txt => {
txt.remove();
});
}
const updateMacro = function(obj) {
let background_deck = findObjs({type:'deck',name:'background'});
if (background_deck.length > 0 && obj.get('deckid') == background_deck[0].get('id')) {
if (background_deck.length > 1) {
sendChat("error","/w gm **background** ๋ฑ์ด **" + background_deck.length + "**๊ฐ ์์ต๋๋ค. ๋จผ์ ์์ฑ๋ 1๊ฐ ๋ฑ์ ๊ธฐ์ค์ผ๋ก ๋งคํฌ๋ก๋ฅผ ์์ฑํฉ๋๋ค.",null,{noarchive:true});
}
let players = findObjs({type:'player'});
let bg_images = findObjs({_type:'card',_deckid:background_deck[0].get('id')});
let bg_macro = findObjs({_type:'macro',name:"๋ฐฐ๊ฒฝ์ ํ"});
let action_str = "!@๋ฐฐ๊ฒฝ ?{๋ฐฐ๊ฒฝ์ ์ ํํ์ธ์";
let gm_list = "";
for (let index = 0; index < bg_images.length; index++) {
const card = bg_images[index];
action_str += "|" + card.get('name');
}
for (let index = 0; index < players.length; index++) {
const player = players[index];
if (playerIsGM(player.id)) {
gm_list += player.id + ",";
}
}
gm_list = gm_list.substring(0,gm_list.length - 1);
action_str += "}";
let options = {name:"๋ฐฐ๊ฒฝ์ ํ",action:action_str,visibleto:gm_list};
if (bg_macro.length > 0) {
bg_macro = bg_macro[0];
bg_macro.set(options);
} else {
options.playerid = players[0].get('id');
bg_macro = createObj('macro',options);
}
}
}
const showHideDecorations = function(name, show) {
const text_deco = findObjs({name: name, _type: 'graphic'});
for (let index = 0; index < text_deco.length; index++) {
const itm = text_deco[index];
if (show) {
if (itm.get('gmnotes').includes('/')) {
const wh = itm.get('gmnotes').split('/');
itm.set({width:parseInt(wh[0]),height:parseInt(wh[1]),layer:'objects'});
}
toFront(itm);
} else {
if (itm.get('gmnotes').length == 0) {
itm.set({gmnotes:itm.get('width')+"/"+itm.get('height')});
}
itm.set({width:1,height:1,layer:'gmlayer'});
}
}
}
const showNextDialogue = function() {
state.vd_stock.splice(0,1);
if (state.vd_stock.length > 0) {
showDialogue();
}
}
const getStringWithMargin = function(amount, length, ratio, str) {
let margin = Math.round((amount - length)/4*ratio);
for (var j=0;j<margin;j++){
str = "ใ
ค" + str + "ใ
ค";
}
return str;
}
const findCharacterWithName = function(who) {
let chat_cha = findObjs({ _type: 'character', name: who});
if (chat_cha.length > 0) {
return chat_cha[0];
} else {
return null;
}
}
const findTokenWithCharacter = function(id, who) {
let arr = findObjs({ _type: 'graphic', name: 'vd_standing', represents: id, _pageid: vdGetCurrentPage(), bar1_value: who});
if (arr.length > 0) {
return arr[0];
}
return null;
}
const removeStanding = function(msg) {
let character = findCharacterWithName(msg.who);
let token = findTokenWithCharacter(character?character.get('_id'):'', msg.who);
if (token) {
token.remove();
arrangeStandings(false);
}
}
const arrangeStandings = function(addNew) {
const currernt_page_id = vdGetCurrentPage();
let tokens = findObjs({ _type: 'graphic', name: 'vd_standing', _pageid: currernt_page_id});
if (tokens.length > 0 || addNew) {
let bg_area = findObjs({ _type: 'graphic', name:'vd_area', _pageid:currernt_page_id});
if (bg_area.length > 0) {
bg_area = bg_area[0];
} else {
sendChat("error1","/w gm vd_area ํ ํฐ์ด ์์ต๋๋ค.",null,{noarchive:true});
return;
}
let tokens_position = [];
const compare = function( a, b ) {
if ( a.left < b.left ){
return -1;
}
if ( a.left > b.left ){
return 1;
}
return 0;
}
for (var i=0;i<tokens.length;i++) {
tokens_position.push({idx:i,left:tokens[i].get('left')});
}
tokens_position.sort(compare);
let final_count = tokens.length + (addNew?1:0);
final_count = final_count<2? 2: final_count;
let space = Math.floor(bg_area.get('width')/final_count);
let left = bg_area.get('left') - Math.floor(bg_area.get('width')/2);
if (space < vd_setting.fit_width) {
left += vd_setting.fit_width/2;
space = Math.floor((bg_area.get('width')-vd_setting.fit_width)/(final_count-1));
} else {
left += space/2
}
let rand = addNew ? Math.floor(Math.random()*(tokens_position.length-1))+1 : Infinity;
rand = rand < 0 ? 0 : rand;
for (var i=0;i<tokens_position.length;i++) {
let token = tokens[tokens_position[i].idx];
token.set('left',left + space * (i + (i>=rand?1:0)));
}
return addNew ? left + space * (rand == Infinity ? 0 : rand) : false;
}
}
// /define: global function
/* (visual_dialogue.js) 220118 ์ฝ๋ ์ข
๋ฃ */