From e163a09b4f711672eadce0bf067ed9d2dab5117d Mon Sep 17 00:00:00 2001
From: SofianeLasri <alasri250@gmail.com>
Date: Sat, 15 Jan 2022 15:44:05 +0100
Subject: [PATCH] enchant & detail

---
 core/classes/Item.php         | 21 +++++++++++++++++++--
 core/classes/Shop.php         |  2 +-
 core/controller/functions.php | 10 ++++++++++
 pages/assets/css/styles.css   | 21 ++++++++++++++++++++-
 pages/client/shops.php        | 35 ++++++++++++++++++++++++++---------
 pages/client/vitrine.php      |  1 +
 6 files changed, 77 insertions(+), 13 deletions(-)

diff --git a/core/classes/Item.php b/core/classes/Item.php
index 98e4352d..6294a5a4 100644
--- a/core/classes/Item.php
+++ b/core/classes/Item.php
@@ -5,11 +5,22 @@ class Item{
     private $css;
     private $type;
     private $id;
+    private $displayName;
+    private $enchants;
     
     public function __construct($item){
         if(is_array($item)){
-            $this->price = $item['price'];
-            $this->id = $item['id'];
+            $this->id = $item['type'];
+
+            if(isset($item['meta'])){
+                if(isset($item['meta']['display-name'])){
+                    $displayNameJson = json_decode($item['meta']['display-name'], true);
+                    $this->displayName = $displayNameJson['text'];
+                }
+                if(isset($item['meta']['enchants'])){
+                    $this->enchants = $item['meta']['enchants'];
+                }
+            }
         }else{
             $this->id=$item;
         }
@@ -66,4 +77,10 @@ public function getRepresentation(){
         }
         return $return;
     }
+    public function getDisplayName(){
+        return $this->displayName;
+    }
+    public function getEnchants(){
+        return $this->enchants;
+    }
 }
\ No newline at end of file
diff --git a/core/classes/Shop.php b/core/classes/Shop.php
index 75639584..ebbcffd9 100644
--- a/core/classes/Shop.php
+++ b/core/classes/Shop.php
@@ -34,7 +34,7 @@ public static function getShops($search=null){
             $shops = Connexion::pdo()->query("SELECT * FROM qs_external_cache NATURAL JOIN qs_shops")->fetchAll(PDO::FETCH_ASSOC);
             for($i=0;$i<count($shops);$i++){
                 $item = yaml_parse($shops[$i]['itemConfig']);
-                $shops[$i]['item'] = new Item(strtolower($item['item']['type']));
+                $shops[$i]['item'] = new Item(strtolower($item['item']));
                 $owner = json_decode($shops[$i]['owner'], true);
                 $shops[$i]['seller'] = new Seller($owner["owner"]);
             }
diff --git a/core/controller/functions.php b/core/controller/functions.php
index 76f69648..d956263d 100644
--- a/core/controller/functions.php
+++ b/core/controller/functions.php
@@ -273,3 +273,13 @@ function isConnected(){
         exit();
     }
 }
+
+function getRandomString($length) {
+    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+    $charactersLength = strlen($characters);
+    $randomString = '';
+    for ($i = 0; $i < $length; $i++) {
+        $randomString .= $characters[rand(0, $charactersLength - 1)];
+    }
+    return $randomString;
+}
\ No newline at end of file
diff --git a/pages/assets/css/styles.css b/pages/assets/css/styles.css
index d07b4879..f8dccea7 100644
--- a/pages/assets/css/styles.css
+++ b/pages/assets/css/styles.css
@@ -128,4 +128,23 @@ .card-top{
     image-rendering: pixelated;
     image-rendering: -moz-crisp-edges;
     image-rendering: crisp-edges;
-}
\ No newline at end of file
+}
+.enchant {
+    text-align: center;
+    
+    background: linear-gradient(to right, #FFF 20%, #bd34eb 40%, #bd34eb 60%, #FFF 80%);
+    background-size: 200% auto;
+    
+    color: #000;
+    background-clip: text;
+    text-fill-color: transparent;
+    -webkit-background-clip: text;
+    -webkit-text-fill-color: transparent;
+    
+    animation: shine 1s linear infinite;
+    @keyframes shine {
+      to {
+        background-position: 200% center;
+      }
+    }
+  }
\ No newline at end of file
diff --git a/pages/client/shops.php b/pages/client/shops.php
index 9f4e01d4..dca09bd8 100644
--- a/pages/client/shops.php
+++ b/pages/client/shops.php
@@ -77,6 +77,7 @@
                             $cardTop = ('<img src="'.getWebsiteSetting("websiteUrl").$representation["texture"][0].'" alt="'.$shop['item']->getLabel().'">');
                         }
 
+                        // Affichage du stock
                         if($shop['stock'] <=10){
                             $badge = "warning";
                             if($shop['stock'] <= 0){
@@ -85,7 +86,21 @@
                         }else{
                             $badge = "success";
                         }
-                        echo ('<div class="col-3 mb-2">
+
+                        // Si l'item possède un nom custom, on va l'afficher
+                        if($shop['item']->getDisplayName() != null){
+                            $displayName = '<i class="icon-minecraft icon-minecraft-name-tag"></i> '.$shop['item']->getDisplayName();
+                        }else{
+                            $displayName = $shop['item']->getLabel();
+                        }
+
+                        // Si l'item est enchant, on va lui appliquer un style custom
+                        if($shop['item']->getEnchants() != null){
+                            $displayName = '<span class="enchant">'.$displayName.'</span>';
+                        }
+
+                        $shopId = getRandomString(4);
+                        echo ('<div class="col-3 mb-2" id="'.$shopId.'" x="'.$shop['x'].'" y="'.$shop['y'].'" z="'.$shop['z'].'" world="'.$shop['world'].'" displayName"'.$shop['item']->getDisplayName().'" enchants="'.json_encode($shop['item']->getEnchants()).'">
                                     <div class="card" style="width: 18rem;">
                                         <div class="card-body">
                                             <span class="badge badge-'.$badge.'">Stock: '.$shop['stock'].'</span>
@@ -93,7 +108,7 @@
                                                 '.$cardTop.'
                                             </div>
                                             
-                                            <h5 class="card-title">'.$shop['item']->getLabel().'</h5>
+                                            <h5 class="card-title">'.$displayName.'</h5>
                                             <div class="d-flex align-items-center">
                                                 <div class="mc-face-viewer-4x" style="background-image:url(\''.$shop['seller']->getSkin().'\')"></div>
                                                 <div class="d-flex flex-column pl-2">
@@ -101,7 +116,7 @@
                                                     <span><strong>Prix:</strong> '.$shop['price'].'€</span>
                                                 </div>
                                             </div>
-                                            <div class="mc-button normal" onclick="goToShop('.$shop['x'].','.$shop['y'].','.$shop['z'].',\''.$shop['world'].'\')">
+                                            <div class="mc-button normal" onclick="goToShop('.$shopId.')">
                                                 <div class="title">Acheter</div>
                                             </div>
                                         </div>
@@ -169,9 +184,10 @@
         <div class="modal-dialog">
             <div class="modal-content" style="background-image: url('<?=getWebsiteSetting("websiteUrl")?>data/images/backgrounds/bg-wood-dark.png');">
                 <div class="modal-header">
-                    <h5 class="modal-title">Coordonnées du magasin</h5>
+                    <h5 class="modal-title">Détails de l'article</h5>
                 </div>
                 <div class="modal-body" id="shopModalBody">
+                    <p>Type d'objet: <span id="shopItemType"></span></p>
                     <div class="form-group">
                         <label>Coordonnées du magasin</label>
                         <div class="d-flex">
@@ -203,11 +219,12 @@
     <script src="<?=getWebsiteSetting("websiteUrl")?>pages/assets/vendors/flickity/js/flickity.pkgd.min.js"></script>
     <script type="text/javascript">
         // On va définir la taille de la div derrière la navbar
-        function goToShop(x, y, z, world){
-            $("#shopXPos").val(x);
-            $("#shopYPos").val(y);
-            $("#shopZPos").val(z);
-            $("#shopMapLink").attr("href", "https://live.mc.sl-projects.com/#"+world+";flat;"+x+","+y+","+z+";5");
+        function goToShop(id){
+            $("#shopItemType").html($("#shopItem"+id).attr("type"));
+            $("#shopXPos").val($("#"+id).attr("x"));
+            $("#shopYPos").val($("#"+id).attr("y"));
+            $("#shopZPos").val($("#"+id).attr("z"));
+            $("#shopMapLink").attr("href", "https://live.mc.sl-projects.com/#"+$("#"+id).attr("world")+";flat;"+$("#"+id).attr("x")+","+$("#"+id).attr("y")+","+$("#"+id).attr("z")+";5");
             $("#shopModal").modal("show");
         }
         
diff --git a/pages/client/vitrine.php b/pages/client/vitrine.php
index a47e37e4..90d6f401 100644
--- a/pages/client/vitrine.php
+++ b/pages/client/vitrine.php
@@ -58,6 +58,7 @@
                         <label>Minecraft Bedrock Edition</label>
                         <input type="text" class="form-control" value="proxy.sl-craft.fr:19132" readonly>
                     </div>
+                    <p>*Le serveur est cross-plateformes, vous jouez sur une unique map.</p>
                 </div>
                 <div class="modal-footer">
                     <div class="mc-button normal" data-dismiss="modal">
-- 
GitLab