-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Just improve your old module and render it wonderfully nicer #9
Open
Siln0z
wants to merge
1
commit into
main
Choose a base branch
from
feature/snowflake_ultimate_version_Hyva_compat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Copyright ยฉ OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\Snowflake\Model\Config\Source; | ||
|
||
use Magento\Framework\Data\OptionSourceInterface; | ||
|
||
class Season implements OptionSourceInterface | ||
{ | ||
public function toOptionArray(): array | ||
{ | ||
return [ | ||
['value' => 'halloween', 'label' => __('Halloween')], | ||
['value' => 'noel', 'label' => __('Noel')], | ||
['value' => 'printemps', 'label' => __('Printemps')], | ||
['value' => 'ete', 'label' => __('รtรฉ')], | ||
['value' => 'automne', 'label' => __('Automne')], | ||
['value' => 'fete_nationale', 'label' => __('Fรชte Nationale')], | ||
['value' => 'nouvel_an', 'label' => __('Nouvel An')], | ||
['value' => 'paques', 'label' => __('Pรขques')], | ||
['value' => 'saint_valentin', 'label' => __('Saint-Valentin')], | ||
['value' => 'fete_travail', 'label' => __('Fรชte du Travail')], | ||
['value' => 'fete_musique', 'label' => __('Fรชte de la Musique')], | ||
['value' => 'hiver', 'label' => __('Hiver')], | ||
['value' => 'carnaval', 'label' => __('Carnaval')], | ||
['value' => 'saint_patrick', 'label' => __('Saint Patrick')], | ||
['value' => 'hanoucca', 'label' => __('Hanoucca')], | ||
['value' => 'ramadan', 'label' => __('Ramadan')], | ||
['value' => 'diwali', 'label' => __('Diwali')], | ||
['value' => 'chinese_new_year', 'label' => __('Nouvel An Chinois')], | ||
['value' => 'fete_meres', 'label' => __('Fรชte des Mรจres')], | ||
['value' => 'fete_peres', 'label' => __('Fรชte des Pรจres')], | ||
['value' => 'action_de_grace', 'label' => __('Action de Grรขce')], | ||
['value' => 'fete_saucisse', 'label' => __('Fรชte ร la Saucisse')], | ||
['value' => 'apero_time', 'label' => __('l\'heure de l\'apรฉro')] | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,72 +5,67 @@ | |
*/ | ||
declare(strict_types=1); | ||
|
||
use Hyva\Theme\Model\ViewModelRegistry; | ||
use Magento\Framework\View\Element\Template; | ||
use Opengento\Snowflake\ViewModel\Snowflake; | ||
|
||
/** @var Template $block */ | ||
/** @var Snowflake $viewModel */ | ||
$viewModel = $block->getData('viewModel'); | ||
/** @var Snowflake $snowflake */ | ||
$snowflake = $block->getData('viewModel'); | ||
?> | ||
<div id="snowflake_container"></div> | ||
|
||
<script> | ||
require([ | ||
'jquery', | ||
'jquery/ui', | ||
'domReady!' | ||
], function($) { | ||
"use strict"; | ||
|
||
<?php if ($viewModel->isForceSnow()): ?> | ||
"use strict"; | ||
|
||
document.addEventListener('DOMContentLoaded', function() { | ||
|
||
// Vรฉrifiez si la neige de saucisses doit commencer | ||
if (forceSnow()) { | ||
letSnow(); | ||
<?php elseif ($viewModel->isApiEnabled()): ?> | ||
let lat, lon, settings = { | ||
"url": "<?= $viewModel->getIpLocatorApiUrl() ?>", | ||
"method": "GET", | ||
"timeout": 0 | ||
}; | ||
$.ajax(settings).done(function (response) { | ||
[lat, lon] = response.loc.split(','); | ||
$.ajax({ | ||
url: '<?= $block->getData('meteoUrl') ?>lat/' + lat + '/lon/' + lon, | ||
type: "GET", | ||
}).done(function (data) { | ||
} else if (isApiEnabled()) { | ||
fetch("<?= $snowflake->getIpLocatorApiUrl() ?>") | ||
.then(response => response.json()) | ||
.then(data => { | ||
let [lat, lon] = data.loc.split(','); | ||
return fetch(`<?= $block->getData('meteoUrl') ?>lat/${lat}/lon/${lon}`); | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.is_snowing) { | ||
letSnow(); | ||
} | ||
}); | ||
}); | ||
<?php endif; ?> | ||
}) | ||
.catch(error => console.error('Error:', error)); | ||
} | ||
|
||
function letSnow() { | ||
let snowMax = <?= $viewModel->getSnowflakeQty() ?>; | ||
let snowColor = ["#DDD", "#BBB", "#AAA", "#EEE", "#CCC"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La couleur permettait d'amรฉliorer l'impression de profondeur sur la "neige", est-ce que tu peux conserver cette ligne quitte ร la commenter pour qu'on voit comment l'intรฉgrer plus tard avec les presets de saisons ? |
||
let snowEntity = "<?= $viewModel->getSnowflakeChar() ?>"; | ||
let snowVSpeed = <?= $viewModel->getSnowflakeVSpeed() ?>; | ||
let snowHSpeed = <?= $viewModel->getSnowflakeHSpeed() ?>; | ||
let snowRotSpeed = <?= $viewModel->getSnowflakeRotSpeed() ?>; | ||
let snowMinSize = <?= $viewModel->getSnowflakeMinSize() ?>; | ||
const snowMaxSize = <?= $viewModel->getSnowflakeMaxSize() ?>; | ||
let snowMax = <?= $snowflake->getSnowflakeQty() ?>; | ||
let snowEntities = <?= $snowflake->getIconsForSelectedSeason() ?>; | ||
let snowVSpeed = <?= $snowflake->getSnowflakeVSpeed() ?>; | ||
let snowHSpeed = <?= $snowflake->getSnowflakeHSpeed() ?>; | ||
let snowRotSpeed = <?= $snowflake->getSnowflakeRotSpeed() ?>; | ||
let snowMinSize = <?= $snowflake->getSnowflakeMinSize() ?>; | ||
const snowMaxSize = <?= $snowflake->getSnowflakeMaxSize() ?>; | ||
const snowRefresh = 50; | ||
const snowMaxBlur = 3; | ||
const snowMaxBlur = 0; | ||
const snowStyles = "cursor: default; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none;"; | ||
|
||
let snow = [], | ||
pos = [], | ||
coords = [], | ||
left = [], | ||
marginBottom, | ||
marginRight; | ||
let snow = []; | ||
let pos = []; | ||
let coords = []; | ||
let left = []; | ||
let marginBottom; | ||
let marginRight; | ||
|
||
let newPositions = ''; | ||
|
||
for (let i = 0; i <= snowMax; i++) { | ||
newPositions += ("<span id='flake" + i + "'" + | ||
" style='" + snowStyles + "position:absolute;top:-" + snowMaxSize + "'>" | ||
+ snowEntity + "</span>"); | ||
// Utiliser l'index modulo pour choisir une icรดne diffรฉrente ร chaque itรฉration | ||
let entity = snowEntities[i % snowEntities.length].trim(); // Utilisation de trim() pour รฉviter les espaces indรฉsirables | ||
newPositions += `<span id='flake${i}' style='${snowStyles} position:absolute; top:-${snowMaxSize}px;'>${entity}</span>`; | ||
} | ||
$('#snowflake_container').html(newPositions); | ||
document.getElementById('snowflake_container').innerHTML = newPositions; | ||
|
||
let snowSize = snowMaxSize - snowMinSize; | ||
marginBottom = document.body.scrollHeight - 5; | ||
|
@@ -80,23 +75,22 @@ $viewModel = $block->getData('viewModel'); | |
coords[i] = 0; | ||
left[i] = Math.random() * 15; | ||
pos[i] = 0.03 + Math.random() / 10; | ||
snow[i] = document.getElementById("flake" + i); | ||
snow[i] = document.getElementById(`flake${i}`); | ||
snow[i].style.fontFamily = "inherit"; | ||
let size = randomise(snowSize) + snowMinSize | ||
let size = randomise(snowSize) + snowMinSize; | ||
snow[i].size = size; | ||
snow[i].speedFactor = snowMaxSize / size / 2; | ||
snow[i].style.filter = "blur(" + (snowMaxBlur * ((snowMaxSize - size) / (snowMaxSize - snowMinSize))) / 2 + "px)"; | ||
snow[i].style.fontSize = snow[i].size + "px"; | ||
snow[i].style.color = snowColor[randomise(snowColor.length)]; | ||
snow[i].style.filter = `blur(${(snowMaxBlur * ((snowMaxSize - size) / (snowMaxSize - snowMinSize))) / 2}px)`; | ||
snow[i].style.fontSize = `${size}px`; | ||
snow[i].style.zIndex = 1000; | ||
snow[i].style.textShadow = "1px 1px 5px #0000DD55"; | ||
snow[i].style.transform = "rotate(0deg)"; | ||
snow[i].vsink = snowVSpeed * snow[i].size / 5; | ||
snow[i].hsink = snowHSpeed * snow[i].size / 5; | ||
snow[i].posX = randomise(marginRight - snow[i].size); | ||
snow[i].posY = randomise(2 * marginBottom - marginBottom - 2 * snow[i].size); | ||
snow[i].style.left = snow[i].posX + "px"; | ||
snow[i].style.top = snow[i].posY + "px"; | ||
snow[i].vsink = snowVSpeed * size / 5; | ||
snow[i].hsink = snowHSpeed * size / 5; | ||
snow[i].posX = randomise(marginRight - size); | ||
snow[i].posY = randomise(2 * marginBottom - marginBottom - 2 * size); | ||
snow[i].style.left = `${snow[i].posX}px`; | ||
snow[i].style.top = `${snow[i].posY}px`; | ||
|
||
snow[i].rotationAngleStep = 0; | ||
snow[i].rotationAngActual = 0; | ||
|
@@ -125,31 +119,38 @@ $viewModel = $block->getData('viewModel'); | |
coords[i] += pos[i]; | ||
snow[i].posY += snow[i].vsink; | ||
snow[i].posX += snow[i].hsink * snow[i].speedFactor; | ||
snow[i].style.left = snow[i].posX + left[i] * Math.sin(coords[i]) + "px"; | ||
snow[i].style.top = snow[i].posY + "px"; | ||
snow[i].style.left = `${snow[i].posX + left[i] * Math.sin(coords[i])}px`; | ||
snow[i].style.top = `${snow[i].posY}px`; | ||
snow[i].rotationAngActual += snow[i].rotationAngleStep; | ||
snow[i].style.transform = "rotate(" + snow[i].rotationAngActual + "deg)"; | ||
snow[i].style.transform = `rotate(${snow[i].rotationAngActual}deg)`; | ||
|
||
// if (snowVSpeed > 0 && (snow[i].posY >= marginBottom - 2 * snow[i].size || parseInt(snow[i].style.left) > (marginRight - 3 * left[i]))) { | ||
if (snowVSpeed > 0 && (snow[i].posY >= marginBottom - 2 * snow[i].size)) { | ||
if (snowVSpeed > 0 && snow[i].posY >= marginBottom - 2 * snow[i].size) { | ||
snow[i].posX = randomise(marginRight - snow[i].size); | ||
snow[i].posY = 0; | ||
} | ||
if (snowVSpeed < 0 && (snow[i].posY < 0)) { | ||
snow[i].posY = document.body.scrollHeight - snow[i].size *2; | ||
if (snowVSpeed < 0 && snow[i].posY < 0) { | ||
snow[i].posY = document.body.scrollHeight - snow[i].size * 2; | ||
} | ||
if (snowHSpeed > 0 && (snow[i].posX >= marginRight - 2 * snow[i].size)) { | ||
if (snowHSpeed > 0 && snow[i].posX >= marginRight - 2 * snow[i].size) { | ||
snow[i].posX = randomise(marginRight - snow[i].size); | ||
snow[i].posY = 0; | ||
} | ||
if (snowHSpeed < 0 && (snow[i].posX < 0)) { | ||
if (snowHSpeed < 0 && snow[i].posX < 0) { | ||
snow[i].posY = document.body.clientWidth - snow[i].size * 2; | ||
} | ||
} | ||
} | ||
|
||
window.addEventListener('resize', resize); | ||
window.setInterval(moveSnow, snowRefresh); | ||
setInterval(moveSnow, snowRefresh); | ||
} | ||
|
||
function forceSnow() { | ||
return <?= $snowflake->isForceSnow() ?>; | ||
} | ||
|
||
function isApiEnabled() { | ||
return <?= $snowflake->isApiEnabled() ?>; | ||
} | ||
}); | ||
</script> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Est-ce que tu peux t'arranger pour conserver les deux champs et ajouter un champ toggle pour utiliser soit les presets, soit un icon custom ?