tanghoong/phpchatblock

PHPChatBlock is a dialogue chat block display component class for PHP

v0.2.39 2021-11-24 05:30 UTC

README

A dialogue chat block display component for php project. A UI component for conversational novel community. Started Date: 30 Aug, 2021 Updated Date: 23 Oct, 2021 Author: Tang Hoong

Description

Just dump the string format which exactly same as sample.txt then ChatBlock will render them into perfect and nice chat blocks.

How

Follow the format from sample.txt:

A: I like apple.
B: I like apple too.

then

require __DIR__ ."/ChatBlock.php";
use TangHoong\ChatBlock\ChatBlock as ChatUI;

$cui = new ChatUI([
    'allowForkScript' => 'https://editor.chatnovel.app/',  // default:null
    'mainCastColor'  => '#198754',
    'castColorMode'  => 'palette', // none, random, palette 
    'chatHeaderSize' => 'large'  // default:normal,small,large
]);
$cui->setColon([':',':']); // both
$cui->setNarrator(['系统','旁白','Narrator','narrator',]);
echo sprintf('<style>%s</style>', $cui->renderCss());
$content = str_replace(["\n"], ["\r\n"], $rawscript); // Depends If code on Window or Linux
if(!is_null($content))
{
  $cui->feed($content);
  echo $cui->render();
}

Roadmap

  • [] 顏文字
  • [] emoji (studying)
  • [] 文字轉語音 (studying)
  • [] Sound clip(mp3 only)
  • [] action button
  • [] Invalid Image handle
  • [] Change chat background (image, video)
  • [] reverse stories (switch lines to major based on header)
  • [] export format (txt,json,csv,custom)
  • [] On click only show the next chat
  • [] Personal Profile for each casts
  • [] Blocks by Comment

Resources refer from

Codepen IMessage css
profile card

Changelog

Oct 2021

  • Optimize the cast() positions
  • Optimize the feed() loop, solve seperator detection bug
  • Script showquote:5-10 (allow include the raw script in certain line)
  • Add chat block color (none, random, palette)
  • Allow bold, italic, code, underline, delete line in chat block
  • Add benchmark mstime
  • Allow @name & #tag inline
  • Allow fork script to live editor
  • Live editor

Sep 2021

  • default narrator ['Narrator','narrator','系统','旁白'];
  • default colon [':',':'];
  • replace --- with ADVANCE
  • custom setBreakPoint('I_LOVE_EMANYAN')
  • setting template
  • Allow @, # in string
  • Added rawscript (will toggle use site class)
  • Fix p, h1-h6 container
  • Allow adjust head size
  • Show once header if the lines belongs to same person
  • Allow show unformatted line as warning messages (only works when single colon as index)
  • Allow export as json
  • showCasts()

Aug 2021

  • rename css file to chatblock.css
  • adding chatblock.js
  • H1-H6 tag
  • p tag
  • Fix narrator display
  • Conversation index (default as #)
  • minimal format (now can run without the characters settings)
  • linebreak
  • Directly wrote as paragraph will be ignore. (php error free)
  • adding 'rawscript#' for display the raw data before parse.
  • setColon() fixed
  • setNarrator() fixed
  • Colon array (default as #)
  • Narrator array (default as narrator)
  • stater template
  • dev tutorial (with sample)
  • allow easy mode use first line as main cast