]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6381 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 10 Oct 2023 16:43:24 +0000 (18:43 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 10 Oct 2023 16:43:24 +0000 (18:43 +0200)
app/Elearning/QuizCompiler/Animations.php
app/Models/QuizTheme.php

index 8b388e0640b9fa5ffe903daf78c9b24cffede318..a0edd1b1385679ffc011e742f434a26b8193981a 100644 (file)
@@ -15,7 +15,9 @@ trait Animations
     const NOK_COLOR = '#D0167C';
     const CONFETTI_COLOR = '#E4FF19';
 
-    protected $animations=[];
+    const TEXT_COLOR = "#ffffff";
+
+    protected $animations = [];
 
     /**
      * @param $vdir VirtualDirectory
@@ -26,16 +28,18 @@ trait Animations
         $colors = [
             self::OK_COLOR => $this->theme->okColor,
             self::CONFETTI_COLOR => $this->theme->okColor,
-            self::NOK_COLOR => $this->theme->nokColor
+            self::NOK_COLOR => $this->theme->nokColor,
+            self::TEXT_COLOR => $this->theme->getTextsColor(),
         ];
         $animationReplace = [];
         $animationPregReplace = [];
 
         // Replace colors
         foreach ($colors as $from => $to) {
-            $f = (new Color($from))->toLottie(5,true);
+            $f = (new Color($from))->toLottie(5, true);
             $t = (new Color($to))->toLottie();
-            $animationPregReplace['/\[' . $f[0] . ',' . $f[1] . ',' . $f[2] . '/'] = '[' . $t[0] . ',' . $t[1] . ',' . $t[2];
+            $animationPregReplace['/"c":{"a":0,"k":\[' . $f[0] . ',' . $f[1] . ',' . $f[2] . '/'] = '"c":{"a":0,"k":[' . $t[0] . ',' . $t[1] . ',' . $t[2];
+            $animationPregReplace['/"fc":\[' . $f[0] . ',' . $f[1] . ',' . $f[2] . '/'] = '"fc":[' . $t[0] . ',' . $t[1] . ',' . $t[2];
         }
         // Replace font
         $font = FluidbookFont::getAvailableFonts()[$this->theme->font ?: 'SourceSans'];
index 3cc2a3098fbfbade2ef68cc2290506c46ea87b59..bdee95dd198dfcc96874d8894e0567143908efb8 100644 (file)
@@ -19,6 +19,7 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 use Cubist\Util\CommandLine\Imagemagick;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Graphics\Resizer;
+use function PHPUnit\Framework\matches;
 
 class QuizTheme extends ToolboxModel
 {
@@ -60,7 +61,7 @@ class QuizTheme extends ToolboxModel
     protected function _font()
     {
         $this->addField('sectionTexts', FormSection::class, __('Textes'));
-        $this->addField('textColor', SelectFromArray::class, __('Couleur des textes'), ['default' => 'auto', 'options' => ['auto' => __('Automatique'), '#ffffff' => __('Blanc'), '#000000' => __('Noir')]]);
+        $this->addField('textColor', SelectFromArray::class, __('Couleur des textes'), ['default' => 'auto', 'options' => ['auto' => __('Automatique'), 'light' => __('Blanc'), 'dark' => __('Noir')]]);
         $this->addField('font', FluidbookFont::class, __('Police de caractères'), ['default' => 'SourceSans', 'databaseDefault' => 'SourceSans']);
     }
 
@@ -93,7 +94,6 @@ class QuizTheme extends ToolboxModel
         $this->addField('backgroundImageMobile', FluidbookThemeImage::class, __('Image ou animation'), ['hint' => __('Taille recommandée : :size', ['size' => '390 x 844px']), 'when' => ['backgroundCustom' => 1]]);
     }
 
-
     protected function _intro()
     {
         $this->addField('sectionIntro', FormSection::class, __('Écran d\'introduction'));
@@ -146,20 +146,28 @@ class QuizTheme extends ToolboxModel
 
     public function getTextsColor()
     {
+        $darkColor = '#383838';
+        $lightColor = '#ffffff';
+
         if ($this->textColor == 'auto' || !$this->textColor) {
             // If auto mode, check between black and white which have the biggest distance (i.e. most contrast) with neutralColor
             $neutral = new \Cubist\Util\Graphics\Color($this->neutralColor);
-            $black = new \Cubist\Util\Graphics\Color('#000000');
-            $white = new \Cubist\Util\Graphics\Color('#ffffff');
+            $black = new \Cubist\Util\Graphics\Color($darkColor);
+            $white = new \Cubist\Util\Graphics\Color($lightColor);
             $distBlack = $neutral->distance($black);
             $distWhite = $neutral->distance($white);
             if ($distWhite > $distBlack) {
-                return '#ffffff';
+                return $lightColor;
             } else {
-                return '#000000';
+                return $darkColor;
             }
         }
-        return $this->textColor;
+        return match ($this->textColor) {
+            'dark' => $darkColor,
+            '#000000' => $darkColor,
+            '#ffffff' => $lightColor,
+            'light' => $lightColor,
+        };
     }
 
     /**