From b80cf7be4eb45eeb5bb5007848389443dc9ab46b Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 3 Oct 2023 18:32:50 +0200 Subject: [PATCH] wip #6336 @3.5 --- app/Elearning/QuizCompiler.php | 36 +++++++++++------------ app/Elearning/QuizCompiler/Animations.php | 7 +++-- app/Fields/FluidbookThemeImage.php | 6 ++-- app/Fields/ThemeBackgroundSize.php | 4 +-- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/app/Elearning/QuizCompiler.php b/app/Elearning/QuizCompiler.php index e128936bf..93290a60f 100644 --- a/app/Elearning/QuizCompiler.php +++ b/app/Elearning/QuizCompiler.php @@ -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() diff --git a/app/Elearning/QuizCompiler/Animations.php b/app/Elearning/QuizCompiler/Animations.php index c5d78fc6d..8b388e064 100644 --- a/app/Elearning/QuizCompiler/Animations.php +++ b/app/Elearning/QuizCompiler/Animations.php @@ -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); } } diff --git a/app/Fields/FluidbookThemeImage.php b/app/Fields/FluidbookThemeImage.php index a726fac3a..fc0f72f09 100644 --- a/app/Fields/FluidbookThemeImage.php +++ b/app/Fields/FluidbookThemeImage.php @@ -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']; } diff --git a/app/Fields/ThemeBackgroundSize.php b/app/Fields/ThemeBackgroundSize.php index a25d13c28..a92ae0c83 100644 --- a/app/Fields/ThemeBackgroundSize.php +++ b/app/Fields/ThemeBackgroundSize.php @@ -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'), ]; } } -- 2.39.5