]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6336 @3.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 3 Oct 2023 16:32:50 +0000 (18:32 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 3 Oct 2023 16:32:50 +0000 (18:32 +0200)
app/Elearning/QuizCompiler.php
app/Elearning/QuizCompiler/Animations.php
app/Fields/FluidbookThemeImage.php
app/Fields/ThemeBackgroundSize.php

index e128936bfea2265faf12f0afb92dda2f276c0022..93290a60f2b454dd66fc6b6941e9230b3982f40c 100644 (file)
@@ -72,6 +72,7 @@ class QuizCompiler extends Base
 
         // Add data related to the current quiz in the "to compile" files
         $this->writeStyles();
+        $this->writeAnimations();
         $this->writeL10n();
         $this->writeData();
         // Run the compiler
@@ -154,40 +155,42 @@ class QuizCompiler extends Base
         // Main background
         $this->sassVariables['background-color'] = Color::colorToCSS($this->theme->backgroundColor);
         $this->sassVariables['background-custom'] = $this->theme->backgroundCustom ? 'true' : 'false';
+
+        $this->data->set('mainBackground', '');
+        $this->data->set('mainBackgroundMobile', '');
+
         if ($this->theme->backgroundCustom) {
-            $this->_addBackgroundVariables('background-desktop', 'background');
+            $this->_addBackgroundVariables('background-desktop', 'background', 'mainBackground');
             if ($this->theme->backgroundCustomMobile) {
-                $this->_addBackgroundVariables('background-mobile', 'background', 'Mobile');
+                $this->_addBackgroundVariables('background-mobile', 'background', 'mainBackgroundMobile', 'Mobile');
             } else {
-                $this->_addBackgroundVariables('background-mobile', 'background');
+                $this->_addBackgroundVariables('background-mobile', 'background', 'mainBackgroundMobile');
             }
         }
 
+
         $this->writeSass();
     }
 
-    protected function _addBackgroundVariables($sassPrefix, $themePrefix, $themeSuffix = '')
+    protected function _addBackgroundVariables($sassPrefix, $themePrefix, $dataKey, $themeSuffix = '')
     {
-        $this->sassVariables[$sassPrefix . '-image'] = '../' . $this->data['theme']->{$themePrefix . 'Image' . $themeSuffix};
 
-        switch ($this->data['theme']->{$themePrefix . 'Size' . $themeSuffix}) {
+        $i=$this->data['theme']->{$themePrefix . 'Image' . $themeSuffix};
+        $this->data->set($dataKey, $i);
+        if(stristr($i,'.json')){
+            $this->animations[$i]=file_get_contents($this->theme->getPageData()->getImageFile($themePrefix . 'Image' . $themeSuffix));
+        }
 
-            case ThemeBackgroundSize::REPEAT:
-                $size = 'auto auto';
-                $repeat = 'repeat';
-                break;
+        switch ($this->data['theme']->{$themePrefix . 'Size' . $themeSuffix}) {
             case ThemeBackgroundSize::RATIO:
                 $size = 'cover';
-                $repeat = 'no-repeat';
                 break;
             case ThemeBackgroundSize::NONE:
-                $size = 'auto auto';
-                $repeat = 'no-repeat';
+                $size = 'none';
                 break;
             default:
             case ThemeBackgroundSize::STRETCH:
-                $size = '100% 100%';
-                $repeat = 'no-repeat';
+                $size = 'fill';
                 break;
 
         }
@@ -206,13 +209,11 @@ class QuizCompiler extends Base
             default => '50%',
         };
 
-        $this->sassVariables[$sassPrefix . '-repeat'] = $repeat;
         $this->sassVariables[$sassPrefix . '-size'] = $size;
         $this->sassVariables[$sassPrefix . '-position-x'] = $positionx;
         $this->sassVariables[$sassPrefix . '-position-y'] = $positiony;
     }
 
-
     protected function _font($f)
     {
         if (!$f) {
@@ -277,7 +278,6 @@ class QuizCompiler extends Base
         $resourcePath = $this->_resourcesPath();
         $vdir->copyDirectory($resourcePath . '/js', 'js');
         $vdir->copyDirectory($resourcePath . '/style', 'style');
-        $this->writeAnimations();
     }
 
     protected function _resourcesPath()
index c5d78fc6d5cfeba0bea687a0c6cbabcf411d004b..8b388e0640b9fa5ffe903daf78c9b24cffede318 100644 (file)
@@ -15,6 +15,8 @@ trait Animations
     const NOK_COLOR = '#D0167C';
     const CONFETTI_COLOR = '#E4FF19';
 
+    protected $animations=[];
+
     /**
      * @param $vdir VirtualDirectory
      * @return void
@@ -39,7 +41,6 @@ trait Animations
         $font = FluidbookFont::getAvailableFonts()[$this->theme->font ?: 'SourceSans'];
         $animationReplace['Source Sans Pro'] = trim($font['font_family'], '"');
         $animationReplace['"fPath":"images/font_0",'] = '';
-        $animations = [];
 
         foreach (Files::getDirectoryIterator($this->_resourcesPath() . '/animations/') as $file) {
             if (!$file->isFile() || $file->getExtension() !== 'json') {
@@ -51,8 +52,8 @@ trait Animations
             foreach ($animationPregReplace as $regex => $replace) {
                 $c = preg_replace($regex, $replace, $c);
             }
-            $animations[$file->getBasename('.' . $file->getExtension())] = $c;
+            $this->animations[$file->getBasename('.' . $file->getExtension())] = $c;
         }
-        $this->data['animations'] = new Data($animations);
+        $this->data['animations'] = new Data($this->animations);
     }
 }
index a726fac3a4eb3bac1994c13eb8124388dfe6cca1..fc0f72f09f7f43964bd95939fc7811f272902ab7 100644 (file)
@@ -7,6 +7,8 @@ use Cubist\Backpack\Magic\Fields\Images;
 class FluidbookThemeImage extends Images
 {
     protected $_translatable = false;
-    protected $_nameAsCollection=false;
-    protected $_renameCollectionOnChange=true;
+    protected $_nameAsCollection = false;
+    protected $_renameCollectionOnChange = true;
+
+    protected $_mimeTypes = ['image/png', 'image/jpeg', 'image/svg+xml', 'image/webp', 'image/gif', 'application/json'];
 }
index a25d13c28233452b02655b242f67dc86d0cd91d4..a92ae0c836ecba950539a0d1ff2c5623abc9e9a2 100644 (file)
@@ -9,7 +9,6 @@ class ThemeBackgroundSize extends SelectFromArray
 
     const STRETCH = 0;
     const RATIO = 2;
-    const REPEAT = 1;
     const NONE = 3;
 
     protected $_default = self::STRETCH;
@@ -19,8 +18,7 @@ class ThemeBackgroundSize extends SelectFromArray
         return [
             self::STRETCH => __('Étirer'),
             self::RATIO => __('Étirer le fond en conservant les proportions'),
-            self::REPEAT => __('Répéter'),
-            self::NONE => __('Ne pas répéter ni étirer'),
+            self::NONE => __('Ne pas répéter'),
         ];
     }
 }