From c05539891ad252ea6935db1bda5f521c5a3a59d4 Mon Sep 17 00:00:00 2001 From: cth-inni Date: Sun, 7 Nov 2021 00:12:28 +0800 Subject: [PATCH] Minor fix Image schema Better replacement on symbol Dont output _ADVANCE_ text-center the notice CSS width --- src/ChatBlock.php | 253 ++++++++++++++++++++++++---------------------- src/chatblock.css | 14 ++- 2 files changed, 142 insertions(+), 125 deletions(-) diff --git a/src/ChatBlock.php b/src/ChatBlock.php index 5918cda..2fa8cc9 100644 --- a/src/ChatBlock.php +++ b/src/ChatBlock.php @@ -23,6 +23,7 @@ function __construct($newObj=null) $this->libpath = 'https://github.com/tanghoong/phpchatblock/'; // use for checking $this->version = '0.2.33'; // Change before each commit $this->linebreak = '\r\n'; // Window, Linux + $this->https = 'https:'; // Window, Linux // Settings $this->rawData = ''; $this->currentCast = ''; @@ -325,7 +326,7 @@ private function _buildLinesFeed($rawData) { if( $detectFlag == false ) { $castname = strstr($lineVal, $tempColon, true); - $content = ltrim(strstr($lineVal, $tempColon), $tempColon); + $content = preg_replace('/'.$tempColon.'/', '', strstr($lineVal, $tempColon), 1); // replace on first match only $checkValid = substr($castname, 0, 2); // Comment script to ignore if(!in_array($castname,$this->SettingBlacklistTag) && $checkValid != '//') { @@ -440,113 +441,122 @@ public function render(){ // } foreach($this->dialogue['lines'] as $dialogue) { - switch($dialogue['_castname']) + if($dialogue['_line'] != $this->SettingBreakPoint) { - case '#': // h1 - $this->currentCast = null; - $tempHtml .= $this->md_render_heading($dialogue,1); - break; - case '##': // h2 - $this->currentCast = null; - $tempHtml .= $this->md_render_heading($dialogue,2); - break; - case '###': // h3 - $this->currentCast = null; - $tempHtml .= $this->md_render_heading($dialogue,3); - break; - case '####': // h4 - $this->currentCast = null; - $tempHtml .= $this->md_render_heading($dialogue,4); - break; - case '#####': // h5 - $this->currentCast = null; - $tempHtml .= $this->md_render_heading($dialogue,5); - break; - case '######': // h6 - $this->currentCast = null; - $tempHtml .= $this->md_render_heading($dialogue,6); - break; - case '---': // scene - $this->currentCast = null; - $tempHtml .= $this->render_cutscene($dialogue); - break; - case 'h1': - case 'h2': - case 'h3': - case 'h4': - case 'h5': - case 'h6': - $this->currentCast = null; - $tempHtml .= $this->render_heading($dialogue); - break; - case 'linebreak': - $this->currentCast = null; - $tempHtml .= '
'; - break; - case 'p': - $this->currentCast = null; - $tempHtml .= $this->render_text($dialogue,'p'); - break; - case 'link': - $this->currentCast = null; - $tempHtml .= $this->render_reflink($dialogue); - break; - case 'showquote': - $this->currentCast = null; - $tempHtml .= $this->render_rawdata($dialogue,$this->rawData); - break; - case 'rawdata_full': - $this->currentCast = null; - $tempHtml .= $this->render_rawdata_full($dialogue,$this->rawData); - break; - case 'codeblock': - $this->currentCast = null; - $tempHtml .= $this->render_codeblock($dialogue); - break; - case 'image': - $this->currentCast = null; - $tempHtml .= $this->render_image_holder($dialogue); - break; - case 'imagecard': - $this->currentCast = null; - $tempHtml .= $this->render_imagecard_holder($dialogue); - break; - case 'mp3': - case 'background': - $this->currentCast = null; - $tempHtml .= $this->render_sound_holder($dialogue); - break; - case 'youtube': - $this->currentCast = null; - $tempHtml .= $this->render_video_holder($dialogue); - break; - case 'decision': - $this->currentCast = null; - $tempHtml .= $this->render_decisions_holder($dialogue); - break; - case 'devtools': - $this->currentCast = null; - $tempHtml .= $this->renderDev($dialogue,$dialogue['_line']); - break; - default: - if(in_array($dialogue['_castname'],$this->narratorList)) - { // Custom narrator + switch($dialogue['_castname']) + { + case '#': // h1 + $this->currentCast = null; + $tempHtml .= $this->md_render_heading($dialogue,1); + break; + case '##': // h2 + $this->currentCast = null; + $tempHtml .= $this->md_render_heading($dialogue,2); + break; + case '###': // h3 + $this->currentCast = null; + $tempHtml .= $this->md_render_heading($dialogue,3); + break; + case '####': // h4 + $this->currentCast = null; + $tempHtml .= $this->md_render_heading($dialogue,4); + break; + case '#####': // h5 + $this->currentCast = null; + $tempHtml .= $this->md_render_heading($dialogue,5); + break; + case '######': // h6 + $this->currentCast = null; + $tempHtml .= $this->md_render_heading($dialogue,6); + break; + case '---': // scene + $this->currentCast = null; + $tempHtml .= $this->render_cutscene($dialogue); + break; + case 'h1': + case 'h2': + case 'h3': + case 'h4': + case 'h5': + case 'h6': $this->currentCast = null; - $tempHtml .= $this->role_narrator($dialogue); - }else{ - if(isset($this->dialogue['casts'][0]) && $this->dialogue['casts'][0]['name'] == $dialogue['_castname']) - { // maincast - $tempHtml .= $this->renderRoleSide($dialogue,'right',$this->settings->mainCastColor); + $tempHtml .= $this->render_heading($dialogue); + break; + case 'linebreak': + $this->currentCast = null; + $tempHtml .= '
'; + break; + case 'p': + $this->currentCast = null; + $tempHtml .= $this->render_text($dialogue,'p'); + break; + case 'link': + $this->currentCast = null; + $tempHtml .= $this->render_reflink($dialogue); + break; + case 'showquote': + $this->currentCast = null; + $tempHtml .= $this->render_rawdata($dialogue,$this->rawData); + break; + case 'rawdata_full': + $this->currentCast = null; + $tempHtml .= $this->render_rawdata_full($dialogue,$this->rawData); + break; + case 'codeblock': + $this->currentCast = null; + $tempHtml .= $this->render_codeblock($dialogue); + break; + case 'image': + $this->currentCast = null; + $tempHtml .= $this->render_image_holder($dialogue); + break; + case 'imagecard': + $this->currentCast = null; + $tempHtml .= $this->render_imagecard_holder($dialogue); + break; + case 'mp3': + case 'background': + $this->currentCast = null; + $tempHtml .= $this->render_sound_holder($dialogue); + break; + case 'youtube': + $this->currentCast = null; + $tempHtml .= $this->render_video_holder($dialogue); + break; + case 'decision': + $this->currentCast = null; + $tempHtml .= $this->render_decisions_holder($dialogue); + break; + case 'devtools': + $this->currentCast = null; + $tempHtml .= $this->renderDev($dialogue,$dialogue['_line']); + break; + default: + if(in_array($dialogue['_castname'],$this->narratorList)) + { // Custom narrator + $this->currentCast = null; + $tempHtml .= $this->role_narrator($dialogue); }else{ - if(!is_null($dialogue['_context'])) - { // others cast - $tempHtml .= $this->renderRoleSide($dialogue,'left',$this->loadCastColor($dialogue['_castname'])); - }else - { // Normal text - $tempHtml .= $this->render_text($dialogue,'sentence'); + if(isset($this->dialogue['casts'][0]) && $this->dialogue['casts'][0]['name'] == $dialogue['_castname']) + { // maincast + // $this->currentCast = null; + $tempHtml .= $this->renderRoleSide($dialogue,'right',$this->settings->mainCastColor); + }else{ + if(!is_null($dialogue['_context'])) + { // others cast + // $this->currentCast = null; + $tempHtml .= $this->renderRoleSide($dialogue,'left',$this->loadCastColor($dialogue['_castname'])); + }else + { // Normal text + $this->currentCast = null; + $tempHtml .= $this->render_text($dialogue,'sentence'); + } } } - } + break; + } + }else + { // Quit if hit $this->SettingBreakPoint break; } } @@ -644,7 +654,7 @@ private function render_imagecard_holder($dialogue) } private function render_rawdata($dialogue, $rawData) { - $tempLine = ''; + $tempHtml = ''; $tempArray = []; if(isset($dialogue['_line']) && $dialogue['_line'] == '--show-data') { // Show all @@ -656,19 +666,22 @@ private function render_rawdata($dialogue, $rawData) $getLineNo = strstr($dialogue['_line'], ':'); $getLineNo = ltrim($getLineNo, ':'); $minMaxVal = explode(',',$getLineNo); - $maxVal = ($minMaxVal[1] < $minMaxVal[0])? 100: $minMaxVal[1]; - $minVal = ($minMaxVal[0] < 0)? 0: $minMaxVal[0]; - $arrData = $this->dialogue['lines']; - for($i = $minVal-1; $i < $maxVal; $i++) + if(isset($minMaxVal[0]) && isset($minMaxVal[1])) { - if(isset($arrData[$i])) + $maxVal = ($minMaxVal[1] < $minMaxVal[0])? 100: $minMaxVal[1]; + $minVal = ($minMaxVal[0] < 0)? 0: $minMaxVal[0]; + $arrData = $this->dialogue['lines']; + for($i = $minVal-1; $i < $maxVal; $i++) { - array_push($tempArray, ($i+1).' '.$arrData[$i]['_line']); + if(isset($arrData[$i])) + { + array_push($tempArray, ($i+1).' '.$arrData[$i]['_line']); + } } + $tempArray = array_values($tempArray); + $tempArray = implode('
',array_values($tempArray)); + $tempHtml = '
'.nl2br($tempArray).'
'; } - $tempArray = array_values($tempArray); - $tempArray = implode('
',array_values($tempArray)); - $tempHtml = '
'.nl2br($tempArray).'
'; } return $tempHtml; } @@ -761,7 +774,7 @@ private function render_cutscene($dialogue) $tempHtml .= '
'; if(isset($dialogue['_context']) && $dialogue['_context'] != '') { - $tempHtml .= $dialogue['_context']; + $tempHtml .= '

'.$dialogue['_context'].'

'; $tempHtml .= '
'; } $tempHtml .= '
'; @@ -776,7 +789,7 @@ private function render_image_holder($dialogue) { $extraClass = $this->settings->extraImageClass; } - $tempHtml .= 'Image'; + $tempHtml .= 'Image'; $tempHtml .= ''; return $tempHtml; } @@ -799,7 +812,7 @@ private function render_video_holder($dialogue) { $link = $this->fn_valid_link($dialogue['_context']); $tempHtml = '
'; - $tempHtml .= ''; + $tempHtml .= ''; $tempHtml .= '
'; return $tempHtml; } @@ -906,13 +919,13 @@ private function renderRoleSide($dialogue,$direction='left',$color='#CCC') { default: case 'small': - $tempHtml .= ''.''.trim($dialogue['_castname']).''; + $tempHtml .= ''.''.trim($dialogue['_castname']).''; break; case 'normal': - $tempHtml .= ''.''.trim($dialogue['_castname']).''; + $tempHtml .= ''.''.trim($dialogue['_castname']).''; break; case 'large': - $tempHtml .= ''.''.trim($dialogue['_castname']).''; + $tempHtml .= ''.''.trim($dialogue['_castname']).''; break; } } @@ -940,7 +953,7 @@ private function renderRoleSide($dialogue,$direction='left',$color='#CCC') $context .= ''; break; case 'youtube': - $context = ''; + $context = ''; break; default: $context = ($dialogue['_context']); diff --git a/src/chatblock.css b/src/chatblock.css index f3679d1..b61367d 100644 --- a/src/chatblock.css +++ b/src/chatblock.css @@ -20,9 +20,9 @@ } .chatblock .imessage p { - border-radius: 1.15rem; + border-radius: 2rem; line-height: 2; - max-width: 75%; + max-width: 90%; padding: 0.5rem 0.75rem; position: relative; word-wrap: break-word; @@ -49,6 +49,7 @@ align-self: flex-end; background-color: #666; color: #fff; + margin-right: 20px; } /* .chatblock p.from-me { @@ -87,7 +88,7 @@ } */ .chatblock p[class^="from-"] { - margin: 0.5rem 0; + /* margin: 0.5rem 0; */ width: fit-content; } @@ -106,8 +107,9 @@ } .chatblock p.narrator { - background-color: #cccccc; - color: #000; + padding: 1.5em!important; + background-color: #FFF; + border: 1px dashed #ccc!important; max-width: 100%; } @@ -115,6 +117,7 @@ align-items: flex-start; background-color: #e5e5ea; color: #000; + margin-left: 20px; } /* .chatblock p.from-them:before { @@ -260,6 +263,7 @@ margin: 0px 4px; } +.text-center, .chatblock .imessage .text-center, .chatblock .imessage h1, .chatblock .imessage h2,